943,682 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 16427
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 12th, 2005
0

Re: Deitel's "C++ How To Program" exercise 2.18

Expand Post »
what about this question.........what is a default comstructor? how are an object's data members initialized if a class has only an implicitly defied default constructor? explain the purpose of data member.

<< moderator edit: split thread (was a reply to this) >>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
mugilan is offline Offline
33 posts
since Aug 2005
Aug 12th, 2005
0

Re: Deitel's "C++ How To Program" exercise 2.18

A default constructor is a constructor that takes no arguments or fully defaulted arguments. The values of the members of your object are set to a bitwise zero unless otherwise specified by default values. The implicit default constructor just zeros all your members.Its purpose is mainly to ensure your objects are created initialised to a certain value rather than containing whatever garbage was previously in those memory locations.
Reputation Points: 19
Solved Threads: 5
Junior Poster
Stoned_coder is offline Offline
164 posts
since Jul 2005
Aug 12th, 2005
0

Re: Deitel's "C++ How To Program" exercise 2.18

explain the difference between a function prototype and function definition.....what about this question......mate
Reputation Points: 10
Solved Threads: 0
Light Poster
mugilan is offline Offline
33 posts
since Aug 2005
Aug 12th, 2005
1

Re: Deitel's "C++ How To Program" exercise 2.18

a function prototype introduces the function to the compiler. It tells the compiler about what arguments the function takes and what it returns. A prototype looks like this...
C++ Syntax (Toggle Plain Text)
  1. return_type func_name( arguments );
  2. // i.e.
  3. int func(char a,int b,long c);
Now a definition also provides code and takes the following structure...
C++ Syntax (Toggle Plain Text)
  1. return_type func_name( arguments )
  2. {
  3. // code here
  4. }
  5.  
  6. // i.e.
  7.  
  8. int func(char a,int b,long c)
  9. {
  10. if (a<c)
  11. return b;
  12. else
  13. return 0;
  14. }
Reputation Points: 19
Solved Threads: 5
Junior Poster
Stoned_coder is offline Offline
164 posts
since Jul 2005
Aug 12th, 2005
0

Re: Deitel's "C++ How To Program" exercise 2.18

this is the last one.......


(employee class)create a class called employee that include three pieces of information as data members - 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. if the monthly salary is not positive, set it to 0. 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
Reputation Points: 10
Solved Threads: 0
Light Poster
mugilan is offline Offline
33 posts
since Aug 2005
Aug 12th, 2005
0

Re: Deitel's "C++ How To Program" exercise 2.18

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.
Quote originally posted by mugilan ...
create a class called employee that include three pieces of information as data members
- 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.
if the monthly salary is not positive,
set it to 0.
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
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Aug 12th, 2005
0

Re: Deitel's "C++ How To Program" exercise 2.18

Originally Posted by mugilan
create a class called employee that include three pieces of information as data members
- 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.
if the monthly salary is not positive,
set it to 0.
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
Reputation Points: 10
Solved Threads: 0
Light Poster
mugilan is offline Offline
33 posts
since Aug 2005
Aug 12th, 2005
0

Re: Deitel's "C++ How To Program" exercise 2.18

Quote originally posted by Dave Sinkula ...
Make an initial attempt
...at code...
Quote originally posted by Dave Sinkula ...
and post that.
:rolleyes:
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Aug 12th, 2005
0

Re: Deitel's "C++ How To Program" exercise 2.18

C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. class employee
  6. {
  7. declare name as a string;
  8. last name as a string;
  9. monthly salary as a int;
  10.  
  11. public:
  12. void getdata(void);
  13. void setdata(void);
  14.  
  15. emlployee()
  16. {
  17. monthly salary = 0
  18. last name = arun;
  19. first name = arun;
  20. };
  21. void employee::getdata(void)
  22. {
  23. cout<<"a first name:";
  24. cin>>name
  25. cout<<"a last name:";
  26. cin>>name
  27. cout<<"monthly salary:";
  28. }
  29. void employee::setdata(void)
  30. {
  31. cout<<"first name";<<first name<<"\n";
  32. cout<<"last name";<<last name<<"\n";
  33. cout<<"monthly salary";<<monthly salary<<"\n";
  34. }
  35. return 0;
  36. }
<< moderator edit: added [code][/code] tags >>



can you plese correct it for me
Reputation Points: 10
Solved Threads: 0
Light Poster
mugilan is offline Offline
33 posts
since Aug 2005
Aug 12th, 2005
0

Re: Deitel's "C++ How To Program" exercise 2.18

This
C++ Syntax (Toggle Plain Text)
  1. declare name as a string;
  2. last name as a string;
  3. monthly salary as a int;
should be like this
C++ Syntax (Toggle Plain Text)
  1. string first;
  2. string last;
  3. 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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: fstream to char and int array
Next Thread in C++ Forum Timeline: How to create a registry?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC