Question

c++ Instructions Overview In this programming challenge you will create a program to handle student test...

c++

Instructions

Overview
In this programming challenge you will create a program to handle student test scores.  You will have three tasks to complete in this challenge.
Instructions

Task 1

Write a program that allocates an array large enough to hold 5 student test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings.

Input Validation: Do not accept negative numbers for test scores.

Task 2

Modify the program so the lowest test score is dropped. This score should not be included in the calculation of the average.
Task 3
Modify the program to allow the user to enter name-score pairs. For each student taking a test, the user types the student’s name followed by the student’s integer test score. Modify the sorting function so it takes an array holding the student names and an array holding the student test scores. When the sorted list of scores is displayed, each student’s name should be displayed along with his or her score.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Task 1:

#include <iostream>

using namespace std;

//function to sort the array arr of size n.

//using bubble sort to sort the array

void sortScores(int arr[], int n) {

for (int i = 0; i < n-1; i++)

{

for (int j = 0; j < n-i-1; j++)

{

if (arr[j] > arr[j+1])

{

int temp = arr[j];

arr[j] = arr[j+1];

arr[j+1] = temp;

}

}

}

}


//functuin to calculate the average of the array arr or size n.

double average(int arr[], int n) {

double sum = 0;

//calculating sum of all elements

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

sum += arr[i];

}

return sum/n;

}


int main() {

//declaring array

int score[5];

//reading user input

cout << "Enter scores of student: " << endl;

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

int temp;

cout << "Student " << i+1 << ": ";

cin >> temp;

//checking if the entered score is negative

while(temp < 0) {

cout << "Score should be a positive number!!" << endl;

cout << "Student " << i+1 << ": ";

cin >> temp;

}

score[i] = temp;

}

sortScores(score, 5); //calliung to sort the array

int sum = 0;

cout << "\n\nStudent Scores: \n";

//pritng the student scores

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

cout << "Student " << i+1 << ": " << score[i] << endl;

}


//printing average

cout << "\n\nAverage score: " << average(score, 5) << endl;

}

_________________________________________________________________________________________________________________________________________________________________________________________________

Task 2:

#include <iostream>

using namespace std;

//function to sort the array arr of size n.

//using bubble sort to sort the array

void sortScores(int arr[], int n) {

for (int i = 0; i < n-1; i++)

{

for (int j = 0; j < n-i-1; j++)

{

if (arr[j] > arr[j+1])

{

int temp = arr[j];

arr[j] = arr[j+1];

arr[j+1] = temp;

}

}

}

}


//functuin to calculate the average of the array arr or size n.

double average(int arr[], int n) {

double sum = 0;

//calculating sum of all elements

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

sum += arr[i];

}

return sum/n;

}

//drop

void dropLowest(int arr[], int n,int* newArr, int *size) {

//initialisng value to 0

*size = 0;

//findign the min, valkue in array

int min = arr[0];

for(int i = 1 ; i < n ; i++) {

if(min > arr[i]) min = arr[i];

}

//if value is not equal to min, then add it to new array and update new array size

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

if(arr[i] != min){

newArr[*size] = arr[i];

*size += 1;

}

}

}

int main() {

//declaring array

int score[5];

//reading user input

cout << "Enter scores of student: " << endl;

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

int temp;

cout << "Student " << i+1 << ": ";

cin >> temp;

//checking if the entered score is negative

while(temp < 0) {

cout << "Score should be a positive number!!" << endl;

cout << "Student " << i+1 << ": ";

cin >> temp;

}

score[i] = temp;

}

sortScores(score, 5); //calliung to sort the array

int sum = 0;

cout << "\n\nStudent Scores: \n";

//pritng the student scores

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

cout << "Student " << i+1 << ": " << score[i] << endl;

}


//printing average

cout << "\n\nAverage score: " << average(score, 5) << endl;

//drop the lowest test score.

//this variable will store the size of the new array without the lowest score.

int size;

int newScore[5];

dropLowest(score, 5, newScore, &size);

cout << "\n\nStudent Scores without lowest: \n";

//pritng the student scores

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

cout << "Student " << i+1 << ": " << newScore[i] << endl;

}

cout << "\n\nNew Average score: " << average(newScore, size) << endl;

}

______________________________________________________________________________________________________________________________________________________________________________________________________

Task 3:

#include <iostream>

using namespace std;

//function to sort the array arr of size n.

//using bubble sort to sort the array

void sortScores(int arr[], string name[], int n) {

for (int i = 0; i < n-1; i++)

{

for (int j = 0; j < n-i-1; j++)

{

//as we swap the score, same we swap the names

if (arr[j] > arr[j+1])

{

int temp = arr[j];

string tempS = name[j];

arr[j] = arr[j+1];

name[j] = name[j+1];

arr[j+1] = temp;

name[j+1] = tempS;

}

}

}

}


//functuin to calculate the average of the array arr or size n.

double average(int arr[], int n) {

double sum = 0;

//calculating sum of all elements

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

sum += arr[i];

}

return sum/n;

}

//drop

void dropLowest(int arr[], int n,int* newArr, int *size) {

//initialisng value to 0

*size = 0;

//findign the min, valkue in array

int min = arr[0];

for(int i = 1 ; i < n ; i++) {

if(min > arr[i]) min = arr[i];

}

//if value is not equal to min, then add it to new array and update new array size

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

if(arr[i] != min){

newArr[*size] = arr[i];

*size += 1;

}

}

}

int main() {

//declaring array

int score[5];

string name[5];

//reading user input

cout << "Enter student details: " << endl;

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

int temp;

cout << "Student " << i+1 << ":\n";

cout << "Name: ";

cin >> name[i];

cout << "score: ";

cin >> temp;

//checking if the entered score is negative

while(temp < 0) {

cout << "Score should be a positive number!!" << endl;

cout << "score: ";

cin >> temp;

}

score[i] = temp;

}

sortScores(score, name, 5); //calliung to sort the array

int sum = 0;

cout << "\n\nStudent Scores: \n";

//pritng the student scores

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

cout << "Student " << i+1 << ": Name: " <<name[i] << "\t\tScore: "<<score[i] << endl;

}


//printing average

cout << "\n\nAverage score: " << average(score, 5) << endl;

//drop the lowest test score.

//this variable will store the size of the new array without the lowest score.

int size;

int newScore[5];

dropLowest(score, 5, newScore, &size);

cout << "\n\nStudent Scores without lowest: \n";

//pritng the student scores

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

cout << "Student " << i+1 << ": " << newScore[i] << endl;

}

cout << "\n\nNew Average score: " << average(newScore, size) << endl;

}

Add a comment
Know the answer?
Add Answer to:
c++ Instructions Overview In this programming challenge you will create a program to handle student test...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • read it carefully C++ Question: Write a program that dynamically allocates an array large enough to...

    read it carefully C++ Question: Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Use pointer notation rather than array notation whenever possible. Input Validation: Do not...

  • Write a program that uses pointer notation to dynamically allocate parallel array(s) large enough to hold...

    Write a program that uses pointer notation to dynamically allocate parallel array(s) large enough to hold a user-defined number of test scores and student names, using parallel arrays. After student names and corresponding scores are entered, the array(s) should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score for the group (do not include the lowest score in the calculation of average grade). The program should display the...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • in C++ Create a program that will calculate a student’s grade average of 5 test scores...

    in C++ Create a program that will calculate a student’s grade average of 5 test scores and assign a letter grade for a student. The program should use a class to store the student’s data including the student’s name and score on each of 5 tests. The program should include member functions to 1) get the student’s test scores, 2) calculate the average of the test scores, and 3) display the results as follows: Test scores for Mary: 100 90...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • Create a C++ program to : Prompt user for seven test score Store the scores into...

    Create a C++ program to : Prompt user for seven test score Store the scores into an array Print the array before and after sorting Print the test average Convert the average to letter grade Search for a test score 90, using linear search Print, if test score 90 was found and at what position Add Comments SEPARATE THE FILES INTO 3 : header.h, functions.cpp, main.cpp

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • Create a C++ program to calculate grades as well as descriptive statistics for a set of...

    Create a C++ program to calculate grades as well as descriptive statistics for a set of test scores. The test scores can be entered via a user prompt or through an external file. For each student, you need to provide a student name (string) and a test score (float). The program will do the followings: Assign a grade (A, B, C, D, or F) based on a student’s test score. Display the grade roster as shown below: Name      Test Score    ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT