/
Example.cpp
57 lines (49 loc) · 1.05 KB
/
Example.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
// https://codevscolor.com/c-plus-plus-student-details-class
#include <iostream>
#include <string>
using namespace std;
class Student
{
private:
string name;
int marks;
public:
void getDetails();
void setDetails();
};
void Student::setDetails()
{
cout << "Enter the name:" << endl;
cin >> name;
cout << "Enter total marks:" << endl;
cin >> marks;
}
void Student::getDetails()
{
cout << "Name: " << name << " ,marks: " << marks << endl;
}
int main(int argc, char const *argv[])
{
int count;
cout << "Enter the total number of students: ";
cin >> count;
if (count > 0)
{
Student studentArray[count];
for (int i = 0; i < count; i++)
{
cout << "For student " << i + 1 << ":" << endl;
studentArray[i].setDetails();
}
cout << "\nYou have entered:" << endl;
for (int i = 0; i < count; i++)
{
studentArray[i].getDetails();
}
}
else
{
cout << "Please enter a valid number." << endl;
}
return 0;
}