Question: In C++ please! Given main.cpp and person.h below, finish the implementation for the person class: person.cpp Here is a sample run of the program assuming
In C++ please!
Given main.cpp and person.h below, finish the implementation for the person class: person.cpp
Here is a sample run of the program assuming on input: first data element is name, second is major, third is ssn, and last is classification
input
Joey Code Computer Science 1234567890 3
output
Student: Joey Code SSN: 123456789 Classification: Junior Major: Computer Science
Note: The input for classification will be an integer between 1 and 5 where 1 = Freshman, 2 = Sophomore, 3 = Junior, 4 = Senior, 5 = Graduate. On classification input you will be given an integer. On output, please spell out the correct classification as indicated.
main.cpp
// This application will test the functionality of the person class
#include
int main () { //create two person objects person personOne; //get data for object, declare variables and then read the data into the variables string name, major; int ssn, classification; getline(cin, name); getline(cin, major); cin >> ssn >> classification; //initialize person object personOne.SetName(name); personOne.SetSSN(ssn); personOne.SetClassification(classification); personOne.SetMajor(major); //output the person data in the object cout << "Name: " << personOne.GetName() << endl; cout << "SSN: " << personOne.GetSSN() << endl; cout << "Classification: " << personOne.GetClassification() << endl; cout << "Major: " << personOne.GetMajor() << endl; return 0; }
person.h
#ifndef person_h #define person_h
//This file defines a person class: its function prototypes and data members
#include
class person { public: //setters void SetName(string); void SetSSN(int); void SetClassification(int); void SetMajor(string); //getters string GetName(); int GetSSN(); //this function will use the private int data member classification but the return value must be string. //Your code must get the number and return what classification string it represents. For example: if the private //data member Classification was 2, you would return sophomore. Remember string literals must be in " " //(Example: return "Sophomore") string GetClassification(); string GetMajor(); private: string Name; int SSN; int Classification; string Major; };
#endif
person.cpp
//This file implements (provides the code) the functions prototyped in the person class definition (person.h) #include "person.h"
//SETTER FUNCTIONS
void person::SetName(string n) { //assign the parameter value n to the private data member Name Name = n; }
//WRITE THE OTHER SETTER FUNCTIONS HERE, that will initialize the private data members of the person class. You can always look //at person.h to see what those functions are.
//GETTER FUNCTIONS
string person::GetName() { //return the contents of the private data member Name to the caller return Name; }
// //WRITE THE OTHER THREE GETTER FUNCTIONS HERE THAT WILL RETURN THE SPECIFIC DATA TO THE APPLICATION. REMEMBER THAT GetClassification(), //the function must return the correct string that matches the integer in the private date member Classification. Remember a string //literal must have quotation marks around it, such as "Sophomore"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
