Error message is identifier expected and declaration terminated incorrectly.
//to define a class Employee
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
class cEmp
{
private:
int eid;
char ename[10];
char dname[10];
float sal;
public:
cEmp();
cEmp(int,char*,char*,float);
void accept();
void display();
float getsal();
int getid();
};
cEmp::cEmp()
{
eid=0;
strcpy(ename,"/0");
strcpy(dname,"/0");
sal=0;
}
cEmp::cEmp(int,char*,char*,float)
{
int id;
float s;
char n[10],d[10];
eid=id;
strcpy(ename,n);
strcpy(dname,d);
sal=s;
} cEmp::void accept() //Error in this line<<<<<<<<<<<<<<<
{
cout<<"Enter empoyee ID:";
cin>>eid;
cout<<"Enter employee name:";
gets(ename);
cout<<"Enter department name";
gets(dname);
cout<<"Enter employee salary:";
cin>>sal;
}
cEmp::void display()
{
cout<<"\nEmployee ID:"<<eid;
cout<<"\nEmployee name:"<<ename;
cout<<"\nDepartment name"<<dname;
cout<<"\nEmployee salary"<<sal;
}
cEmp::void getid()
{
return eid;
}
cEmp::void getsal()
{
return sal;
}
void main()
{
clrscr();
do
{
cout<<"\t\tMenu";
cout<<"\n\n\t1.\tDisplay all the employees' info.";
cout<<"\n\n\t2.\tDisplay specific employes' info.";
cout<<"\n\n\t3.\tDisplay employee with max salary.";
cout<<"\n\n\tEnter choice:";
int n,i,a;
cin>>a;
switch(a)
{
case 1:
for(i=0;i<n;i++)
c[i].display();
break;
case 2:
cout<<"Enter ID:";
int x;
cin>>x;
for(i=0;i<n;i++)
if(c[i].getid()==x)
c[i].display();
break;
case 3:
float max=0;
for(i=0;i<n;i++)
if(c[i].getsal()>max)
max=c[i].getsal();
for(i=0;i<n;i++)
if(c[i].getsal()==max)
c[i].display();
break;
}
cout<<"\nDo you want to continue?(y/n):";
char y;
cin>>y;
}
while(y=='y');
{
getch();
}
return();
}
The return types of several of the member functions have been removed. They need to be put back and they need to match the function prototype in the class declaration. Remember, any time a function returns a value, the function return type cannot be void.
Where is this c array? : - switch (a)
-
{
-
case 1:
-
for (i = 0; i<n; i++)
-
c[i].display();
-
break;
-
case 2:
-
cout << "Enter ID:";
-
int x;
-
cin >> x;
-
for (i = 0; i<n; i++)
-
if (c[i].getid() == x)
-
c[i].display();
-
break;
-
-
The char y is inside the braces and the while is outside the braces: - char y;
-
cin >> y;
-
-
} while (y == 'y'); <---y has been destroyed.
You cannot use variables inside braces from outside the braces. Instead you define variables outside the braces and use them from inside nested braces. Since the nested braces are still inside the outer braces, the variables can be used because they are still inside the outer braces.
7 1694
I can't find any reason for this error as all the braces are in the appropriate positions. please help thanks in advance.
The name of the function is cEmp::accept().
So this is correct: - void cEmp::accept()
-
{
-
etc...
and not: - cEmp::void accept()
-
{
-
etc...
This error occurs in several places. Also, in some places the return value of the function in the class definition does not match the return value in the function definition.
Hopefully, this is enough to get you unstuck.
When I remove void from the function I get a host of errors by the compiler saying that the
functions are not member functions of the class cEmp
errors- cEmp::accept() - accept() is not a member of cEmp
- display(), "
- getid(), "
- getsal(), "
- undefined symbol c at line 91
- undefined symbol y at line 116
- expression syntax at line 120
also a warning stating that max is assigned to a value that is never used.
- #include<iostream.h>
-
#include<stdio.h>
-
#include<string.h>
-
#include<conio.h>
-
-
class cEmp
-
{
-
private:
-
-
int eid;
-
char ename[10];
-
char dname[10];
-
float sal;
-
-
public:
-
-
cEmp();
-
cEmp(int,char*,char*,float);
-
void accept();
-
void display();
-
float getsal();
-
int getid();
-
};
-
-
cEmp::cEmp()
-
{
-
eid=0;
-
strcpy(ename,"/0");
-
strcpy(dname,"/0");
-
sal=0;
-
}
-
-
cEmp::cEmp(int,char*,char*,float)
-
{
-
int id;
-
float s;
-
char n[10],d[10];
-
eid=id;
-
strcpy(ename,n);
-
strcpy(dname,d);
-
sal=s;
-
-
}
-
cEmp::accept()
-
{
-
cout<<"Enter empoyee ID:";
-
cin>>eid;
-
cout<<"Enter employee name:";
-
gets(ename);
-
cout<<"Enter department name";
-
gets(dname);
-
cout<<"Enter employee salary:";
-
cin>>sal;
-
}
-
-
cEmp::display()
-
{
-
cout<<"\nEmployee ID:"<<eid;
-
cout<<"\nEmployee name:"<<ename;
-
cout<<"\nDepartment name"<<dname;
-
cout<<"\nEmployee salary"<<sal;
-
}
-
-
cEmp::getid()
-
{
-
return eid;
-
}
-
-
cEmp::getsal()
-
{
-
return sal;
-
}
-
-
void main()
-
{
-
clrscr();
-
do
-
{
-
cout<<"\t\tMenu";
-
cout<<"\n\n\t1.\tDisplay all the employees' info.";
-
cout<<"\n\n\t2.\tDisplay specific employes' info.";
-
cout<<"\n\n\t3.\tDisplay employee with max salary.";
-
cout<<"\n\n\tEnter choice:";
-
int n,i,a;
-
cin>>a;
-
switch(a)
-
{
-
case 1:
-
for(i=0;i<n;i++)
-
c[i].display();
-
break;
-
case 2:
-
cout<<"Enter ID:";
-
int x;
-
cin>>x;
-
for(i=0;i<n;i++)
-
if(c[i].getid()==x)
-
c[i].display();
-
break;
-
case 3:
-
float max=0;
-
for(i=0;i<n;i++)
-
if(c[i].getsal()>max)
-
max=c[i].getsal();
-
for(i=0;i<n;i++)
-
if(c[i].getsal()==max)
-
c[i].display();
-
break;
-
}
-
cout<<"\nDo you want to continue?(y/n):";
-
char y;
-
cin>>y;
-
-
}
-
while(y=='y');
-
{
-
getch();
-
}
-
return();
-
}
-
here's the code wrapped, I know the indentation is a little off. Thanks in advance, really appreciate it!
The return types of several of the member functions have been removed. They need to be put back and they need to match the function prototype in the class declaration. Remember, any time a function returns a value, the function return type cannot be void.
Where is this c array? : - switch (a)
-
{
-
case 1:
-
for (i = 0; i<n; i++)
-
c[i].display();
-
break;
-
case 2:
-
cout << "Enter ID:";
-
int x;
-
cin >> x;
-
for (i = 0; i<n; i++)
-
if (c[i].getid() == x)
-
c[i].display();
-
break;
-
-
The char y is inside the braces and the while is outside the braces: - char y;
-
cin >> y;
-
-
} while (y == 'y'); <---y has been destroyed.
You cannot use variables inside braces from outside the braces. Instead you define variables outside the braces and use them from inside nested braces. Since the nested braces are still inside the outer braces, the variables can be used because they are still inside the outer braces.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike Fisher |
last post by:
I'm seeing an error when I try to run/debug a web
service. Although it doesn't happen every time, it does
occur more than half of the times I hit F5. It appears
to be returned by the the JIT...
|
by: Marco Gerlach |
last post by:
Hello,
on one of our customers servers we get following error on first ASPX-page:
An error occurred while try to load the string resources (GetModuleHandle
failed with error -2147023888)
...
|
by: Razzie |
last post by:
Hi all,
I was working on a little project, worked fine, but now all of a sudden I
get:
The compiler failed with error code -1073741502
as an error message (when running the site, not...
|
by: Mark |
last post by:
I'm just starting out in an introductory ASP.Net course, and am trying to run
a simple program but keeping getting an error.
I'm running XP, have installed Internet Information Services (5.1) ,...
|
by: Roger Wang |
last post by:
HELP!!!!
We have got a W2k server running IIS5 with .NET framework 1.1 and .NET
framework SP1. All ASP.NET applications cannot run on this box. It all
returned with the same error:
...
|
by: jeffpriz |
last post by:
We've got an issue here where we regularly receive an error page with
the message
"Compiler Error Message: The compiler failed with error code 2000."
when we begin debug on our projects.
The...
|
by: Ram |
last post by:
Hey,
I have a Windows 2000 Advanced Server SP4 with Framework 1.1 installed.
I have an ASPNet website that every now and then I get the following
error:
"Compiler Error Message: The compiler...
|
by: bhanupoornakumar |
last post by:
Hi .. when i am setting a website i am getting the following error..
The compiler failed with error code -1073741819.
This is the full error .. u can see below.
Compilation Error ...
|
by: Frinavale |
last post by:
I've been trying to test my web application using Internet Explorer 8 (release candidate 1) and have been experiencing some major problems. I'm hoping you can help me with this one.
I have a...
|
by: kmsandeep17 |
last post by:
when i host my site on go daddy it give error
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |