Only the memory required to store num (entered by user) number of floating-point data is declared dynamically. Test Case 1 Input (stdin) 6 5.5 6.6 7.7 8.8 3.3 2.2 Expected Output Displaying GPA of students. Student1 :5.5 Student2 :6.6 Student3 :7.7 Student4 :8.8 Student5 :3.3 Student6 :2.2 Test Case 2 Input (stdin) 3 8.8 8.9 5.9 Expected Output Displaying GPA of students. Student1 :8.8 Student2 :8.9 Student3 :5.9
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int num;
// cout << "Enter total number of students: ";
cin >> num;
float* ptr;
// memory allocation of num number of floats
ptr = new float[num];
//cout << "Enter GPA of students." << endl;
for (int i = 0; i < num; ++i)
{
cin >> *(ptr + i);
}
cout << "\nDisplaying GPA of students." << endl;
for (int i = 0; i < num; ++i) {
cout << "Student" << i + 1 << " :" << *(ptr + i) << endl;
}
// ptr memory is released
delete [] ptr;
return 0;
}