Answer to Question #194361 in C++ for Dorcus

Question #194361

Write a program that will calculate a student's year marks for all his subjects. The program must read the subject code, the assignment marks for two assignments and the percentage that each assignment contributes towards the year mark, for each subject that a student is registered for. Create an input file called assignments.dat


1
Expert's answer
2021-05-18T02:55:23-0400
#include <bits/stdc++.h> 
#include<iostream>
#include <stdio.h>
#include <string>
#include <set>
#include <stack>
using namespace std;


#define NO_OF_STUDENTS	3
#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
APPROVED BY CLIENTS