I am having trouble cleaning this mess up. This overloaded program is supposed to utilize an overloaded equality operator that should return true if the two student’s objects are equal and false if the two are student objects are not equal. And include an overloaded assignment operator in the Student class that assign one Student object to another, that allows for multiple assignments such as student1=student2=student3. And use the overloaded ++ operator to display a message indicating whether the student objects are the same. Last, call copy constructor to create third Student object using one of the existing Student object created.
The display example should be:
Enter student1 name: John Smith
Enter student1 SSN: 123456789
Enter student2 name: Jane Smith
Enter student2 SSN: 123456789
Those are not the same students
After using the assignment operator, those are the same students
After using the copy constructor, those are the same students
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Student
{
private:
string name; // Student Name
int SSN; // Social Sercurity Number (SNN)
public:
Student();
Student(string name, int SNN); // Constructor
bool operator ==(const Student&);
Student(const data_copy& );
string getname();
int getSSN();
string display_name();
int display_ssn();
};
Student :: Student(string name ,int SSN) // Definition of constructor
{
name = name_in;
SSN = SSN_in;
}
bool Student :: operator ==(Student& student) // Overloaded Equality
{
if(strcmp(student1.name, student2.name))
{
if(student1.SSN !== student2.SSN)
cout<<"Those are not the same students"<<endl;
else
cout<<"Those are the same students"<<endl;
}
}
void Student :: Student(const Student&, data_copy) //Copy Constructor
name = data_copy.name;
SSN = data_copy.SSN;
string Student:: getname() // Gets user input for Overloaded Equality
{
return name;
}
int Student:: getSSN() // Gets user input for Overloaded Equality
{
return SSN;
}
int main ()
{
Student student1; // First object
Student student2; // Second Object
Student student3; // Third Object: Object for multiple assignments stu1=stu2=stu3
string name;
int SSN;
cout<<"Enter student1 name:\n";
getline(cin, student1_name);
cout<<"Enter student1 ssn:\n";
getline(cin, student1_ssn);
cout<<"Enter student2 name:\n";
getline(cin, student2_name);
cout<<"Enter student2ssn:\n";
getline(cin, student2_ssn);
if (student1 == student2) // Use overloaded opreator to display a message for student obj. are same.
{
cout<<"After using the assignment operator";
cout<<"Those are the same students."<<endl;
if(student1 == student3) // Calls copy constructor of the Student obj. to create 3rd student using one of the existing stu,obj to display message.
cout<<"After using the copy constructor";
cout<<"Those are the same students."<<endl;
}
return 0;
}
|