Question

In: Computer Science

CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise...

CODE IN C++ PLEASE

Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling is free; otherwise, the shipping and handling is $10 per item. Design an algorithm that prompts Jason to enter the number of items ordered and the price of each item. The algorithm then outputs the total shipping and handling fee, and the billing amount. Your algorithm must use a loop (repetition structure) to get the price of each item. (For simplicity, you may assume that Jason orders no more than five items at a time.) An example of the program is shown below: Enter the number of items ordered: 3 Enter the price of item no. 1: 79.00 Enter the price of item no. 2: 23.50 Enter the price of item no. 3: 1.99 The shipping and handling fee is: $30.00 The billing amount is: $134.49 Since your program handles currency, make sure to use a data type that can store decimals with a decimal precision of 2.

Solutions

Expert Solution

#include <iostream>
using namespace std;
int main()
{
   float n, temp, totalPrize = 0;
   cout<<"Enter the number of items ordered: ";
   cin>>n;

   for (int i = 1; i <= n; ++i)
   {
       cout<<"Enter the price of item no. "<<i<<": ";
       cin>>temp;

       totalPrize = totalPrize + temp;
   }

   if (totalPrize >= 200)
   {
       cout<<"The shipping and handling fee is: $0.00"<<endl;
       cout<<"The billing amount is: $"<<totalPrize<<endl;
   } else {
       float shippingAndHandlingFee = n * 10;
       totalPrize = totalPrize + shippingAndHandlingFee;

       cout<<"The shipping and handling fee is: $"<<shippingAndHandlingFee<<endl;
       cout<<"The billing amount is: $"<<totalPrize+n<<endl;
   }

   return 0;
}


Related Solutions

Instructions Write a program to implement the algorithm that you designed in Exercise 19 of Chapter...
Instructions Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING) C++ CODE Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200...
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
Write a pseudo code for an O (n7log3n) algorithm. Please write in C++.
Write a pseudo code for an O (n7log3n) algorithm. Please write in C++.
Write a program in C++ to implement Binary Search Algorithm. Assume the data given in an...
Write a program in C++ to implement Binary Search Algorithm. Assume the data given in an array. Use number of data N at least more than 10. The function Binary Search should return the index of the search key V.
Write the code in C++. Write a program to implement Employee Directory. The main purpose of...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of the class is to get the data, store it into a file, perform some operations and display data. For the purpose mentioned above, you should write a template class Directory for storing the data empID(template), empFirstName(string), empLastName(string), empContactNumber(string) and empAddress(string) of each Employee in a file EmployeeDirectory.txt. 1. Write a function Add to write the above mentioned contact details of the employee into EmployeeDirectory.txt....
please write a C program that implements Quick Sort algorithm.
please write a C program that implements Quick Sort algorithm.
Please write code in C, thank you. Write a program that reads a list of integers,...
Please write code in C, thank you. Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: all even Ex: If the input is: 5 1 3 5 7 9...
Code in C++ please You are going to write a program for Computer test which will...
Code in C++ please You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly and provide the test to the user. When the user done the program must give the user his final score
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
Write and test a C program to implement Bubble Sort. . In your C program, you...
Write and test a C program to implement Bubble Sort. . In your C program, you should do: Implement the array use an integer pointer, get the size of the array from standard input and use the malloc function to allocate the required memory for it. Read the array elements from standard input. Print out the sorted array, and don’t forget to free the memory. Debug your program using Eclipse C/C++ CDT.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT