c++ programming, classes anf objects.

Hello everyone, i am getting a compilation error from the code below. It is when i am naming a variable with my user defined type. Can anyone hint me on how to correct the mistake.


#include<iostream>
#include<cstring>
#include<cstdlib>

using namespace std;

class person
{
private:
char ID[10];
char SNAME[100];
char FNAME[100];
float SALARY;

public:
person(char I[],char S[],char F[] ,float SAL)
{
strcpy(ID,I);
strcpy(SNAME,S);
strcpy(FNAME,F);
SALARY=SAL;
}


void enterdetails();

void displaydetails();


};



void person :: enterdetails()
{
cout<<"Enter ID here:"<<endl;
cin.getline(ID,10);

cout<<"Enter first name here:"<<endl;
cin.getline(FNAME,100);

cout<<"Enter surname here:"<<endl;
cin.getline(SNAME,100);

cout<<"Enter salary here:"<<endl;
cin>>SALARY;

cin.ignore();
}

void person :: displaydetails()
{
cout<<"First name is"<<FNAME<<endl;
cout<<"Surname is"<<SNAME<<endl;
cout<<"ID is"<<ID<<endl;
cout<<"Salary is "<<SALARY<<endl;

}

int main ()
{
person p[2];

person X("UJIji8j", "GILDARTS","JED",1234.5);

int i;

for (i=0;i<2;i++)
{
p[i].enterdetails();

}
for(i=0;i<2;i++)
{
p[i].displaydetails();
}

cout<<X.displaydetails();

cin.ignore();

system ("pause");

return EXIT_SUCCESS;
}



Error messages would be nice.
Hello thePHPdev, here are the error messages, can i have a hint on the problem?


C:\Dev-Cpp\TRIAL.PASS.!!!.cpp In function `int main()':
66 C:\Dev-Cpp\TRIAL.PASS.!!!.cpp expected primary-expression before "p"
66 C:\Dev-Cpp\TRIAL.PASS.!!!.cpp expected `;' before "p"
74 C:\Dev-Cpp\TRIAL.PASS.!!!.cpp `p' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
83 C:\Dev-Cpp\TRIAL.PASS.!!!.cpp `X' undeclared (first use this function)
You need a default constructor. You also need to change this cout<<X.displaydetails(); to this X.displaydetails();

Please use code tags its the button that looks like this <> on the righthand side of your screen, when you post
Last edited on
Thank you very much Yanson.
Topic archived. No new replies allowed.