CSCE 2004 - Homework 3 
Due Date – March 1 at 11:59 PM 
Hard Copy: By beginning of next class or lab period.

The objective of this programming assignment is to become familiar with C++ functions and methods for problem decomposition. This assignment is divided into 2 parts. You will be modifying 2 different programs to fill in the missing code, which are CodeA.cpp and CodeB.cpp. These files are provided with this homework, you can download and update them.

1.     Part 1

Problem Statement

For your first problem, you will write a main program that calls functions that are already written and provided to you.

The program simulates a Pizza store (UofA Pizza). A customer can purchase Pizza by cash or by a credit card. In either case, the customer should enter the type of Pizza he/she wants to buy, the size and the number of Pizzas. The customer should be able to buy more than one type of Pizza. The customer should be able to cancel the purchasing process after choosing the Pizza type and before continuing purchasing. If the customer pays in cash, he/she should get change back (if any).

Design: 
Once Think about how you can use the provided functions in your main() function, how the parameters need to be passed to the functions, the type of parameters that are being used and how you can use the return values. A skeleton of the main program is included with comments showing the necessary steps where work needs to be provided. The necessary variables for your program are already declared, therefore all you need to do is use them in your work.
 DO NOT CHANGE THE FUNCTIONS THEMSELVES !!! You just need to create a main program that uses them. If you feel you need extra variables in the main program, you may add them, but they should not be necessary.

The following HW3a Sample output for a completed program is provided as an example.

HW3a Sample output

 

Name: U of A Pizza

ID: 11111111

 

|=================================================

|           Welcome to Our PIZZA Store                                                           

|           You Have 4 Types of Pizza:                                                              

| Type         Price:   L       M        S                                                                      

| ---------------------------------------------------------------------------- 

| ---------------------------------------------------------------------------- 

| 1. Chicken          $15.00  $10.30   $8.10                                                     

| 2. Veggie           $13.00  $11.45   $6.20                                                      

| 3. Pepperoni        $8.00   $5.15    $3.10                                                     

| 4. Cheese           $6.00   $5.30    $2.50                                                        

|=================================================

 

 

What type of Pizza you like to Buy, Enter a Number between 1 and 4:  2

 

================================================================|

You have chosen VEGGIE Pizza.

================================================================|

 

Please, confirm your choice; (Y)es or (N)o? y

You have confirmed your choice to buy VEGGIE Pizza

What is the Size of the Pizza You Want? S for Small, M for Medium, L for Large: l

 

How Many Pizzas Do You Want to Buy?(Enter Positive Number less than 100): 3

 

You want to continue buying Pizza, Y or N?:  y

What type of Pizza you like to Buy, Enter a Number between 1 and 4:  1

 

================================================================|

You have chosen CHICKEN Pizza.

================================================================|

 

Please, confirm your choice; (Y)es or (N)o? y

You have confirmed your choice to buy CHICKEN Pizza

What is the Size of the Pizza You Want? S for Small, M for Medium, L for Large: s

 

How Many Pizza You Want to Buy?(Enter Positive Number less than 100): 2

 

You Want to continue buying Pizza, Y or N?:  n

 

 Your Bill is: 55.2

 Please, choose how to pay: (C) for cash or (D) for Credit Card: c

Enter Sufficient Cash, Greater Than or Equal to  55.2: 60

 

Thank You!

 

+-------------------------------------------------

|Your Bill is: $55.20

|Your Change is: $4.80

+-------------------------------------------------

 

Implementation: 

The first thing your program should do is echo your name and UAID to the screen so that your executable, when run, tells us who wrote the program. You should also include your name and UAID in the comments at the top of the program.

The second thing your program should do is to let a user choose his/her payment type (cash or credit). Then, there should be a menu asking the customer what type of Pizza he/she wants to purchase. Then, depending on the choice, the program calls the appropriate function to do some calculations. At the end, the customer should get a bill of his/her purchase as well as a change back if any in case of cash payment.

Start your program with comments based on your design and add portions of code a little at a time. Compile and run your program on a regular basis, so you always have something that runs, even if it only does part of the job. Make sure you have completed the first task, e.g., printing your name to the screen, before you start writing code for the second task.

Remember to add comments to your program to explain your program. Do this before/during programming instead of waiting until the end. Also, have your program print out YOUR NAME at the top of the program for identification purposes.

2.     Part 2

Problem Statement: 
You are to fill in the missing code to create a program that handles registering courses in the CSCE department. The menu should display the name and the time of the offered courses. A student cannot register for courses that have a conflict in their times (you should handle this in your program). A student can register for at least 4 courses and at most for 6 courses. You can display 6 courses only as offered by the department for Fall 2012. After registering for courses, the student should pay the tuition and fees using cash or credit card, and s/he should get the change back  in case of cash as done in the previous part. Finally, the program should print out the schedule of courses for the student, the cost, and the change if any.

 

Design: 

Each major step is handled by an appropriately named function. The design has already been done for you. The main program is written, and it calls the functions to do the tasks. Your task is to fill in the functions so that they accomplish the overall goal.

You MUST NOT modify the main program. Each function is described more fully in the comments in its header.

Implementation:

The following HW3b Sample output for a completed program is provided as an example. Your output does not need to match the sample output - it is purely for your information about control flow. Note that CodeB.cpp, as given, does not compile.

Start by making function prototypes or null-bodied functions for each function called by main so that the program compiles. For non-void returning functions, have the function return a dummy value (e.g., true or -1 or 'C', whatever makes sense).

Once the program compiles, fill in each function with a print statement that says "In function name\n". You can run the program and watch it work. Finally, pick one function at a time and replace the print statement with the code needed to allow the main program to operate properly.

 

HW3b Sample output

Name: Student

ID: 11111111

 

|=============================================== =

|           Welcome to Our CSCE at UofA                                                        

|   You Have 6 courses offered for Fall 2012                                         

| Name         Time:Day    Start   End                                                             

| -----------------------------------------------------------------------------

| -----------------------------------------------------------------------------

| 1. CSCE2014       MWF    9.00 - 10.00

| 2. CSCE2024       MWF   11.00 - 12.00

| 3. CSCE2554       MWF    9.00 - 10.00

| 4. CSCE2664       MWF   11.00 - 12.00

| 5. CSCE3011        TT       9.30 - 11.00

| 6. CSCE3314        TT       11.00 - 12.30

|=================================================

 

 

How many courses you want to register? Choose a number between 4 and 6:  4

 

Enter the Number of the course you want to register, Enter number between 1 and 6: 1

 

Enter the Number of the course you want to register, Enter number between 1 and 6: 2

 

Enter the Number of the course you want to register, Enter number between 1 and 6: 5

 

Enter the Number of the course you want to register, Enter number between 1 and 6: 6

 

 Your Tuition is: 10401.80

 and Your Fees are: 925.56

 Please, choose how to pay: (C) for cash or (D) for Credit Card: c

Enter Sufficient Cash, Greater Than 11327.36: 12000

 

Thank You!

 

The Courses you have Registered are:

Name           Time

CSCE2014     MWF 9.00-10.00

CSCE2024     MWF 11.00-12.00

CSCE3011     TT 9.30-11.00

CSCE3314     TT 11.00-12.30

 

 

 

+-------------------------------------------------

|Your Bill is: $11327.36

|Your Change is: $672.64

+-------------------------------------------------

 

 

3.     Testing and Debugging:

Test your program to check that it operates correctly for all of the requirements listed above. Also check for the error handling capabilities of the code. Save your testing output in text files for submission on the program due date. Show that your program works for different cases.

A.   Testing Part 1: Use the following test cases to test the correctness of your code in Part 1.

 

Test Case 1

Name: U of A Pizza

ID: 11111111

 

|===============================

|           Welcome to Our PIZZA Store           

|           You Have 4 Types of Pizza:               

| Type         Price:   L              M                S       

| -------------------------------------------------

| -------------------------------------------------

| 1. Chicken         $15.00  $10.30   $8.10     

| 2. Veggie            $13.00  $11.45   $6.20     

| 3. Pepperoni    $8.00    $5.15      $3.10     

| 4. Cheese           $6.00    $5.30      $2.50     

|===============================

 

 

What type of Pizza you like to Buy, Enter a Number between 1 and 4:  3

 

================================================================|

You have chosen PEPPERONI Pizza.

================================================================|

 

Please, confirm your choice; (Y)es or (N)o? y

You have confirmed your choice to buy PEPPERONI Pizza

What is the Size of the Pizza You Want? S for Small, M for Medium, L for Large: l

 

How Many Pizza You Want to Buy?(Enter Positive Number less than 100): 3

 

You want to continue buying Pizza, Y or N?:  y

What type of Pizza you like to Buy, Enter a Number between 1 and 4:  4

 

================================================================|

You have chosen CHEESE Pizza.

================================================================|

 

Please, confirm your choice; (Y)es or (N)o? y

You have confirmed your choice to buy CHEESE Pizza

What is the Size of the Pizza You Want? S for Small, M for Medium, L for Large: m

 

How Many Pizza You Want to Buy?(Enter Positive Number less than 100): 5

 

               You want to continue buying Pizza, Y or N?:  n

             

               [ After that, Choose to pay by cash and enter 100 dollars ]

 

 

Test Case 2

Name: U of A Pizza

ID: 11111111

 

|===============================

|           Welcome to Our PIZZA Store           

|           You Have 4 Types of Pizza:              

| Type         Price:   L              M                S       

| -------------------------------------------------

| -------------------------------------------------

| 1. Chicken         $15.00  $10.30   $8.10      

| 2. Veggie            $13.00  $11.45   $6.20     

| 3. Pepperoni    $8.00    $5.15      $3.10     

| 4. Cheese           $6.00    $5.30      $2.50     

|===============================

 

 

What type of Pizza you like to Buy, Enter a Number between 1 and 4:  9

What type of Pizza you like to Buy, Enter a Number between 1 and 4:  3

 

================================================================|

You have chosen PEPPERONI Pizza.

================================================================|

 

Please, confirm your choice; (Y)es or (N)o? y

You have confirmed your choice to buy PEPPERONI Pizza

What is the Size of the Pizza You Want? S for Small, M for Medium, L for Large: f

What is the Size of the Pizza You Want? S for Small, M for Medium, L for Large: m

 

How Many Pizza You Want to Buy?(Enter Positive Number less than 100): -8

 

How Many Pizza You Want to Buy?(Enter Positive Number less than 100): 4

 

               You want to continue buying Pizza, Y or N?:  n

        

               [After that, Choose to pay by credit card]

Test Case 3

Name: U of A Pizza

ID: 11111111

 

|===============================

|           Welcome to Our PIZZA Store           

|           You Have 4 Types of Pizza:               

| Type         Price:   L              M                S       

| -------------------------------------------------

| -------------------------------------------------

| 1. Chicken         $15.00  $10.30   $8.10     

| 2. Veggie            $13.00  $11.45   $6.20     

| 3. Pepperoni    $8.00    $5.15      $3.10     

| 4. Cheese           $6.00    $5.30      $2.50     

|===============================

 

 

What type of Pizza you like to Buy, Enter a Number between 1 and 4:  3

 

================================================================|

You have chosen PEPPERONI Pizza.

================================================================|

 

               Please, confirm your choice; (Y)es or (N)o? n

 

           [Not confirming the transaction should force the program to exit. In addition, it           

            should print out a message for the customer telling him/her that the transaction was  

            canceled. Hence, no bill should be shown to the customer ]

 

B.    Testing Part 2. Use the following test cases to test the correctness of your code in Part 2.

          Test Case 1. The following test case is the same as the sample output that we have shown before. Your program should work as demonstrated by this case. You do not have to show the same menu, you can  

                              choose different courses and times.

                             

Name: Student

ID: 11111111

 

|===================================

|           Welcome to Our CSCE at UofA                   

|   You Have 6 courses offered for Fall 2012     

| Name         Time:Day    Start   End                        

| -------------------------------------------------------

| -------------------------------------------------------

| 1. CSCE2014       MWF    9.00 - 10.00

| 2. CSCE2024       MWF   11.00 - 12.00

| 3. CSCE2554       MWF   9.00 - 10.00

| 4. CSCE2664       MWF   11.00 - 12.00

| 5. CSCE3011        TT       9.30 - 11.00

| 6. CSCE3314        TT      11.00 - 12.30

|===================================

 

 

How many courses you want to register? Choose a number between 4 and 6:  4

 

 Now, You Can Select the Courses You Want to Register, one by one ..

 

Enter the Number of the course you want to register for, Enter number between 1 and 6: 1

 

Enter the Number of the course you want to register for, Enter number between 1 and 6: 2

 

Enter the Number of the course you want to register for, Enter number between 1 and 6: 5

 

Enter the Number of the course you want to register for, Enter number between 1 and 6: 6

 

 Your Tuition is: 10401.80

 and Your Fees is: 925.56

 Please, choose how to pay: (C) for cash or (D) for Credit Card: c

Enter Sufficient Cash, Greater Than 11327.36: 12000

 

Thank You!

 

The Courses you have Registered for are:

Name         Time

CSCE2014     MWF 9.00-10.00

CSCE2024     MWF 11.00-12.00

CSCE3011     TT 9.30-11.00

CSCE3314     TT 11.00-12.30

 

 

 

+-------------------------------------------------

|Your Bill is: $11327.36

|Your Change is: $672.64

+-------------------------------------------------


       

        Test Case 2. Your code should do some error checking as demonstrated by the following test case.

Name: Student

ID: 11111111

 

|===================================

|           Welcome to Our CSCE at UofA                   

|   You Have 6 courses offered for Fall 2012     

| Name         Time:Day    Start   End                        

| -------------------------------------------------------

| -------------------------------------------------------

| 1. CSCE2014       MWF    9.00 - 10.00

| 2. CSCE2024       MWF    11.00 - 12.00

| 3. CSCE2554       MWF    9.00 - 10.00

| 4. CSCE2664       MWF   11.00 - 12.00

| 5. CSCE3011        TT       9.30 - 11.00

| 6. CSCE3314        TT      11.00 - 12.30

|===================================

 

 

How many courses you want to register? Choose a number between 4 and 6:  7

Invalid Choice! How many courses you want to register? Choose a number between 4 and 6:  4

 

 Now, You Can Select the Courses You Want to Register, one by one ..

 

Enter the Number of the course you want to register for, Enter number between 1 and 6: 8

 

Invalid Course

 

Enter the Number of the course you want to register for, Enter number between 1 and 6: 1

 

Enter the Number of the course you want to  register for, Enter number between 1 and 6: 2

 

Enter the Number of the course you want to register for, Enter number between 1 and 6: 4

 

Enter the Number of the course you want to register for, Enter number between 1 and 6: 6

 

 Your Tuition is: 10401.80

 and Your Fees is: 925.56

 Please, choose how to pay: (C) for cash or (D) for Credit Card: u

 

 Invalid Choice! Please, choose how to pay: (C) for cash or (D) for Credit Card: c

Enter Sufficient Cash, Greater Than 11327.36: 10000

Insufficient Money! Enter Sufficient Cash, Greater Than 11327.36: 12000

 

Thank You!

 

The Courses you have Registered for are:

Name         Time

CSCE2014     MWF 9.00-10.00

CSCE2024     MWF 11.00-12.00

CSCE3314     TT 11.00-12.30

 

 

 

+-------------------------------------------------

|Your Bill is: $11327.36

|Your Change is: $672.64

+-------------------------------------------------

 

4.     Documentation:

When you have completed your C++ program, write a short report (less than one page long) describing what the objectives were, what you did, and the status of the program. Does it work properly for all test cases? Are there any known problems? Add this to the report file submitted electronically.

5.     Submission

Click on the “Upload Files” button. Next, create a new folder and name it “HW3”. Then, click on the folder and upload two files; one for the code (Code.cpp or Code.txt) and the other for testing and documentation (Report.txt). Make sure to upload the code in one of the two formats .txt or .cpp format. When you finish uploading, confirm your uploading by clicking on “Send for Marking” button.

The dates on your electronic submission will be used to verify that you met the due date above. More than 3 days late will not be accepted. So hand in your best effort on the due date.

You should also PRINT a copy of these files and hand them in during the first class or lab that follows the assignment deadline. Include the Homework Grading Cover Sheet that is linked from the Projects page. Points will be deducted if the cover page is missing.

6.     Late Submission Penalties

·         Electronic copy submitted late: 1st day: -10 points, 2nd day: -20 points. 3rd day: -30 points, After: -100 points

·         No hardcopy submitted: -20 points

·         Hardcopy submitted late: -10 points

·         Incorrect format (electronic copy): 1 reminder and -10 points, After: -100 points