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
|
#include <iostream>
#include <string>
#include <sstream>
#define Mark 5
using namespace std;
struct sStud{
string Name;
int Group;
int Ses[Mark];
};
void input(int, sStud*);
double average(double*, sStud*, int);
void input(int i, sStud *p)
{
int n, t;
string mystr;
for(n=0; n<i; n++){
cin.get();
cout<<"Enter student's name: ";
getline(cin,p->Name);
cout<<"Enter student's group: ";
getline(cin,mystr);
stringstream(mystr)>>p->Group;
cout<<"Enter 5 student's marks: ";
for(t=0; t<Mark; t++){
cin>>p->Ses[t];
}
}
}
double average(double *a, sStud *p, int i)
{
int n;
double res[10];
a=&res[10]; //I don't know where I should point to array here or
cout<<endl;
cout<<"Students with average mark more than 4.0:"<<endl;
for(n=0; n<i; n++){
if((res[n]=(double)(p->Ses[0]+p->Ses[1]+p->Ses[2]+p->Ses[3]+p->Ses[4])/5)
>=4.0){
cout<<p->Name<<endl;
cout<<"Group ES-"<<p->Group<<endl;
}
}
cout<<res[0]<<", "<<res[1]<<", "<<res[2]<<", "<<res[3]<<", "<<res[4]<<endl;
if(res[0]<=4 && res[1]<=4 && res[2]<=4 && res[3]<=4 && res[4]<=4){
cerr<<"No one student with average mark more then 4.0"<<endl;
}
return *a;
}
int main()
{
int i, n, t;
double *a, res[10];
sStud *p, st;
cout<<"Enter number of students: ";
cin>>i;
a=&res[10]; //here
p=&st;
input(i,p);
average(a,p,i);
return 0;
}
|