In C++, create an array called session1 that has 44 elements (44 students in session1). Each element of the array is an object of Student, where Student is declared as 'struct' with three data members called identification, scores, and grade. Randomly assign grades for each element ranging from [50,100]. MUST USE DYNAMIC ARRAYS.
Answer :- The C++ code for doing so is written below-
#include <iostream>
using namespace std;
typedef struct
{
int id;
int score;
float grade;
}student;
int main()
{
student* s = new student[44]; //dynamically creating the array for
44 students
cout << "Enter the grade of students: " << endl;
// storing information
for(int i = 0; i < 44; ++i)
{
s[i].id = i+1;
cout << "For id number" << s[i].id << ","
<< endl;
cout << "Enter grade: ";
cin >> s[i].grade;
cout << endl;
}
cout << "Displaying the grade: " << endl;
// Displaying information
for(int i = 0; i < 44; ++i)
{
cout << "\nRoll number: " << i+1 << endl;
cout << "Grade: " << s[i].grade << endl;
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.