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

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2005
Posts: 31
Reputation: mugilan is an unknown quantity at this point 
Solved Threads: 0
mugilan mugilan is offline Offline
Light Poster

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

 
0
  #1
Aug 12th, 2005
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) >>
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

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

 
0
  #2
Aug 12th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 31
Reputation: mugilan is an unknown quantity at this point 
Solved Threads: 0
mugilan mugilan is offline Offline
Light Poster

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

 
0
  #3
Aug 12th, 2005
explain the difference between a function prototype and function definition.....what about this question......mate
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

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

 
1
  #4
Aug 12th, 2005
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...
  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...
  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. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 31
Reputation: mugilan is an unknown quantity at this point 
Solved Threads: 0
mugilan mugilan is offline Offline
Light Poster

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

 
0
  #5
Aug 12th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

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

 
0
  #6
Aug 12th, 2005
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.
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
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 31
Reputation: mugilan is an unknown quantity at this point 
Solved Threads: 0
mugilan mugilan is offline Offline
Light Poster

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

 
0
  #7
Aug 12th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

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

 
0
  #8
Aug 12th, 2005
Originally Posted by Dave Sinkula
Make an initial attempt
...at code...
Originally Posted by Dave Sinkula
and post that.
:rolleyes:
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 31
Reputation: mugilan is an unknown quantity at this point 
Solved Threads: 0
mugilan mugilan is offline Offline
Light Poster

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

 
0
  #9
Aug 12th, 2005
  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

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

 
0
  #10
Aug 12th, 2005
This
  1. declare name as a string;
  2. last name as a string;
  3. monthly salary as a int;
should be like this
  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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC