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...
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...
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...
IN C LANGUAGE This program will read in a series of strings and print only the...
IN C LANGUAGE This program will read in a series of strings and print only the consonants (including Y) until the word "stop" appears. No string will be longer than 100 characters. A consonant is any letter that is not a vowel. Don't forget to follow the standard read pattern! Examples Enter a string: Hello Hll Enter a string: World! Wrld Enter a string: 123! Enter a string: stop Enter a string: stop
Program this using C please The program will read from standard input two things - a...
Program this using C please The program will read from standard input two things - a string str1 on the first line of stdin (this string may be an empty string) - a string str2 on the second line of stdin (this string may be an empty string) Note that stdin does not end with '\n'. The program will output a string that is the concatenation of string str1 and string str2 such that any lower-case alphabet character (a-z) will...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
Complete the following table and test whether there is a difference among the group means at...
Complete the following table and test whether there is a difference among the group means at a 0.025 level of significance. Source df SS MS F Among Groups 787.5 3.5 Within Groups 16 1200 Total
write a c++ program to read two matrices with any size. Your program should have at...
write a c++ program to read two matrices with any size. Your program should have at least the following functions Main() Read a Matrix Add two matrices Subtract two matrices multiply two matrices display a matrice
Please write a complete C coding program (NOT C++) that has the following: (including comments) -...
Please write a complete C coding program (NOT C++) that has the following: (including comments) - declares two local integers x and y - defines a global structure containing two pointers (xptr, yptr) and an integer (z) - declares a variable (mst) by the type of previous structure - requests the values of x and y from the user using only one scanf statement - sets the first pointer in the struct to point to x - sets the second...
Write a C++ program that will read in the number of nodes (less than 10) and...
Write a C++ program that will read in the number of nodes (less than 10) and a adjacency relation representing a graph. The program will create an adjacency matrix from the adjacency relation. The program will then print the following items: 1. Print the adjacency matrix 2. Determine if there are any isolated nodes and print them 3. Determine if an Euler path exists Sample run output Please input the number of nodes: 6 Please input the adjacency relation: {(1,2),(1,5),(2,1),(2,3),(3,2),(3,4),(4,3),(4,5),(5,1),(5,4)}...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT