Question

In: Computer Science

C++, Complete this program as directed // This program will read in a group of test...

C++, Complete this program as directed

// This program will read in a group of test scores (positive integers from 1 to 100)
// from the keyboard and then calculate and output the average score
// as well as the highest and lowest score. There will be a maximum of 100 scores.
// PLACE YOUR NAME HERE
#include <iostream>
using namespace std;
typedef int GradeType[100]; // declares a new data type:
// an integer array of 100 elements
float findAverage (const GradeType, int); // finds average of all grades
int findHighest (const GradeType, int); // finds highest of all grades
int findLowest (const GradeType, int); // finds lowest of all grades
int main()
{
GradeType grades; // the array holding the grades.
int numberOfGrades; // the number of grades read.
int pos; // index to the array.
float avgOfGrades; // contains the average of the grades.
int highestGrade; // contains the highest grade.
int lowestGrade; // contains the lowest grade.
// Read in the values into the array
pos = 0;
cout << "Please input a grade from 1 to 100, (or -99 to stop)" << endl;

cin >> grades[pos];
while (grades[pos] != -99)
{
// Fill in the code to read the grades
}
numberOfGrades = ; // Fill blank with appropriate identifier
// call to the function to find average
avgOfGrades = findAverage(grades, numberOfGrades);
cout << endl << "The average of all the grades is " << avgOfGrades << endl;
// Fill in the call to the function that calculates highest grade
cout << endl << "The highest grade is " << highestGrade << endl;
// Fill in the call to the function that calculates lowest grade
// Fill in code to write the lowest to the screen
return 0;
}
//********************************************************************************
// findAverage
//
// task: This function receives an array of integers and its size.
// It finds and returns the average of the numbers in the array
// data in: array of floating point numbers
// data returned: average of the numbers in the array
//
//********************************************************************************
float findAverage (const GradeType array, int size)
{
float sum = 0; // holds the sum of all the numbers
for (int pos = 0; pos < size; pos++)
sum = sum + array[pos];
return (sum / size); //returns the average

}

//****************************************************************************
// findHighest
//
// task: This function receives an array of integers and its size.
// It finds and returns the highest value of the numbers in the array
// data in: array of floating point numbers
// data returned: highest value of the numbers in the array
//
//****************************************************************************
int findHighest (const GradeType array, int size)
{
/ Fill in the code for this function
}
//****************************************************************************
// findLowest
//
// task: This function receives an array of integers and its size.
// It finds and returns the lowest value of the numbers in the array
// data in: array of floating point numbers
// data returned: lowest value of the numbers in the array
//
//****************************************************************************
int findLowest (const GradeType array, int size)
{
// Fill in the code for this function
}

Solutions

Expert Solution

Please find below the code, code screenshots and output screenshots. Please refer to the screenshot of the code to understand the indentation of the code.  Please get back to me if you need any change in code. Else please upvote

CODE:

// This program will read in a group of test scores (positive integers from 1 to 100)

// from the keyboard and then calculate and output the average score

// as well as the highest and lowest score. There will be a maximum of 100 scores.

// PLACE YOUR NAME HERE

#include <iostream>

using namespace std;

typedef int GradeType[100]; // declares a new data type:

// an integer array of 100 elements

float findAverage (const GradeType, int); // finds average of all grades

int findHighest (const GradeType, int); // finds highest of all grades

int findLowest (const GradeType, int); // finds lowest of all grades

int main()

{

    GradeType grades; // the array holding the grades.

    int numberOfGrades; // the number of grades read.

    int pos; // index to the array.

    float avgOfGrades; // contains the average of the grades.

    int highestGrade; // contains the highest grade.

    int lowestGrade; // contains the lowest grade.

   

    // Read in the values into the array

    pos = 0;

    cout << "Please input a grade from 1 to 100, (or -99 to stop)" << endl;

    cin >> grades[pos];

    while (grades[pos] != -99)

    {

        pos++; //Increment pos by 1

        cin >> grades[pos]; //Reading the grades

    }

    numberOfGrades = pos--; //pos - 1 will be the number of grades

   

    // call to the function to find average

    avgOfGrades = findAverage(grades, numberOfGrades);

    cout << endl << "The average of all the grades is " << avgOfGrades << endl;

   

    // call to the function that calculates highest grade

    highestGrade = findHighest(grades, numberOfGrades);

    cout << endl << "The highest grade is " << highestGrade << endl;

   

    // call to the function that calculates lowest grade

    lowestGrade = findLowest(grades, numberOfGrades);

    cout << endl << "The lowest grade is " << lowestGrade << endl;

   

    return 0;

}

//********************************************************************************

// findAverage

//

// task: This function receives an array of integers and its size.

// It finds and returns the average of the numbers in the array

// data in: array of floating point numbers

// data returned: average of the numbers in the array

//

//********************************************************************************

float findAverage (const GradeType array, int size)

{

    float sum = 0; // holds the sum of all the numbers

    for (int pos = 0; pos < size; pos++)

      sum = sum + array[pos];

       

    return (sum / size); //returns the average

}

//****************************************************************************

// findHighest

//

// task: This function receives an array of integers and its size.

// It finds and returns the highest value of the numbers in the array

// data in: array of floating point numbers

// data returned: highest value of the numbers in the array

//

//****************************************************************************

int findHighest (const GradeType array, int size)

{

    int highest = array[0]; // holds the highest of all the numbers. Initialize it to first element

    for (int pos = 0; pos < size; pos++){ //loop through each array elements

        if(highest < array[pos]) //if current highest is less than array element

            highest = array[pos]; //make array element as highest

    }

    return highest;

}

//****************************************************************************

// findLowest

//

// task: This function receives an array of integers and its size.

// It finds and returns the lowest value of the numbers in the array

// data in: array of floating point numbers

// data returned: lowest value of the numbers in the array

//

//****************************************************************************

int findLowest (const GradeType array, int size)

{

    int lowest = array[0];   // holds the lowest of all the numbers. Initialize it to first element

    for (int pos = 0; pos < size; pos++){ //loop through each array elements

        if(lowest > array[pos]) //if current lowest is greater than array element

            lowest = array[pos]; //make array element as lowest

    }

    return lowest;

}

OUTPUT:


Related Solutions

Write a complete C program that read the text below and save the text in a...
Write a complete C program that read the text below and save the text in a new file "second.txt" with the same text written in all uppercase. "Beedle the Bard was an English wizard and author of wizarding fairytales. Beedle was born in Yorkshire, England. At some point in his life he wrote The Tales of Beedle the Bard . The only known image of Beedle is a woodcut that shows him with a "luxuriant" beard. Beedle wrote in ancient...
In this assignment, you shall create a complete C++ program that will read from a file,...
In this assignment, you shall create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name Next it will need to read three integer values that will represent the 3 exam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student. Below...
In this program you will read a file specifying a directed graph G as a list...
In this program you will read a file specifying a directed graph G as a list of edges. Each edge u →v is listed on one line as u v. The input file simply lists the edges in arbitrary order as pairs of vertices, with each edge on a separate line. The vertices are numbered in order from 1 to the total number of vertices. The program outputs the out-degree sequence for GSCC in increasing order. For example for the...
In this program you will read a file specifying a directed graph G as a list...
In this program you will read a file specifying a directed graph G as a list of edges. Each edge u →v is listed on one line as u v. The input file simply lists the edges in arbitrary order as pairs of vertices, with each edge on a separate line. The vertices are numbered in order from 1 to the total number of vertices. The program outputs the out-degree sequence for GSCC in increasing order. For example for the...
Complete the given C++ program (prob1.cpp) to read an array of integers, print the array, and...
Complete the given C++ program (prob1.cpp) to read an array of integers, print the array, and then find the index of the largest element in the array. You are to write two functions, printArray() and getIndexLargest(), which are called from the main function. printArray() outputs integers to std::cout with a space in between numbers and a newline at the end. getIndexLargest () returns the index of the largest element in the array. Recall that indexes start at 0. If there...
For your first project, write a C program (not a C++ program!)that will read in a...
For your first project, write a C program (not a C++ program!)that will read in a given list of non-negative integers and a target integer and checks if there exist two integers in the list that sum up to the target integer. Example:List: 31, 5, 8, 28, 15, 21, 11, 2 Target: 26 Yes!, 44 No! your C program will contain the following: •Write a function that will make a copy of the values from one array to another array....
Complete the program to read in values from a text file. The values will be the...
Complete the program to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows) and the number...
Complete the program to read in values from a text file. The values will be the...
Complete the program to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows) and the number...
Write a C++ program to read characters from the keyboard until a '#' character is read....
Write a C++ program to read characters from the keyboard until a '#' character is read. Then the program will find and print the number of uppercase letters read from the keyboard.
Write and test a C program to implement Bubble Sort. . In your C program, you...
Write and test a C program to implement Bubble Sort. . In your C program, you should do: Implement the array use an integer pointer, get the size of the array from standard input and use the malloc function to allocate the required memory for it. Read the array elements from standard input. Print out the sorted array, and don’t forget to free the memory. Debug your program using Eclipse C/C++ CDT.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT