Write a program to read the GPA of students from users and display the details using dynamic memory allocation.
Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.
Include the following member function in the Main class
Member FunctionDescriptionvoid display(float arr[], int size)This method is used to display the student's GPA details.
In the main method, obtain input from the user in the console and call the display method to display the GPA details.
Note:
Use a new keyword to create a dynamic array to store the GPA details.
OUTPUT
Enter total number of students:
2
Enter GPA of students
7.8
6.7
Students GPA Details
Student1 : 7.8
Student2 : 6.7
#include <iostream>
using namespace std;
void display(float arr[], int size){
cout<<"\nStudents GPA Details\n";
for(int i=0;i<size;i++){
cout<<"\nStudent"<<(i+1)<<":"<<arr[i];
}
}
int main()
{
cout<<"\nEnter total number of students:";
int n;
cin>>n;
float *GPA = new float[n];
cout<<"\nEnter GPA of students: \n";
for(int i=0;i<n;i++){
cin>>GPA[i];
}
display(GPA,n);
delete [] GPA;
return 0;
}
Comments
Leave a comment