46.7k views
5 votes
Write a program that will ask the user to input 5 test grades. Store the test grades in an array. Last output the tests from the array onto the display screen.

Sample Run: Your program must run exactly like the example below.

Enter grade 1: 100

Enter grade 2: 90

Enter grade 3: 89

Enter grade 4: 77

Enter grade 5: 100

Grade #1: 100

Grade #2: 90

Grade #3: 89

Grade #4: 77

Grade #5: 100

Press any key to continue

2 Answers

6 votes

Answer:

Following are the program of C++

#include <iostream> // header file

#include <iomanip> // header file

using namespace std; // namespace

int main() // main function

{

int grade[5],k; // declaration of array and variable

for (int i = 0; i< 5; i++) // iterating over the loop

{

cout << "Enter grade ";

cin >> grade[i]; // read the grade by the user

}

k=0;

while(k<5) // iterating over the loop

{

cout << "Grade #" << k + 1 << ": ";

cout << grade[k] << endl; // display the grade

k++; // increment of i

}

}

Output:

Enter grade 45

Enter grade 5

Enter grade 8

Enter grade 6

Enter grade 7

Grade #1: 45

Grade #2: 5

Grade #3: 8

Grade #4: 6

Grade #5: 7

Step-by-step explanation:

User Rlatief
by
4.2k points
4 votes

Answer:

Following are the program of C++

#include <iostream> // header file

#include <iomanip> // header file

using namespace std; // namespace

int main() // main function

{

int grade[5],k; // declaration of array and variable

for (int i = 0; i< 5; i++) // iterating over the loop

{

cout << "Enter grade ";

cin >> grade[i]; // read the grade by the user

}

k=0;

while(k<5) // iterating over the loop

{

cout << "Grade #" << k + 1 << ": ";

cout << grade[k] << endl; // display the grade

k++; // increment of i

}

}

Output:

Enter grade 45

Enter grade 5

Enter grade 8

Enter grade 6

Enter grade 7

Grade #1: 45

Grade #2: 5

Grade #3: 8

Grade #4: 6

Grade #5: 7

Explanation:

The description of the program is given below.

  • Declared an array "grade" of int type
  • Read the grade elements by the user using the for loop
  • finally, display the grade in the given format which is mention in the question.
User GoWiser
by
4.5k points