May 15, 2010 at 2:08am UTC
#include<iostream.h>
#include<fstream.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<iomanip.h>
struct person
{
char flag;
char empcode[5];
char name[40];
int age;
float sal;
}p;
class group
{
public:
fstream f;
group();
void addrec();
void listrec();
void modirec();
void delrec();
void exits();
};
int main( )
{
int choice;
char v;
"textcolor(YELLOW)";
group g;
do
{
"gotoxy(15,1)";
cout<<"================================================";
"gotoxy(15,2)";
cout<<"<<SOFT TECH.CORPORATION PVT.LTD>> <<MAIN MENU>>";
"gotoxy(15,3)";
cout<<"================================================";
"gotoxy(15,7)";
cout<<"PRESS THE SPECIFIED KEYS BELOW TO SELECT";
"gotoxy(15,8)";
cout<<"----------------------------------------";
"gotoxy(12,12)";
cout<<"1:ADD RECORD";
"gotoxy(12,14)";
cout<<"2:LIST RECORD";
"gotoxy(12,16)";
cout<<"3:MODIFY RECORD";
"gotoxy(12,18)";
cout<<"4:DELETE RECORD";
"gotoxy(12,20)";
cout<<"5:EXIT";
"gotoxy(12,25)";
cout<<"YOUR CHOICE"<<" ";
cin>>choice;
"clrscr()";
switch(choice)
{
case 1:
g.addrec();
break;
case 2:
g.listrec();
break;
case 3:
g.modirec();
break;
case 4:
g.delrec();
break;
case 5:
g.exits();
exit(0);
default:
cout<<"\nPRESS THE SPECIFIED KEYS ONLY";
"delay(1500)";
break;
}
}
while(choice!=0);
}
void group::group(void)
{
f.open("praveee.dat",ios::binary|ios::in|ios::out);
p.flag=' ';
if(!f)
{
cout<<endl<<"UNABLE TO OPEN FILE:";
exits();
}
}
void group::addrec( )
{
char ch;
f.seekp(0L,ios::end);
do
{
cout<<"\n<<TO RETURN TO THE MAIN MENU PRESS 'm' KEY ELSE PRESS 'a' >>:";
cin>>ch;
if(ch=='m'||ch=='M')
main();
cout<<"\nENTER EMPLOYEE CODE:";
cin>>p.empcode;
cout<<"\nENTER EMPLOYEE NAME:";
cin>>p.name;
cout<<"\nENTER AGE :";
cin>>p.age;
cout<<"\nENTER SALARY:";
cin>>p.sal;
p.flag=' ';
f.write((char*)&p,sizeof(p));
cout<<"\nADD ANOTHER RECORD?(Y/N):";
cin>>ch;
cout<<"\n";
}
while(ch=='y'||ch=='Y');
}
void group::listrec()
{
int j=1,a,c=0;
f.seekg(0L,ios::beg);
cout<<"\n\t\t\tLIST OF PROGRAMS PRESENTS ARE";
cout<<"\n\n\n\n "<<"CODE"<<" "<<" NAME"<<" "<<"AGE"<<"";
"SALARY";
cout<<"\n\t ---------------------------------------";
while(f.read((char*)&p,sizeof(p)))
{
cout<<"\n";
if(p.flag!='*')
{
cout<<endl<<"RECORD";
NO:"<<j++<<setw(8)<<p.empcode<<setw(14)<<p.name<<setw(9)<<p.age<<setw(12)<<p.s";
"al";
c++;
}
}
f.clear();
if(c==0)
{
"gotoxy(10,10)";
cout<<"NO RECORD EXIT";
"gotoxy(10,12)";
cout<<"\n\nPRESS ANY KEY...";
getch();
}
else
{
cout<<endl<<endl<<"\n\n\n\n\tPRESS ANY KEY...";
getch();
}
}
void group::modirec( )
{
char code[5];
int count=0;
long int pos;
cout<<"ENTER EMPLOYEE CODE WHOSE RECORD IS TO BE MODIFIED :";
cin>>code;
f.seekg(0L,ios::beg);
while(f.read((char*)&p,sizeof(p)))
{
if(strcmp(p.empcode,code)==0)
{
cout<<endl<<"ENTER NEW RECORD";
cout<<endl<<"ENTER EMPLOYEE NAME:";
cin>>p.name;
cout<<endl<<endl<<"ENTER AGE :";
cin>>p.age;
cout<<endl<<endl<<"ENTER SALARY :";
cin>>p.sal;
p.flag=' ';
pos=count*sizeof(p);
f.seekp(pos,ios::beg);
f.write((char*)&p,sizeof(p));
return;
}
count++;
}
cout<<endl<<"NO EMPLOYEE IN FILE WITH CODE="<<code;
cout<<"\n\nPRESS ANY KEY...";
getch();
f.clear();
}
void group::delrec( )
{
char code[5];
long int pos;
int count=0;
cout<<"\nENTER EMPLOYEE CODE TO BE DELETED:";
cin>>code;
f.seekg(0L,ios::beg);
while(f.read((char*)&p,sizeof(p)))
{
if(strcmp(p.empcode,code)==0)
{
p.flag='*';
pos=count*sizeof(p);
f.seekp(pos,ios::beg);
f.write((char*)&p,sizeof(p));
return;
}
count++;
}
cout<<endl<<"NO EMPLOYEE IN FILE WITH CODE="<<code;
cout<<endl<<endl<<"PRESS ANY KEY...";
getch();
f.clear();
}
void group::exits( )
{
f.close();
}
When i compile it it says;
88 return type specification for constructor invalid
Can someone help me. I need some explanations also.
May 15, 2010 at 2:19am UTC
void group::group(void )
You've assigned a return type to your constructor. That's illegal.
May 15, 2010 at 2:41am UTC
Last edited on May 18, 2010 at 6:37am UTC
May 15, 2010 at 4:12am UTC
Hi Archaic,
This mean I need remove void group::group(void) it?
I tried before, but still have error. Do you have any explanation? ?Thanks.
May 15, 2010 at 4:32am UTC
Yes. I follow your advice to get rid of the "void" parts. But have the other error as below;
88 expected unqualified-id before '{' token
88 expected `,' or `;' before '{' token
90 expected unqualified-id before '{' token
90 expected `,' or `;' before '{' token
May 15, 2010 at 5:09am UTC
Thank. I fixed it already, but the result said "unable to open file" and the format is confusion.
Is it regarding the system problem? I'm using Dev C++
May 15, 2010 at 5:15am UTC
Make sure the file you're trying to open is in the same directory as the program is. Alternatively, you could specify the exact path to the file. In regards to the formatting, usage of \n
and endl
will help.
Last edited on May 15, 2010 at 5:17am UTC
May 15, 2010 at 9:25am UTC
group::group()
f.open("praveee.dat",ios::binary|ios::in|ios::out);
p.flag=' ';
if(!f)
{
cout<<endl<<"UNABLE TO OPEN FILE:";
exits();
Sorry for bothering you again.
I want to insert the "XXXX.txt file" replace to "praveee.dat" file. What can I do?
May 15, 2010 at 9:37am UTC
Is praveee.dat in the working directory?
May 15, 2010 at 9:59am UTC
Yes. But now want o output the listing record in "XXXX.txt" file.