0% found this document useful (0 votes)
61 views3 pages

Prokom-Tugas 3

This document provides details for Assignment 3 on control structures in C++. It includes 9 programming problems dealing with selection and repetition constructs. Students are asked to write C++ programs that use control structures to solve problems related to employee pay, carpet pricing, haircut recommendations, inflation calculations, sound velocity, converting years to Roman numerals, approximating pi, solving quadratic equations, and scoring blackjack hands. The assignment is individual and due on March 31, 2022.

Uploaded by

Fee Md
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

Prokom-Tugas 3

This document provides details for Assignment 3 on control structures in C++. It includes 9 programming problems dealing with selection and repetition constructs. Students are asked to write C++ programs that use control structures to solve problems related to employee pay, carpet pricing, haircut recommendations, inflation calculations, sound velocity, converting years to Roman numerals, approximating pi, solving quadratic equations, and scoring blackjack hands. The assignment is individual and due on March 31, 2022.

Uploaded by

Fee Md
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Computer Programming

Assignment 3

Title: Control Structure


Learning Outcome: Students are able to understand Control Structure (Selection and Repetition) in
C++
Deadline: March 31, 2022!
Category: Individual Assignment
Problems:
1. An employee is paid at a rate of IDR125000 per hour for the first 40 hours worked in a week. Any
hours over that are paid at the overtime rate of oneand-one-half times that. From the worker’s gross
pay, 6% is withheld for Social Security tax, 14% is withheld for federal income tax, 5% is withheld
for state income tax, and IDR100.000 per week is withheld for union dues. If the worker has three
or more dependents, then an additional IDR750.000 is withheld to cover the extra cost of health
insurance beyond what the employer pays. Write a program that will read in the number of hours
worked in a week and the number of dependents as input and will then output the worker’s gross
pay, each withholding amount, and the net take-home pay for the week. For a harder version, write
your program so that it allows the calculation to be repeated as often as the user wishes [20]

2. A store sells carpets for IDR120.0000 per meter. If a customer buys more than 10 m of carpet, they
get a discount of 15% on every additional meter of carpet they purchase. Write a program that inputs
the carpet length that a user wishes to buy, stores the value in a double variable, and then calculates
and outputs the total cost of the carpet [20]

3. The following flowchart contains a series of questions to determine what kind of haircut to get. Write
a program that asks the questions to the user and outputs the recommended haircut. [20]

4. It is difficult to make a budget that spans several years, because prices are not stable. If your
company needs 500 pencils per year, you cannot simply use this year’s price as the cost of pencils
two years from now. Because of inflation the cost is likely to be higher than it is today. Write a
program to gauge the expected cost of an item in a specified number of years. The program asks
for the cost of the item, the number of years from now that the item will be purchased, and the rate
of inflation. The program then outputs the estimated cost of the item after the specified period. Have
the user enter the inflation rate as a percentage, such as 2.6%. Your program should then convert

Assignment 3: Control Structure in C++


Computer Programming

the percentage to a decimal fraction, such as 0.056, and should use a loop to estimate the price
adjusted for inflation. ( Hint: Use a loop.) [20]

5. Sound travels through air as a result of collisions between the molecules in the air. The temperature
of the air affects the speed of the molecules, which in turn affects the speed of sound. The velocity
of sound in dry air can be approximated by the formula:

velocity ≈ 331.3 + 0.61 × Tc

where Tc is the temperature of the air in degrees Celsius and the velocity is in m/s. Write a program
that allows the user to input a starting and an ending temperature. Within this temperature range,
the program should output the temperature and the corresponding velocity in 1° increments. For
example, if the user entered 0 as the start temperature and 2 as the end temperature, then the
program should output
At 0 degrees Celsius the velocity of sound is 331.3 m/s
At 1 degrees Celsius the velocity of sound is 331.9 m/s
At 2 degrees Celsius the velocity of sound is 332.5 m/s. [20]

6. Write a program that accepts a year written as a four-digit Arabic (ordinary) numeral and outputs
the year written in Roman numerals. Important Roman numerals are V for 5, X for 10, L for 50, C
for 100, D for 500, and M for 1,000. Recall that some numbers are formed by using a kind of
subtraction of one Roman “digit”; for example, IV is 4 produced as V minus I, XL is 40, CM is 900,
and so on. A few sample years: MCM is 1900, MCML is 1950, MCMLX is 1960, MCMXL is 1940,
MCMLXXXIX is 1989. Assume the year is between 1000 and 3000. Your program should include a
loop that lets the user repeat this calculation until the user says she or he is done [20]

7. An approximate value of pi can be calculated using the series given below:

pi = 4 [ 1 – 1/3 + 1/5 – 1/7 + 1/9 ... + ((–1)n)/(2n + 1) ]

Write a C++ program to calculate the approximate value of pi using this series. The program takes
an input n that determines the number of terms in the approximation of the value of pi and outputs
the approximation. Include a loop that allows the user to repeat this calculation for new values n
until the user says she or he wants to end the program [20]

8. Write a C++ program that solves a quadratic equation to find its roots. The roots of a quadratic
equation
ax2 + bx + c = 0 (where a is not zero)

are given by the formula (−b ± sqrt(b2 − 4ac)) / 2a

The value of the discriminant (b 2 − 4ac) determines the nature of roots. If the value of the
discriminant is zero, then the equation has a single real root. If the value of the discriminant is
positive then the equation has two real roots. If the value of the discriminant is negative, then the
equation has two complex roots. The program takes values of a, b, and c as input and outputs the
roots. Be creative in how you output complex roots. Include a loop that allows the user to repeat this
calculation for new input values until the user says she or he wants to end the program. [20]

Assignment 3: Control Structure in C++


Computer Programming

9. Write a program that scores a blackjack hand. In blackjack, a player receives from two to five cards.
The cards 2 through 10 are scored as 2 through 10 points each. The face cards—jack, queen, and
king—are scored as 10 points. The goal is to come as close to a score of 21 as possible without
going over 21. Hence, any score over 21 is called “busted.” The ace can count as either 1 or 11,
whichever is better for the user. For example, an ace and a 10 can be scored as either 11 or 21.
Since 21 is a better score, this hand is scored as 21. An ace and two 8s can be scored as either 17
or 27. Since 27 is a “busted” score, this hand is scored as 17. The user is asked how many cards
she or he has, and the user responds with one of the integers 2, 3, 4, or 5. The user is then asked
for the card values. Card values are 2 through 10, jack, queen, king, and ace. A good way to handle
input is to use the type char so that the card input 2, for example, is read as the character '2', rather
than as the number 2. Input the values 2 through 9 as the characters '2' through '9'. Input the values
10, jack, queen, king, and ace as the characters 't', 'j', 'q', 'k', and 'a'. (Of course, the user does not
type in the single quotes.) Be sure to allow upper- as well as lowercase letters as input. After reading
in the values, the program should convert them from character values to numeric card scores, taking
special care for aces. The output is either a number between 2 and 21 (inclusive) or the word Busted.
You are likely to have one or more long multiway branches that use a switch statement or nested
if-else statement. Your program should include a loop that lets the user repeat this calculation until
the user says she or he is done. [30]

Instruction:
1. ODD NRP: 1, 3, 5, 7, 9 and EVEN NRP: 2, 4, 6, 8, 9
2. Write a report in Bahasa or English and submit it into myITS Classroom!
3. The file to submit is only NRP.pdf
4. Please use the report template. (available on MyITSC)

Assignment 3: Control Structure in C++

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy