Answer to Question #194060 in C++ for Mpopo

Question #194060

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 the student is registered for. COS1511 30 66 70 49 COS1512 25 76 75 67 COS1521 10 58 90 62 COS1501 50 62 50 57 INF1501 40 82 60 78 INF1511 20 24 80 55 The first field in each line represents the subject code, followed by the percentage that assignment 1 contributes towards the year mark and the student’s mark (a percentage) for assignment 1. Then follow the percentage that assignment 2 contributes towards the year mark and the student’s mark for assignment 2. Your program must read the file line by line, calculate the student’s year mark for the subject as a percentage and write the subject code and the year mark to an output file yearmark.dat.


1
Expert's answer
2021-05-19T11:58:15-0400
#include <iostream>
#include <string>
#include <fstream>


using namespace std;


int main()
{
	ofstream fout;
	fout.open("yearmark.dat");
	if (!fout)
	{
		cout << "File not open!" << endl;
		return 0;
	}
	string temp;
	int p1, p2;
	int m1, m2;
	int count = 1;
	int result;
	while (true)
	{


		cout << "***** Student #" << count << " ******" << endl;
		cout << "Course name(enter 00 to exit): ";
		cin >> temp;
		if (temp == "00")
		{
			cout << "Thank you for using program. Good Bye!" << endl;
			break;
		}
		cout << "Enter percentage #1: ";
		cin >> p1;
		cout << "Enter mark #1: ";
		cin >> m1;


		cout << "Enter percentage #2: ";
		cin >> p2;
		cout << "Enter mark #2: ";
		cin >> m2;
		result = (int)(double(m1 * p1) / 100.00 + double(m2 * p2) / 100.00);
		cout << "Year mark is: " << result << endl;
		cout << "Save record in file...." << endl;
		fout << "Student #" << count << " " << temp << " " << result << endl;
		count++;
	}
	system("pause");
	fout.close();
	return 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
APPROVED BY CLIENTS