Lab exercise 3 objectives
- Write C++ programs
- Compile C++ programs
- Implement programs that use
std::cin
andstd::cout
correctly - Implement programs that use conditional statements
Instructions
Answer the programming problems sequentially (i.e., answer prob01 before prob02). If you have questions let your instructor or the lab assistant know. You can also consult your classmates.
When you answer two programming problems correctly, let your instructor know and wait for further instruction.
Lab exercise guide
Here’s a link to the Lab exercise guide in case you need to review the lab exercise objectives, grading scheme, or evaluation process.
Holideals at the Movies!
We have special movie tickets on holidays! Prices are discounted when you buy a pair of tickets.
Create a program for the HoliDeals event that computes the subtotal for a pair of tickets. The program should ask the the ages of the first and second guests to compute the price.
There are different pricing structures based on the guests’ age.
Children tickets cost $10 (age below 13)
Young Adult tickets cost $13 (age below 21)
Adult tickets cost $15 (age below 65)
Senior tickets cost $10 (age 65 and over)
To simplify the problem, let’s assume that parents/guardians will always accompany pairs of children who will watch a movie.
The pricing structure should be displayed to the user. Please see the sample output below to guide the design of your program.
Welcome to HoliDeals at the Movies!Tickets tonight can only be bought in pairs.Here are our movie ticket deals:Children - $10.00Young Adults - $13.00Adults - $15.00Seniors - $10.00Please enter the age of the person for the first guest: 15Please enter the age of the person for the second guest: 16The Subtotal for the ticket cost is: $26.00
Submission checklist
- Compiled and ran the driver (main).
- Manually checked for compilation and logical errors.
- Ensured no errors on the unit test (make test).
Code evaluation
Open the terminal and navigate to the folder that contains this exercise. Assuming you have pulled the code inside of /home/student/labex02-tuffy
and you are currently in /home/student
you can issue the following commands
cd labex02-tuffy
You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.
cd prob01
When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01
, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02
for example.
cd ..cd prob02
Use the clang++
command to compile your code and the ./
command to run it. The sample code below shows how you would compile code save in main.cpp
and into the executable file main
. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.
clang++ -std=c++17 main.cpp -o main./main
You can run one, two, or all the commands below to test
your code, stylecheck
your code’s design, or formatcheck
your work. Kindly make sure that you have compiled and executed your code before issuing any of the commands below to avoid errors.
make testmake stylecheckmake formatcheck
A faster way of running all these tests uses the all
parameter.
make all
Submission
- When everything runs correctly, let’s copy your code into the Github repository. The first step is to add your code to what is called the staging area using git’s
add
command. The parameter afteradd
is the name of the file you want to add. There are cases when you have multiple changed files, so you can just type . (period) to add all modified files.git add main.cpp
- Once everything is in the staging area, we use the
commit
command to tell git that we have added everything we need into the staging area.git commit
- In case it asks you to configure global variables for an email and name, just copy the commands it provides then replace the dummy text with your email and Github username.
git config --global user.email "[email protected]"git config --global user.name "Tuffy Titan"
When you’re done, make sure you type
git commit
again. - Git will ask you to describe what you have added to the staging area. By default, you will use a command-line based editor called nano. Go ahead and provide a description then press Ctrl + x to exit. Press Y to confirm that you want to make changes and then press Enter.
- Lets push all changes to the Github repository using git’s
push
command. Provide your Github username and password when you are asked.git push
- When you finish the exercise, go back to Titanium and click on the
Add submission
button in the lab exercise page. Provide a short message in the text area such as “finished lab exercise” and click onSave changes
. Finally click onSubmit assignment
to inform your instructor that you are done.
Roller coaster ride height
Create a program that prompts the passenger for their height to determine if they can safely ride the roller coaster. Print the appropriate messages according to their height. Please see the sample outputs below to guide the design of your program.
Safe
You must be at least 55 inches to safely ride the TuffyTwister.Please enter your height in inches: 72Congratulations! You are tall enough to ride!
Unsafe
You must be at least 55 inches to safely ride the TuffyTwister.Please enter your height in inches: 50Safety is our first priority. Unfortunately, we can't let you ride yet.
Submission checklist
- Compiled and ran the driver (main).
- Manually checked for compilation and logical errors.
- Ensured no errors on the unit test (make test).
Code evaluation
Open the terminal and navigate to the folder that contains this exercise. Assuming you have pulled the code inside of /home/student/labex02-tuffy
and you are currently in /home/student
you can issue the following commands
cd labex02-tuffy
You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.
cd prob01
When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01
, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02
for example.
cd ..cd prob02
Use the clang++
command to compile your code and the ./
command to run it. The sample code below shows how you would compile code save in main.cpp
and into the executable file main
. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.
clang++ -std=c++17 main.cpp -o main./main
You can run one, two, or all the commands below to test
your code, stylecheck
your code’s design, or formatcheck
your work. Kindly make sure that you have compiled and executed your code before issuing any of the commands below to avoid errors.
make testmake stylecheckmake formatcheck
A faster way of running all these tests uses the all
parameter.
make all
Submission
- When everything runs correctly, let’s copy your code into the Github repository. The first step is to add your code to what is called the staging area using git’s
add
command. The parameter afteradd
is the name of the file you want to add. There are cases when you have multiple changed files, so you can just type . (period) to add all modified files.git add main.cpp
- Once everything is in the staging area, we use the
commit
command to tell git that we have added everything we need into the staging area.git commit
- In case it asks you to configure global variables for an email and name, just copy the commands it provides then replace the dummy text with your email and Github username.
git config --global user.email "[email protected]"git config --global user.name "Tuffy Titan"
When you’re done, make sure you type
git commit
again. - Git will ask you to describe what you have added to the staging area. By default, you will use a command-line based editor called nano. Go ahead and provide a description then press Ctrl + x to exit. Press Y to confirm that you want to make changes and then press Enter.
- Lets push all changes to the Github repository using git’s
push
command. Provide your Github username and password when you are asked.git push
- When you finish the exercise, go back to Titanium and click on the
Add submission
button in the lab exercise page. Provide a short message in the text area such as “finished lab exercise” and click onSave changes
. Finally click onSubmit assignment
to inform your instructor that you are done.
Salary Calculator
Create a program that computes the salary based on an employee’s hourly wage and hours worked. Use the following formulas:
Less than or equal to 40 hours worked
hourly wage * hours worked
Over 40, but less than or equal to 65 hours worked
(hourly wage * 40) + (hours worked - 40) * (hourly wage * 1.5)
Over 65 hours worked
(hourly wage * 40) + (hourly wage * 1.5) * 25 + (hours worked - 65) * hourly wage * 2
Please see the sample output below to guide the design of your program.
Hourly wage: 12Hours worked: 20Total Salary Owed: $240.00
Submission checklist
- Compiled and ran the driver (main).
- Manually checked for compilation and logical errors.
- Ensured no errors on the unit test (make test).
Code evaluation
Open the terminal and navigate to the folder that contains this exercise. Assuming you have pulled the code inside of /home/student/labex02-tuffy
and you are currently in /home/student
you can issue the following commands
cd labex02-tuffy
You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.
cd prob01
When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01
, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02
for example.
cd ..cd prob02
Use the clang++
command to compile your code and the ./
command to run it. The sample code below shows how you would compile code save in main.cpp
and into the executable file main
. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.
clang++ -std=c++17 main.cpp -o main./main
You can run one, two, or all the commands below to test
your code, stylecheck
your code’s design, or formatcheck
your work. Kindly make sure that you have compiled and executed your code before issuing any of the commands below to avoid errors.
make testmake stylecheckmake formatcheck
A faster way of running all these tests uses the all
parameter.
make all
Submission
- When everything runs correctly, let’s copy your code into the Github repository. The first step is to add your code to what is called the staging area using git’s
add
command. The parameter afteradd
is the name of the file you want to add. There are cases when you have multiple changed files, so you can just type . (period) to add all modified files.git add main.cpp
- Once everything is in the staging area, we use the
commit
command to tell git that we have added everything we need into the staging area.git commit
- In case it asks you to configure global variables for an email and name, just copy the commands it provides then replace the dummy text with your email and Github username.
git config --global user.email "[email protected]"git config --global user.name "Tuffy Titan"
When you’re done, make sure you type
git commit
again. - Git will ask you to describe what you have added to the staging area. By default, you will use a command-line based editor called nano. Go ahead and provide a description then press Ctrl + x to exit. Press Y to confirm that you want to make changes and then press Enter.
- Lets push all changes to the Github repository using git’s
push
command. Provide your Github username and password when you are asked.git push
- When you finish the exercise, go back to Titanium and click on the
Add submission
button in the lab exercise page. Provide a short message in the text area such as “finished lab exercise” and click onSave changes
. Finally click onSubmit assignment
to inform your instructor that you are done.
Cash Back
There are three credit card tiers available. The green card has a 10% cash back bonus, the yellow card has a 5% cash back bonus, and the red card has a 2% cash back bonus. Write a program that will compute the total cash back you receive. The program should ask the user to enter the type of card (‘g’ = green, ‘y’ = yellow, ‘r’ = red) as well as the amount of money spent. Display the amount of cash back earned showing 2 decimal places.
Take note that different user input results in a different output. Your program should also account for invalid card types by displaying an error message. Please see the sample outputs below to guide the design of your program.
Valid input
Please enter type of card ('g' = green, 'y' = yellow, 'r' = red): yPlease enter amount of money spent: $42.12Amount of cash back received: $2.11
Invalid input
Please enter type of card: cPlease enter amount of money spent: $42.12Invalid card type.
Submission checklist
- Compiled and ran the driver (main).
- Manually checked for compilation and logical errors.
- Ensured no errors on the unit test (make test).
Code evaluation
Open the terminal and navigate to the folder that contains this exercise. Assuming you have pulled the code inside of /home/student/labex02-tuffy
and you are currently in /home/student
you can issue the following commands
cd labex02-tuffy
You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.
cd prob01
When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01
, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02
for example.
cd ..cd prob02
Use the clang++
command to compile your code and the ./
command to run it. The sample code below shows how you would compile code save in main.cpp
and into the executable file main
. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.
clang++ -std=c++17 main.cpp -o main./main
You can run one, two, or all the commands below to test
your code, stylecheck
your code’s design, or formatcheck
your work. Kindly make sure that you have compiled and executed your code before issuing any of the commands below to avoid errors.
make testmake stylecheckmake formatcheck
A faster way of running all these tests uses the all
parameter.
make all
Submission
- When everything runs correctly, let’s copy your code into the Github repository. The first step is to add your code to what is called the staging area using git’s
add
command. The parameter afteradd
is the name of the file you want to add. There are cases when you have multiple changed files, so you can just type . (period) to add all modified files.git add main.cpp
- Once everything is in the staging area, we use the
commit
command to tell git that we have added everything we need into the staging area.git commit
- In case it asks you to configure global variables for an email and name, just copy the commands it provides then replace the dummy text with your email and Github username.
git config --global user.email "[email protected]"git config --global user.name "Tuffy Titan"
When you’re done, make sure you type
git commit
again. - Git will ask you to describe what you have added to the staging area. By default, you will use a command-line based editor called nano. Go ahead and provide a description then press Ctrl + x to exit. Press Y to confirm that you want to make changes and then press Enter.
- Lets push all changes to the Github repository using git’s
push
command. Provide your Github username and password when you are asked.git push
- When you finish the exercise, go back to Titanium and click on the
Add submission
button in the lab exercise page. Provide a short message in the text area such as “finished lab exercise” and click onSave changes
. Finally click onSubmit assignment
to inform your instructor that you are done.
Credit Card Approval
Create a program that will recommend a credit card to a customer based on their credit score. The list below shows the required credit scores for each type of credit card.
0 - 579: Ineligible for Tuffy credit cards580 - 669: Eligible for the Silver Tuffy Card670 - 799: Eligible for the Gold Tuffy Card800 - 850: Eligible for the Platinum Tuffy Card
Take note that credit scores below 0 and above 850 are invalid. Inform the customer when they provide invalid credit score values.
Please see the sample output below to guide the design of your program.
Sample valid inputs
Thank you for applying for the Tuffy Credit card. Please enter your credit score.Credit Score: 600You are eligible for the Silver Tuffy Card.Thank you for using our program, please come again!
Thank you for applying for the Tuffy Credit card. Please enter your credit score.Credit Score: 560Unfortunately, you are ineligible for Tuffy credit cards at the moment. Please try again at a later date.Thank you for using our program, please come again!
Sample invalid input
Thank you for applying for the Tuffy Credit card. Please enter your credit scoreCredit Score: 900That is an invalid credit score. Please run the program again and provide a valid credit score.
Submission checklist
- Compiled and ran the driver (main).
- Manually checked for compilation and logical errors.
- Ensured no errors on the unit test (make test).
Code evaluation
Open the terminal and navigate to the folder that contains this exercise. Assuming you have pulled the code inside of /home/student/labex02-tuffy
and you are currently in /home/student
you can issue the following commands
cd labex02-tuffy
You also need to navigate into the problem you want to answer. To access the files needed to answer problem 1, for example, you need to issue the following command.
cd prob01
When you want to answer another problem, you need to go back up to the parent folder and navigate into the next problem. Assuming you are currently in prob01
, you can issue the following commands to go to the parent folder then go into another problem you want to answer; prob02
for example.
cd ..cd prob02
Use the clang++
command to compile your code and the ./
command to run it. The sample code below shows how you would compile code save in main.cpp
and into the executable file main
. Make sure you use the correct filenames required in this problem. Take note that if you make any changes to your code, you will need to compile it first before you see changes when running it.
clang++ -std=c++17 main.cpp-o main./main
You can run one, two, or all the commands below to test
your code, stylecheck
your code’s design, or formatcheck
your work. Kindly make sure that you have compiled and executed your code before issuing any of the commands below to avoid errors.
make testmake stylecheckmake formatcheck
A faster way of running all these tests uses the all
parameter.
make all
Submission
- When everything runs correctly, let’s copy your code into the Github repository. The first step is to add your code to what is called the staging area using git’s
add
command. The parameter afteradd
is the name of the file you want to add. There are cases when you have multiple changed files, so you can just type . (period) to add all modified files.git add main.cpp
- Once everything is in the staging area, we use the
commit
command to tell git that we have added everything we need into the staging area.git commit
- In case it asks you to configure global variables for an email and name, just copy the commands it provides then replace the dummy text with your email and Github username.
git config --global user.email "[email protected]"git config --global user.name "Tuffy Titan"
When you’re done, make sure you type
git commit
again. - Git will ask you to describe what you have added to the staging area. By default, you will use a command-line based editor called nano. Go ahead and provide a description then press Ctrl + x to exit. Press Y to confirm that you want to make changes and then press Enter.
- Lets push all changes to the Github repository using git’s
push
command. Provide your Github username and password when you are asked.git push
- When you finish the exercise, go back to Titanium and click on the
Add submission
button in the lab exercise page. Provide a short message in the text area such as “finished lab exercise” and click onSave changes
. Finally click onSubmit assignment
to inform your instructor that you are done.
Reviews
There are no reviews yet.