-
Notifications
You must be signed in to change notification settings - Fork 0
/
RaiseTution_OperatorOverload.cpp
65 lines (53 loc) · 1.55 KB
/
RaiseTution_OperatorOverload.cpp
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
//operator overloading
#include <iostream>
#include <string>
using namespace std;
class Student {
public:
string name;
char result;
// Constructor
Student(string n, char r) : name(n), result(r) {}
// Function to display result
void displayResult() {
cout << "Student: " << name << " - Result: ";
if (result == 'P' || result == 'p') {
cout << "Pass" << endl;
} else if (result == 'F' || result == 'f') {
cout << "Fail" << endl;
} else {
cout << "Invalid Input" << endl;
}
}
// Overloading << operator for displaying student information
friend ostream &operator<<(ostream &output, const Student &s) {
output << "Student: " << s.name << " - Result: ";
if (s.result == 'P' || s.result == 'p') {
output << "Pass";
} else if (s.result == 'F' || s.result == 'f') {
output << "Fail";
} else {
output << "Invalid Input";
}
return output;
}
};
int main() {
Student students[10];
cout << "Enter the results for 10 students:" << endl;
for (int i = 0; i < 10; i++) {
string name;
char result;
cout << "Student " << i + 1 << " name: ";
cin >> name;
cout << "Result (P for Pass, F for Fail): ";
cin >> result;
students[i] = Student(name, result);
}
cout << "Result Summary:" << endl;
cout << "-----------------" << endl;
for (int i = 0; i < 10; i++) {
cout << students[i] << endl;
}
return 0;
}