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:
- MGMT623 Leadership & Team Management Assignment No.2 Fall...
- ENG301 Business Communication Assignment No. 02 Due Date...
- International Marketing (MKT630) Assignment No. 01 May 3,...
- FIN622_ Corporate Finance Assignment # 1 fall 2010 idea...
- CS614 Data Warehousing Assignment No. 2 08-12-2014
- Vuhelp.net website is easy as compare to other websites?
- Assignment NO. 01 MGT401 Financial Accounting II Fall 2014
- STA630 Research Methods Assignment No.1 Solution Spring...
- Fundamentals Of Algorithms CS502-Spring 2014 Assignment No 1
- ENG101 English Comprehension Assignment 4 Deadline 29 July...
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; }
: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)