-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.cpp
More file actions
103 lines (92 loc) · 1.57 KB
/
Copy pathscore.cpp
File metadata and controls
103 lines (92 loc) · 1.57 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
#include<iostream>
#include<cmath>
#include<fstream>
#include<string>
int main(){
using namespace std;
string data;
int total=0;
int boytotal=0;
int girltotal=0;
int boynumber=0;
int girlnumber=0;
struct student{
string name;
string sex;
float score=0;
};
student stuscore[30];
int i;
freopen("score.csv","r",stdin);
string line;
string name,sex,score;
while(getline(cin,line))
{
i=0;
stringstream ss(line);
getline(ss,name,",");
getline(ss,sex,",");
getline(ss,score,",");
sex.erase(0.1);
score.erase(0,1);
float sc=stof(score);
student stuscore[i]=(name,sex,sc);
}
for(int a=0;a<=i;a++)
cout<<stuscore[a].score<<" ";
/*for(int a=0;a<=i;a++)
{
total+=stuscore[a].score;
}
int average=total/(i+1);
for(int a=0;a<=i;a++)
{
if(stuscore[a].sex=="male") {
boytotal+=stuscore[a];
boynumber++;
}
else continue;
}
int boyaverage=boytotal/boynumber;
for(int a=0;a<=i;a++)
{
if(stuscore[a].sex=="female") {
girltotal+=stuscore[a];
girlnumber++;
}
else continue;
}
int girlaverage=girltotal/girlnumber;
student order[30];
for(int a=0;a<=i;a++)
{
order[a]=stuscore[a];
}
for(int a=0;a<=i;a++)
{
for(int b=i;b>0;b--)
{
if(order[b].score>order[b-1].score)
{
student x=order[b];
order[b]=order[b-1];
order[b-1]=x;
}
else continue;
}
}
cout<<"average of all: "<<average<<endl;
cout<<"average of male: "<<boyaverage<<endl;
cout<<"average of female: "<<girlaverage<<endl;
cout<<"order of their score: "<<endl;
for(int a=0;a<=i;a++)
{
cout<<order[a].name<<endl;
cout<<order[a].sex<<endl;
cout<<order[a].score<<endl;
cout<<endl;
}
*/
infile.close();
return 0;
}