Cannot compile the program in Dev C++

#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.
void group::group(void)

You've assigned a return type to your constructor. That's illegal.
Last edited on
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.
You just need to get rid of the "void" parts.

group::group()

http://cplusplus.com/doc/tutorial/classes/
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
88 expected unqualified-id before '{' token
88 expected `,' or `;' before '{' token


I got those errors when I had:

group::group

Which is missing its parentheses. It should be:

group::group()
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++
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 \nand endl will help.
Last edited on
To check if a file is open and readable, consider ifstream::good(). I like using good() more than is_open(), anyway...
http://cplusplus.com/reference/iostream/ios/good/
http://cplusplus.com/reference/iostream/ifstream/is_open/

-Albatross
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?
Is praveee.dat in the working directory?
Yes. But now want o output the listing record in "XXXX.txt" file.
Topic archived. No new replies allowed.