Question

In: Computer Science

Write a C++ program that outputs to a file, final marks and average mark for a...

Write a C++ program that outputs to a file, final marks and average mark for a primary school class. Your program should also output to a second a file, the student names and their average mark in ascending order. This is an example of how your program in action could look like: Sample Input Please enter student name and student number Kgosi Kgosi 20150986 Please student marks for Setswana, Maths, Science, English, and Social Studies 80 70 80 65 100 Please enter any comments about the Student Sample Output First File *************************************Report************************************************* Student Name: Kgosi Kgosi Student Number: 20150986 Course Name Marks % Letter Grade Setswana 80 A - Maths 70 B Science 80 AEnglish 65 B - Social Studies 100 A+ Average: 79 Excellent Comments: **************************************************************************************************** Page 3 of 4 The program should also generate a second file listing all students and their average mark. The list of students should be arranged according to their marks in descending order. Sample Output Second File Kgosi Kgosi 79 Masego Ndi 59 Des Rinn 23

Solutions

Expert Solution

Please let me know if anything is required. I am happy to help you.

Please share me the grading ranges to give the grades for the each subject.

Code:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
  
ofstream outfile;
outfile.open("file1.txt"); //to store the contents of student details in file1
  
ofstream outfile1;
outfile1.open("file2.txt"); //file listing all students and their average marks arranged in descending order

  
int number;
cout<<"Please enter how many students data you want to enter : "; //taking total number of students
cin>>number;
int grades[number]; //array to store the average marks
string names[number]; //array to store the names
  
for(int i=0;i<number;i++)
{
string student_name;
int student_number;
cout<<"Please enter student name and student number : "; //taking student name and student number from the user
cin>>student_name>>student_number;
names[i] = student_name;
  
//taking the marks for the each subject
int Set,Ma,Sci,Eng,Soc;
cout<<"Please Enter student marks for Setswana, Maths, Science, English, and Social Studies : ";
cin>>Set>>Ma>>Sci>>Eng>>Soc;
  
string Comments;
cout<<"Please enter any comments: ";
  
cin>>Comments; //taking Comments from the user
  
//writing the student and their marks details in file1
outfile<<"Student Name: "<<student_name<<" Student Number: "<<student_number<<" Course Name Marks % Letter Grade Setswana "<<Set<<" - Maths "<<Ma<< "B Science "<<Sci<<" English "<<Eng<<" - Social Studies "<<Soc<<" Average: "<<(Set+Ma+Sci+Eng+Soc)/5<<" Comments: "<<Comments<<"\n";
  
grades[i]=(Set+Ma+Sci+Eng+Soc)/5; //calculating the average marks

}
  
  
//sorting the names and the average marks according to the average marks
for (int i = 0; i < number-1; i++)   
{
for (int j = 0; j < number-i-1; j++)
{
if (grades[j] > grades[j+1])
{
int temp = grades[j];
grades[j] = grades[j+1];
grades[j+1]= temp;
  
string temp1 = names[j];
names[j] = names[j+1];
names[j+1] = temp1;
  
}
}
}
  
  
for (int j = number-1; j >= 0; j--)
{

outfile1<<names[j]<<" "<<grades[j]<<" "; //in descending order storing the names and average marks in second file
}
cout<<"\n";

return 0;
}

Test Case:

output files:

File 1:

File2:


Related Solutions

Write a C++ program that outputs a histogram of student Marks for a Mid-term-1 Examination. The...
Write a C++ program that outputs a histogram of student Marks for a Mid-term-1 Examination. The program should input each student’s Marks as an integer and store the Marks in a dynamic array. Marks should be entered until the user enters -1 for marks. The program should then scan through the Dynamic array and compute the histogram. In computing the histogram, the minimum value of a marks is 0 but your program should determine the maximum value entered by the...
Write the programs in JavaScript: Write a program that reads a text file and outputs the...
Write the programs in JavaScript: Write a program that reads a text file and outputs the text file with line numbers at the beginning of each line.
Write a JavaScript program that computes the average of a collection of numbers and then outputs...
Write a JavaScript program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
Write a FORTRAN program that computes the average of a collection of numbers and then outputs...
Write a FORTRAN program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
Using Java Write a program that reads a file of numbers of type int and outputs...
Using Java Write a program that reads a file of numbers of type int and outputs all of those numbers to another file, but without any duplicate numbers. You should assume that the input file is sorted from smallest to largest with one number on each line. After the program is run, the output file should contain all numbers that are in the original file, but no number should appear more than once. The numbers in the output file should...
Using Java Write a program that reads a file of numbers of type int and outputs...
Using Java Write a program that reads a file of numbers of type int and outputs all of those numbers to another file, but without any duplicate numbers. You should assume that the input file is sorted from smallest to largest with one number on each line. After the program is run, the output file should contain all numbers that are in the original file, but no number should appear more than once. The numbers in the output file should...
write a program on c++ that outputs a calendar for a given month in a given...
write a program on c++ that outputs a calendar for a given month in a given year, given the day of the week on which the 1st of the month was. The information in numeric format (months are: 1=Januay, 2=February 3=March, 4= April, 5= May, 6= June, 7= July... etc days are 1=Sunday, 2=Monday, 3= Tuesday, 4= Wednesday, 5= Thursday, 6= Friday and 7= Saturday ). The program output that month’s calendar, followed by a sentence indicating on which day...
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
Write a program that takes its input from a file of number type double and outputs...
Write a program that takes its input from a file of number type double and outputs the average of the numbers in the file to the screen. The file contains nothing but numbers of the type double separated by blanks and/ or line breaks. If this is being done as a class assignment, obtain the file name from your instructor. File name: pr01hw05input.txt 78.0 87.5 98.1 101.0 4.3 17.2 78.0 14.5 29.6 10.2 14.2 60.7 78.3 89.3 29.1 102.3 54.1...
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT