CPTR 124 Fundamentals of Programming
This lab introduces conditional execution.
Forming a Team
You are encouraged to choose a partner from this class as a teammate. You two will work together on this assignment.You are not required to work with someone else; you may work alone if you prefer.
Familiarize yourself with the assignment
Read over the complete lab before you begin creating your project and C++ source file.
Housekeeping
You will need to create a separate Visual Studio project for each program.What to do
Write C++ programs to solve the following problems:- Pizza Selection
You must make a choice between two pizza offerings. The two pizzas have the exact same toppings, but are different sizes. Both pizzas are round, and both have the same crust thickness. Given the diameter and price of each pizza, compute the cost per square inch of each pizza. The area of a circle is given by the formula A = πr2. (In your program you should use for π a constant named PI equal to 3.14159.) One pizza is considered a better deal than the other if its cost per square inch is lower. Choose pizza number 1 if its cost per square inch is less than or equal to the cost per square inch of pizza 2. If pizza number 2 is a better deal, select it instead.
Receive four floating point values from the user. These values represent, respectively, the diameter of pizza 1 (in inches), the price of pizza 1 (in dollars and cents), the diameter of pizza 2, and the price of pizza 2. Compute the better deal and justify the choice by providing the cost per square inch of pizza. A typical program execution might be:
Please enter the 1st pizza diameter in inches:10 Please enter the price of the 1st pizza:7.99 Please enter the 2nd pizza diameter in inches:12 Please enter the price of the 2nd pizza:9.99 The 1st pizza costs 0.101732, and the 2nd pizza costs 0.0883311 The 2nd pizza is the better deal because 0.0883311 dollars per square inch is less than 0.101732 dollars per square inch.
Another typical run yields:
Please enter the 1st pizza diameter in inches:12 Please enter the price of the 1st pizza:8.99 Please enter the 2nd pizza diameter in inches:10 Please enter the price of the 2nd pizza:10.00 The 1st pizza costs 0.0794891, and the 2nd pizza costs 0.127324 The 1st pizza is the better deal because 0.0794891 dollars per square inch is less than or equal to 0.127324 dollars per square inch.
- Maximum of Five
Write a program that allows the user to enter in exactly five integer values. The program then should print the largest of the five values entered. A sample run is shown here:
Even if there is a tie for the maximum value, just print the maximum once.Please enter five integer values: 20 -1 6 31 19 The maximum is 31.
Hint: You can use very simple conditional expressions, but to do so you will need to introduce an additional variable. The tradeoff of an extra variable for the greatly simplified logic is a good one.
- Pizza Selection
-
Check out
I will review your lab with you before you leave. Be prepared to answer questions about any parts of your programs. After you have been checked out, please submit your C++ source code (the .cpp files) to eclass.
-
Log out
Don't forget to log out on your lab workstation and take your USB drive before you leave the lab.