Question

In: Computer Science

In the space provided below write a C++ program that computes the total cost of books...

In the space provided below write a C++ program that computes the total cost of books you want to order from an online bookstore. It does so by first asking how many books are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then calls two functions: one for computing the taxes and another for computing the delivery charges. The function which computes delivery charges works as follows: It adds a 5% delivery charge for standard delivery if the total is below $1,000, and an additional 10% charge if you want an expedited next day delivery. The tax and delivery charges are added to the bill and the total cost is displayed.

Using the embed icon shown above, upload a series of screenshots that demo the execution of your program.

Thank you in advance!

Solutions

Expert Solution

The tax percentage is not known by me and hence TAX is initialized with 7.5. Change it if required.

The C++ code is:

main.cpp

#include <iostream>
#include <string.h>
using namespace std;

#define TAX 7.5

float calcTax( float amount);
float calcDelivery( float amount, char express);

int main()
{
        int numBook;
        cout << "\tEnter the total number of Books: ";
        cin >> numBook;

        float bookPrices[numBook];
        float amount = 0;
        cout << "\tEnter the prices of the books: ";
        for(int i = 0; i < numBook; ++i)
        {
                cin >> bookPrices[i];
                amount += bookPrices[i];
        }

        char ch;
        cout << "\n\tDo you want express delivery?(Y/N): ";
        cin >> ch;
        ch = toupper(ch);

        float taxTotal = calcTax( amount);
        float deliveryCharge = calcDelivery( amount, ch);

        float totalAmount = amount + taxTotal + deliveryCharge;

        cout << "\n\tAmount on books: " << amount;
        cout << "\n\tTotal tax: " << taxTotal;
        cout << "\n\tDelivery Charge: " << deliveryCharge;
        cout << "\n\tTotal Amount: " << totalAmount;

        return 0;
}

float calcTax( float amount)
{
        float res;
        res = amount*(TAX/100);
        return res;
}

float calcDelivery( float amount, char express)
{
        float res = 0;
        if (amount < 1000)
                res = amount*(5.0/100);
        if (express == 'Y')
                res += amount*(10.0/100);
        return res;
}

Sample Output :

Hope it helps.


Related Solutions

In the space provided below write a C program that computes the total cost of items...
In the space provided below write a C program that computes the total cost of items you want to order online. It does so by first asking how many items are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then adds a 5% delivery charge for standard delivery if the total is below $1,000, and an additional 10% charge if you want an expedited next day...
In the space provided below write a C program that computes the total cost of items...
In the space provided below write a C program that computes the total cost of items you want to order online. It does so by first asking how many items are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then adds a 5% delivery charge for standard delivery if the total is below $1,000, and an additional 10% charge if you want an expedited next day...
In the space provided below write a C ++ program that computes the total amount of...
In the space provided below write a C ++ program that computes the total amount of money you are depositing in your bank account. Your program does this by asking you to first enter the number and amount of each check you are depositing, and then it asks you to enter the type of cash bills being deposited and how many of each type, also the types of coins being deposited, and the number of each coin type.
In the space provided below write a C program that computes the total amount of money...
In the space provided below write a C program that computes the total amount of money you have stored in your piggy bank. Your program does this by asking you for number of pennies, nickels, dimes, and quarters in the piggy bank and then displays how much money in total is in the piggy bank.
C++ program that runs on Visual Basic that computes the total cost of books you want...
C++ program that runs on Visual Basic that computes the total cost of books you want to order from an online bookstore. It does so by first asking how many books are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then calls two functions: one for computing the taxes and another for computing the delivery charges. The function which computes delivery charges works as follows: It...
In the space provided below write a C++ program that asks the user to enter their...
In the space provided below write a C++ program that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen as well as onto a file.
In the space provided below write a ******C program********* that asks the user to enter their...
In the space provided below write a ******C program********* that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen. Using the embed icon shown above, also include screenshots demoing the execution of your program. Please write carefully. Thank you
Write a program in C that computes the area of a circle (Area = pi *...
Write a program in C that computes the area of a circle (Area = pi * r2) and the volume of a sphere (Volume = 4/3 * pi * r3). Both formulas use r which is the radius. Declare a float variable pi = 3.14159. Get the value of r from the keyboard and store it in a float variable. Display both the area of the circle and the volume of the sphere.
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT