Implement a class Student. A Student has a first name (string), last name (string) and CGPA (float).
Write a default constructor, an overloaded constructor with three parameters (first name, last
name and CGPA). In addition provide methods (functions) to return the full name and CGPA.
Write a small program to test your class by creating an object and invoking different functions
to get and set different class members.
#include<iostream>
#include<string>
using namespace std;
class Student
{
string first_name;
string last_name;
float CGPA;
public:
Student(){}
Student(string _first_name, string _last_name,float _CGPA)
:first_name(_first_name), last_name(_last_name), CGPA(_CGPA){}
void SetFullName()
{
cout << "Please, enter a first name of student: ";
cin >> first_name;
cout << "Please, enter a last name of student: ";
cin >> last_name;
}
void SetCGPA()
{
cout << "Please, enter a CGPA of student: ";
cin >> CGPA;
}
string GetFullName()
{
return first_name + " " + last_name;
}
float GetCGPA()
{
return CGPA;
}
};
int main()
{
Student a;
a.SetFullName();
a.SetCGPA();
cout << "Full name of student is " << a.GetFullName();
cout << "\nCGPA of student is " << a.GetCGPA();
Student b("John", "Gouver", 79);
cout << "\nFull name of student is " << b.GetFullName();
cout << "\nCGPA of student is " << b.GetCGPA();
}
Comments
Leave a comment