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 [thread=15829]this[/thread]) >>

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.

explain the difference between a function prototype and function definition.....what about this question......mate

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...

return_type func_name( arguments );
// i.e.
int func(char a,int b,long c);

Now a definition also provides code and takes the following structure...

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;
}
Comments
Another good reply. And a late "welcome" to DaniWeb.

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

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
- 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 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

#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;
}

<< moderator edit: added [code][/code] tags >>

can you plese correct it for me

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.

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.)

<< moderator edit: added code tags: [code][/code] >>

#include<iostream>
using namespace std;

class employee
{
	string first;
	string last;
	int salary;

public:
	void getdata(void);
	void setdata(void);

	employee()
	{
		monthly salary = 0
		last name;
		first name;
	}
};
	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;
	}

<< moderator edit: added code tags: [code][/code] >>

why still got error.....

why still got error.....

can post error?


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.)

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.

way.cpp(16): error C2065: 'monthly' : undeclared identifier

way.cpp(16): error C2146: syntax error : missing ';' before
identifier 'salary'

way.cpp(17): error C2146: syntax error : missing ';' before identifier 'last'

way.cpp(17): error C2146: syntax error : missing ';' before identifier 'name'

way.cpp(17): error C2065: 'name' : undeclared identifier name


way.cpp(18): error C2146: syntax error : missing ';' before identifier 'name'

way.cpp(18): error C3861: 'name': identifier not found, even with argument-dependent lookupc:

.cpp(24): error C2593: 'operator >>' is ambiguousc:\

.cpp(24): error C3861: 'name': identifier not found, even with argument-dependent lookup

.cpp(26): error C2593: 'operator >>' is ambiguous

way.cpp(26): error C3861: 'name': identifier not found, even with argument-dependent lookup

.cpp(31): error C2143: syntax error : missing ';' before '<<'c:\

.cpp(32): error C2143: syntax error : missing ';' before '<<'

way.cpp(33): error C2143: syntax error : missing ';' before '<<'

.cpp(34): error C2562: 'employee::setdata' : 'void' function returning a value

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.

<< moderator edit: added code tags: [code][/code] >>

#include<iostream>
using namespace std;

class employee
{
	string first;
	string last;
	int salary;

public:
	void getdata(void);
	void setdata(void);

	employee()
	{
		monthly salary = 0;
		last_name;
		first_name;
	}
};
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;
}

<< moderator edit: added code tags: [code][/code] >>

but i am still got error....but less error....can you tell where is the problem

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.

brother i want to ask you.......the program that i write is it can use for this question

(employee class) create a class called employee that include three
pieces of information as data members - a first name (type 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 salaryis not
positive, set it to 0. write a test program that demonstrates class
employee's capabilties. create two employee objects and display each object's
yearly salary.then give each employee a 10 percent rase and display
each employee's yerly salary again.......please teach me how to do it

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.

#include<iostream>
using namespace std;

class employee
{
    string first;
    string last;
    int salary;

public:
    void getdata(void);
    void setdata(void);

    employee()
    {
         salary = 0;  
              last ;
             first ;
    }
};
int main()
{
    void employee::getdata(void)
    {
        cout<<"a first name:";
        cout<<"a last name:";
        cout<<"monthly salary:";
    }
    void employee:setdata(void)
    {
        cout<<"first name"<<  <<"\n";
        cout<<"last name"<<  <<"\n";
        cout<<"monthly salary"<<   <<"\n";
    }
    return 0;
}  

now i only got 2 errors.......getdata and setdata is the problem how to fixed it

 way.cpp(24): error C2601: 'employee::getdata' : local function definitions are illegal:

.cpp(30): error C2601: 'employee::setdata' : local function definitions are illegal

Edited 3 Years Ago by pyTony: fixed formating

Don't nest functions.

And the whole business of nested functions is not an improvement.

That is, don't try to define a function within another function.

And if you don't start using code tags, I may just quit trying. You can edit your post, you know.

int main()
{
    void employee::getdata(void)
    {
        cout<<"a first name:";
        cout<<"a last name:";
        cout<<"month;y salary:";
    }
    void employee::setdata(void)
    {
        cout<<"first name";<<  <<"\n";
        cout<<"last name";<<  <<"\n";
        cout<<"monthly salary";<<  <<"\n";
    }
    return 0;
}           



   void employee::getdata(void)
   void employee::setdata(void)      

this two have to be up main.....is it

Edited 3 Years Ago by pyTony: fixed formating

.....void getdata(void)
void setdata(void)


only this two error......i still dont know how to do this

[left]#include<iostream>
#include<string>
using namespace std;

class employee
{
string first;
string last;
int salary;

public:
void getdata(void);
void setdata(void);

employee()
{
salary = 0;
last="";
first="";
}
};
 
void employee::getdata(void)
{
cout<<"\na first name: " << first;
cout<<"\na last name: " << last;
cout<<"\nmonthly salary: " << salary;
}
void employee::setdata(void)
{
cout<<"first name?: ";
cin >> first;
cout<<"last name?: ";
cin >> last;
cout<<"monthly salary?: ";
cin >> salary;
}

int main()
{
	employee E;
	E.setdata();
	cout << "\n Stuff just entered: \n";
	E.getdata();
return 0;
}[/left]

There you go.

is that the answers for this question........or i need to change a bit

(employee class) create a class called employee that include three
pieces of information as data members - a first name (type 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 salaryis not
positive, set it to 0. write a test program that demonstrates class
employee's capabilties. create two employee objects and display each object's
yearly salary.then give each employee a 10 percent rase and display
each employee's yerly salary again.......please teach me how to do it

mugilan: Post your attempts using [CODE] tags. But make attempts. Replying to everyone else's thread (which I deleted) with your same question and code untouched from the last time anyone tried to help is... well, please stop. Try. Ask specific questions like, "How do I add 10%?" for example.

So if you need a set and a get function for each data member. You'd need 6 functions to handle your 3 data members. Can you take a stab at it?

Edited 3 Years Ago by diafol: fixed formatting

This article has been dead for over six months. Start a new discussion instead.