# Lab exercise 3 Problems Solved

35.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

5/5 - (1 vote)

# Lab exercise 3 objectives

1. Write C++ programs
2. Compile C++ programs
3. Implement programs that useÂ `std::cin`Â andÂ `std::cout`Â correctly
4. 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.00
Seniors - \$10.00

Please enter the age of the person for the first guest: 15
Please enter the age of the person for the second guest: 16

The Subtotal for the ticket cost is: \$26.00
``````

# Submission checklist

1. Compiled and ran the driver (main).
2. Manually checked for compilation and logical errors.
3. 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 test
make stylecheck
make formatcheck
``````

A faster way of running all these tests uses theÂ `all`Â parameter.

``````make all
``````

# Submission

1. 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 afterÂ `add`Â 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
``````
2. 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
``````
3. 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.

4. 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.
5. 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
``````
6. 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 onÂ `Save changes`. Finally click onÂ `Submit 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.
Congratulations! You are tall enough to ride!
``````

## Unsafe

``````You must be at least 55 inches to safely ride the TuffyTwister.
Safety is our first priority. Unfortunately, we can't let you ride yet.
``````

# Submission checklist

1. Compiled and ran the driver (main).
2. Manually checked for compilation and logical errors.
3. 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 test
make stylecheck
make formatcheck
``````

A faster way of running all these tests uses theÂ `all`Â parameter.

``````make all
``````

# Submission

1. 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 afterÂ `add`Â 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
``````
2. 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
``````
3. 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.

4. 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.
5. 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
``````
6. 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 onÂ `Save changes`. Finally click onÂ `Submit 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: 12
Hours worked: 20
Total Salary Owed: \$240.00
``````

# Submission checklist

1. Compiled and ran the driver (main).
2. Manually checked for compilation and logical errors.
3. 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 test
make stylecheck
make formatcheck
``````

A faster way of running all these tests uses theÂ `all`Â parameter.

``````make all
``````

# Submission

1. 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 afterÂ `add`Â 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
``````
2. 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
``````
3. 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.

4. 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.
5. 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
``````
6. 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 onÂ `Save changes`. Finally click onÂ `Submit 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): y
Please enter amount of money spent: \$42.12
Amount of cash back received: \$2.11
``````

## Invalid input

``````Please enter type of card: c
Please enter amount of money spent: \$42.12
Invalid card type.
``````

# Submission checklist

1. Compiled and ran the driver (main).
2. Manually checked for compilation and logical errors.
3. 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 test
make stylecheck
make formatcheck
``````

A faster way of running all these tests uses theÂ `all`Â parameter.

``````make all
``````

# Submission

1. 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 afterÂ `add`Â 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
``````
2. 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
``````
3. 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.

4. 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.
5. 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
``````
6. 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 onÂ `Save changes`. Finally click onÂ `Submit 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 cards
580 -  669: Eligible for the Silver Tuffy Card
670 -  799: Eligible for the Gold Tuffy Card
800 -  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: 600

You 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: 560

Unfortunately, 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 score
Credit Score: 900

That is an invalid credit score. Please run the program again and provide a valid credit score.
``````

# Submission checklist

1. Compiled and ran the driver (main).
2. Manually checked for compilation and logical errors.
3. 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 test
make stylecheck
make formatcheck
``````

A faster way of running all these tests uses theÂ `all`Â parameter.

``````make all
``````

# Submission

1. 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 afterÂ `add`Â 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
``````
2. 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
``````
3. 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.

4. 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.
5. 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
``````
6. 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 onÂ `Save changes`. Finally click onÂ `Submit assignment`Â to inform your instructor that you are done.
• Lab_03.zip