Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ programming and Problem Solving by Nell Dale (Chapter 13, 3 Programming Prob

ID: 3792015 • Letter: C

Question

C++ programming and Problem Solving by Nell Dale (Chapter 13, 3 Programming Problem), If you can please update the book solutions

Many instructors like to see the distribution of scores on an exam before they assign grades. You're working for an art history professor who has asked you to develop a program that will read all of the scores from an exam and print out a bar chart that shows their distribution. The range of the scores varies from exam to exam, and there are at most 250 students in the class. Use or modify the SortedList class from this chapter as necessary to help you do this task. The integer scores are entered into a file called exams.dat in random order. Your program's job is to read in the data, sort it, and output a bar chart with one * (star) for each exam that has a particular score. The first bar in the chart should be the highest score, and the last bar in the chart should be the lowest score. Each line of output should start with the score value, followed by the appropriate number of stars. When there is a score value that didn't appear on any exams, just output the value and no stars, then go to the next line.

Explanation / Answer

#include<iostream>
#include<fstream>
using namespace std;
//To store exam score of 250 students
int examScore[250], len;
//Read exam score from the file
void ReadScore()
{
//Declares an object of ifstream for reading
ifstream rfile;
//Opens the file input.txt in read mode
rfile.open("Exams.dat");
len = 0;
//Loops till end of the file
while(!rfile.eof())
{
//Reads a character
rfile>>examScore[len++];
}//End of while loop
}//End of read function

//Function to show exam scores
void ShowScore()
{
cout<<" Exam Score ";
//Loops till end of array
for(int x = 0; x < len; x++)
cout<<examScore[x]<<" ";
cout<<endl;
}//End of show score function

//Function to sort score
void SortScore()
{
int Temp, x, y;
//Loops till end of array
for(x = 0; x < len; x++)
{
//Loops till end of array - current x value - 1
for(y = 0; y < len - x - 1; y++)
{
//Checks if the current exam score is less than the next exam score value then swap
if(examScore[y] < examScore[y + 1])
{
//Swapping
Temp = examScore[y];
examScore[y] = examScore[y + 1];
examScore[y + 1] = Temp;
}//End of if
}//End of for loop for variable y
}//End of for loop for variable x
}//End of function

//Function to display bar chart
void BarChart()
{
//Loops till end of array
for(int x = 0; x < len; x++)
{
//Displays the exam score
cout<<examScore[x]<<" ";
//Displays number of stars based on the exam score value
for(int y = 0; y < examScore[x]; y++)
cout<<"*";
cout<<endl;
}//End of for loop
}//End of barchart function

//Main function
int main()
{
ReadScore();
SortScore();
ShowScore();
BarChart();
}

Output


Exam Score 92 92 87 82 80 79 77 61 61 57 45 40 37 35 32 22 21 21 20 17 12 10
92 ********************************************************************************************
92 ********************************************************************************************
87 ***************************************************************************************
82 **********************************************************************************
80 ********************************************************************************
79 *******************************************************************************
77 *****************************************************************************
61 *************************************************************
61 *************************************************************
57 *********************************************************
45 *********************************************
40 ****************************************
37 *************************************
35 ***********************************
32 ********************************
22 **********************
21 *********************
21 *********************
20 ********************
17 *****************
12 ************
10 **********

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote