Thread: CS201 Assignment 4 Solution, June 2010

1. CS201 Assignment 4 Solution, June 2010

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;
}```

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

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

5. Originally Posted by ZalimJin
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,
hmmmmmmm

6. thanks viki.

7. thanks for the cs201 solution