Apr 1, 2012 at 1:48pm UTC
void processData(string nameP, string & addrP, float & salaryP, int employP)
blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah
processData("Ms. Shirley Sithole", address, sallary, 88123); //VALID OR NOT?
processData(name, "45Ashley Road, Birch Court, Kempton Park", salary, employeeNumber); //VALID OR NOT?
processData("Who are you?", address, 8750.00, 909); //VALID OR NOT?
Apr 1, 2012 at 3:16pm UTC
It depend's on what you actually wrote as the function body. Include more info if you want a answer.
Right now most of them are accurate if you are trying to call a function, but rather it's compilable depends on you function parameter and body.
Last edited on Apr 1, 2012 at 3:25pm UTC
Apr 1, 2012 at 3:38pm UTC
1. #include <iostream>
2. #include <string>
3. using namespace std;
4. void processData(string nameP, string & addrP, float & salaryP,
int employP)
5. {
6. if (nameP == "Who are you?")
7. nameP = "Mr. Ghost";
8. if (salaryP > 10000.00)
9. salaryP += 0.08 * salaryP;
10. else
11. salaryP += 0.10 + salaryP;
12. cout << "New salary for employee number " << employP << " : R"
<< salaryP << endl;
13. }
14. int main()
15. {
16. string name, address;
17. float salary;
18. int employeeNumber;
19. cin >> name >> address >> salary >> employeeNumber;
20. processData("Ms. Shirley Sithole", address, salary, 88123);
21. employeeNumber = 54321;
22. name = "Mr. John Smith";
23. processData(name, "45 Ashley Road, Birch Court, Kempton Park",
salary, employeeNumber);
24. processData("Who are you?", address, 8750.00, 909);
25. return 0;
Apr 1, 2012 at 3:51pm UTC
Given this declaration:
void processData(string nameP, string & addrP, float & salaryP, int employP)
This is valid:
processData("Ms. Shirley Sithole" , address, sallary, 88123);
These are invalid (I've underlined the offending arguments):
1 2
processData(name, "45Ashley Road, Birch Court, Kempton Park" , salary, employeeNumber);
processData("Who are you?" , address, 8750.00 , 909);
Why? Because when you pass an object by reference, you actually need the object to exist with an address.
In the first call, use
1 2
string address = "45Ashley Road, Birch Court, Kempton Park" ;
processData(name, address , salary, employeeNumber);
For the second call use:
1 2
float salary = 8750.f
processData("Who are you?" , address, salary, 909);
Last edited on Apr 1, 2012 at 3:52pm UTC
Apr 1, 2012 at 4:14pm UTC
Thanks for the reply
how come processData("Ms. Shirley Sithole", address, sallary, 88123); a valid function?
int number = 100;
string game = “poker”;
int members;
int rounds = 6;
playGame(number, “blackjack”, members, 3);
are these valid:
1. void playGame(int numberP, string & gameP, int membersP,
int roundsP);
2. void playGame(int & numberP, string gameP, int & membersP,
int roundsP);