Hi there,
sorry if this is really stupid but I am trying as hard as I can to understand classes from a book. I have declared my class and put in the accessor functions and declared everything private/public as I have been told.
I want to write a program that keeps a employee record. It asks the user for the data and then prints it back out to confirm it has all worked and has been stored correctly.
I have cut down the code attached to just one peice of data (the employee number) and two accessor methods untill I get this right. The problem is that when I run the program it just flicks up the console screen and then it vanishes despite the system("PAUSE"); after return 0; (I know, I know it's bad and I proboly shouldn't use it).
Can anyone tell me what I'm doing wrong and how to fix it. Many thanks
Code:
#include <iostream>using namespace std;
class record
{
private:
int p_number;
public:
void setp_number(int number);
int getp_number();
};
//accessor functions//
//1
void record::setp_number(int number)
{
p_number = number;
}
//get1
int record::getp_number()
{
return p_number;
}
int main()
{
int number;
record Clive;
cout << "set employee number: ";
cin >> number;
cout << "Thanks! To confirm:...." << endl;
cout << "Clive is number: " << Clive.getp_number();
return 0;
system("PAUSE");
}