Question

In: Computer Science

Create a C++ program which will accept an unlimited number of scores and calculates the average...

Create a C++ program which will accept an unlimited number of scores
and calculates the average score. You will also need to prompt for the
total points possible. Assume each test is worth 100 points.

Requirements.

• Enter the Student ID first, then prompt for grades. Keep prompt-
ing for grades until the client enters ’calc’. That triggers final pro-
cessing.

• Make your code as reliable as possible.
• Make your program output easy to read.
• You cannot use anything from the standard template library.
• Use functions whenever possible to modularize your code. Use
function prototypes and code the functions under the main().
• Style guide elements apply comments, layout, Program Greeting,
Source File Header, and variables, etc. etc.

1. // Specification A1 - OOP
Code this assignment using at least one class. Put this comment
above the class declaration.
2. // Specification A2 - Sort Grades
Sort the grades before printing them under specification C2. High
to low. Use any sort you wish, but code your own sort.
3. // Specification A3 - Logfile
Log the grades to a text file for archival purposes.
4. // Specification A3 - <Description>
Replace A3 with one feature of your own choosing. You can code
A3 as it appears if you wish and skip this.

Solutions

Expert Solution

#include <iostream>
#include <string.h>
#include <fstream>

using namespace std;

// Specification A1 - OOP
class Scores{
int max_score;
int *scores;
int tot_scores;
int sid;
  
public:
Scores(int max){
max_score = max;
scores = new int(max_score);
tot_scores = 0;
}
  
void getScores(){
string inp;
int x;
  
cout << "Enter student id: ";
cin >> sid;
for(tot_scores = 0; tot_scores < max_score; tot_scores++){
cout << "Enter score " << tot_scores + 1 << ": " ;
cin >> inp;
if(inp.compare("calc") == 0){
break;
}
char char_array[inp.length()];
strcpy(char_array, inp.c_str());
sscanf (char_array,"%d",&x);
scores[tot_scores] = x;
}
}
  
// Specification A2 - Sort Grades
void sortScores(){
int i,j,x;
for(i = 0; i < tot_scores - 1; i++){
for(j = i + 1; j < tot_scores; j++){
if(scores[i] < scores[j]){
x = scores[j];
scores[j] = scores[i];
scores[i] = x;
}
}
}
}
  
void displayScores(){
int sum = 0;
cout << "Student ID: " << sid << endl;
for(int i = 0; i < tot_scores; i++){
cout << "score " << i + 1 << ": " << scores[i] << endl;
sum += scores[i];
}
cout << "Average Score : " << sum / tot_scores << endl;
}
  
// Specification A3 - Logfile
void archiveScores(){
ofstream myfile;
myfile.open ("archive.txt");
myfile << "Student ID: " << sid << endl;
for(int i = 0; i < tot_scores; i++){
myfile << "score " << i + 1 << ": " << scores[i] << endl;
}
myfile.close();
}
};

int main()
{
int max;
   cout << "Enter possible total scores:";
cin >> max;
  
Scores sc(max);
  
sc.getScores();
sc.sortScores();
sc.displayScores();
sc.archiveScores();
   return 0;
}


Related Solutions

Create a program that calculates the average of 3 test scores. Make use of an array...
Create a program that calculates the average of 3 test scores. Make use of an array to store the integer scores. const int size = 3; int testScores[size]; Send this array to a function that actually calculates and returns the average. 1. Tell the user what the program does. 2. Prompt the user to enter the integer scores. ( Use a for loop to do this. ) 3. Create and implement a function with prototype: double average( int a[], int...
create a c++ proram to accept a positive number in the main program. Create and call...
create a c++ proram to accept a positive number in the main program. Create and call the following functions 1. 1. OddorEven -to determine if the number is an odd or even number ( do not use $ or modul opeartor) and will return " even number " or " odd number ". 2. Factorial - to compute the factorial of N. 3. Power - to compute the power of N without using pow function. display the result in the...
Create the flowchart and a C++ .cpp program that calculates the average snowfall for a week....
Create the flowchart and a C++ .cpp program that calculates the average snowfall for a week. The program should use a loop to execute 7 times asking the user to input the snowfall for each day of the week in inches. The program should calculate the total and average snowfall for the week. The program should then display the result and then ask the user if they wish to repeat the program or close the program.
Create a C++ program that will accept any number of grades for an exam. The grades...
Create a C++ program that will accept any number of grades for an exam. The grades will be input as 4 for an A, 3 for a B, 2 for a C, 1 for a D, and 0 for an F. After all grades have been entered, allow the user to enter -1 to exit. Output the number of grades in each category. Using arrays.
Write a C program that calculates the average grade for a specified number of students from...
Write a C program that calculates the average grade for a specified number of students from each student's test1 and test2 grades. The program must first ask the user how many students there are. Then, for each student, the program will ask the user for the test1 grade (grade #1) and test2 grade (grade #2). The program should be able to handle up to 100 students, each with 2 grades (test1 and test2). Use a two-dimensional float array to store...
Write a C program that calculates the average grade for a specified number of students from...
Write a C program that calculates the average grade for a specified number of students from each student's termtest and final grade. The program must first ask the user how many students there are. Then, for each student, the program will ask the user for the termtest grade (grade #1) and final grade (grade #2). The program should be able to handle up to 100 students, each with 2 grades (termtest and final). Use a two dimensional float array to...
Write a program that calculates the average of a group of test scores, where the lowest...
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 a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered. void calcAverage() should calculate and display the average of the four highest scores. This function...
In C Program #include Create a C program that calculates the gross and net pay given...
In C Program #include Create a C program that calculates the gross and net pay given a user-specified number of hours worked, at minimum wage. The program should compile without any errors or warnings (e.g., syntax errors) The program should not contain logical errors such as subtracting values when you meant to add (e.g., logical errors) The program should not crash when running (e.g., runtime errors) When you run the program, the output should look like this: Hours per Week:...
Write a python program that calculates the average number of words per sentence in the input...
Write a python program that calculates the average number of words per sentence in the input text file. every sentence ends with a period (when, in reality, sentences can end with !, ", ?, etc.) and the average number of sentences per paragraph, where a paragraph is any number of sentences followed by a blank line or by the end of the text.
Create a C # program that calculates what a worker must be paid if each day...
Create a C # program that calculates what a worker must be paid if each day I work different hours during the week. The price per hour is 80.0.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT