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:
- Declare three 1D arrays each of size 15 to represent the Id, Grade, and Percentage arrays.
- 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.
- Store the data into the Id and Grade arrays, and calculate the percentage grade for each student, storing it in the Percentage array.
- 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;
}