| | |
Deitel's "C++ How To Program" exercise 2.18
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2005
Posts: 31
Reputation:
Solved Threads: 0
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) >>
<< moderator edit: split thread (was a reply to this) >>
•
•
Join Date: Jul 2005
Posts: 164
Reputation:
Solved Threads: 5
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.
•
•
Join Date: Jul 2005
Posts: 164
Reputation:
Solved Threads: 5
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...
Now a definition also provides code and takes the following structure...
C++ Syntax (Toggle Plain Text)
return_type func_name( arguments ); // i.e. int func(char a,int b,long c);
C++ Syntax (Toggle Plain Text)
return_type func_name( arguments ) { // code here } // i.e. int func(char a,int b,long c) { if (a<c) return b; else return 0; }
•
•
Join Date: Aug 2005
Posts: 31
Reputation:
Solved Threads: 0
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
(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
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),write a test program that demostrates class employee's capabilities.
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.
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
•
•
Join Date: Aug 2005
Posts: 31
Reputation:
Solved Threads: 0
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
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
•
•
•
•
Originally Posted by Dave Sinkula
Make an initial attempt
•
•
•
•
Originally Posted by Dave Sinkula
and post that.
"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
•
•
Join Date: Aug 2005
Posts: 31
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; class employee { declare name as a string; last name as a string; monthly salary as a int; public: void getdata(void); void setdata(void); emlployee() { monthly salary = 0 last name = arun; first name = arun; }; 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; }
can you plese correct it for me
This should be like this
Spelling is important. 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.
C++ Syntax (Toggle Plain Text)
declare name as a string; last name as a string; monthly salary as a int;
C++ Syntax (Toggle Plain Text)
string first; string last; int salary;
Spelling is important.
emlployee() { monthly salary = 0 last name = arun; first name = arun; } };
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
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: fstream to char and int array
- Next Thread: How to create a registry?
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






