In: Computer Science
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a Student, and then finally GPA. Have items neatly line up in columns.
I need help creating a derived class called student that finds GPA (between 0.0 and 4.0) and credits completed (between 0 and 199).
Source code:
#include <iostream>
using namespace std;
struct student
{
char name[50];
int roll;
float Credits;
};
int main()
{
student s;
cout << "Enter the student information," << endl;
cout << "Enter the student name: ";
cin >> s.name;
cout << "Enter roll number: "<<endl;
cin >> s.roll;
cout << "Enter Credits Completed(0 to 199): "<<endl;
cin >> s.Credits;
cout << "Displaying Information," << endl;
cout << "Name: " << s.name << endl;
cout << "Roll: " << s.roll << endl;
cout<<"GPA and Grade: "<<s.Credits;
if (s.Credits>150){
cout << "GPA 4 Grade: A"<<endl;
}
else if(150>s.Credits>100){
cout<<"GPA 3 Grade: B"<<endl;
}
else if(100>s.Credits>50){
cout<<"GPA 2 Grade: C"<<endl;
}
else if(50>s.Credits){
cout<<"GPA 1 Grade: D"<<endl;
}
return 0;
}
The output: