Saturday, October 24, 2009

Passing Arguments by Value


This illustrates the technique used to pass arguments by value to a function.

#include 

#include

using namespace std;



string GetName()

{

string FirstName, LastName, FN;



cout << "Employee's First Name: ";

cin >> FirstName;

cout << "Employee's Last Name: ";

cin >> LastName;



FN = FirstName + " " + LastName;

return FN;

}



int main()

{

string FullName;

double Hours;

double GetHours(string FullName);



FullName = GetName();

Hours = GetHours(FullName);



cout << "\nEmployee's Name: " << FullName;

cout << "\nWeekly Hours: " << Hours << " hours\n\n";



return 0;

}



double GetHours(string FullName)

{

double Mon, Tue, Wed, Thu, Fri, TotalHours;



cout << endl << FullName << "'s Weekly Hours\n";

cout << "Monday: ";

cin >> Mon;

cout << "Tuesday: ";

cin >> Tue;

cout << "Wednesday: ";

cin >> Wed;

cout << "Thursday: ";

cin >> Thu;

cout << "Friday: ";

cin >> Fri;



TotalHours = Mon + Tue + Wed + Thu + Fri;

return TotalHours;

}

No comments:

Post a Comment

Popular Posts