-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent info.cpp
More file actions
41 lines (34 loc) · 1.1 KB
/
student info.cpp
File metadata and controls
41 lines (34 loc) · 1.1 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
#include <iostream>
using namespace std;
class Student {
public:
int roll;
string name;
float gpa;
};
int main() {
int num_students;
cout << "Enter the number of students: ";
cin >> num_students;
Student* students = new Student[num_students];
for (int i = 0; i < num_students; ++i) {
cout << "Enter details for student " << i + 1 << ":\n";
cout << "Roll Number: ";
cin >> students[i].roll;
cout << "Name: ";
cin.ignore(); // Clear the input buffer before taking string input
getline(cin, students[i].name);
cout << "GPA: ";
cin >> students[i].gpa;
}
cout << "\nDisplaying Student Data:\n";
for (int i = 0; i < num_students; ++i) {
cout << "Student " << i + 1 << ":\n";
cout << "Roll Number: " << students[i].roll << endl;
cout << "Name: " << students[i].name << endl;
cout << "GPA: " << students[i].gpa << endl;
cout << "---------------------------\n";
}
delete[] students; // Free the allocated memory
return 0;
}