Class to set student name & id
Hi GUys,
I have created a class to set the student name & class id. But the student id don't let me compile becase it is an integer.
Can someome help me to fix it please ?
Thanks,
My code is below for your attention:
// Class header
#include <string>
using namespace std;
class student3
{
private:
string name;
int id;
public:
// transformer methods
void setname( string );
void setid( int );
// accessor methods
string getname();
int getid();
};
#include "student3.h"
void student3::setname( string myname )
{
name = myname;
}
void student3::setid( int myid )
{
id = myid;
}
string student3::getname()
{
return name;
}
int student3::getid()
{
return id;
}
#include <iostream>
#include "student3.h"
using namespace std;
main()
{
string nm;
int id;
student3 stud1, stud2;
cout << "Please enter name " << endl;
cin >> nm;
stud1.setname( nm );
cout << "Please enter id " << endl;
cin >> id;
stud1.setid( id );
cout << "The name of the first student is " << stud1.getname() << endl;
cout << "The id of the first student is " << stud1.getid() << endl;
system( "pause" );
}
|