I'm having hard time to fill the homework that my teacher assigned to us this morning, I missed a day of class and missed a lot of lectures.
Please help! I have no idea how to find the largest and the lowest number, and please don't explain it by words I prefer example, so I could see what's happening. My teacher sent me this code to fill. I'm sitting with no one to ask for help, found this web, register, then this. I hope you guys can help me ASAP. THANKS!
// This program will read in a group of test scores( positive integers from 1 to 100)
// from the keyboard and then calculates and outputs 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;
const int ARRAY_SIZE=100;
float findAverage (int array[], int size); // finds average of all grades
int findHighest (int array[], int size); // finds highest of all grades
int findLowest (int array[], int size); // finds lowest of all grades
int main()
{
int grades[ARRAY_SIZE]; // the array holding the grades.
int temp; // variable for the input number
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.
cout << "Please input a grade from 1 to 100, (or -99 to stop)" << endl;
// Fill in the call to the function that calculates highest grade
highestGrade= findHighest(grades, numberOfGrades);
// Fill in the call to the function that calculates lowest grade
cout << endl << "The average of all the grades is " << avgOfGrades << endl;
cout << endl << "The highest grade is " << highestGrade << endl;
// Fill in code to write the lowest to the screen
return 0;
} // end main
//****************************************************************************
// 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, size
// data returned: avarage of the numbers in the array
//
//****************************************************************************
float findAverage (int array[], int size)
{
float sum = 0; // holds the sum of all the numbers
if( size <=0 )
return 0;
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, size
// data returned: highest value of the numbers in the array
//
//***************************************************************************
int findHighest (int array[], int size)
{
//****************************************************************************
// 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, size
// data returned: lowest value of the numbers in the array
//
//****************************************************************************
// This program will read in a group of test scores( positive integers from 1 to 100)
// from the keyboard and then calculates and outputs 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>
usingnamespace std;
constint ARRAY_SIZE=100;
float findAverage (int array[], int size); // finds average of all grades
int findHighest (int array[], int size); // finds highest of all grades
int findLowest (int array[], int size); // finds lowest of all grades
#include <iostream>
usingnamespace std;
constint ARRAY_SIZE=100;
float findAverage (int array[], int size); // finds average of all grades
int findHighest (int array[], int size); // finds highest of all grades
int findLowest (int array[], int size); // finds lowest of all grades
int main()
{
int grades[ARRAY_SIZE]; // the array holding the grades.
int temp; // variable for the input number
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.
cout << "Please input a grade from 1 to 100, (or -99 to stop)" << endl;
cin >> temp;
if(temp!=-99 )
{
while(temp > 100 || temp < 0)
{
cout<<"Enter grade, grade > 0 and grade < 101"<<endl;
cin>>temp;
}
}
elsereturnfalse;
pos=0;
while(pos < ARRAY_SIZE && temp != -99)
{
// Fill in the code to assign temp to the next element in intArray
grades[pos] = temp;
// Fill in the code to read the next number
grades[pos];
++pos;
}// end for
numberOfGrades=ARRAY_SIZE; // Fill blank with appropriate identifier
avgOfGrades = findAverage(grades, numberOfGrades);
// Fill in the call to the function that calculates highest grade
highestGrade= findHighest(grades, numberOfGrades);
// Fill in the call to the function that calculates lowest grade
cout << endl << "The average of all the grades is " << avgOfGrades << endl;
cout << endl << "The highest grade is " << highestGrade << endl;
// Fill in code to write the lowest to the screen
return 0;
} // end main
//****************************************************************************
// 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, size
// data returned: avarage of the numbers in the array
//
//****************************************************************************
float findAverage (int array[], int size)
{
float sum = 0; // holds the sum of all the numbers
if( size <=0 )
return 0;
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, size
// data returned: highest value of the numbers in the array
//
//***************************************************************************
int findHighest (int array[], int size)
{
int largest;
while(largest < size)
largest=array[largest];
return largest;
// Fill in the code for this function
} // end findHighest
//****************************************************************************
// 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, size
// data returned: lowest value of the numbers in the array
//
//****************************************************************************
int findLowest (int array[], int size)
{
// Fill in the code for this function
} // end findLowest
You might find the bubblesort in a C++ book a useful example