Nice code, one confusion though, why we are using setter and getter, while they are not used in intmain(); just because assigment mentioned them. I mean maybe we can make use of them/
View more random threads:
- phy301 assignment no 2 idea solution spring 2011
- MCM 511 Theories of Communication Assignment No. 1 Fall...
- CS403 Database Management Systems Assignment No. 2 December...
- CS201-Introduction to Programming Assignement No.1 Due Date...
- Assignment No. 4 SEMESTER Spring 2013 CS301- Data Structures
- CS402 Assignment 4 Solution July 2010
- ORGANIZATIONAL BEHAVIOR (MGT 502) ASSIGNMENT NO. 01...
- CS402 Theory of Automata Assignment No.6 Solution Fall...
- Assignment No. 3 MTH 101 (Fall 2010)
- Managerial Economics - Eco404 Assignment No.1 Solution Fall...
Code:Solution:- #include <iostream> 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: "<<name<<endl; cout<<"Roll number: "<<rollNumber<<endl; cout<<"Semester: "<<semester<<endl; cout<<"Current GPA: "<<cgpa<<endl<<endl; } }; int main() {Student a; Student b("name",2345,"Spring 2010",3.5); a.print(); b.print(); system("pause"); return 0; }
Sponsored Links
:o:o--------------------------------------------------------------------------------------:o:o
[B]The more knowledge you have, the greater will be your fear of Allah.[/B]
Please Join My [B]Group Vuhelp[/B][B], Birthday Wishing, Daily Hadees[/B] [CODE][B]http://vuhelp.net/groups/vuhelp.html[/B]
[B]http://vuhelp.net/groups/birthday-wishing.html[/B]
[B]http://vuhelp.net/groups/daily-hadees.html[/B][/CODE]
[CENTER][B][COLOR="Red"][SIZE="4"]Email: [email]viki@vuhelp.net[/email][/SIZE][/COLOR][/B][/CENTER]
Nice code, one confusion though, why we are using setter and getter, while they are not used in intmain(); just because assigment mentioned them. I mean maybe we can make use of them/
Instead we can enhance your print function in such a way to use getter function,
void print()
{cout<<"Student Information\n";
cout<<"Name: "<<get_name<<endl;
cout<<"Roll number: "<<get_roll<<endl;
cout<<"Semester: "<<get_semester<<endl;
cout<<"Current GPA: "<<get_cgpa<<endl<<endl;
}
Just a thought,
:o:o--------------------------------------------------------------------------------------:o:o
[B]The more knowledge you have, the greater will be your fear of Allah.[/B]
Please Join My [B]Group Vuhelp[/B][B], Birthday Wishing, Daily Hadees[/B] [CODE][B]http://vuhelp.net/groups/vuhelp.html[/B]
[B]http://vuhelp.net/groups/birthday-wishing.html[/B]
[B]http://vuhelp.net/groups/daily-hadees.html[/B][/CODE]
[CENTER][B][COLOR="Red"][SIZE="4"]Email: [email]viki@vuhelp.net[/email][/SIZE][/COLOR][/B][/CENTER]
There are currently 1 users browsing this thread. (0 members and 1 guests)