-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent percentage.cpp
More file actions
67 lines (58 loc) · 1.94 KB
/
student percentage.cpp
File metadata and controls
67 lines (58 loc) · 1.94 KB
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
#include <iostream>
using namespace std;
class Student {
private:
int rollNo;
string name;
string subjects[3];
int maxMarks[3];
int minMarks[3];
int obtainMarks[3];
public:
void setData(int rollNo, string name, string sub1, string sub2, string sub3) {
this->rollNo = rollNo;
this->name = name;
subjects[0] = sub1;
subjects[1] = sub2;
subjects[2] = sub3;
for(int i=0; i<3; i++) {
cout << "Enter max marks for " << subjects[i] << ": ";
cin >> maxMarks[i];
cout << "Enter min marks for " << subjects[i] << ": ";
cin >> minMarks[i];
cout << "Enter obtain marks for " << subjects[i] << ": ";
cin >> obtainMarks[i];
}
}
void showResult() {
cout << "Roll No.: " << rollNo << endl;
cout << "Name: " << name << endl;
for(int i=0; i<3; i++) {
cout << subjects[i] << ":\t" << obtainMarks[i] << "/" << maxMarks[i] << endl;
}
float totalMarks = obtainMarks[0] + obtainMarks[1] + obtainMarks[2];
float percentage = (totalMarks / (maxMarks[0] + maxMarks[1] + maxMarks[2])) * 100;
cout << "Percentage: " << percentage << "%" << endl << endl;
}
};
int main() {
Student students[3];
for(int i=0; i<3; i++) {
int rollNo;
string name, sub1, sub2, sub3;
cout << "Enter details of student " << i+1 << endl;
cout << "Roll No.: ";
cin >> rollNo;
cout << "Name: ";
cin.ignore(); // To clear input buffer
getline(cin, name);
cout << "Enter name of three subjects: ";
cin >> sub1 >> sub2 >> sub3;
students[i].setData(rollNo, name, sub1, sub2, sub3);
}
cout << endl << "Result of all students:" << endl << endl;
for(int i=0; i<3; i++) {
students[i].showResult();
}
return 0;
}