QuestionQuestion

Program #1

The local high school student council is selling pizzas for a fund raiser. In order to keep things simple, there are only two sizes of pizza available, and all pizzas on one order must be the same type (size and number of toppings). Write a program to help compute the charge for one order.

Specifications:
• Customers may order medium or large pizzas. All pizzas on one order must be the same size. Prices are 4.99 for medium pizzas, and 7.99 for large pizzas.
• Pizzas are standard cheese pizzas with no toppings. If the customer to add toppings, they are charged 85 cents for each additional topping. All pizzas on one order must have the
same number of toppings.   
• If the customer wants the order delivered, there is a 12% delivery fee.
• If the customer is a student council member, they will receive 90 cents off each pizza ordered.
• The program should output a pizza bill, formatted as shown on the next page.

Implementation Requirements:   
Data Storage:
• The program must use constants for ALL fixed values (therefore, there should be no hardcoded numbers in your program).
• The program shall use descriptive names for all constants and variables, and follow the naming conventions in the Coding Standards.
• The program shall use double type constants and variables for all floating point values (not float).
The user will enter the following input:
• The pizza size o Read the pizza size as a single character ( 'm'/'M' for medium or 'l'/'L' for large). The user may enter the character in either upper or lowercase. Use a pre-defined function from the cctype library to insure that the character is stored in uppercase when your code uses the value later to decide what to charge and what to display.
• The number of pizzas the customer wants
• The number of toppings the customer wants on each pizza
• Whether the customer is a student council member o Read answer from the user as a string: "yes" or "no" o The prompt should indicate that the string must be entered in all lowercase letters.
o The string value entered will be tested later, to decide whether to give a discount.
• Whether the customer wants the pizza delivered o Read from the user as a single character ( 'd'/'D' for delivery, 'p'/'P' for pickup).   
o After reading the input character, the program will store a value into a Boolean variable called deliver (true for customers who want delivery, false for customers who will pick up their own pizza) and use only that Boolean in later processing, when testing the value to decide whether to charge for delivery.
o The user may enter the character in either upper or lowercase. The program must use a logical operator to test for both upper and lowercase when deciding whether to store true or false in the Boolean value (i.e. Use a logical operator instead of using a cctype predefined function).
NOTE: No error checking of the user input is required. You may assume that the user entered a valid answer for each question, and assume also valid input for test cases.
Required User-Defined Function:
• Create separate a user-defined function to calculate the per pizza charge.   
• The function will take two input parameters: the pizza size amd the number of toppings. • The function will return the cost per pizza.

Sample Input 1:
Pizza Bill Calculation Program

Pizza Size medium or large (M/L)? m
Enter the number of pizzas ordered: 3
Enter the number of toppings per pizza: 3
Student Council member? (yes or no, all lowercase): yes
Delivery or pickup (D/P)? d

Sample Output 1:
ORDER DETAILS
Pizza Size:          medium
Number of Toppings:       3
Cost per Pizza:         7.54
Number of Pizzas:          3

PIZZA BILL
Pizza Total:          22.62
Discount:               2.70 -
---------
Subtotal:             19.92
Delivery Cost:          2.39 +
---------
Bill Total:            22.31

Notes on Sample Output:
a) Make your program displays a couple of blank lines after all input has been entered and before the pizza order details and bill are displayed.
b) All order details and bill amounts should line up on the right.
c) The pizza size should be displayed in a word (not a character).
d) If the customer is not a student council member, the discount should be 0.00.
e) If the customer does not want delivery, then the delivery charge should be 0.00.

Sample Input and Output 2:
Pizza Bill Calculation Program

Pizza Size medium or large (M/L)? L
Enter the number of pizzas ordered: 1
Enter the number of toppings per pizza: 0
Student Council member? (yes or no, all lowercase): no
Delivery or pickup (D/P)? P

ORDER DETAILS
Pizza Size:            large
Number of Toppings:       0
Cost per Pizza:         7.99
Number of Pizzas:          1

PIZZA BILL
Pizza Total:            7.99
Discount:               0.00 -
                   ---------
Subtotal:               7.99
Delivery Cost:          0.00 +
                   ---------
Bill Total:             7.99

Press any key to continue . . .

Program #2
For 2011 and 2012, there were two tax credits available to help offset the costs of higher education by reducing the amount paid in income tax. They are the American Opportunity Credit and the Lifetime Learning Credit. A taxpayer may choose to claim only one of these two credits for each student in a single tax year. Married taxpayers, filing separately, may not claim either of these credits.

You will write a program that carries out the logic for the Lifetime Learning Credit (modified from IRS form 8863). A taxpayer may be allowed up to 20% of the first $10,000 of qualified educational expenses (i.e. $2,000) as a tax credit, depending upon his/her income. Sample input and output that can be used as a test case is also given below.

Possible Required Input:
• Filing status (one of the following)
1. Single,
2. Married, Filing Jointly,
3. Head of Household,         
4. Qualifying Widow,
5. Married, Filing Separately.

• Amount of Qualified Educational Expenses
• Adjusted Gross Income (1040 line 38)

Sample Input 1a
Lifetime Learning Credits Worksheet Creation Program

1 - Single
2 - Married, Filing Jointly
3 - Head of Household
4 - Qualifying Widow(er)
5 - Married, Filing Separately
Enter your filing status from above (1-5): 2

If the user enters 1-4 (but not 5), you will also need to read the other input:

Sample Input 1b
Enter the Amount of Qualified Educational Expenses for 2011: 8350
Enter your Adjusted Gross Income (from 1040 line 38): 105000
NOTE: No error checking of the user input is required. You may assume that the user entered a valid answer for each question.
Exit Codes (when returning from main)

In your previous programs, you have seen the line:
return 0; used to return from the main function.   

When we finish running the code in the main function, the program is done executing. So when you return from within main, it finishes the execution of main, and ends the program. (Note that returning from any function other than main does not end the program.)

So the return line causes the program to end execution, and returns an "exit code" of 0 (zero) to the operating system. On most operating systems, an exit code of zero indicates that the program ran successfully.   

A program can also return from main using any other integer value as the exit code, to indicate that the program exited for some specific reason.   

For example, this line in main:
return 5;
will cause the program to exit and pass back exit code 5 to the operating system. It is up to the programmer to decide what each exit code means. See WBW section 3.8 for more details.

You will use a couple of different exit codes in this program, depending upon what line causes an early exit, as described below.

Program Description
After the initial program header has been displayed, and the program has read the filing status from the user, use the following instructions to create a Lifetime Learning Credit worksheet for the user.

IRS instructions for each line of the worksheet
Line 1 Enter the filing status on line 1.
Is the filing status "Married, Filing Separately"
Yes. Display a message explaining that the Lifetime Learning Credit is not available if you file as "Married, Filing Separately"            
Pause and then Exit the program with exit code 1.            
Do not complete the rest of this worksheet).
No. Continue with remaining lines on form.
Line 2 Enter the Qualified Educational Expenses for the year on Line 2.
Line 3 Enter the smaller of line 2 or expense limit of $10,000 on line 3.
Line 4 Tentative Lifetime Learning Credit: Multiply line 3 by 20% (0.20) and enter the result on line 4.
Line 5 Determine the Income Limit amount for your filing status from the list below and enter it on line 5:
Single, Head of household, Qualifying Widow(er) - $ 61,000      Married filing jointly - $ 122,000
Line 6 Enter the adjusted gross income from Form 1040, line 38 on line 6.
Line 7 Subtract line 6 from line 5 to determine how much your income is under the limit. Is the result zero or less?
Yes. Skip lines 8 and 9, and display 0 for line 10.   
Pause and then Exit the program with exit code 7.             (Do not complete the rest of this worksheet).
No. Enter the subtraction result on line 7 and continue.
Line 8 Determine the Difference Cutoff amount for your filing status from the list below and enter it on line 8:
Single, Head of household, Qualifying Widow(er) - $ 10,000      Married filing jointly - $ 20,000
Line 9 Is the line 7 equal to or more than line 8?
Yes. Full credit allowed.   
Enter 1.0 on line 9
No. Partial credit allowed.
Divide line 7 by line 8, and enter the result on line 9, rounded to 3 decimal places
Line 10 Multiply line 4 by line 9 and enter result on line 10.
This is your Lifetime Learning Credit.   
Enter the line 10 results on Form 1040, line 49.

Program Logic Summary
• Read the input for line 1 (filing status) from the user.
• Perform a test to determine if the taxpayer should continue, or if the exit condition for line 1 has been met.
o If the line 1 exit condition is met, there will be no credit.   o Display a message saying to (see Sample 3 Output below). Pause, and then return from main with exit code 1, to indicate that the line 1 exit condition was met.
return 1;
• If the line 1 exit condition is not met, read the input for line 2 (qualified educational expenses) from the user.
• Perform a test to determine the amount for line 3 and store the result.
• Perform the necessary calculations for line 4 and store the result.
• Determine the line 5 income limit that applies for the filing status entered, and store the result. HINT: Also store the filing status description string here.
• Read the input for line 6 (adjusted gross income) from the user.
• Display the worksheet title and lines 1 through 6.
• Perform the line 7 test to determine if the taxpayer should continue, or if the worksheet is complete.
o If the subtraction result is 0 or less, the worksheet calculations are complete. Display 0 on line 10 (See Sample 2 Output below). Pause, and then return from main with exit code 7, to indicate that the line 7 exit condition was met.
return 7;
o If the line 7 exit condition is not met, continue.
• Perform a test to determine the amount for line 8 and store the result.
• Call the user-defined function to find the amount for line 9 and store the result returned.
• Perform necessary calculation to store the values for line 10.
• Display the remaining results for lines 7 through 10 on the worksheet, making sure that line 9 is displayed to 3 decimal places (see Sample 1 Output below).

Processing Logic Notes

• If the program exits on line 1, only a message will be displayed as output.
• If the program exits on line 7, only the worksheet title and lines 1 – 6 and 10 will be displayed, along with the message about where to enter the results.   
• If neither exit condition (from line 1 or line 7) is met, then the program will display the entire worksheet and return from the main function with an exit code of 0 (to indicate the successful completion of the entire worksheet).
return 0;
• For line 9, write a user-defined function that will compute the amount to enter on line 9.
o The function shall take two input arguments:   the line 7 amount and the line 8 amount.
o The function will test if line 7 is equal to or more than line 8, and then compute the correct results for line 9.
o The function will return the floating point result.
o No other computations should be performed within this function.
Examples:    Input arguments of line 7 = 15000 and line 8 = 10000 would return 1.0
Input arguments of line 7 = 12222 and line 8 = 20000 would return 0.6111

Display Output   
Display a Lifetime Learning Credit Worksheet that adheres to the formatting constraints shown below (decimals in dollar values should line up as shown).

Sample 1 Output (no early exit – using sample inputs 1a and 1b from above)

Lifetime Learning Credit Worksheet

1. Filing Status: Married, Filing Jointly
2. Qualified Educational Expenses:                      8350.00
3. Smaller of line 2 or Expense Limit:                  8350.00
4. Tentative Lifetime Learning Credit:                  1670.00
5. Income Limit: 122000.00
6. Adjusted Gross Income: 105000.00
7. Line 5 – Line 6: 17000.00
8. Filing status difference cutoff:       20000.00
9. Portion of tentative credit allowed:                   0.850
10. Lifetime Learning Credit:                            1419.50
***Enter amount from worksheet line 10 on form 1040 line 49
Press any key to continue . . .

Sample Output Notes

• Make sure there are a couple of blank lines AFTER all input has been entered and BEFORE the worksheet is displayed.
• Lines 1 or 7 may cause the program to display some results and immediately exit, without displaying the rest of the worksheet (see samples 2 and 3 below)

Sample 2 Input
Lifetime Learning Credits Worksheet Creation Program

1 - Single
2 - Married, Filing Jointly
3 - Head of Household
4 - Qualifying Widow(er)
5 - Married, Filing Separately
Enter your filing status from above (1-5): 5

Sample 2 Output (early exit on line 1)
No Lifetime Learning Credit allowed when Married, Filing Separately

***Enter 0 on form 1040 line 49

Press any key to continue . . .

Sample 3 Input
Lifetime Learning Credits Worksheet Creation Program

1 - Single
2 - Married, Filing Jointly
3 - Head of Household
4 - Qualifying Widow(er)
5 - Married, Filing Separately
Enter your filing status from above (1-5): 3

Enter the Amount of Qualified Educational Expenses for 2011: 14400

Enter your Adjusted Gross Income (from 1040 line 38): 65000

Sample 3 Output (early exit after line 7)
Lifetime Learning Credit Worksheet

1. Filing Status:                           
Head of Household 2. Qualified Educational Expenses:                     14400.00
3. Smaller of line 2 or Expense Limit:                10000.00
4. Tentative Lifetime Learning Credit:                  2000.00
5. Income Limit:                            61000.00
6. Adjusted Gross Income:                   65000.00
----------------------------------------------------------------
10. Lifetime Learning Credit:                               0.00
***Enter amount from worksheet line 10 on form 1040 line 49
Hints
• Work on one line at a time. Make sure each line is working correctly before moving on to the next line and any subsequent calculations.
• Use the example input and output to help you.
• Remember to declare constants for ALL fixed values.
• HINT: Use a separate variable to store your calculation for each line. Remember to use descriptive variable names.   
NOTE about Exit Codes

If you want to view the exit code that your program returned to the operating system, you can. First run your program from a DOS prompt by typing the name of the executable file:
c:\> program2.exe
After the program finishes executing and you get another DOS promot, you can view the exit code by typing:
c:\> echo %errorlevel%
The exit code that your program returned will be displayed.

Documentation

1) Be sure to include top of program comments that include: Your name, the course, and the assignment number What the program does including:
What is Input
Processing Performed
What is Output

2) Comment any constants/variables whose names are not completely descriptive.

3) You must also include a comment above each user-defined function that includes:
What the function does
A description of the parameters that are input to the function A description of what is returned from the function.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

// constants
const double mPizzaPrice = 4.99;
const double lPizzaPrice = 7.99;
const double toppingPrice = 0.85;
const double feePercent = 0.12;
const double discount = 0.90;

/**
* The function will take two input parameters: the pizza size
* and the number of toppings
* @param pizzaSize
* @param toppingNum
* @return the cost per pizza.
*/
double perPizzaCharge(char pizzaSize, int toppingNum){
    double price ;
    if (pizzaSize == 'M') {
       price = mPizzaPrice;
    } else {
       price = lPizzaPrice;
    }
    price += toppingNum * toppingPrice;
    return price;
}

int main() {

    cout<<" Pizza Bill Calculation Program\n\n";
   
    char pizzaSize ;
    cout<<" Pizza Size medium or large (M/L)? ";
    cin>>pizzaSize;
    pizzaSize = toupper(pizzaSize);...
$80.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats