#include<iostream>
#include<string>
using namespace std;
float getAmount(float &priceP,string itemP,int
&howmanyP)
{
float total=priceP;
if(itemP!="book" && priceP>200)
itemP="book";
else if(itemP=="birthday card" && howmanyP>=10)
priceP=priceP+10/5;
//Here we need to find the value of different variable
till this state line of execution
total+=priceP;
if(priceP<=12)
itemP="pencil";
howmanyP=50;
return total;
}
int main()
{
string item;
float price=10,fee;
int howmany=40;
fee=20;
item="birthday card";
fee=getAmount(price,item,howmany);
if(item=="book")
fee+=100;
else if(item=="pencil")
fee-=6;
else fee+=15;
cout<<"Total cost for items bought is :
R"<<fee<<endl;
return 0;
}
The value of different variables at line 10 (or marked by bold sentence) are :-
priceP = 12
itemP = "birthday card"
howmanyP = 40
fee = 20
total = 10
item = "birthday card"
According to the values calculated option 1 and option 3 are correct.
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 <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...
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....
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(); 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> 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; }
#include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...
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...