Question

CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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!

Add a comment
Know the answer?
Add Answer to:
CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete C++ program that reads students names and their test scores from an input...

    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...

    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...

    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...

    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...

  • help with C++

    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.

  • Write a program that performs the following: 1. Presents the user a menu where they choose...

    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...

    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...

    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...

  • c++ Instructions Overview In this programming challenge you will create a program to handle student test...

    c++ Instructions Overview In this programming challenge you will create a program to handle student test scores.  You will have three tasks to complete in this challenge. Instructions Task 1 Write a program that allocates an array large enough to hold 5 student test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the...

  • Create a C++ program to calculate grades as well as descriptive statistics for a set of...

    Create a C++ program to calculate grades as well as descriptive statistics for a set of test scores. The test scores can be entered via a user prompt or through an external file. For each student, you need to provide a student name (string) and a test score (float). The program will do the followings: Assign a grade (A, B, C, D, or F) based on a student’s test score. Display the grade roster as shown below: Name      Test Score    ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT