I need some help with this Overloaded program

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;
} 
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
#include <iostream>
#include <string>

class Student
{
    private:

        std::string name;
        int SSN = 0 ; // http://www.stroustrup.com/C++11FAQ.html#member-init

    public:

        Student() = default ; // http://www.stroustrup.com/C++11FAQ.html#default
        Student( std::string name, int ssn ) : name(name), SSN(ssn) {}
        Student( const  Student& that ) = default ; 

        bool operator== ( const Student& that ) const // *** const ***
        { return this->name == that.name && this->SSN == that.SSN ; }

        bool operator!= ( const Student& that ) const // *** principle of least surprise ***
        { return !( *this == that ) ; }

};

Student make_student( int student_number )
{
    std::string name;
    int ssn;

    std::cout << "Enter Student" << student_number << " name: ";
    std::getline( std::cin, name);

    std::cout << "Enter Student" << student_number << " ssn: ";
    std::cin >> ssn ;
    std::cin.ignore( 1000, '\n' ) ; // throw away the new line

    return Student( name, ssn ) ;
}

void noisy_compare( const Student& a, const Student& b )
{
    if( std::addressof(a) == std::addressof(b) ) std::cout << "These are aliases of the same object.\n" ;
    else if( a == b ) std::cout << "These are the same students.\n" ;
    else std::cout << "These are different students.\n" ;
}

int main ()
{
	Student student1 = make_student(1) ;
	const Student student2 = make_student(2) ;

	noisy_compare( student1, student2 ) ;

	student1 = student2 ;
	std::cout << "After using the assignment operator: " ;
	noisy_compare( student1, student2 ) ;

        const Student student3( student1 ) ;
	std::cout << "After using the copy constructor: " ;
	noisy_compare( student1, student3 ) ;

	const Student& alias = student1 ;
	std::cout << "After creating an alias: " ;
	noisy_compare( student1, alias ) ;
}
Topic archived. No new replies allowed.