Question

In: Computer Science

In Visual Studios 2017, using c++, Create a class (Scores) that stores test scores (integers) in...

In Visual Studios 2017, using c++, Create a class (Scores) that stores test scores (integers) in an array (assume a maximum of 100 scores). The class should have a constructor that allows the client to specify the initial value of the scores (the same initial value applies to all of them) and another default constructor that initializes them to 0. The class should have functions as follows:

1. A member function that adds a score to the array.  The client must not pass the array index to the object.   This member function returnsan error indication if the value is invalid – i.e. negative test scores are not permitted.

2. A member function to sort the array in ascending order.

3. A member function to compute the average of the scores in the array, and

4. A member function to display the scores.

Note that you will need to be careful about sorting the array and computing the average of the scores.  Because your constructor will initialize all members of the array to be a value, you do not want to include these values in your average calculation nor in your sort function. Write a program (client) that uses the class by creating a Scores object and prompting the user for a file name. Appropriate error checking is required to ensure that the file exists and can be opened successfully. The client should read the file contents and store them in the object. The file will be formatted so that the first line contains the number of scores, and each successive line contains a score. A typical input file might contain:

4

90

85

99

94

The client should read and store the contents of the file, sort and display the scores, and compute and display the average score. All output should be labeled appropriately, and validity checking should be done on input and storage of the data. If an error is encountered in the input, the program should output an error message indicating which item was invalid, and the entire program should then terminate.

The executing program should look something like this:

In the screen above, notice that the average is displayed with decimal points.  Whenever you are calculating an average, nevertruncate the decimal portion until you are told to do so.  In this lab, you are not to truncate the average.

If a negative score is read in, the program might look something like this:

If a non-numeric score is read in, the program might look something like this:

In the screen above, notice that the program pauses long enough to read the error message that is displayed.  

Use good coding style (modular, separate .h and .cpp class files, no globals, meaningful comments, etc.) throughout your program.

Solutions

Expert Solution

If you have any doubts, please give me comment...

Scores.h

#pragma once

#include<iostream>

using namespace std;

class Scores {

private:

int scoresList[100];

int size;

public:

Scores();

Scores(int list);

bool addScore(int val);

void sortScore();

double averageScores();

void displayScores();

};

Scores.cpp

#include "Scores.h"

Scores::Scores(int val) {

size = 0;

for (int i = 0; i < 100; i++) {

scoresList[i] = val;

}

}

Scores::Scores() {

size = 0;

for (int i = 0; i < 100; i++) {

scoresList[i] = 0;

}

}

bool Scores::addScore(int val) {

if (val < 0) {

return false;

} else {

scoresList[size] = val;

size++;

return true;

}

}

void Scores::sortScore() {

// This Logic will Sort the Array of elements in Ascending order

int temp;

for (int i = 0; i < size; i++) {

for (int j = i + 1; j < size; j++) {

if (scoresList[i] > scoresList[j]) {

temp = scoresList[i];

scoresList[i] = scoresList[j];

scoresList[j] = temp;

}

}

}

}

double Scores::averageScores() {

double total = 0;

for (int i = 0; i < size; i++) {

total = total + scoresList[i];

}

return ((double)total) / size;

}

void Scores::displayScores() {

for (int i = 0; i < size; i++) {

cout << scoresList[i] << endl;

}

}

scoresDriver.cpp

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

#include "Scores.h"

using namespace std;

int main() {

// Define local variables

int score, num;

string inputFile;

// uses inData for input file stream

ifstream inData;

cout << "Enter the input file :";

// getline is used for if user enters a space for a file name

getline(cin, inputFile);

inData.open(inputFile.c_str());

// checks to see if the file is valid

if (inData.fail()) {

cout << "File Not Found";

return 1;

}

inData >> num;

if (num < 0) {

cout << "Invalid Score Entered: " << num<<endl;

return 0;

}

Scores scoreslist;

for (int i = 0; i < num; i++) {

inData >> score;

bool value = scoreslist.addScore(score);

if (!value)

cout << "Invalid score entered :" << num << endl;

}

cout<<setprecision(2)<<fixed;

scoreslist.sortScore();

cout << "Displaying Scores After Sorting :" << endl;

scoreslist.displayScores();

cout << "Average Score :" << scoreslist.averageScores() << endl;

// system("pause");

return 0;

}


Related Solutions

I need this code in C++ form using visual studios please: Create a class that simulates...
I need this code in C++ form using visual studios please: Create a class that simulates an alarm clock. In this class you should: •       Store time in hours, minutes, and seconds. Note if time is AM or PM. (Hint: You should have separate private members for the alarm and the clock. Do not forget to have a character variable representing AM or PM.) •       Initialize the clock to a specified time. •       Allow the clock to increment to the...
C# Programming language!!! Using visual studios if possible!! PrimeHealth Suite You will create an application that...
C# Programming language!!! Using visual studios if possible!! PrimeHealth Suite You will create an application that serves as a healthcare billing management system. This application is a multiform project (Chapter 9) with three buttons. The "All Accounts" button allows the user to see all the account information for each patient which is stored in an array of class type objects (Chapter 9, section 9.4).The "Charge Service" button calls the Debit method which charges the selected service to the patient's account...
Program is to be written in C++ using Visual studios Community You are to design a...
Program is to be written in C++ using Visual studios Community You are to design a system to keep track of either a CD or DVD/Blu-ray collection. The program will only work exclusively with either CDs or DVDs/Blu-rays since some of the data is different. Which item your program will work with will be up to you. Each CD/DVD/Blu-ray in the collection will be represented as a class, so there will be one class that is the CD/DVD/Blu-ray. The CD...
Your task is to create a book ordering form using VISUAL STUDIOS, with the code and...
Your task is to create a book ordering form using VISUAL STUDIOS, with the code and screenshots 1. Boxes for first name, last name, address. 2. Radio buttons to select: hard cover, soft cover, ebook. 3. Drop down list to select the book (make up three or four book names). 4. Radio buttons to select credit card (at least Visa, Master Card, American Express). 5. Box to enter credit card numbers. 6. The credit card box MUST verify that numbers...
Using Visual Studio in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
Code should be written in C++ using Visual Studios Community This requires several classes to interact...
Code should be written in C++ using Visual Studios Community This requires several classes to interact with each other. Two class aggregations are formed. The program will simulate a police officer giving out tickets for parked cars whose meters have expired. You must include both a header file and an implementation file for each class. Car class (include Car.h and Car.cpp) Contains the information about a car. Contains data members for the following String make String model String color String...
Must be written in C++ in Visual studios community In this lab, you will modify the...
Must be written in C++ in Visual studios community In this lab, you will modify the Student class you created in a previous lab. You will modify one new data member which will be a static integer data member. Call that data member count. You also add a static method to the Student class that will display the value of count with a message indicating what the value represents, meaning I do not want to just see a value printed...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
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 an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT