Question

// PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); //...

// PLACE YOUR NAME HERE

#include <iostream>

using namespace std;

float findAverage (int [], int); // finds average of all //grades

int findHighest (int [], int); // finds highest of all //grades

int findFirstFail( int[]);

int main()

{

int grades[100]; // the array holding 100 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 inderOfFail; // contains the position of first failing score.

//A failing score is below 50

//you will need to edit the code to read 100 values from a text //file

// 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++;

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

cin >> grades[pos];

}

numberOfGrades = pos; // number of values stored.

// 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 identifies the highest grade

// and assigns the value returned to the identifier highestGrade

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

// write the code as a loop to output all the elements

//Fill in the call of the function that returns at index of a score //less than 50.

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 array

//

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

float findAverage (int 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, size of the array

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

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

int findHighest (int array[], int size)

{

// Fill in the code for this function

}

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

// findFirstFail

//

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

// It finds and returns the position of the first score less than 50 //of the numbers in the array. A score of less than 50 is a failing //score

// data in: array of floating point numbers, size of the array

// data returned: index of the first element found to hold a value less //than 50

//

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

int findFirstFail (int array[], int size)

{

// Fill in the code for this function

}

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

int findHighest (int array[], int size)

{

int max = array[0];

for(int i=1; i<size; i++)

{

if(array[i] > max)

max = array[i];

}

return max;

}

int findFirstFail (int array[], int size)

{

int index = 0;

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

{

if(array[i] < 50)

{

index = i;

break;

}

}

return index;

}

Add a comment
Know the answer?
Add Answer to:
// PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); //...
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
  • #include <iostream> using namespace std; int * newZeroArray(int size) { //your code here } int main()...

    #include <iostream> using namespace std; int * newZeroArray(int size) { //your code here } int main() { int size = 10; int * A = newZeroArray(size); for(int i = 0; i < size; i++) cout << A[i] << " "; cout << endl; }Write a function that takes a size, creates a new array of that size with all zeros, and returns the array. If the size is not a valid size for an array, do not return a valid...

  • Arrays C++ #include <iostream> using namespace std; int main() {       int   tests[6]; // array declaration...

    Arrays C++ #include <iostream> using namespace std; int main() {       int   tests[6]; // array declaration       int   sum = 0;       float avg;       //input test scores       cout << " Enter " << 6 << " test scores: " << endl;       for (int i = 0; i < 6; i++)       {             cout << "Enter Test " << i + 1 << ": ";             cin >> tests[i];       }       return 0; }    Type...

  • #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool...

    #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...

  • #include<iostream> #include<cstdlib> using namespace std; int main() {     // create array of size 20    ...

    #include<iostream> #include<cstdlib> using namespace std; int main() {     // create array of size 20     int arr[20];         int i;         cout<<"scores : ";     for( i = 0 ; i < 20 ; i++ )     {         // generate a random number i range 70 - 100 an add it to arr         arr[i] = rand() % 31 + 70;                 cout<<arr[i]<<" ";     }         // store the total score     int total = 0;...

  • #include<iostream> using namespace std; int main() { float num,avg,sum=0.0; int count=0; bool moreNumbers=true; cout<<"Enter grades:"<<endl; while(moreNumbers)...

    #include<iostream> using namespace std; int main() { float num,avg,sum=0.0; int count=0; bool moreNumbers=true; cout<<"Enter grades:"<<endl; while(moreNumbers) { cin>>num; if(num < 0) { moreNumbers=false; } else { count = count+1; sum=sum+num; } } avg=sum/count; cout<<"Average grade:"<<avg<<endl; cout<<"How many grades were entered:"<<count<<endl; return 0; } Question: We need to add another loop to check input. Just like the input loop we already have, this one should use a boolean variable as a control. So, the logic could be something like this: Loop...

  • One dimensional array What this code print #include <iostream> using namespace std; int main () {...

    One dimensional array What this code print #include <iostream> using namespace std; int main () { const int SIZE = 7; int numbers [SIZE] = {1, 2, 4, 8): // Initialize first 4 elements cout << “Here are the contents of the array:\n"; for (int index = 0; index < SIZE: index++} cout << numbers[index] << “ “; cout << endl; return 0; }

  • #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...

    #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){    int number;    int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl;    displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl;    return 0;       } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...

  • Fix the following program (C++). #include <iostream> #include <cmath> #include <vector> #include <limits> using namespace std;...

    Fix the following program (C++). #include <iostream> #include <cmath> #include <vector> #include <limits> using namespace std; /* * Calculate the square of a number */ float square (float x) { return x*x; } /* * Calculate the average from a list of floating point numbers */ float average(vector<float>& values) { float sum = 0.0f; float average; for (float x : values) sum += x; average = sum / values.size(); return average; } /** Calculate the standard deviation from a vector...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input:...

    c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...

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