100k views
2 votes
Write a C++ program to read and store the data of 15 students. The input data of each of the 15 students consists of:

Id
Grade (integer), input grade should be valid in the range 0 .. 20
The program should do the following:
Declare three 1D arrays each of size 15 representing Id, Grade and Percentage arrays (Do not use 2D Arrays)
Read from the user Id and a valid grade (use validation loop) for each student and store the data into arrays, (the Id array and the Grade array) both are 1D arrays.
Find the percentage grade of each student and store it in the Percentage array.
Display all the data (Id, Grade and Percentage of all the 15 students) in a table (use setw) (DO NOT use ‘\t’). Display a heading for the table as shown below in the sample:
Example of a sample output of a table with heading:
ID Grade Percentage Grade
=====================================
900123 20 100
900234 10 50
900345 15 75

1 Answer

7 votes

Final answer:

To write a C++ program to read and store the data of 15 students, follow these steps: declare three 1D arrays for ID, Grade, and Percentage; use a loop to read and store the data for each student, validating the grade input; calculate the percentage grade for each student and display all the data in a table format.

Step-by-step explanation:

To write a C++ program to read and store the data of 15 students, you can follow these steps:

  1. Declare three 1D arrays each of size 15 to represent the Id, Grade, and Percentage arrays.
  2. Use a loop to read the Id and a valid grade for each student, making sure it is within the range of 0 to 20.
  3. Store the data into the Id and Grade arrays, and calculate the percentage grade for each student, storing it in the Percentage array.
  4. Display all the data in a table format using setw to align the columns.

Here is an example code snippet to illustrate the implementation:

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
int Id[15];
int Grade[15];
int Percentage[15];

for (int i = 0; i < 15; i++) {
cout << "Enter Id for student " << i+1 << ": ";
cin >> Id[i];

while (true) {
cout << "Enter Grade for student " << i+1 << ": ";
cin >> Grade[i];

if (Grade[i] >= 0 && Grade[i] <= 20)
break;
else
cout << "Invalid Grade. Please enter a valid value between 0 and 20." << endl;
}

Percentage[i] = (Grade[i] * 100) / 20;
}

cout << "ID Grade Percentage" << endl;
cout << "==============================" << endl;

for (int i = 0; i < 15; i++) {
cout << setw(6) << Id[i] << setw(6) << Grade[i] << setw(6) << Percentage[i] << endl;
}

return 0;
}

User Jjwdesign
by
7.8k points