I have created a program store user data in file.
But i am only getting one error only but i am unable to debug it.
Please help me
I used turbo C++ compiler

Error is on the line
int employee::search_for_employee( int choice, name_temp[20] , email_temp[50])

Here is my code

#include	<iostream.h>
#include	<conio.h>
#include	<fstream.h>
#include	<string.h>
#include	<stdio.h>
#include	<stdlib.h>

//****************************Start of Class declaration*************************
class employee
{
		private:
		char name[20];
		long int empCode;
		char designation[20];
		float salary;
		char email[50];

		public:
		//Gets data from the user
		void getdata()
		{
			cout << "Enter the name of employee:  "; gets(name);
			cout << "Enter the email of employee:  "; gets(email);
			cout << "Enter the designation of employee:  "; gets(designation);
			cout << "Enter the code of employee:  "; cin >> empCode ;
			cout << "Enter the salary of employee:  "; cin >> salary ;
		}

		//Shows data of the employee
		void showdata()
		{
			cout << "Name of the employee: " << name << endl ;
			cout << "Email of the employee: " << email << endl ;
			cout << "Designation of the employee: " << designation << endl ;
			cout << "Employee Code : " << empCode << endl ;
			cout << "Salary of the employee: " << salary << endl ;
		}
		int search_for_employee(int choice, char name_temp[20], char email_temp[50] );
		void modify_employee();
};

//Searches for employee in file
int employee::search_for_employee( int choice, name_temp[20]  , email_temp[50])
{
		int return_value = 0;

        //Comparison Process starts
		switch(choice)
		{
			case 1: if (strcmp(name_temp,name) == 0)
					  return_value = 1;
					  break;
			case 2: if ( empCode_temp == empCode)
					  return_value = 1;
					  break;
			case 3: if (strcmp(email_temp,email) == 0)
					  return_value = 1;;
					  break;
			default: cout << "Wrong choice entered! Program will now terminate!";
		}
		return return_value;
}

//Changes value of data in employee
void employee::modify_employee()
{
		int choice;
		cout<<"Here is the original record :" << endl;
		showdata();
		cout << endl;
		cout<<"Press 1 to change Name " << endl;
		cout<<"Press 2 to change Employee code" << endl;
		cout<<"Press 3 to change Email ID " << endl;
		cout<<"Press 4 to chane  salary of employee " << endl;
		cout<<"Press 5 to change designation " << endl;
		cout<<"Enter your option :";
		cin >> choice;

		switch(choice)
		{
			case 1: 	cout<<"Enter new Name : ";
						gets(name);
						break;
			case 2: 	cout<<"Enter new Employee code : ";
						cin >> empCode;
						break;
			case 3: 	cout<<"Enter new Email ID : ";
						gets(email);
						break;
			case 4: 	cout<<"Enter new Designation: ";
						gets(designation);
			default :	cout<<"Wrong Option !!";
		}
}
//*************************End of class declaration****************************

//Search for employee
void employee_search()
{
		cout << endl;
		employee emp;
		char name_temp[20], email_temp[50];
		int empCode_temp;
		fstream f1;
		f1.open("EMPLOYEE.DAT",ios::binary|ios::in);

		cout << "Press 1 to search employee by name" << endl;
		cout << "Press 2 to search employee by Employee Code" << endl ;
		cout << "Press 3 to search employee by email" << endl ;
		int choice1; cin >> choice1;
		switch(choice1)
		{
			case 1: 	cout<<"Enter Name : ";
						gets(name_temp);
						break;
			case 2: 	cout<<"Enter Employee code : ";
						cin >> empCode_temp ;
						break;
			case 3: 	cout<<"Enter Email ID : ";
						gets(email_temp);
						break;
			default :	cout<<"Wrong Option !!";
		}

		while( f1.read((char*) &emp, sizeof(emp)) )
		{
			if(emp.search_for_employee(choice1, name_temp, empCode_temp) == 1)
			{
				emp.showdata();

			}
		}
}

//Adds a new employee to a file
void add_employee()
{
		employee emp;
		fstream f1;
		f1.open("EMPLOYEE.DAT",ios::binary|ios::app);

		cout<<"\nEnter the details of the employee : \n";
		emp.getdata();

		f1.write((char*) &emp, sizeof(emp));
		f1.close();
}

//Displays list of all employees present in file
void display_all_employee()
{
		employee emp;
		fstream f1;
		int empNum = 1;

		f1.open("EMPLOYEE.DAT",ios::binary|ios::in);
		while( f1.read((char*) &emp, sizeof(emp)) )
		{
			cout << endl;
			cout << empNum << ". " ;
			emp.showdata();
			empNum++;
		}
		f1.close();
}

//Edits employee
void edit_employee()
{
		cout << endl;
		employee emp;
		char name_temp[20], email_temp[50];
		int empCode_temp;
      int file_modified = 0;
		fstream f1,f2;
		f1.open("EMPLOYEE.DAT",ios::binary|ios::in);
		f2.open("TEMP.DAT",   ios::binary|ios::out);

		cout << "Press 1 to search employee by name" << endl;
		cout << "Press 2 to search employee by Employee Code" << endl ;
		cout << "Press 3 to search employee by email" << endl ;
		int choice1; cin >> choice1;
		switch(choice1)
		{
			case 1: 	cout<<"Enter Name : ";
						gets(name_temp);
						break;
			case 2: 	cout<<"Enter Employee code : ";
						cin >> empCode_temp ;
						break;
			case 3: 	cout<<"Enter Email ID : ";
						gets(email_temp);
						break;
			default :	cout<<"Wrong Option !!";
		}


		while( f1.read((char*) &emp, sizeof(emp)) )
		{
			if( emp.search_for_employee(choice1, name_temp, empCode_temp) == 1 )
			{
				file_modified++ ;
				emp.modify_employee();
			}
			f2.write((char *) &emp, sizeof(emp));
		}

		if ( file_modified == 0 )
		cout << "No records found!";
}

void main()
{
		cout << "Welcome to employee management program!" ;
		cout << endl;

		int choice;
		clrscr();
		cout<<"Main Menu:\n";
		cout<<"Press 1 to add a new employee " << endl;
		cout<<"Press 2 to display all employees " << endl;
		cout<<"Press 3 to search employee " << endl;
		cout<<"Press 4 to modify employee " << endl;
		cout<<"Enter your choice : ";
		cin >> choice;

		switch(choice)
		{
			case 1:  add_employee();	break;
			case 2:  display_all_employee();	break;
			case 3:  employee_search();	break;
			case 4:  edit_employee();	break;
			default: cout<<"\nWrong Choice Entered !!Please try again!\n\n";
		}
		getch();

}

Please ignore my bad programming practise for now. I just need to finish this program.THanks in advance

I did not look over the whole program, so I am not sure what you are trying to do with that function. But

employee::search_for_employee( int choice, name_temp[20] , email_temp[50])

is wrong because the function has to have a type of a variable passed to it, and name_temp[20] is an array item, without a type.
If you want to pass an array to a function, you can use pointers, but not what you are doing.

Edited 5 Years Ago by sergent: n/a

i am getting the following error.

) expected

on the line
int employee::search_for_employee( int choice, name_temp[20] , email_temp[50])

I plugged your code into Bloodshed.

I'm merely a beginner, but I believe you should include <iomanip> and namespace std. Also, your main should be of integer data type, so it can return 0 to the system when it closes.

Beyond that, you've referenced a few variables that are not declared in the proper scope. I Believe line 53 is a good example. empCode_temp is not declared until line 103 in another function.

My limited understanding doesn't allow me to comment much further. I'm sure I'm off by a mile anyways ;)

Good luck.

This article has been dead for over six months. Start a new discussion instead.