If you write each statement on its own line, you can see that it spells out much of the initial code for you. Make an initial attempt and post that.
create a class called employee that include three pieces of information as data members[indent] - a first name(tye string),
a last name(type string)
and a monthly salary(type int).
your class should have a constructor that initializes the three data members.
provide a set and a get function for each data member. [indent]if the monthly salary is not positive,[indent]set it to 0. [/indent][/indent][/indent]write a test program that demostrates class employee's capabilities.
create two employee objects and
display each object's yearly salary.
then give each employee a 10 percent raise and display each employee's yearly salary again
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Make an initial attempt
...at code...and post that. :rolleyes:
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
This
declare name as a string;
last name as a string;
monthly salary as a int;
should be like this
string first;
string last;
int salary;
Spelling is important.
emlployee()
{
monthly salary = 0
last name = arun;
first name = arun;
}
};
Good indentation helps. String literals are enclosed in double-quotes.
There's more, like returning a value from a void function or misplaced semicolons, but let's try a little at a time for now.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Yeah, I figured so.but let's try a little at a time for now.But I'm not clairvoyant, so please post your latest.(Oh, I'm repeating my signature.)
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
why still got error.....
can post error?
Variable names likefirst name are not valid because whitespace separates tokens. That's much of the reason us old crusty folks use underscores and write it as first_name. It may look ugly to some, but it keeps the compiler happy. (And it's kinda like I wrote earlier.)
Do you have some introductory text you to work with, or are you strictly learning on the fly with the 'net? A book would help immensely, but we'll do what we can.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Honestly, are you reading these posts?Variable names like first name are not valid because whitespace separates tokens. That's much of the reason us old crusty folks use underscores and write it as first_name. It may look ugly to some, but it keeps the compiler happy. (And it's kinda like I wrote earlier.)Your subsequent questions were already answered in this thread as well.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
but i am still got error....but less error....can you tell where is the problem
I've been trying.
The answer(s) has(have) already been posted in this thread.
[edit]
int main()
{
void employee::getdata(void)
{
cout<<"a first name:";
cin>>name;
cout<<"a last name:";
cin>>name;
cout<<"monthly salary:";
}
void employee::setdata(void)
{
cout<<"first name";<<first name<<"\n";
cout<<"last name";<<last name<<"\n";
cout<<"monthly salary";<<monthly salary<<"\n";
}
return 0;
}
And the whole business of nested functions is not an improvement.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
brother i want to ask you.......the program that i write is it can use for this question
please teach me how to do it
I'm trying to do so without blatantly dumping working source code that I could easily write in obvious violation of the homework policy . Instead, I am trying to encourage you to learn and hopefully accelerate the process, with your help, by pointing to various bits that are most glaringly errors. But a one-sided teaching/learning process benefits neither.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314