Question

In: Computer Science

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 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>
#include <iomanip>
using namespace std;

int main() {
    int n;
    double shipping = 0, price, total = 0;
    cout << "Enter the number of items ordered: ";
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cout << "Enter the price of item no. " << i+1 << ": ";
        cin >> price;
        total += price;
    }
    if (total < 200) {
        shipping = 10*n;
    }
    cout << setprecision(2) << fixed;
    cout << "The shipping and handling fee is: $" << shipping << endl;
    cout << "The billing amount is: $" << total+shipping << endl;
    return 0;
}


Related Solutions

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...
The goal of this exercise is to implement the shuffling algorithm from this chapter. 1. In...
The goal of this exercise is to implement the shuffling algorithm from this chapter. 1. In the repository for this book, you should find the file named Deck.java. Check that you can compile it in your environment. 2. Implement the randomInt method. You can use the nextInt method provided by java.util.Random, which we saw in Section 7.6. Hint: To avoid creating a Random object every time randomInt is invoked, consider defining a class variable. 3. Write a swapCards method that...
Programming Exercise 11-2 QUESTION: In this chapter, the class dateType was designed to implement the date...
Programming Exercise 11-2 QUESTION: In this chapter, the class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables. Add a member function, isLeapYear, to check...
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 a program to implement Apriori Algorithm on web log data?   do a google search for...
Write a program to implement Apriori Algorithm on web log data?   do a google search for any keyword and store the results in a file or take some web log data from internet and apply apriori algorithm to get a meaningful conclusion from the data
In python Write a program to implement RSA algorithm based on the public key. def encryptmessage():...
In python Write a program to implement RSA algorithm based on the public key. def encryptmessage(): def decryptmessage(): encryptmessage () decryptmessage () No in-built functions and third-party APIs will be allowed.
Write a program to implement the Romberg Algorithm. Input: f(x), an interval [a,b], N (the number...
Write a program to implement the Romberg Algorithm. Input: f(x), an interval [a,b], N (the number of subintervals on the finest grid on level 0 is 2^N, therefore, N is usualy a small integer) Output: the triangle generated by Romberg Algorithm.
Write pseudocode to implement the paranoid algorithm. (You vs 2 other players)
Write pseudocode to implement the paranoid algorithm. (You vs 2 other players)
(Write a C# program DO NOT USE CLASS)Implement the merge sort algorithm using a linked list...
(Write a C# program DO NOT USE CLASS)Implement the merge sort algorithm using a linked list instead of arrays. You can use any kind of a linked structure, such as single, double, circular lists, stacks and/or queues. You can populate your list from an explicitly defined array in your program. HINT: You will not be using low, middle and high anymore. For finding the middle point, traverse through the linked list while keeping count of the number of nodes. Break...
Implement a C++ program to implement the Banker’s algorithm for deadlock avoidance. Number of process 5,...
Implement a C++ program to implement the Banker’s algorithm for deadlock avoidance. Number of process 5, number of resources 3 and the number of instances of each given resource is in available. You should complete the functionalities for safe state check and resource request processing. To Do 1. Complete the definition of isSafe function. The function take, the process array, 1D array of available resources, 2D array storing current allocation, and 2D array of current need. The function does not...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT