Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language: c++ CS 1336, Project Assignment 3 Discount calculation for software sales There are two parts to this assignment. In part 1 you will create

Language: c++

CS 1336, Project Assignment 3 Discount calculation for software sales

There are two parts to this assignment. In part 1 you will create a grading application. In part 2 you will update the grading application.

Post the program code as source files (text files) with an extension of .cpp. There are two parts to this program, so you will need two .cpp files.

Your submission on eLearning should use the following names:

cs1336p03part1yourName.cpp and cs1336p03part1screenshotYourName.jpg

cs1336p03part2yourName.cpp and cs1336p03part2 screenshotYourName.jpg Part 1: Creating the application A software company sells a package that retails for $99. Quantity discounts are given according to the following table:

Quantity

Discount

1 - 10

No discount

11 - 30

10%

31 60

15%

61 - 90

20%

91 or more

25%

Note that if a customer purchases 11 30 units they get a 10% discount on all of the units they purchase. The rule is the same for the rest of the discount levels they get that discount for their entire purchase.

If the number of units sold is 150 or more output a message saying the customer is a preferred customer.

Think about the types of things that could change in the future as the business changes. It is likely that the price of the software could change. Also, the company may want to change the discount levels and discount percentages. The company could add new discount levels or reduce the number of discount levels. Finally, the number of units that have to be sold to be a preferred customer could change as well. You need to think about how you can write your code so that these changes can be made in a way that minimizes the amount of code that has to change.

The retail price of the software must be kept in a const variable and not hard coded in your application code. Note that the const variables are NOT global. You will have to decide what functions need the const variables.

The same is true for all of the discounts and quantity levels, and for the preferred customer level. These must also be const variables.

For example, the list price and preferred customer values can be defined as follows (you can use different names if you want to):

const double RETAIL_PRICE = 99.0; const int PREFERRED_CUSTOMER_LEVEL = 150;

You will be using a set of functions do to the following tasks. See details see the section Function requirements below.

General tasks for the application:

You will be writing a program that asks the user for the number of units sold (read using cin) and computes the total sales for the purchase. Keep the calculated total sales in a variable.

The application needs to output the discount the customer qualified for, the number of units sold and the amount of the sale.

Your application will output a message if the customer is a preferred customer.

Your application must validate the input and make sure the number of units is greater than 0. If

the input quantity is not valid you need to output a message and exit the program.

Function requirements: Here is a summary of what needs to be done in the main function:

Your main function needs to have a main processing loop. Within the loop you will call the following functions: 1. Call the getQuantity function. This will return back the input from the application user. A

return value of 0 indicates that no processing should be performed. A value greater than 0, the number of items being purchased, will be processed as follows.

a. The following steps, in your main function, all of these tasks assume that the value returned back from getQuantity is > 0.

Note: You can also use an alternate implementation and have the getQuantity function check the value and reprompt the user if they enter in a value < 0. The output must still match what is shown in the sample output below.

2. Call the getDiscount function with the value returned back from getQuantity. The getDiscount function returns the discount percent the customer gets for the quantity of items being purchased. The quantity is passed to the function as an argument. The

return value will be between 0 and 1 and specifies the % of the discount the customer

will get (.15 is 15%, 0 is no discount).

Next call calculateSale. The two arguments passed to the calculateSale function are the

number of items being purchased (from getQuantity) and the discount to be applied (returned from getDiscount). The calculateSale function returns back the total revenue from the sale.

Now you call displaySale. You need to pass to it the number of items purchased, the discount for the purchase, and the total revenue (returned from the call to calculateSale). There is no return value from the displaySale function.

Finally, your main function needs to call the isPreferred function (passing to it the number of items purchased by the customer). If isPreferred returns back a true value the main function should call the displayPreferred function. The displayPreferred function does not take any parameters.

If the quantity you read in is 0 your program should end (you drop out of the loop). If the quantity is not equal to 0 your main processing loop will begin again and do steps 1 through 5

Here is some pseudo-code for the main function:

NumberOfItems = -1 While (NumberOfItems != 0) 

NumberOfItems = getQuantity() // step 1 If (NumberOfItems > 0)

 // do steps 2 through 5 End If 

End While

Here is a summary of what needs to be done in the functions:

getQuantity: This function will read from cin the quantity of the software being purchased. If the user enters in an invalid quantity (less than 0), an error message should be displayed and the function should reprompt the user to enter in a valid value.

If the value is 0 just return the value back. If the quantity is one or more, the function should just return back the quantity entered by the user. The value returned should be an int.

See the sample runs below to see what needs to be displayed if the users input is not valid.

getDiscount: This function takes one parameter of type int. It is the number of items being purchased. The functions should determine the discount percent for the quantity of items being purchased. See the table at the start of this assignment for the valid discounts (including no discount). The discount should be returned back to the caller and will be of type double (examples of valid discounts for part 1 are 0, .1, .15, and so on). So, a 15% discount would be returned as .15.

calculateSale: The calculateSale function takes two parameters and returns back a value of type double. The first parameter is the quantity of items being purchased. The second parameter is the discount for this customer. The total revenue needs to be calculated and returned back from the function. The revenue is the price of the software times the quantity sold less any discount.

displaySale: This function does not return back a value. It does, however, take three parameters. The first parameter is the quantity of items being purchased. The second parameter is the discount for this customer, and the third parameter is the revenue from the current sale. The function needs to display the details of the sale to the console output (cout). See the sample runs below for details on what needs to be displayed.

isPreferred: The isPreferred function takes one parameter and returns back a bool value. The input parameter is the quantity of items purchased by this customer. The function needs to determine if the customer is a preferred customer or not. If the customer is a preferred customer the function needs to return back true. If the customer is not a preferred customer the function should return back false.

displayPreferred: This function does not take any input parameters and does not return back a value. It should simply output a message (to cout) stating that this is a preferred customer. See the sample runs for an example of the message to be displayed.

Format the output with two decimal places for the total sales in the format $xxxx.xx. See the sample output below for examples of the output you need to provide.

Here is sample output from the application. User input is in bold:

Enter the number of units sold: 200[Enter] The customer purchased 200 units and qualified for a 25% discount The total sale for the customer is $14850.00 The customer is a preferred customer

Enter the number of units sold: 5[Enter] The customer purchased 5 units and does not qualify for a discount The total sale for the customer is $495.00

Enter the number of units sold: 16[Enter] The customer purchased 16 units and qualified for a 10% discount The total sale for the customer is $1425.60

Enter the number of units sold: -1[Enter] The number of units must be 1 or more

Enter the number of units sold: 30[Enter] The customer purchased 30 units and qualified for a 10% discount The total sale for the customer is $2673.00

Enter the number of units sold: 0[Enter] In addition to the above you should run your program multiple times and test the boundary conditions.

Test cases that you should run: -1, 1, 10, 11, 30, 31, 60, 61, 90, 91, 149, 150.

Part 2: Updating the software sales program Note: Make sure you save your part 1 code before you make any changes to the code. You will need to

submit the source code for both parts 1 and 2.

A software company now sells the software package with a retail price of $109.49. The preferred customer level needs to be changed to 175. A customer that purchases 175 or more copies is a preferred customer.

Quantity discounts are given according to the following table:

Quantity

Discount

1 - 21

No discount

22 - 42

8%

43 - 63

16%

64 - 84

24%

85 - 109

33%

110+

45%

As with your application in part 1, you should run your program multiple times and test the boundary conditions. Some of these have changed with part 2. Note that the retail price of the software has changed.

Here is a run for part 2 of the application:

Enter the number of units sold: 1[Enter] The customer purchased 1 units and does not qualify for a discount

The total sale for the customer is $109.49

Enter the number of units sold: 21[Enter] The customer purchased 21 units and does not qualify for a discount The total sale for the customer is $2299.29

Enter the number of units sold: 22[Enter] The customer purchased 22 units and qualified for a 8% discount The total sale for the customer is $2216.08

Enter the number of units sold: 109[Enter] The customer purchased 109 units and qualified for a 33% discount The total sale for the customer is $7996.05

Enter the number of units sold: 110[Enter] The customer purchased 110 units and qualified for a 45% discount The total sale for the customer is $6624.15

Enter the number of units sold: 175[Enter] The customer purchased 175 units and qualified for a 45% discount The total sale for the customer is $10538.41 The customer is a preferred customer

Enter the number of units sold: -1[Enter] The number of units must be 1 or more

Enter the number of units sold: 0[Enter] Test cases that you should run: -1, 1, 21, 22, 42, 43, 63, 64, 84, 85, 109, 110, 174, 175.

Part 1 Grading: 80 points

You need to submit your source code for part 1. This is the code that existed before you make the changes required by part 2.

Part 1 will be graded as follows:

% of Grade

Function

15

Comments, meaningful variable names and formatter per the C++ text book.

50

Correct output values and formatting

35

You must have all of the functions required by the problem description. This includes the parameters being passed properly, the return values being returned properly. You should have no global variables.

Part 2 Grading: 20 points

You need to submit the source code for part 2 that includes the changes you made to the discount levels.

The grade for part 2 depends on your making the changes to your code from part 1 so that the output is correct with the new discount levels.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

1. What do I want to achieve?

Answered: 1 week ago

Question

Describe the sources of long term financing.

Answered: 1 week ago

Question

4. Support and enliven your speech with effective research

Answered: 1 week ago

Question

3. Choose an appropriate topic and develop it

Answered: 1 week ago