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++ 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...
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:...
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.
DO IN C++ Secret Codes! Create a program that will accept a message from the user...
DO IN C++ Secret Codes! Create a program that will accept a message from the user and either encrypt ordecrypt it with the following algorithms: To encrypt: - get the character you wish to encrypt - find the index of that character in the alphabet array - add the shift offset to the index - add the increment to the index - "wrap around" the new index so the result is between 0 and 29 - find the character at...
Create a working C# Program that will accept an input and has the following class. areaCircle...
Create a working C# Program that will accept an input and has the following class. areaCircle – computes the area of the circle volumeCube – computes the volume of a cube perimeterTraingle – computes the perimeter of a triangle surfaceAreaRect – computes the surface area of a rectangle *You may usePass by Value and/or Pass by Reference *Using ConsoleApp
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of test scores where the lowest score is dropped. It should use the following functions a) void getScores should have 4 double reference parameters (one for each test score) getScores should do the following: - read 4 test scores from the text file Lab11C.txt (Important: declare your ifstream infile and open the file inside this function, not in the main function) - store them in...
Create a C++ program that will ask the user for how many test scores will be...
Create a C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. (no fstream) The data needs to include the student’s first name, student number test score the fields should be displayed with a total width of 15. The prompt should be printed with a header in the file explaining what each is: ex. First Name student number Test Score 1) mike 6456464   98 2) phill...
Create a C++ program that calculates an unbiased standard deviation of 5 input numbers. Please Submit:...
Create a C++ program that calculates an unbiased standard deviation of 5 input numbers. Please Submit: 1. A flowchart of your program. (3 points) 2. Your C++ program with a heading comment, also appropriate spacing and indentation in the program body. 3. Copy of a screenshot after your program is executed. (Section 2 and3: 7 points) /* ELEN 1301 Programming Assignment #8. Name : Your name. Student ID : Your student ID #. Due date : Purpose of the program...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT