Hello everyone. I am writing a program which takes in information to various arrays. I input the info using "set" functions. I then need to output that info from an output function. I'm having problems getting to the information. I think I need to return a pointer to the beginning of the array, although I'm having alot of problems.
Thanks,
J
Code:
#include <iostream>
using namespace std;
struct Person
{
char Fname[20],Lname[20];
float age;
int ssn[9],enumber[9];
};
class Employee
{
private:
int enumber[9],ssn[9];
float wage;
char job_title[10];
Person Per;
public:
Employee();
~Employee(){};
void SetFname(int emp);
void SetLname(int emp);
void Setage();
void Setssn(int emp);
void Setenumber(int emp);
void Setwage();
void Setjob_title();
char GetFname();
char GetLname();
void Getage();
int Getssn();
int Getenumber();
void Getwage();
void Getjob_title();
void output();
void salary();
void flipflop();
};
Employee::Employee()
{
int i=0,j=0;
cout<<"Constructor."<<endl;
wage=0;
for (i=0;i<=9;++i)
{
enumber[i]=0;
ssn[i]=0;
}
}
void Employee::SetFname(int emp)
{
cout<<"BEGIN SETFNAME FUNCTION."<<endl;
cout<<"Enter the first name of the employee."<<endl;
cin.ignore();
cin.getline (Per.Fname,20,'\n');
cout<<Per.Fname<<endl;
}
void Employee::SetLname (int emp)
{
cout<<"BEGIN SETLNAME FUNCTION."<<endl;
cout<<"Enter the last name of the employee."<<endl;
cin.getline (Per.Lname,20,'\n');
cout<<Per.Lname<<endl;
}
void Employee::Setssn(int emp)
{
cout<<"SETSSN Function"<<endl;
cout<<"Enter the social security number of the employee."<<endl;
cin>>Per.ssn[emp];
cout<<Per.ssn[emp]<<endl;
}
void Employee::Setenumber(int emp)
{
int i;
cout<<"SETENUMBER FUNCTION."<<endl;
cout<<"Enter the employee number."<<endl;
cin>>Per.enumber[emp];
cout<<Per.enumber[emp]<<endl;
}
void Employee::output()
{
int emp;
cout<<"Which employee's information would you like to view?"<<endl;
cin>>emp;
cout<<"Last name: "<<GetLname()<<endl;
cout<<"First name: "<<GetFname()<<endl;
cout<<"Employee number: "<<Getenumber()<<endl;
cout<<"Employee ssn: "<<Getssn()<<endl;
}
int Employee::Getssn()
{
cout<<"Getssn function"<<endl;
return (0);
//return (Per.ssn[value]);
}
int Employee::Getenumber()
{
cout<<"Getenumber function"<<endl;
return(0);
//return (Per.age);
}
char Employee::GetLname()
{
cout<<"GetLname function"<<endl;
return (0);
//return(Per.Lname);
}
char Employee::GetFname()
{
cout<<"GetFname function"<<endl;
return (0);
//return (Per.Fname);
}
void main()
{
int emp=-1,choice;
Employee empl[10];
while(emp<0||emp>9)
{
cout<<"Choose and employee 0-9"<<endl;
cin>>emp;
}
do
{
cout<<"Please select what you would like to edit from the menu:"<<endl;
cout<<"1) Enter the first name."<<endl<<"2) Enter the last name."<<endl<<"3) Enter the social security number."<<endl;
cout<<"4) Enter the employee number."<<endl<<"5) Enter all of the information."<<endl<<"6) Output the information for employee."<<endl;
cin>>choice;
switch(choice)
{
case 1:
empl[emp].SetFname(emp);
break;
case 2:
empl[emp].SetLname(emp);
break;
case 3:
empl[emp].Setssn(emp);
break;
case 4:
empl[emp].Setenumber(emp);
break;
case 5:
cout<<"Please enter all of the employees information."<<endl;
empl[emp].SetFname(emp);
empl[emp].SetLname(emp);
empl[emp].Setssn(emp);
empl[emp].Setenumber(emp);
break;
case 6:
cout<<"The employees information is: "<<endl;
empl[emp].output();
break;
}
}
while (choice<1||choice>6);
}
J
Comment