Answer to Question #308319 in C++ for stuti

Question #308319

Apply Structures and Pointers in C++ to Store & Retrieve Information, Calculate Total, and Average of 10 Students.


1
Expert's answer
2022-03-09T07:53:48-0500
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;


#define NO_OF_STUDENTS	10
#define NO_OF_SUBJECTS	2


struct Student
{
	int ID;
	int Marks[NO_OF_SUBJECTS];
	int Total;	
};


main(void)
{
	int n,r,Flag=1,c,FlagID=0;
	int Subjects_CODE[NO_OF_SUBJECTS],SID;
	struct Student S[NO_OF_STUDENTS];
	
	for(n=0;n<NO_OF_SUBJECTS;n++) Subjects_CODE[n]=n+100;
	n=0;
	while(Flag)
	{
		Flag=0;
		cout<<"\n\nPress 1 to enter Marks";
		cout<<"\nPress 2 to view  Marks";
		cout<<"\nPress 0 to QUIT";
		cout<<"\nEnter Option (0 to 2): "; cin>>Flag;
		if(Flag==1)
		{
			if(n<NO_OF_STUDENTS)
			{
				cout<<"\nEnter Student ID: "; cin>>S[n].ID;
				S[n].Total=0;	
				for(c=0;c<NO_OF_SUBJECTS;c++)
				{
					cout<<"\nEnter Marks for Subject Code ("<<Subjects_CODE[c]<<") :";  cin>>S[n].Marks[c];	
					S[n].Total = S[n].Total + S[n].Marks[c];	
				}
				n++;
			}
			else cout<<"\nNo more students can be added.";
		}
			if(Flag==2)
			{
				cout<<"\n\nEnter the Student ID: "; cin>>SID;
				FlagID=0;
				for(c=0;c<n;c++)
				{
					if(SID==S[c].ID)
					{
						FlagID=1;
						for(r=0;r<NO_OF_SUBJECTS;r++)
						{		
							cout<<"\nSubject Code ("<<Subjects_CODE[r]<<") : "<<S[c].Marks[r];	
						}
						cout<<"\nTotal = "<<S[c].Total;
					}	
				}
				if(FlagID==0) cout<<"\nNo student with ID = "<<SID<<" found.";
			}
			if(Flag==0) exit(0);
	}
	
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog