forked from Anuragcoderealy/Codenewhacktober
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_details.cpp
59 lines (51 loc) · 1.12 KB
/
student_details.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
57
58
59
#include <iostream>
#include <string>
using namespace std;
class Student
{
private:
string name;
int roll;
int marks;
public:
void getDetails();
void displayDetails();
};
void Student::getDetails()
{
cout << "Enter the name : ";
cin >> name;
cout << "Enter roll number: ";
cin >> roll;
cout << "Enter total marks : ";
cin >> marks;
}
void Student::displayDetails()
{
cout << "Name: " << name << " Roll Number: " << roll << " Marks: " << marks << endl;
}
int main()
{
int numOfStudents;
cout << "Enter the number of students : ";
cin >> numOfStudents;
if (numOfStudents > 0)
{
Student stu[numOfStudents];
for(int i = 0; i < numOfStudents; i++)
{
cout << "\nFor student " << i + 1 << " :" << endl;
stu[i].getDetails();
}
cout << "\n\nDetails of all students: " << endl;
for(int i = 0; i < numOfStudents; i++)
{
stu[i].displayDetails();
}
}
else
{
cout << "Please enter a valid number." << endl;
}
return 0;
}