-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct.cpp
More file actions
116 lines (87 loc) · 1.36 KB
/
struct.cpp
File metadata and controls
116 lines (87 loc) · 1.36 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<iostream>
using namespace std;
typedef struct student
{
char name[10];
int age; float avg,marks;
}a;
void getdata(a *p);
void printdata(a *p);
a avg(a *p);
void sortdata(a *p);
void getdata(a *p)
{
for(int i=0;i<5;i++)
{
cout<<"\nEnter name marks age";
cin>>p[i].name>>p[i].marks>>p[i].age;
}
}
void printdata(a *p)
{
for(int i=0;i<5;i++){
cout<<p[i].name<<'\t'<<p[i].marks<<'\t'<<p[i].age;cout<<endl;}
}
a avg(a *p)
{
a t;
t.avg=(p[0].marks+p[1].marks+p[2].marks+p[3].marks+p[4].marks)/5;
return t;
}
void sortdata(a *p)
{
for(int i=0;i<5;i++)
for(int j=i+1;j<5;j++)
if(p[i].avg < p[j].avg)
{
a t;
t=p[i];
p[i]=p[j];
p[j]=t;
}
}
int main()
{
int i;
a *p;
p=new a[5];
getdata(p);
printdata(p);
a t;
t=avg(p);
cout<<endl<<"Class Avg: "<<t.avg;
sortdata(p);
printdata(p);
}
harish@harish-VPCEH38FN:~$ ./a.out
Enter name marks age
har
90
12
Enter name marks age
res
80
34
Enter name marks age
tryy
76
21
Enter name marks age
uiy
99
34
Enter name marks age
iuo
87
45
har 90 12
res 80 34
tryy 76 21
uiy 99 34
iuo 87 45
Class Avg: 86.4har 90 12
res 80 34
tryy 76 21
uiy 99 34
iuo 87 45
harish@harish-VPCEH38FN:~$