Presentation is loading. Please wait.

Presentation is loading. Please wait.

Parameters I string ask(string nz) { string thing; cout << "What goes like " << nz << "?"; cin >> thing; return thing; } void Sing(string animal, string.

Similar presentations


Presentation on theme: "Parameters I string ask(string nz) { string thing; cout << "What goes like " << nz << "?"; cin >> thing; return thing; } void Sing(string animal, string."— Presentation transcript:

1 Parameters I string ask(string nz) { string thing; cout << "What goes like " << nz << "?"; cin >> thing; return thing; } void Sing(string animal, string noise) { cout << "The " << "animal" << " " << animal << " goes like " << noise << noise << noise << endl; } void main() { string noise = "quack "; string animal = ask(noise); Sing(animal,noise); } Formal Parameter Actual Parameter (Argument)

2 Parameters II void sing(string vo) { cout << vo << vo << vo << vo; } string Sing(string animal, string sound) { cout << animal << " goes like "; sing(sound); return "\n"; } void main() { string noise = "quack "; string animal = "duck"; cout << Sing(animal,noise); } duck goes like quack quack quack quack Press any key to continue

3 Type Coercion void main() { double r; int i=1,j=2, k; k = r = 3; cout << i/r << endl; cout << i/k << endl; cout << i/r/r << "\n\n"; cout << i/r/k << endl; cout << i/k/r << "\n\n"; cout << j/(r/k)/r << endl; cout << j/(k/r)/k << endl; } 0.333333 0 0.111111 0 0.666667 Press any key to continue

4 Simple Tax double tax (double price) { return price*7.5/100; } double buy_one() { double p; cout << "Input the price: $"; cin >> p; return p; } void main() { cout << "The tax is $" << tax(buy_one()) << "\n\n"; cout << tax(buy_one()) << "The tax is $" << "\n\n"; } Input the price: $34 The tax is $2.55 Input the price: $34 The tax is $2.55 Input the price: $34 2.55The tax is $ Press any key to continue

5 Buy two items void main() { double p,tx,total,m; p = buy_one(); tx = tax(p); total = p+tx; p = buy_one(); tx = tax(p); total = total+p+tx; cout << "after tax : $" << total; cout << "\n\n" << "Input the amount of money taken: $"; cin >> m; cout << "The change is $" << m-total << "\n\n"; } Input the price: $30 Input the price: $20 after tax : $53.75 Input the amount of money taken: $100 The change is $46.25 Press any key to continue

6 Buy two items II void main() { double p,m; p = buy_one() + buy_one(); p = p + tax(p); cout << "after tax : $" << p; cout << "\n\n" << "Input the amount of money taken: $"; cin >> m; cout << "The change is $" << m-p << "\n\n"; } Input the price: $30 Input the price: $20 after tax : $53.75 Input the amount of money taken: $100 The change is $46.25 Press any key to continue


Download ppt "Parameters I string ask(string nz) { string thing; cout << "What goes like " << nz << "?"; cin >> thing; return thing; } void Sing(string animal, string."

Similar presentations


Ads by Google