CS201 Assignment # 4 Solution

No Comments


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 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.

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: "<
<<<<<<<<<="" <="" <="" <="" a.print();="" a;="" b("name",2345,"spring="" b.print();="" cgpa<<<<"current="" cout<<"roll="" cout<<"semester:="" gpa:="" int="" iostream="" main()="" name<<<<="" }=""><

Please do make changes in these assignment otherwise every one who copy this assignment as it is will awarded zero marks 
Next PostNewer Post Previous PostOlder Post Home

0 comments

Post a Comment