You don't know how to write a function that will set a value?
You don't know how to write a function that will get a value?
Even with the examples given?

[edit]If I gave you some prototypes, do you think you could make an attempt at filling in the rest?

#include <iostream>
#include <string>
using namespace std;

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

public:
   employee() : first(""), last(""), salary(0) {}
   string getfirst();
   string getlast();
   int    getsalary();
   void   setfirst(string f);
   void   setlast(string l);
   void   setsalary(int s);
};

string employee::getfirst()
{
   // ...
}

string employee::getlast()
{
   // ...
}

int employee::getsalary()
{
   // ...
}

void employee::setfirst(string f)
{
   // ...
}

void employee::setlast(string l)
{
   // ...
}

void employee::setsalary(int s)
{
   // ...
}

\\what to write there.....please help only ones....please

You've got to be kidding. You don't even have a guess as to how a function such as getsalary would be coded? Let's see, you need to return the salary.

<< moderator edit: this is the last time I add [code][/code] tags before I close this thread and send you to follow this link I keep posting >>

#include<iostream>
#include<string>
using namespace std;

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

public:
	employee();first('''),last('''),salary(0){10%}
	string getfirst();
	string getlast();
	int salary();
	void setfirst(string f);
	void setlast(string l);
	void setsalary(int s);
};
string employee::getfirst()
{
	cout<<"\na first name:"<<first;
}
string employee::getlast()
{
	cout<<"\na last name:"<<last;
}
string employee::getsalary()
{
	cout<<"\n monthly salary:"<<salary;
}
void employee::setfirst(string f)
{
	cout<<"first name?:";
	cin>>first;
}
void employee::setlast(string l)
{
	cout<<"last name?:";
	cin>>last;
}
void employee::setsalary(int s)
{
	cout<<"monthly salary?:";
	cin>>salary;
}
int main()
{
	employee E;
	E.setdata();
	cout<<"\n stuff just entered:\n";
	E.getdata();
	return 0;
}

is it like this....

I have no idea how you are trying to butcher the constructor.
The get functions need to return a value. [edit]Or maybe you could do it this way instead -- but you wouldn't declare the function as returning a value.[/edit]
But the set functions can be done that way. Taking use input as you do, you don't need a parameter to the function.
Your main is still a copy that someone else gave you, so that doesn't tell me much.

that is the best thing can i do.......please write for me the rest and main.....i am doing this question for more than 2 weeks....or give me a tips

#include<iostream>
#include<string>
using namespace std;


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


public:
employee(): first(""),last(""),salary(0){}
string getfirst();
string getlast();
int getsalary();
void setfirst(string f);
void setlast(string l);
void setsalary(int s);
};
string employee::getfirst()
{
return first;
}
string employee::getlast()
{
return last;
}
int employee::getsalary()
{
return salary;
}
void employee::setfirst(string f)
{
cout<<"first name?:";
cin>>first;
}
void employee::setlast(string l)
{
cout<<"last name?:";
cin>>last;
}
void employee::setsalary(int s)
{
cout<<"monthly salary?:";
cin>>salary;
}
int main()
{
employee E;
E.setdata();
cout<<"\n stuff just entered:\n";
E.getdata();
return 0;
}



i got two error in main.....can you help me
commented: Use code tags. +0
#include<iostream>
#include<string>
using namespace std;


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


public:
employee(): first(""),last(""),salary(0){}
string getfirst();
string getlast();
int getsalary();
void setfirst(string f);
void setlast(string l);
void setsalary(int s);
};
string employee::getfirst()
{
return first;
}
string employee::getlast()
{
return last;
}
int employee::getsalary()
{
return salary;
}
void employee::setfirst(string f)
{
cout<<"first name?:";
cin>>first;
}
void employee::setlast(string l)
{
cout<<"last name?:";
cin>>last;
}
void employee::setsalary(int s)
{
cout<<"monthly salary?:";
cin>>salary;
}
int main()
{
employee E;
string f("game");
string l();
int s();
cout<<"\n stuff just entered:\n";
E.getdata();
return 0;
}

i got one error.....E.getdata(); what to write here

For the getdata member function to be called, it has to be defined first.

Mugilan --

Just wanted to write you and encourage you NOT to give up. Look at all you have learned so far. Keep on trying, and you will get it. No one writes a program perfectly the first time (except perhaps Narue, but she is a coding Goddess).

Keep working at it. You are well on the way, and in the end, you will feel good that you did the hard parts yourself. That is the honorable thing to do! You are in good hands with Dave.

Christian

thanks

can anybody help me on this question write a program that use a statement to calculate and print the average of several integers. assume the last value read is the sentinel 9999. a typical input sequence might be

10 8 11 7 9 9999

10,,,,,8,,,,,11,,,,,7,,,,,9,,,,,,,9999

can you help me please on this question..................


write single statements that performs the following on,

intialize the 10 elements of integer array counts to zero
add 1 to each of the 15 elements of integer array bonus
read 12 values for double array monthly temperatures from the keyboard
print the 5 values o integer array best score in column format

write a program that prints the powers of the nteger 2, namely 2,4,8,16,32,64, etc your while loop should not terminate(i.e you should create an infinite loop) to do this, simply use keyword true as the expression for while statement. what happens when you run this program.....

#include<iostream>
using std::cout;
using std::cin;
using std::endl;


int main()
{
long bound;
cout<<"enter a positive integer:";
cin>>bound;
cout<<"fibonacci numbers <"<<bound<<":\n0, 1";
long f0=0, f1=1;
while(true)   //error:infinite loop!  (press <ctrl>+c.)
{
long f2 = f0 + f1;
cout <<","<< f2;
f0 = f1;
f1 = f2;
}
return 0;
}

i write this program for that question......are this is correct or i need to change it

did you compile and run your program? If not, then you should do so to see the output. But for now, I would change "while(frue)" to something that will limit the output to the first 10 numbers or so and then quit on its own. It will make debugging a little easier.

To get powers of two requires multiplication. for example, 1*2 = 2, 2 * 2 = 4, 4 * 2 = 8, 8 * 2 = 16, ...

Or you can also do it my addition , 1 + 1 = 2, 2 + 2 = 4, 4 + 4 = 8, 8 + 8 = 16, 16 + 16 = 32, ...


with that in mind, now look at your program. the calculations inside the while loop are all wrong. all you need is one variable -- f0 -- and add it to itself

int f0 = 1;

// power of 2
f0 = f0 + f0;
cout << f0 << ", ";

thanks i am done with that question.....can you help on this.... read 12 values for double array monthly temperatures from the keyboard......write single statement that perform,,,,

thanks i am done with that question.....can you help on this.... read 12 values for double array monthly temperatures from the keyboard......write single statement that perform,,,,

And I suppose you want me to take your classes for you and do all your homework :mrgreen:

no.....please help me only ones

is it like this

#include<iostream>
using namespace std;


int main()
{
for(i = 0; i<=11; i++){
printf("enter a temperature:");
cout<<"monthly temperature:"
scanf("%f", &monthlytemperature);
}
}

I haven't read this whole thread, so I don't know what all those ... mean in your previous post.

did you try to compile it? Obviously not because it contains a few syntax errors, like missing declarations of variables.

when you want to count from 0 to (but not including) 12, most people code it like this:

for(i = 0; i < 12; ++i){
#include<iostream>
using namespace std;
int i;
typedef float sequence[];

int main()

{

    for (i = 0; i<=12; i++){
        printf("enter a Temperature:");
        scanf("%f", "&monthly Temperature[i]");
    }
}  

when it runs...it say run time error

what compiler are you using? Your program still has several syntax errors and the compiler should have spit out several error messages. Did you fix them? or just ignore them? NEVER ignore errors and warnings. Nobody can help you very much if you don't post exactly what you tried to compile -- I forgot to being my crystle ball today.

use your book and compare the syntax of what you wrote to examples in the book. if they look good, then do a dry run of your program on paper, write out each variable and what happens to its contents in each iteration of the loop. maybe youll find an error in your logic...(although in the last case its a syntax prob)
understand the concepts first, then attempt the code, unless it seems intuitive, dont just read the chapter and tackle the questions. understanding is a must.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.