-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent1.cpp
63 lines (57 loc) · 1.13 KB
/
Student1.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
60
61
62
63
#include <iostream>
#include <string.h>
using namespace std;
class Student1
{
private:
char name[40];
int mks[4], total;
public:
void accept();
void display();
Student1()
{
strcpy(name, "\0");
for (int i = 0; i < 4; i++)
mks[i] = 0;
total=0;
}
};
void Student1::accept()
{
char nm[2];
cout << "\nEnter your name: ";
// gets(name);
cin.getline(name, 40);
cout << "\nEnter the marks of 4 subjects: \n";
for (int i = 0; i < 4; i++)
{
cin >> mks[i];
total += mks[i];
}
cin.getline(nm, 2);
}
void Student1::display()
{
cout << "\n Name : " << name;
cout << "\n Marks Obtained : ";
for (int i = 0; i < 4; i++)
cout << mks[i] << ",";
cout << "\n Total marks = "<< total;
}
int main()
{
Student1 s[3];
int i = 0;
for (i = 0; i < 3; i++)
{
s[i].accept();
printf("-----------------------------------------------------");
}
for (i = 0; i < 3; i++)
{
s[i].display();
printf("\n");
}
return 0;
}