-
Notifications
You must be signed in to change notification settings - Fork 0
/
RaiseTution_FunctionOverload.cpp
56 lines (44 loc) · 1.2 KB
/
RaiseTution_FunctionOverload.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
//function 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 overloading
void displayResult() {
displayResult(name, result);
}
void displayResult(string name, char result) {
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;
}
}
};
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++) {
students[i].displayResult();
}
return 0;
}