Question

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 number of students. When the program starts, it should ask the user for the number of students to be processed. Then it should use the new operator to dynamically allocate an array of that size.

The program should then:

  • Call a function to input and validate the student grades and store them in the array.
  • Call a function to sort the array in ascending (increasing) order.
  • Call a value-returning function that returns the floating-point average of the grades.
  • Call a function that displays a neat table of student grades in sorted order. Include appropriate column headings for your table. Following the table, display the average score with appropriate label.

In general, you should use array notation when processing arrays because it makes your code easier to read and understand. However, to give you some practice using pointers with an array, I want you to use only pointer notation in your function to calculate the average. That is, you must declare the array parameter using pointer notation instead of array notation, and inside the function you must use pointer notation instead of array notation to access the array elements. If you do not understand this requirement, contact me.

Sample Output

        Grade
        -----
           75
           81
           88
        -----
Average  81.3

Requirements/Hints:

  1. Global variables are variables that are declared outside any function. Do not use global variables in your programs. Declare all your variables inside functions

Extra Credit:

For 5% extra credit, include the student's name along with the grade. Use a struct to hold the name and grade for one student. The name should be a C++ string object. Your array will now be an array of structs. Your program output should look something like:

Name                  Score
---------------------------
Jim Smith                75
Victor Montero           81
Christa Kim              88
---------------------------
Average                81.3

Important: to receive the extra credit you must turn in both versions of your program - the version with grades only and the version with names and grades.

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

Thanks for the question.


Here is the completed code for this problem. Comments are included so that you understand whats going on. Let me know if you have any doubts or if you need anything to change.


Thank You !!


=============================================================================

#include<iostream>
#include<iomanip>
#include<string>

using namespace std;

// ask user to enter the score, validates it between 1 and 105 and returns the score
int getStudentScore() {
int score=0;
while(score<1 || score>105) {
cout<<"Enter student score: ";
cin>>score;
if(score<1 || score>105)
cout<<"Score cannot be less than 0 or greater than 105"<<endl;
}
return score;
}

// using bubble sort to sort the scores in the array
// takes in the pointer and the size
void sortScores(int *scorePtr, int length) {

int i, j;
for (i = 0; i < length-1; i++)
// Last i elements are already in place
for (j = 0; j < length-i-1; j++) {
if (*(scorePtr+j) > *(scorePtr+j+1)) {
int temp = *(scorePtr+j);
*(scorePtr+j)=*(scorePtr+j+1);
*(scorePtr+j+1)=temp;
}
}
}

// returns the average score, takes in the pointer and the size
double getAverage(int *scorePtr, int length){
double total=0;
for(int i=0; i<length;i++){
total+=*(scorePtr+i);
}
return total/length;

}

int main() {

int studentCount=0;
cout<<"Enter the number of students: ";
cin>>studentCount;

int *scorePtr = new int[studentCount]; // returns the address of the first index of the array
for(int index=0; index<studentCount; index++) {
*(scorePtr+index)=getStudentScore();
}

sortScores(scorePtr,studentCount); // passes the pointer and the size of the array
double average = getAverage(scorePtr,studentCount); // passes the pointer and the size of the array

cout<<"\t Grade"<<endl;
cout<<"\t -----"<<endl;
for(int index=0; index<studentCount; index++) {
cout<<"\t "<<*(scorePtr+index)<<endl; // access the value at that index
}
cout<<"\t -----"<<endl<<"Average";
cout<<fixed<<showpoint<<setprecision(2)<<setw(10)<<average<<endl;

}

Add a comment
Know the answer?
Add Answer to:
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...
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
  • 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...

  • Using C programming For this project, you have been tasked to read a text file with student grade...

    Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • 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 a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • C++ Use C++ functions and build a program that does the most basic job all students...

    C++ Use C++ functions and build a program that does the most basic job all students have to contend with, process the grades on a test and produce a summary of the results. The big wrinkle is, it should be a multi-file program. -Requires three simple things: Figure out the best score of all scores produced Figure out the worst score of all scores produced Assign a letter grade for each score produced Complete this lab by writing three functions....

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a...

    Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

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