Question

1 2 3 #include <iostream> #include <string> using namespace std; float getAmount (float & pricep, string item, int & howmany)

Which of the options below correctly reflects the situation after Line 14 has been executed? Option 1 Line (price) price 12 [

Option 2 Line 14 [price] IpriceP 10 [item] birthday card [howmany] howmany 50 [fee] 20 itemp book total 20 Option 3 Line

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Execution of the program starts from the main function

Initially

item = "birthday card"

price = 10

howmany = 40

At line 24, we encounter a function call. Now, control moves to getAmount() function

Now, we have the following values

priceP = 10

itemP = "birthday card"

howmanyP = 40

totalP = 10 as totalP = priceP

Since itemP = "birthday card" and howmanyP = 40, we execute from line 10

priceP = priceP + 10/5

= 10 + 2

= 12

New value of priceP = 12

total+ = priceP which means total = total + priceP

New value of total = 22

Since priceP is equal less to 12, we will update itemP = "pencil"

howmanyP = 50

The return statement will send total to main function

After the execution of line 14, we have the following values

priceP = 12

total = 22

howmanyP = 50

itemP = "pencil"

Note: The value of the fee variable is wrong in all the options. It must be 22 as the value of total is returned

Options 2 and 3 are incorrect as itemP value is "pencil"

In Options 1 and 4, the values of other variables are correct except for the fee's value. Since the variable fee's value isn't correct, it is hard to predict which option is correct.

But options 2 and 3 are certianly incorrect.

Add a comment
Know the answer?
Add Answer to:
1 2 3 #include <iostream> #include <string> using namespace std; float getAmount (float & pricep, string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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...

    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;...

    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 <sstream> #include <string> using namespace std; int main() {    const int index...

    #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...

  • 1 #include <string> 2 #include <iostream> 3 using std::string; 4 using std::cout; 5 using std::endl; 7...

    1 #include <string> 2 #include <iostream> 3 using std::string; 4 using std::cout; 5 using std::endl; 7 class Pet 8 { 9   public: 10       string name; 11       virtual void print( ) const; 12}; 13 14 class Dog:public Pet 15 { 16   public: 17       string breed; 18       virtual void print( ) const; 19}; 20 21 int main( ) 22 { 23   Dog vdog; 24   Pet vpet; 25   vdog.name = "Tiny"; 26   vdog.breed = "Great Dane"; 27   vpet =...

  • #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem;...

    #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem; double menuPrice; }; void getData(menuItemType menuList[]); void showMenu(menuItemType menuList[], int x); void printCheck(menuItemType menuList[], int menuOrder[], int x); int main() { const int menuItems = 8; menuItemType menuList[menuItems]; int menuOrder[menuItems] = {0}; int orderChoice = 0; bool ordering = true; int count = 0; getData(menuList); showMenu(menuList, menuItems); while(ordering) { cout << "Enter the number for the item you would\n" << "like to order, or...

  • Please add a detailed comment for this program. #include<iostream> #include<string> #include<fstream> #include<sstream> #include<cctype> using namespace std;...

    Please add a detailed comment for this program. #include<iostream> #include<string> #include<fstream> #include<sstream> #include<cctype> using namespace std; int is_palindrome(string word){ int len = word.size(); for(int i=0; i<len/2; i++){ if(toupper(word[i])!=toupper(word[len-i-1])) return 0; } return 1; } int have_vowels3(string word){ int cnt = 0; for(int i=0; i<word.size(); i++){ if(tolower(word[i])=='a' || tolower(word[i])=='e' || tolower(word[i])=='i' || tolower(word[i]) =='o' || tolower(word[i]) == 'u') cnt++; } if(cnt>=3) return 1; else return 0; } int have_consecutives(string word){ for(int i=0; i<word.size()-1; i++){ if(tolower(word[i])=='o' && tolower(word[i+1]=='o')) return 1; } return...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure...

    #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...

  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT