Question

In: Computer Science

In C++ 2. Test Scores #2 Modify the program #1 to allow the user to enter...

In C++

2. Test Scores #2

Modify the program #1 to allow the user to enter name-score pairs. For each student taking a test, the user types a string representing the name of the student, followed by an integer representing the student's score. (use a structure) Modify the average-calculating function so they take arrays of structures, with each structure containing the name and score of a single student. In traversing the arrays, use pointers notation rather than array indices. (myArray->name or *(myArray).name) Make it a class. You will need a destructor because you are using dynamic arrays.

Solutions

Expert Solution

Solution:

Here is the code updated for you:

#include <iostream>
#include <iomanip>
using namespace std;

typedef struct
{
string name;
double testScore;
}Records;

//Function prototypes
void arrSelectSort(Records *, int);
double arrAvgScore(Records *, int);
//Allow the user to enter name-score pairs.

int main()
{
//Define variables
Records *TestScores;
double total = 0.0, average;
int numTest, count;
//Get the number of test scores you wish to average and put in order
cout << "How many test scores do you wish to enter?";
cin >> numTest;
//Dynamically allocate an array large enough to hold that many scores
TestScores = new Records[numTest];
//Get the test scores
cout << "Enter the test scores below.\n";
for (count = 0; count < numTest; count++)
{
//Display score
cout << "Name " << (count + 1) << ": ";
cin >> (TestScores + count)->name;
cout << "Test Score " << (count + 1) << ": ";
cin >> TestScores[count].testScore;
// Input validation. Only numbers between 0-100
while ((TestScores + count)->testScore<0 || (TestScores + count)->testScore>99)
{
cout << "You must enter a scores that non-negative" << endl;
cout << "Please enter again: ";
cin >> TestScores[count].testScore;
}
}
//Dsiplay the results
arrSelectSort(TestScores, numTest);
average = arrAvgScore(TestScores, numTest);
cout << fixed << showpoint << setprecision(2);
cout << "The test scores, sorted in ascending order, are: \n";
for (count = 0; count < numTest; count++)
cout << (TestScores + count)->name << " " << (TestScores + count)->testScore << endl;
cout << endl;
cout << "The average of all the test score is " << average << endl;
//Free dynamically allocated memory
delete [] TestScores;
TestScores = 0; //make TestScores point to null
//Display the Test Scores in ascending order
//system ("pause");
return 0;
}
//Ascending order selection sort
void arrSelectSort(Records *arr, int size)
{
int startScan;
int minIndex;
double minElem;
for(startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minElem = (arr + startScan)->testScore;
for(int index = startScan; index < size; index++)
{
if ((arr + index)->testScore < minElem)
{
minElem = (arr + index)->testScore;
minIndex = index;
}
}
if(minIndex!=startScan)
{
Records temp = arr[minIndex];
arr[minIndex] = arr[startScan];
arr[startScan] = temp;
}
}
}
double arrAvgScore (Records *arr, int size)
{
double total = 0,average;
int numTest;
for (int count = 0; count < size; count++)
{
total += (arr + count)->testScore;
}
average = total / size;
return average;
}

#please consider my effort and give me a like...thank u....


Related Solutions

In c++, modify this program so that you allow the user to enter the min and...
In c++, modify this program so that you allow the user to enter the min and maximum values (In this case they cannot be defined as constants, why?). // This program demonstrates random numbers. #include <iostream> #include <cstdlib> // rand and srand #include <ctime> // For the time function using namespace std; int main() { // Get the system time. unsigned seed = time(0); // Seed the random number generator. srand(seed); // Display three random numbers. cout << rand() <<...
In C++ Modify the program #1 to allow the user to enter name-score pairs. For each...
In C++ Modify the program #1 to allow the user to enter name-score pairs. For each student taking a test, the user types a string representing the name of the student, followed by an integer representing the student's score. (use a structure) Modify the average-calculating function so they take arrays of structures, with each structure containing the name and score of a single student. In traversing the arrays, use pointers notation rather than array indices. (myArray->name or *(myArray).name) Make it...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
Write a C++ program that : 1. Allow the user to enter the size of the...
Write a C++ program that : 1. Allow the user to enter the size of the matrix such as N. N must be an integer that is >= 2 and < 11. 2. Create an vector of size N x N. 3. Call a function to do the following : Populate the vector with N2 distinct random numbers. Display the created array. 4. Call a function to determines whether the numbers in n x n vector satisfy the perfect matrix...
Write a program that asks the user to enter five test scores. The program should display...
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: calcAverage: This method should accept five test scores as arguments and return the average of the scores. determineGrade: This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale: Score Letter Grade 90-100...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program should display a letter grade for each score and the average test score. Hint: Declare local variables under main() program Prompts the user to enter 5 test scores Define a function to calculate the average score: this should accept 5 test scores as argument and return the avg Define a function to determine the letter grade: this should accept a test score as argument...
Modify the Tip Calculator app to allow the user to enter the number of people in...
Modify the Tip Calculator app to allow the user to enter the number of people in the party. Calculate and display the amount owed by each person if the bill were to be split evenly among the party members. Code: ----------------TipCalculator.java----------------------- import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class TipCalculator extends Application { @Override public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("TipCalculator.fxml")); Scene scene = new Scene(root); // attach scene graph to scene...
Instructions Write a Java program that asks the user t enter five test scores. The program...
Instructions Write a Java program that asks the user t enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: * calcAverage -- This method should accept five test scores as arguments and return the average of the scores. * determineGrade -- This method should accept a test score as an argument and return a letter grade for the score, based on the following...
create a program that will allow the user to enter a start value from 1 to...
create a program that will allow the user to enter a start value from 1 to 5, a stop value from 10 to 12 and a multiplier from 1 to 4. the program must display a multiplication table from the values entered. for example if the user enters: start 2, stop 10 and multiplier 3, the table should appear as follows: 3*2=6 3*3=9 3*4=12 . . . 3*10=30
Write a C++ program to allow a user to enter in any positive number greater than...
Write a C++ program to allow a user to enter in any positive number greater than or equal to zero. The program should not continue until the user has entered valid input. Once valid input has been entered the application will determine if the number is an abundant number or not and display whether or not the number is an abundant number. If the user enters in a 0 the program should quit. An abundant number is a number n...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT