Question

Part II – Cost Calculator (15 Points) A software company sells a package that retails for...

Part II – Cost Calculator (15 Points)

A software company sells a package that retails for $ 99. Quantity discounts are given according to the following table:

Quantity

Discount

10 to 19

20%

20 to 49

30%

50 to 99

40%

100 or more

50%

Write a program that asks the user to enter the number of packages purchased. The program should then display the discount percentage, amount of the discount (can be 0) and the total amount of the purchase after the discount. Format the output to two decimal places, include % sign after the discount percentage and $ before the discount amount & total amount. Your program should include the following functions:

  1. discount_percentage – This function will receive number of packages purchased as a parameter and will return the discount percentage.
  2. main – This function will perform the following tasks:
    1. Ask use for the quantity
    2. Use discount_percentage function to calculate the discount percentage
    3. Calculate amount (quantity * 99)
    4. Calculate discount amount (amount * discount percentage /100)
    5. Calculate total amount (amount – discount amount)
    6. Display discount percentage, amount of discount, and total amount
    7. Display an error message if quantity is less than 0 (negative number)
    8. Use try/except construct to catch any errors
  3. Click Run -> Run Module
  4. Type main() to run your program
  5. If there are any syntax errors then fix those errors and run your program again.
  6. Use the quantity given in the following table to test your program for different possible outcomes.
  7. If you get the correct results (shown in the last three columns) then your program is working as expected.

    Run Number

    Quantity

    Output

    Discount Percentage

    Discount Amount

    Total Amount

    1

    abc

    Display Error Message

    2

    -5

    Display Error Message

    3

    5

    0.00%

    $0.00

    $495.00

    4

    19

    20.00%

    $376.20

    $1504.80

    5

    55

    40.00%

    $2178.00

    $3267.00

    6

    105

    50%

    $5197.50

    $5197.50

    Once you are satisfied with your results then take a screen shot of run number 1, 3 and 6 and past them below.Paste your screen shot below this line

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

PROGRAM

//-----------------------------------------//

//Program to calculate discount

//-----------------------------------------//

//include header files

#include<iostream>

#include<iomanip>

//include std namespace

using namespace std;

//--------------------------------------

//Function to find and return discount rate

//Input: number of packages

//Output: Discount rate

//Side Effects: None

//--------------------------------------

float discount_percentage(int p)

{

    if(p>=100) return 50.0;

    if(p>=50) return 40.0;

    if(p>=30) return 30.0;

    if(p>=20) return 20.0;

    return 0;

}

//main function

int main(void)

{

    int packages; //holds number of packages

    float amount, //holds total amount

          discountAmt,//holds discount amount

          discountPercentage; //holds discount percentage

    char c; //temporary variable

    //repeat until user opt to stop

    do{

        //read quantity from user

        cout<<endl<<"Enter the number of packages purchased: ";

        //handle data exception

        try

        {

            cin>>packages;

            if(packages < 1)throw(packages);

        }

        catch(int packages)

        {

            cout<<endl<<"Invalid input. \nQuantity must be a whole number greater than 0\n\n";

            return 0;

        }

        //calculate and display the results

        discountPercentage = discount_percentage(packages);

        discountAmt = packages*99*discountPercentage/100.0;

        amount = packages*99 - discountAmt;

        cout<<fixed<<setprecision(2);

        cout<<"Discount percentage = "<< discountPercentage <<" %"

            <<endl<<"Amount of discount = "<<"$ "<< discountAmt<<" and"

            <<endl<<"Total amount = "<<amount;

        cout<<endl<<endl<<"Calculate more (y/n): ";

        cin>>c;

    }

    while(c=='y'||c=='Y');

}

SCREENSHOT OF PROGRAM

1 // -// //Program to calculate discount 3 // -- -// 4 5 //include header files 6 7 #include<iostream> 8 #include<iomanip> 9

66 67 68 69 70 71 72 <<endl<< Amount of discount = <<$<< discountAmt<< and <<endl<<Total amount = <<amount; cout<<end

OUT OF THE PROGRAM IN CODE::BLOCK

Enter the number of packages purchased: aaa

Invalid input.

Quantity must be a whole number greater than 0

Enter the number of packages purchased: -5

Invalid input.

Quantity must be a whole number greater than 0

Enter the number of packages purchased: 5

Discount percentage = 0.00 %

Amount of discount = $ 0.00 and

Total amount = 495.00

Calculate more (y/n): y

Enter the number of packages purchased: 19

Discount percentage = 0.00 %

Amount of discount = $ 0.00 and

Total amount = 1881.00

Calculate more (y/n): y

Enter the number of packages purchased: 55

Discount percentage = 40.00 %

Amount of discount = $ 2178.00 and

Total amount = 3267.00

Calculate more (y/n): y

Enter the number of packages purchased: 105

Discount percentage = 50.00 %

Amount of discount = $ 5197.50 and

Total amount = 5197.50

Calculate more (y/n):

SCREENSHOT OF THE OUTPUT IN CODE::BLOCK

C:\TURBOC3\Turbo C++\discount.exe Х Enter the number of packages purchased: abc Invalid input. Quantity must be a whole num

C:\TURBOC3\Turbo C++\discount.exe х Enter the number of packages purchased: 5 Discount percentage = 0.00 % Amount of discou

Add a comment
Know the answer?
Add Answer to:
Part II – Cost Calculator (15 Points) A software company sells a package that retails for...
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
  • <Program 1: 50 points> software.cpp A software company sells a package that retails for $99. Quantity...

    <Program 1: 50 points> software.cpp A software company sells a package that retails for $99. Quantity discounts are given according to the following table. Quantity Discount 10-19 20% 20-49 30% 50-99 40% 100 or more 50% Write a program that asks for today's date (you MUST use cin >> date. Do not use getline(cin, date)), the company name and the quantity they wish to buy and computes the total cost of the purchase. If the user enters a negative value...

  • Computer science help! A software company sells their software packages for $99.00 each. They would like...

    Computer science help! A software company sells their software packages for $99.00 each. They would like you to write a program that will calculate and display an invoice for their customers. Quantity discounts are given according to the following table: Quantity   Discount 1 - 9 No discount 10 – 19 20% 20 – 49 30% 50 - 99 40% 100 or more 50% Write a C++ program that asks for the customer’s name and the number of software packages sold...

  • Code in c++ please Q1: Software Sales A software company sells a package that retails for...

    Code in c++ please Q1: Software Sales A software company sells a package that retails for $99. Quantity discounts are given according to the following table: QuantityDiscount 10-19 20-49 50-99 100 or more 20% 30% 40% 50% : Write a program that asks for the number of units sold and computes the total cost of the purchase. Input validation: Make sure the number of units is greater than 0. Q2: Book Club Points Community Booksellers has a book club that...

  • Q4 130 Quantity discounts are given according to the following table O points) A software company...

    Q4 130 Quantity discounts are given according to the following table O points) A software company sells one software package regularly for 99 QR Quantity Discount 20% 10-19 20-49 50-99 |00 or more 40% 50% write ρ program that asks for the number of items sold, and computes the total cost of the purchase. if the user enters an invalid number of items, the program displays invalid Purchasel" message. Sample output Enter number of items: 25 Total cost is 1732.5...

  • NOTE: All C++ programs that you write must have comments at the top with the program...

    NOTE: All C++ programs that you write must have comments at the top with the program name, your name, and the pseudocode describing what the program will do. 1. Create a new program that will calculate the total cost for software purchased from a store. Each software package costs $99.00, but discounts are given on the total cost, based on the number of packages purchased. a. Ask the user for the number of packages they want to buy b. Calculate...

  • Python Language 3. Shipping Charges The Fast Freight Shipping Company charges the following rates (per 500...

    Python Language 3. Shipping Charges The Fast Freight Shipping Company charges the following rates (per 500 miles shipped): 1. Number Guessing Game Write a program for players to guess the number that the program randomly generated. Your program should randomly generate an integer between 1 and 10. After a player guessing a number, your program should display "Too small", "Too large", or "That's it!". Weight of Package (in Kilograms) 2 kg or less Over 2 kg but not more than...

  • Python 3.7 to be used. Just a simple design a program that depends on its own. You should also not need to import anythi...

    Python 3.7 to be used. Just a simple design a program that depends on its own. You should also not need to import anything. No code outside of a function! Median List Traversal and Exception Handling Create a menu-driven program that will accept a collection of non-negative integers from the keyboard, calculate the mean and median values and display those values on the screen. Your menu should have 6 options 50% below 50% above Add a number to the list/array...

  • Lab #2 - Book Sale Calculator Submit Assignment Download Work file Download Runtime Be sure to...

    Lab #2 - Book Sale Calculator Submit Assignment Download Work file Download Runtime Be sure to include comments at the top of each procedure and at the top of the file. Be sure to use meaningful names for all buttons and labels. In this project, R 'n R Refreshment needs to expand the book sale project done previously. In addition to calculating individual sales and discounts, management wants to know the total number of books sold, the total number of...

  • excel for accounting Buckeye Company sells three products and offers quantity discounts to the customers. Buckeye...

    excel for accounting Buckeye Company sells three products and offers quantity discounts to the customers. Buckeye Company wants you to make a worksheet that will allow the salesperson (the user) to input the item and the quantity of the item that their customer wants to purchase. The worksheet will then calculate a price quote that the salesperson can give to the customer. The three products and the selling price are as follows: Item Unit Price Portable hard drive $99.00 Thumb...

  • The procedure is a sample and needs to be modified. The software used is oracle 11g. Provide screen shot of the program running. EX:NO:7 PLISOL PROCEDURE & FUNCTION AIM To develop the package for...

    The procedure is a sample and needs to be modified. The software used is oracle 11g. Provide screen shot of the program running. EX:NO:7 PLISOL PROCEDURE & FUNCTION AIM To develop the package for finding the number of students under each percentage for individual courses using PLISQL procedure and function. DATABASE SCHEMA STUDENT (ST_ID, NAME, COURSECODE, COURSENAME, TOTAL MARKS, PERCENTAGE) PROCEDURE STEP 1: Start STEP 2: Create a table with table name student. STEP 3: Insert at least 4 records...

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