CIS 22A C++
Project Exam Statistics
Here is what your program will do: first it welcomes the user and
displays the purpose of
the program. It then prompts the user to enter the name of an input
file (such as
scores.txt). Assume the file contains the scores of the final
exams; each score is
preceded by a 5 characters student id. Create the input file: copy
and paste the following
data into a new text file named scores.txt
DH232 89
DR123 100
AJ222 98
SW111 45
12AB1 82
516BC 99
2ABCD 100
333XY 92
TY4XZ 45
AC234 78
9QWE9 45
JP200 89
AK323 100
The program should read the contents of the file into two arrays,
determine what needs to
be determined, and displays the following results:
• The total number of students in the array
• The class average
• The lowest score in the array followed by the ids of the students
with that
score
• The highest score in the array followed by the ids of the
students with that
score
Finally, the program should write to another file the scores below
the average, and the
corresponding ids. The program prompts the user to enter the name
of an output file
Design: Your program should include several functions in addition
to main()
// NOTE: You must write documentation for each function!
Pseudocode: // see next page
Pseudo-code:
1. Display welcome & info about the program
2. Create 2 arrays in main (assume the maximum class size is
45)
3. Read data from file into two arrays and also count the number of
students in the input
file.
4. Calculate the class average
5. Find the lowest score
6. Find the highest score
7. Display the average and the number of students
8. Display the lowest score followed by the ids of the students
with that score
9. Display the highest score followed by the ids of the students
with that score
10. Write to another file the scores below the average, and the
corresponding ids. The
program prompts the user to enter the name of an output file
11. Display an “end of the program” message.
Here is the code for the above assignment.
Feel free to comment on any doubt and give thumbs up!
Code:
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
// constant variable for the size of the array
const int MAX_SIZE = 45;
/*
this function takes two arguments
an array of integer type and number of elements in the array
and return the lowest element in the array
*/
int findLowestScore(int score[] , int size)
{
int lowest = score[0];
for (size_t i = 1; i < size; i++)
{
if (score[i] < lowest)
{
lowest = score[i];
}
}
return lowest;
}
/*
this function takes two arguments
an array of integer type and number of elements in the array
and return the highest element in the array
*/
int findHighestScore(int score[] , int size)
{
int highest = score[0];
for (size_t i = 1; i < size; i++)
{
if (score[i] > highest)
{
highest = score[i];
}
}
return highest;
}
/*
this function takes two arguments
an array of integer type and number of elements in the array
and return the average
*/
double calculateAverage(int score[] , int size)
{
double sum = 0.0;
for (size_t i = 0; i < size; i++)
{
sum += score[i];
}
return sum / size;
}
/*
this function takes four arguments
an 2D array of char type, an array of integer type, number of elements in the array and lowest marks
and display the student IDs with the lowest marks
*/
void displayLowestScore(char data[][6] , int score[] , int size , int lowest )
{
cout << "Lowest score in the class is : " << lowest << endl;
cout << "Student IDs with the lowest score are : " << endl;
for (int i = 0; i < size; i++)
{
if(score[i] == lowest){
cout << data[i] << "\n";
}
}
}
/*
this function takes four arguments
an 2D array of char type, an array of integer type, number of elements in the array and highest marks
and display the student IDs with the highest marks
*/
void displayHighestScore(char data[][6] , int score[] , int size , int highest)
{
cout << "Highest score in the class is : " << highest << endl;
cout << "Students IDs with the highest score are : " << endl;
for (size_t i = 0; i < size; i++)
{
if(score[i] == highest){
cout << data[i] << endl;
}
}
}
// main method
int main()
{
cout << "************Welcome***************************\n";
cout << "This program reads information of students \nfrom file and calculates various statistics from the data!\n";
cout << "**********************************************\n\n";
cout << "Enter name of an input file\n";
string fileName ;
getline(cin , fileName);
ifstream fin;
fin.open(fileName);
if (!fin.is_open())
{
cout << "Error! File not found!\n";
exit(1);
}
char data[MAX_SIZE][6];
int score[MAX_SIZE];
int numberOfStudents = 0;
while (!fin.eof())
{
fin >> data[numberOfStudents];
fin >> score[numberOfStudents];
data[numberOfStudents][5] = '\0';
++numberOfStudents;
}
fin.close();
int lowestScore = findLowestScore(score , numberOfStudents);
int highestScore = findHighestScore(score , numberOfStudents);
double classAverage = calculateAverage(score , numberOfStudents);
cout << "Total number of students : " << numberOfStudents << endl;
cout << "Average of class : " << classAverage << endl;
cout << endl;
displayLowestScore(data,score,numberOfStudents,lowestScore);
cout << endl;
displayHighestScore(data,score,numberOfStudents,highestScore);
string outputFileName ;
cout << endl << "Enter the name of output file: \n" ;
getline(cin,outputFileName);
ofstream fout(outputFileName);
if(!fout.is_open()){
cout << "Error! Cannout open file!\n";
exit(1);
}
for (size_t i = 0; i < numberOfStudents; i++)
{
if(score[i] < classAverage){
fout << data[i] << " " << score[i] << endl ;
}
}
fout.close();
}
Screenshot

Thank You!
CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...
Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...
Java Program: In this project, you will write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will...
have to create five different functions above and call it in the
main fucntion.
Project Exam Statistics A CIS 22A class has two midterm exams with a score between 0 and 100 each. Fractional scores, such as 88.3 are not allowed. The students' ids and midterm exam scores are stored in a text file as shown below // id exam1 exam2 DH232 89 92 Write a program that reads data from an input file named exams.txt, calculates the average of...
What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...
Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score(display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a for loop.
C++ programming language Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in...
Name your c++ file cpp. BScore_LastNameFirstName.cpp Write a program that contains a function call Input. The Input function should accept 2 decimal test scores that was entered from the user and stores them in an array. Don’t store any number less than 0. Return the array to main. Inside main, the program should pass the array and the total number of scores to countBGrade function. The countBGrade function should count how many B scores (80 to 89) were entered by...
Write a program that performs the following: 1. Presents the user a menu where they choose between: a. Add a new student to the class i. Prompts for first name, last name ii. If assignments already exist, ask user for new student’s scores to assignments b. Assign grades for a new assignment i. If students already exist, prompt user with student name, ask them for score ii. Students created after assignment will need to...
Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...
programming language is C++. Please also provide an explanation of
how to create a file with the given information and how to use that
file in the program
Let's consider a file with the following student information: John Smith 99.0 Sarah Johnson 85.0 Jim Robinson 70.0 Mary Anderson 100.0 Michael Jackson 92.0 Each line in the file contains the first name, last name, and test score of a student. Write a program that prompts the user for the file name...