Problem Statement: Student class
You 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
You 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
You are required to create two objects of student class. One object should be initialized with default constructor, and second object should be initialized with overloaded constructor.
Then you should display the values of both objects using display() function.
Then you should display the values of both objects using display() function.
Solution:-
#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: "<
Please do make changes in these assignment otherwise every one who copy this assignment as it is will awarded zero marks
0 comments
Post a Comment