Answer to Question #5457 in C++ for zuhaib abbasi
Question #5457
write a program in c++ to input the name of student and marks of three subject,calculate the total marks and average marks.
Expert's answer
# 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";
& }
}
void main(){
input();
range();
getch();
}
# 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";
& }
}
void main(){
input();
range();
getch();
}
Need a fast expert's response?
Submit orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Leave a comment