Question

Fix this C++ code so that the function prototypes come before main. Main needs to be...

Fix this C++ code so that the function prototypes come before main. Main needs to be declared first. Then call to the functions from inside of main.

#include<cstdlib>
using namespace std;

//prompt user for input
void getGrades(int gradeArray[],int size)
{
for(int i=0; i<size; i++)
{
cout<<"Enter the grade "<<i+1<<": ";
cin>>gradeArray[i];
}
}

// finding average of all numbers in array
float computeAverage(int numbers[],int size)
{
float sum=0;
for(int i=0; i<size; i++)
{
sum = sum + numbers[i]; //compute sum of all numbers in array
}
return(sum/size); // average is sum divided by numbers of elements
}

//print the array
void printInts(int intArray[],int size)
{
for(int i=0; i<size; i++)
{
cout<<intArray[i]<<" ";
}
}

//generate random numbers within given range
int getRandom(int begin,int end)
{
int randomNumber= begin + ( rand() % ( end - begin + 1 ) ); //using rand function for getting random number
return(randomNumber);
}
int main()
{
int grades[10];
getGrades(grades,10); //get input
cout<<"\nAverage of grades: "<<computeAverage(grades,10); //calculate average

int randomArray[20];
for(int i=0; i<20; i++)
{
randomArray[i]=getRandom(1,50); //fill randomArray
}
cout<<"\n\nContent of random array : ";
printInts(randomArray,20); //print randomArray
cout<<"\nAverage of random array: "<<computeAverage(randomArray,20);

return(0);
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>
#include <ctime>
#include <stdio.h>      
#include <stdlib.h> 

using namespace std;

//prompt user for input
void getGrades(int gradeArray[],int size);

// finding average of all numbers in array
float computeAverage(int numbers[],int size);

//print the array
void printInts(int intArray[],int size);

//generate random numbers within given range
int getRandom(int begin,int end);

int main()
{
int grades[10];
getGrades(grades,10); //get input
cout<<"\nAverage of grades: "<<computeAverage(grades,10); //calculate average

int randomArray[20];
for(int i=0; i<20; i++)
{
randomArray[i]=getRandom(1,50); //fill randomArray
}
cout<<"\n\nContent of random array : ";
printInts(randomArray,20); //print randomArray
cout<<"\nAverage of random array: "<<computeAverage(randomArray,20);

return(0);
}

void getGrades(int gradeArray[],int size)
{
for(int i=0; i<size; i++)
{
cout<<"Enter the grade "<<i+1<<": ";
cin>>gradeArray[i];
}
}

// finding average of all numbers in array
float computeAverage(int numbers[],int size)
{
float sum=0;
for(int i=0; i<size; i++)
{
sum = sum + numbers[i]; //compute sum of all numbers in array
}
return(sum/size); // average is sum divided by numbers of elements
}

//print the array
void printInts(int intArray[],int size)
{
for(int i=0; i<size; i++)
{
cout<<intArray[i]<<" ";
}
}

//generate random numbers within given range
int getRandom(int begin,int end)
{
int randomNumber= begin + ( rand() % ( end - begin + 1 ) ); //using rand function for getting random number
return(randomNumber);
}
Add a comment
Know the answer?
Add Answer to:
Fix this C++ code so that the function prototypes come before main. Main needs to be...
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
  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write...

    Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write a program that adds the following to the fixed code. • Add a function that will use the BubbleSort method to put the numbers in ascending order. – Send the function the array. – Send the function the size of the array. – The sorted array will be sent back through the parameter list, so the data type of the function will be void....

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

    // 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. // #include <iostream> using namespace std; float findAverage (const int[], int); // finds average of all grades int findHighest (const int[], int); // finds highest of all grades int findLowest (const int[], int); //...

  • What did I do wrong with this C++ code? Assume that we don't need to ask...

    What did I do wrong with this C++ code? Assume that we don't need to ask users for the number of students. #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size; int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total; // average grade and total grades //**************start your code here************************ cout<<"How many student grades...

  • Implement and test a function that uses dynamic array to store students’ grades and calcuate the...

    Implement and test a function that uses dynamic array to store students’ grades and calcuate the average grade. // This program demonstrates the use of dynamic array // it #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size = 2; grades = new float[size];    int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total;...

  • #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:" <<...

  • // 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; //...

  • Please help me finish my code. Before the final pause in the main function, create an...

    Please help me finish my code. Before the final pause in the main function, create an ArrayList of another type such as double, char, short, bool, float, etc. Your choice. Add five data items to your array as we did for the int and string array lists. Print them out with a for loop as we did before. Print out the count and capacity of your new array list. Source.cpp #include #include #include #include "ArrayList.h" using namespace std; /// Entry...

  • Modify this C++ below to show the selection sorting algorithm method. Then write a test program...

    Modify this C++ below to show the selection sorting algorithm method. Then write a test program and show that it works. HINT: Replace the bubbleSort function with the selectionSort. Your test program should perform the following steps: Create an array of random numbers. Display the array in its original order. Pass the array to your sorting function. Display the array again to show that it has been sorted. Provide a screen shot showing that the above steps are working. CODE:...

  • How to measure the average performance of sorting algorithms with different sizes and numbers(with arrayList<Integer>) and...

    How to measure the average performance of sorting algorithms with different sizes and numbers(with arrayList<Integer>) and compare with a graph? I have these methods: //This one receives one size(n) parameter    public static ArrayList<Integer> RandomArray(int n){               ArrayList<Integer> randomArray = new ArrayList<Integer>(n);               Random rand = new Random(); //--- random number        rand.setSeed(System.currentTimeMillis());               for(int i = 0; i < n; i++ ) {            //loop for creating...

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