Answer: Option 2) Price = 12, item = "birthday card", howmany = 50, fee = 37
Reason:
Debugging Function: getAmount(float & priceP, string itemP, int & howmanyP)
As we can see, the variables priceP and howamny are passed by reference and itemp is passed by value.
So, inside the function, when the line 6 executes, we get total = 10, next line 9 executes and value of priceP is updated to 12. Then, total is updated to 22 by adding priceP to it in line 11.Then, Line 12 executes and sets the value of itemP to "pencil", but as it is passed by value, item inside the main() remains the same. Then line 15 returns the value of total.
After the line 24 executes, we get the updated value of fee equal to 22, price = 12, howmany = 50 and item = "birthday card". The as the item is neither a book or a pencil, so statement 29 executes and the value of fee is incremented by 15, i.e fee = 37.
So, Option 2 is correct and all other options 1, 3 and 4 are wrong.
1 2 3 #include <iostream> #include <string> using namespace std; float getAmount (float & pricep, string...
1 2 3 #include <iostream> #include <string> using namespace std; float getAmount (float & pricep, string item, int & howmany) 4 5 6 7 8 9 10 11 12 13 14 15 16 = float total priceP; if (item != "book" && price > 200) itemP = "book"; else if (item == "birthday card" && howmanyP >= 10) priceP priceP + 10 / 5; total += priceP; if (price <= 12) itemP = "pencil"; howmany = 50; return total; ب...
1 2 3 #include <iostream> #include <string> using namespace std; float getAmount (float & pricep, string item, int & howmany) 4 5 6 7 8 9 10 11 12 13 14 15 16 = float total priceP; if (item != "book" && price > 200) itemP = "book"; else if (item == "birthday card" && howmanyP >= 10) priceP priceP + 10 / 5; total += priceP; if (price <= 12) itemP = "pencil"; howmany = 50; return total; ب...
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...
#include <iostream> #include <string> using namespace std; //Write a function that changes all characters in a string to dashes string to_dash(string s){ for(int i = 0; i < s.length(); i++){ } return s; } int main(){ string s; cin >> s; s = to_dash(s); cout << s << endl; }
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...
4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....
#include <iostream> using namespace std; - // Guess the output for the below program. // Assume address of a,b,c as 4004, 4008, 4016 respectively. int main() { float a = 12.5; int b = 10; double c = 3.1412; float aptr = &a; int *bptr = &b; double *cptr = &c; cout << "value of variable a,b,c:"<< a <<""<<b<<""<<<<<endl; cout << "Address of variable a,b,c:"<<&a<<""<<&b<<""<<&c << endl; cout << "value of aptr, bptr, cptr:" << aptr <<""<<bptr <<"" << cptr...
#include <iostream> #include <sstream> #include <string> using namespace std; int main() { const int index = 5; int head = 0; string s[index]; int flag = 1; int choice; while (flag) { cout << "\n1. Add an Item in the Chores List."; cout << "\n2. How many Chores are in the list."; cout << "\n3. Show the list of Chores."; cout << "\n4. Delete an...
Find the problems with this program #include <iostream> using namespace std; struct Student { string name; int grade; } int main() { struct Student mary; Mary:name = "Mary"; Mary:grade = 100; cout << mary:name " got a " << mary:grade << endl; return 0; }
Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) { hours = 0; minutes = 0; isAfternoon = false; //check to make sure there are 5 characters if (//condition to check if length of string is wrong) { cout << "You must enter a valid military time in the format 00:00" << endl; } else { //check to make sure the colon is in the correct...