CS201 Assignment # 4 Solution
Saturday, June 26, 2010 Posted In CS and IT Edit ThisYou are required to write a class named “Student “. Student class has the following data members
·
Name
·
Roll Number
·
Semester
·
CGPA
Student class should have
Default and overloaded constructors
Getter and setter functions
A display function that will display the values of data members of an object
Then you should display the values of both objects using display() function.
#include
using namespace std;
class Student{
private:
string name;
int rollNumber;
string semester;
double cgpa;
public:
Student(string n,int r,string s,double c )
{name=n;
rollNumber=r;
semester=s;
cgpa=c;
}
Student()
{name="";
rollNumber=0;
semester="Summer 2010";
cgpa=4.0;
}
string get_semester()
{return semester;
}
void set_semester(string n)
{semester=n;
}
void set_roll(int n)
{rollNumber=n;
}
int get_roll()
{return rollNumber;
}
void set_name(string n)
{name=n;
}
string get_name()
{return name;
}
void set_cgpa(double n)
{cgpa=n;
}
double get_cgpa()
{return cgpa;
}
void print()
{cout<<"Student Information\n";
cout<<"Name: "<