-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCGPI.cpp
More file actions
81 lines (72 loc) · 2.21 KB
/
CGPI.cpp
File metadata and controls
81 lines (72 loc) · 2.21 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
/*Write a program to enter records of Five students, which should contain fields like roll No., name, CGPI, semester. (a) List all
record of all students having CGPI greater than k. (b) Insert a new record of student at kth position and print the final record.
*/
#include <iostream>
#include <vector>
using namespace std;
struct Student {
int rollNo;
string name;
float CGPI;
int semester;
};
vector<Student> students;
void insertRecord(int k, int rollNo, string name, float CGPI, int semester) {
Student newStudent = {rollNo, name, CGPI, semester};
students.insert(students.begin() + k, newStudent);
}
void printRecords() {
for (int i = 0; i < students.size(); i++) {
cout << "Roll No: " << students[i].rollNo << endl;
cout << "Name: " << students[i].name << endl;
cout << "CGPI: " << students[i].CGPI << endl;
cout << "Semester: " << students[i].semester << endl;
cout << endl;
}
}
int main() {
int n = 5;
for (int i = 0; i < n; i++) {
int rollNo, semester;
string name;
float CGPI;
cout << "Enter record for student " << i + 1 << ":" << endl;
cout << "Roll No: ";
cin >> rollNo;
cout << "Name: ";
cin >> name;
cout << "CGPI: ";
cin >> CGPI;
cout << "Semester: ";
cin >> semester;
students.push_back({rollNo, name, CGPI, semester});
}
cout << "All records:" << endl;
printRecords();
cout << "Enter a value of k: ";
float k;
cin >> k;
cout << "Records of students having CGPI greater than " << k << ":" << endl;
for (int i = 0; i < students.size(); i++) {
if (students[i].CGPI > k) {
cout << "Roll No: " << students[i].rollNo << endl;
cout << "Name: " << students[i].name << endl;
cout << "CGPI: " << students[i].CGPI << endl;
cout << "Semester: " << students[i].semester << endl;
cout << endl;
}
}
int kth;
cout << "Enter the position k at which you want to insert a new record: ";
cin >> kth;
int rollNo;
string name;
float CGPI;
int semester;
cout << "Enter the rollNo, name, CGPI and semester of the new student: ";
cin >> rollNo >> name >> CGPI >> semester;
insertRecord(kth, rollNo, name, CGPI, semester);
cout << "Final records:" << endl;
printRecords();
return 0;
}