write a program in c++ to input the name of student and marks of three subject,calculate the total marks and average marks.
1
Expert's answer
2011-12-08T09:13:24-0500
# include<iostream.h> # include<conio.h> # include <string.h>
struct StudStruct{ & char name[50]; & int marks[3]; & int total; & int average; & };
int N, i, j; char answer; StudStruct student[100];
void input(){ N=0; answer = 'R'; while (answer!='Q'){ & cout<<"\nPress N to add new student and Q to stop adding students: "; & cin>>answer; & if (answer=='Q'){ & break; & } & if (answer=='N'){ & cout<<"Input student's name: "; & cin>>student[N].name; & cout<<"Input first mark:"; & cin>>student[N].marks[0]; & cout<<"Input second mark:"; & cin>>student[N].marks[1]; & cout<<"Input third mark:"; & cin>>student[N].marks[2]; & N++; & } & if ((answer!='N')&&(answer!='Q')){ & cout<<"Please, enter valid answer\n\n"; & } & } }
void range(){ if (N==0) cout<<"Please enter one student at least"; else for (i=0;i<N;i++){ & student[i].total = student[i].marks[0]+student[i].marks[1]+student[i].marks[2]; & student[i].average = student[i].total/3; & cout<<student[i].name<<": total mark = "<<student[i].total<<" average mark = "<<student[i].average<<"\n"; & } }
Comments
Leave a comment