Whats Wrong again zzz!!URgent

Did i made a mistake again? Look bottom of my code for my specific question which is bolded in the comments Thanks...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Employee
{
protected:
	char EmployeeID[7] , Name[21] , EmployeeType , Department[7],TelephoneNumber[8];
	int	count ;
public :
	//Constructor & Destructor 
	Employee(char *EID = " ",char *Namep = " " ,char EType = '@',char *D = " ",char *TelNo = " ",int C = 0) ;
	//****************************
	//Assessor method
	friend ifstream& operator >>(ifstream& , Employee&) ;
	char *Get_EmployeeID(){return EmployeeID ; };
	char *Get_Name(){return Name ;} ;
	char *Get_Department(){return Department ;} ;
	char *Get_TelephoneNumber(){return TelephoneNumber ;} ;
	int Get_count(){return count ;} ;
	char Get_EmployeeType(){return EmployeeType ;} ;
	void Display() ;
} ;



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Employee:: Employee(char* EID ,char *Namep,char EType,char* D ,char *TelNo ,int C) 
{
	
	ifstream in ;
	in.open("EMPLOYEE.dat",ios::in) ;
	if (in.fail()) 
	{
		cerr <<"The Employee file cannot be found" ;
		system("pause") ;
		exit(1)  ;
	}		
	if(strcmp(EID," ") == 0 || (strcmp(Namep," ")==0) || EType == '@',strcmp(D," ") == 0 || strcmp(TelNo," ") == 0 || C == 0)
	{
		in.get(Department,7);
		in >> count ;
		in.ignore(20,'\n') ;
		in.get(EmployeeID,7) ;
		in.get(Name,21) ;
		in.get(TelephoneNumber,8),
		in >> EmployeeType ;
		in.ignore(20,'\n') ; 
	}
	
}



ifstream& operator >> (ifstream& infile , Employee& E) 
{
	infile.get(E.EmployeeID,7) ;
	infile.get(E.Name,21) ;
	infile.get(E.TelephoneNumber,8) ;
	infile >> E.EmployeeType ;
	infile.ignore(20,'\n') ;
	return infile ;
}



1
2
3
4
5
6
7
void Employee::Display()
{
	cout <<setiosflags(ios::left|ios::fixed) ;
	cout <<endl ;
	cout << setw(14) << EmployeeID << setw(21) << Name<< setw(15)  ;
	cout <<TelephoneNumber <<EmployeeType <<endl  ;
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
int count = 0 ;
	const int Size = 4 ;// max number of employee 
	Employee *Staff[Size] ;
	ifstream infile ;
	infile.open("EMPLOYEE.dat",ios::in) ;
	if(infile.fail())
	{
		cerr << " The Employee file does not exist " ;
		system("pause") ;
		exit(1) ;
	}

	infile.ignore(20,'\n') ;
	while(!infile.eof())
	{
		Employee *Employeep = new Employee  ;
		infile >> *Employeep ;
		Staff[count] = Employeep ;
		Staff[count]->Get_EmployeeID() ; //This part it does not work,as in there is no output.On the other hand, Staff[count]->Display() works,
//Please explain to me my mistakes... Thanks
		system("pause") ;
		count++ ;
	} 	

	infile.close() ;


"EMPLOYEE.DAT"

MAN4E23
A34889Tan Beng Soo 7783456S
Z23669Tan Chee Y ong 5668877S
D2356 Shiva Kumar 3744552H
Last edited on
Bumpz Anyone?
Get_EmployeeID() doesn't print anything.
Can u elaborate? I thought i have the function to return the employee ID?
Get_EmployeeID() doesn't print anything. It returns the employee ID, but nothing is done with it. Nothing. It's just discarded because it's not read into anything: not cout, not an ofstream, it's just discarded. You may want a variable to store the data in so that you may do something with it later.

-Albatross
I don't get quite what you are saying
you are saying that the value of EmployeeID is being discarded after it comes out of the function.
Thus
Staff[count]->Get_EmployeeID()
has no value.
If so should i store the value as
1
2
char*temp  ;
strcpy(temp,Staff[0]->Get_Name())



Last edited on
Oh, it has a value, but it is discarded. Those are two different things.

Your general idea for storing it is right, though.

Why not use strings?

-Albatross
Staff[count]->Get_EmployeeID()

What Albatross is saying is that you're calling the function but not assigning it to anything.
Okay thanks people :)
Topic archived. No new replies allowed.