-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex09.cpp
81 lines (74 loc) · 1.76 KB
/
ex09.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <cstring>
using namespace std;
const int SLEN = 30;
struct student
{
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
int getinfo(student pa[], int n);
void display1(student st);
void display2(const student * ps);
void display3(const student pa[], int n);
int main()
{
cout << "Enter class size: ";
int class_size;
cin >> class_size;
while (cin.get() != '\n')
continue;
student * ptr_stu = new student[class_size];
int entered = getinfo(ptr_stu, class_size);
for (int i = 0; i < entered; i++)
{
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
}
display3(ptr_stu, entered);
delete [] ptr_stu;
cout << "Done\n";
return 0;
}
int getinfo(student pa[], int n)
{
int i;
for (i = 0; i < n; i++)
{
cout << "Enter the full name of student: " << i + 1 << ": ";
cin.getline(pa[i].fullname, SLEN);
if (strlen(pa[i].fullname) == 0)
break;
cout << "Enter hobby: " << i + 1 << ": ";
cin.get(pa[i].hobby, SLEN);
cout << "Enter OOP level: " << i + 1 << ": ";
cin >> pa[i].ooplevel;
cin.get();
}
return i;
}
void display1(student st)
{
cout << "\ndisplay1() output:\n";
cout << st.fullname << endl;
cout << st.hobby << endl;
cout << st.ooplevel << endl;
}
void display2(const student * ps)
{
cout << "\ndisplay2() output:\n";
cout << ps->fullname << endl;
cout << ps->hobby << endl;
cout << ps->ooplevel << endl;
}
void display3(const student pa[], int n)
{
cout << "\ndisplay3() output:\n";
for (int i = 0; i < n; i++)
{
cout << pa[i].fullname << endl;
cout << pa[i].hobby << endl;
cout << pa[i].ooplevel << endl;
}
}