Using Classes for C++ project. Chapter 8

This is my assignment for Ch.8 in my c++ class. I understand how classes work but I'm lost on to where to begin the assignment. I know its lengthy and I have the code, given from my instructor, needed below to begin.
Any pointers or suggestions before I begin would be awesome
THANKS


Chapter 8 Assignment: Creating a Class
Doctor Sheldon Cooper recently realized that many of his friends and coworkers are lonely, so he has decided to help them and untold others by creating an online friendship program that will bring people together.
For this assignment, help Sheldon start this great work by creating a lonelyPerson class. He feels that the class should contain private data with answers to the following important friendship questions (stored in an appropriate variable type):
What is your name?
What was your score on your most recent IQ test?
What is your gender?
How old are you?
Have you learned differential equations yet?
Can you program in C++?
Do you agree that loop quantum gravity theory is ridiculous?
And exactly two other yes/no questions (you decide what those should be – I picked “Are you a scientist?” and “Do you like Star Trek?”).

There should be two constructors: a default constructor that has no arguments and a constructor that accepts eight arguments, one for each of the nine private data values. Include a member function called printRawData() with one argument. The input to that function should be the address of an ostream object. Use this prototype:

void printRawData(ostream& fout);

That way, if the input to the function is “cout” then the output will go to the screen. Otherwise it will go to the specified output file. It will output the data in the following format:

Sheldon Cooper
187 M 29 1 1 1 1 1

Note that 1 means true and 0 means false. For someone with an unknown IQ, the value will be 100.

Include a member function called printDataNice() that also has an address to an ostream object as the input. An example of how that output should look is below.

Include a member function called getData that accepts an address of a ifstream as an input and reads the data in that stream to assign values to all of the object’s private data. The data will be formatted in the same two-line format as above.

Include a member function called getScore that accepts a lonelyPerson object as an input argument and returns an integer compatibility score that measures the similarity between the object and the input object. Use this formula:

cScore = 100 + 10*(the number of matches) – 2*abs(IQ difference) – 5*abs(age difference)

There are five yes/no questions so there could be at most five matches.

Also, overload the addition operator to call on the getScore function so that the expression
cout << personA + personB;
would print the compatibility score for the two people.

I expect there will be three files in your project: a cpp file that contains my main function as a driver, a header file that contains the class definition and a cpp file that contains the definitions for the class member functions. I have attached the main cpp file that you need. You will use that file without any changes to test your lonelyPerson code.

Here is the output that you should get:
Sheldon Cooper
187 1 29 1 1 1 1 1

Sheldon Cooper is 29 years old with an IQ score of 187.
He has learned differential equations.
He is a scientist, knows how to program in C++, and
likes Star Trek.
Sheldon Cooper prefers string theory!

Amy Farrah Fowler is 31 years old with an IQ score of 188.
She has learned differential equations.
She is a scientist, knows how to program in C++, and
likes Star Trek.
Amy Farrah Fowler prefers string theory!

Howard Wolowitz is 30 years old with an IQ score of 127.
He has learned differential equations.
He is not a scientist, knows how to program in C++, and
likes Star Trek.
Howard Wolowitz actually prefers Quantum Gravity theory.

Penny from across the Hall is 24 years old with an IQ score of 100.
She has not yet learned differential equations.
She is not a scientist, does not how to program in C++, and
does not like Star Trek.
Penny from across the Hall actually prefers Quantum Gravity theory.

Sheldon Cooper, here are your friendship scores:
Your friendship score with Amy Farrah Fowler is 138
Your friendship score with Howard Wolowitz is 5
Your friendship score with Penny from across the Hall is -99
Press any key to continue . . .

Here is the beginning of the program I am given.
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include "lonelyPerson.h"

/* This is the driver program to test your class. Do not change this program. I will use it
to test the lonelyPerson class that you are going to write.

Programmer: Dan Justice, April 2011
*/

using namespace std;

int main(int argc, char *argv[])
{ // Declare a Sheldon using a constructor that contains a complete initialization
lonelyPerson Sheldon("Sheldon Cooper", 187, true, 29, true, true, true, true, true);

// Use empty constructor to declare three more lonelyPeople
lonelyPerson AmyFarrahFowler,Howard,Penny;

// Read data for the three lonelyPeople
string fileName;
fileName = "lonelyPeople.txt";
ifstream fin;
fin.open(fileName.c_str());
AmyFarrahFowler.getData(fin);
Howard.getData(fin);
Penny.getData(fin);

// Display Sheldon's data in both formats and then print everyone else's data
Sheldon.printRawData(cout);
cout << endl;
Sheldon.printDataNice(cout);
cout << endl;
AmyFarrahFowler.printDataNice(cout);
cout << endl;
Howard.printDataNice(cout);
cout << endl;
Penny.printDataNice(cout);
cout << endl;

// Display Sheldon's Friendship score with the three other people
cout << Sheldon.getName() << ", here are your friendship scores:" << endl;
cout << "Your friendship score with "
<< AmyFarrahFowler.getName() << " is " << Sheldon + AmyFarrahFowler << endl;
cout << "Your friendship score with "
<< Howard.getName() << " is " << Sheldon + Howard << endl;
cout << "Your friendship score with "
<< Penny.getName() << " is " << Sheldon + Penny << endl;


system("PAUSE");
return EXIT_SUCCESS;
}










How much do you have so far? If you haven't started then it should look something like this:
1
2
3
4
5
6
7
8
9
10
11
#include<whatever>

class lonelyPerson
{
    public:
        //constructors and public member functions such as getName()
    private:
        //private data
};

//function definitions and whatnot 
Topic archived. No new replies allowed.