Answer to Question #284248 in C++ for Mehtab

Question #284248

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.

1
Expert's answer
2022-01-02T18:17:19-0500
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog