hey plzz help...
i'm encountering many errors in dis code segment..
plz try n remove d errors asap...
n tell me how to generate a database in C++

/*
-----------------------------------------------------------------------------
-------------- PROGRAM TO IMPLEMENT THE PAYROLL OF EMPLOYEES ----------------
-----------------------------------------------------------------------------
*/
#include<fstream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 50

// ADMINISTRATOR CLASS
class admin
{
	private:
		char e_name[30];  	//employee name
		int e_id;              //employee id
		char e_add[50];       //employee address
		float basic;        //employee's basic salary
	public:
		void get_edata();     // get data for employee
		void display_edata(); //display details of employees
		void modify_edata();  //modify details
		void del_edata();
		void write_erecords();
		int getid()
		{
			return (e_id);
		}
}obj,obj2;
class salary
{
	public:
		float DA,HRA,TA;
		salary()
		{
			DA=0.20;
			HRA=0.16;
			TA=0.10;
		}

		float e_tsalary(float basic)
		{
			float tot_sal;
			tot_sal=basic+(basic*DA)+(basic*HRA)+(basic*TA);
			return tot_sal;
		}

};
class employee
{
	private:
		int emp_id;
	public:
		void search();
};

void employee :: search()
{
	admin ad;
	char found;
	fstream fin("EMP.TXT",ios::in|ios::out);
	cout<<"Enter the employee id to be searched : ";
	cin>>emp_id;
	cout<<endl;
	while(!fin.eof())
	{
		fin.read((char *)&ad,sizeof(ad));
		if(emp_id==ad.getid())
		{
			ad.display_edata();
			found='y';
			break;
		}
	}
	if(found=='n')
		cout<<"Employee's id not found";
	fin.close();
}

void admin :: get_edata()
{
	salary s;
	cout<<"ENTER THE EMPLOYEE NAME : ";
	gets(e_name);
	cout<<endl;
	cout<<"ENTER THE EMPLOYEE ID : ";
	cin>>e_id;
	cout<<endl;
	cout<<"ENTER THE EMPLOYEE ADDRESS : ";
	gets(e_add);
	cout<<endl;
	cout<<"ENTER THE BASIC SALARY : ";
	cin>>basic;
	cout<<endl;
}
void admin :: display_edata()
{

	salary s;
	cout<<"EMPLOYEE NAME : ";
	puts(e_name);
	cout<<endl;
	cout<<"EMPLOYEE ID : ";
	cout<<e_id;
	cout<<endl;
	cout<<"EMPLOYEE ADDRESS : ";
	puts(e_add);
	cout<<endl;
	float totalsal;
	totalsal=s.e_tsalary(basic);
	cout<<"TOTAL SALARY : ";
	cout<<totalsal;
	cout<<endl;
}
void admin :: modify_edata()
{
	cout<<"Employee Name : ";
	puts(e_name);
	cout<<endl;
	cout<<"Employee ID : ";
	cout<<e_id;
	cout<<endl;
	cout<<"Basic Salary is : "<<basic;
	cout<<endl;
	cout<<"Enter the new details : "<<endl;
	char nm[30]=" ";
	double id, basic_e;
	cout<<"Enter New Name (Press '.' to retain old one): "<<endl;
	gets(nm);
	cout<<endl;
	cout<<"Enter New ID : "<<endl;
	cin>>id;
	cout<<endl;
	cout<<"Enter Basic Salary : "<<endl;
	cin>>basic_e;
	cout<<endl;
	if(strcmp(nm,".")!=0)
		strcpy(e_name,nm);
	if(id!=e_id)
		e_id=id;
	if(basic_e!=basic)
		basic=basic_e;
}

void menuad()
{
int ch,n;
cout<<"**************MENU************** \n";
cout<<"ENTER WHAT YOU WANT TO DO : \n";
cout<<"1. ADD  DATA \n";
cout<<"2. APPEND DATA \n";
cout<<"3. SHOW DATA \n";
cout<<"4. MODIFY DATA \n";
cout<<"5. DELETE DATA: \n";
cout<<"6. EXIT ";
cout<<"\n Enter your choice";
cin>>ch;
switch(ch)
{
case 1:
	ofstream fot("EMPLOYEE.TXT",ios::out|ios::binary);
	obj.get_edata();
	fot.write((char *)&obj, sizeof(obj));
	cout<<"\n First Record added";

	fot.close();
	getch();
	clrscr();
	menuad();
	break;
case 2:
	fstream fo("EMPLOYEE.TXT" ,ios::in| ios ::app |ios::binary);
	char ans='y';
	while(ans=='y')
	{
		obj.get_edata();
		fo.write( (char *)&obj, sizeof(obj));
		cout<<"\n Record added \n";
		clrscr();
		cout<<"\n Want to enter more records?(y/n)";
		cin>>ans;
	}
	fo.close();
	getch();
	clrscr();
	menuad();
	break;
case 3:
	ifstream fi( "EMPLOYEE.TXT" ,ios::in);
	fi.seekg(0);
	while(!fi.eof())
	{
		fi.read((char *)&obj,sizeof(obj));
		obj.display_edata();
	}
	fi.close();
	getch();
	clrscr();
	menuad();
	break;

case 4:
	admin ad;
	fstream fio("EMP.TXT",ios::in|ios::out|ios::binary);
	ofstream fin("EMP.TXT",ios::in|ios::out|ios::binary);
	int empid;
	cout<<"Enter the Employee ID : ";
	cin>>empid;
	cout<<endl;
	long pos;
	char found='f';
	while(!fio.eof())
	{
		pos=fio.tellg();
		fio.read((char *)&ad,sizeof(ad));
		fin.open("EMP.TXT",ios::in);
		if(ad.getid()==empid)
		{
			ad.modify_edata();
			fio.seekg(pos);
			fio.write((char *)&ad,sizeof(ad));
			found='t';
			break;
		}
	}
	if(found=='f')
		cout<<"File not found"<<endl;
		fio.seekg(0);
		cout<<"Now contents of file are : "<<endl;
		while(!fio.eof())
		{
			fio.read((char *) & ad,sizeof(ad));
			ad.display_edata();
			break;
		}
	fio.close();
	fin.close();
	getch();
	clrscr();
	menuad();
	break;
case 5:
	admin obj;
	found='f';
	char confirm='n';
	ifstream fin1("EMPLOYEE.TXT",ios::in);
	ofstream oin("TEMP.TXT",ios::out);
	cout<<"Enter the employee id to be searched : ";
	cin>>empid;
	cout<<endl;
	while(!fin1.eof())
	{
		fin1.read((char *)&obj,sizeof(obj));
		if(empid==obj.getid())
		{
			obj.display_edata();
			found='y';
			cout<<"confirm deletion ?";
			cin>>confirm;
			if(confirm=='n')
			{
			oin.write((char*)&obj,sizeof(obj));
			}
		}
		else
			oin.write((char *)&obj, sizeof(obj));

	}
	if(found=='f')
	{
		cout<<"Employee's id not found";
	}
	remove("EMPLOYEE.TXT");
	rename("TEMP.TXT","EMPLOYEE.TXT");
	fin1.open("EMPLOYEE.TXT");
	while(!fin1.eof())
	{
		fin1.read((char *)&obj,sizeof(obj));
		if(fin1.eof()) break;
		obj.display_edata();
	}
	while(!fin1.eof())
	{
		fin1.read((char *) &obj, sizeof(obj));
		if(obj.getid()==empid)
		{
			found='t';
			obj.display_edata();
			getch();
		}

	}
	if(found=='f')
	cout<<"no record found \n";
	fin1.close();
	oin.close();
	getch();
	clrscr();
	menuad();
	break;
case 6:
	exit(0);
	break;
default:
	cout<<"Wrong choice";
}

}
void menuemp()
{
	employee emp;
	cout<<"***********************************"<<endl;
	cout<<"		EMPLOYEE'S MENU		  "<<endl;
	cout<<"1.SEARCHING "<<endl;
	cout<<"2.EXIT"<<endl;
	int ch;
	cin>>ch;
	switch(ch)
	{
		case 1:
			emp.search();
			getch();
			clrscr();
			menuemp();
			break;
		case 2:
			exit(0);
			break;
		default:
			break;
	}
}

void menu()
{
	int ch,c,d;
	admin ad;
	employee emp;
	cout<<"**************MENU************** \n";
	cout<<"ENTER WHAT YOU ARE : \n";
	cout<<"1. ADMINISTRATOR \n";
	cout<<"2. EMPLOYEE \n";
	cout<<"3. EXIT \n";
	cout<<"ENTER YOUR CHOICE : \n";
	cin>>ch;
	switch(ch)
	{
		case 1: clrscr();
			menuad();
			break;
		case 2: clrscr();
			menuemp();
			break;
		case 3:
			exit(0);
			break;
		default:
			cout<<"WRING CHOICE ENTERED !!!!!! ";
			break;
	}
}

void main()
{
	clrscr();
	employee emp;
	int n;
	menu();
	getch();
}

Please use full words and sentences.

Please tell us what errors, and where your compiler indicates the errors are. If the code compiles and runs but gives wrong results, explain what it should do and what it'd doing wrong. This is a big piece of code to just jump into. Some comments in the code might help as well.

Also, this should not have been posted as a "Code Snippet" - that heading is meant for good code meant to be used as and example or to demonstrate something interesting. Just post your code in a forum posting.

Edited 6 Years Ago by vmanes: n/a

Dis iz error: U dint explan nutin. U writ 2 mch cde an dnt tst it. Plzzzz expln wat prblm iz. We dun unrstnd prblm. && U dint spk English. Cnt unrstnd not English

Comments
Yes
Nice :D

1st sorry 4 my mistake..
next the code isnt able to delete the records...
once d data is added into d file, dat data is lost sumwhere..
modification changes are also nt getting saved

Im pretty sure that code is copy pasted...

fstream is also included twice.

One error down, more to go!

Edited 6 Years Ago by LevyDee: n/a

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