-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment2.cpp
More file actions
112 lines (90 loc) · 2.6 KB
/
Copy pathAssignment2.cpp
File metadata and controls
112 lines (90 loc) · 2.6 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
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 <vector> // For dynamic course list
using namespace std;
int num = 0;
class Student {
string name;
string roll_number;
float CGPA;
vector<string> courses; // Use vector for dynamic course storage
public:
void course();
void grade();
void display();
void validate();
};
void Student::course() {
cout << "Enter number of courses to add: ";
cin >> num;
cin.ignore(); // Prevent input skipping when using getline()
courses.resize(num); // Resize vector to fit number of courses
for (int i = 0; i < num; i++) {
cout << "Enter name of course - " << i + 1 << ": ";
getline(cin, courses[i]);
}
cout << "All courses have been successfully added" << endl;
}
void Student::grade() {
cout << "Enter student roll number: ";
cin.ignore();
getline(cin, roll_number);
cout << "Enter student CGPA: ";
cin >> CGPA;
cout << "CGPA has been successfully updated" << endl;
}
void Student::display() {
cout << "Name: " << name << endl;
cout << "Roll number: " << roll_number << endl;
cout << "CGPA: " << CGPA << endl;
if (!courses.empty()) {
for (size_t i = 0; i < courses.size(); i++) {
cout << "Course - " << i + 1 << ": " << courses[i] << endl;
}
} else {
cout << "No course has been opted by student." << endl;
}
}
void Student::validate() {
// Implementation if needed
}
class StudentManagementSystem {
protected:
string name;
string roll_number;
float CGPA;
vector<string> courses;
public:
// Default Constructor
StudentManagementSystem() {
name = "Unknown";
roll_number = "XXXXXXX";
CGPA = 0.0;
}
// Parameterized Constructor
StudentManagementSystem(string n, string r_no, float GP) {
name = n;
roll_number = r_no; // Fixed incorrect assignment
CGPA = GP;
cout << "Enter number of courses student has opted: ";
cin >> num;
cin.ignore();
courses.resize(num);
for (int i = 0; i < num; i++) {
cout << "Enter name of course - " << i + 1 << ": ";
getline(cin, courses[i]);
}
}
void display_record();
};
void StudentManagementSystem::display_record () {
}
int main() {
int num2;
cout << "Enter number of students in class: ";
cin >> num2;
StudentManagementSystem S1_A[] = {
{"Ankit", "24A1001", 6.5},
{"Avesh", "24A2002", 7.6}
};
return 0;
}