0% found this document useful (0 votes)
25 views17 pages

Bonus Assignment

ECE 1108
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)
25 views17 pages

Bonus Assignment

ECE 1108
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/ 17

Assignment programming fundamentals

1. Product of Three Numbers


Write a program that assigns the values 10, 20, and 30 to three integer
variables and then stores the product of these three variables in another
variable, product.
2. The Golden Ratio
The golden ratio is a ratio that appears in nature and produces pleasing,
harmonious proportions. For rectangles, if the width is approximately
1.62 times the height, they will be in this ratio. Write a program that
calculates the appropriate width for a rectangle with height 5 cm so that it
fulfills this ratio.
3. Display Count of Lines
Write a program that displays the count of lines with and without
comments for a program of 1050 lines in total. Assume that 36 percent of
the lines contain comments.
4. Restaurant Bill
Write a program that computes the tax and tip on a restaurant bill for a
patron with a $88.67 meal charge. The tax should be 6.75 percent of the
meal cost. The tip should be 20 percent of the total after adding the tax.
Display the meal cost, tax amount, tip amount, and total bill on the screen.
5. Pounds to Kilograms
The SI system of units is an internationally agreed decimal system of
measurement that uses the kilogram as the unit of weight. Earlier systems
used different units, such as the stone. In 1835, the United Kingdom
defined the stone as weighing 14 pounds, or 6.35 kg. Write a program that
stores your personal weight in pounds in a variable and calculates and
displays your weight in both stones and kilograms.
TIP: Use the double data type for all variables in this program.
6. Total Calories
In most countries, it is compulsory to display the total calories on the label
of prepackaged food. For strawberry jam this is very easy, because there
are only three ingredients: strawberries, sugar, and lemon juice, and for
every 100 g strawberries, there is 100 g of sugar and 5 g of lemon juice.
Write a program that defines the following variables:
strawberriesKcal: This variable will hold the number of kilocalories per
100 g of strawberries. Initialize the variable to 36.
sugarKcal: This variable will hold the number of kilocalories per 100 g of
sugar. Initialize the variable to 40.
lemonKcal: This variable will hold the number of kilocalories per 100 g
of lemon juice. Initialize the variable to 32.
The program should calculate the total amount of jam produced by
starting out with 400 g of strawberries. It should also calculate the total
kilocalories present in this amount of jam. Display the total amount of jam
and the total kilocalories on the screen.
7. Ocean Levels
Assuming the ocean’s level is currently rising at about 1.5 millimeters per
year, write a program that displays:
• The number of millimeters higher than the current level that the
ocean’s level will be in 5 years.
• The number of millimeters higher than the current level that the
ocean’s level will be in 7 years.
• The number of millimeters higher than the current level that the
ocean’s level will be in 10 years.
8. Total Purchase
A customer in a store is purchasing five items. The prices of the five items
are as follows:
Price of item 1 = $15.95
Price of item 2 = $24.95
Price of item 3 = $6.95
Price of item 4 = $12.95
Price of item 5 = $3.95
Write a program that holds the prices of the five items in five variables.
Display each item’s price, the subtotal of the sale, the amount of sales tax,
and the total. Assume the sales tax is 7 percent.
9. Cyborg Data Type Sizes
You have been given a job as a programmer on a Cyborg supercomputer.
In order to accomplish some calculations, you need to know how many
bytes the following data types use: char, int, float, and double. You do not
have any technical documentation, so you can’t look this information up.
Write a C++ program that will determine the amount of memory used by
these types and display the information on the screen.
10. Digital Colors
Digital colors can be represented as a combination of red, green, and blue,
with an alpha value specifying how opaque they are. Each value is one
byte, and thus in the range of 0 to 255. Instead of having 4 one-byte values,
the colors can be stored in one unsigned int of 4 bytes. The single number
is a sum of the alpha value multiplied by 16,777,216; the red multiplied
with 65,536; the green with 256; and blue. Write a program that represents
the color (128, 255, 128, 64), where the first value is the alpha value.
11. Distance per Tank of Gas
A car with a 20-gallon gas tank averages 23.5 miles per gallon when
driven in town, and 28.9 miles per gallon when driven on the highway.
Write a program that calculates and displays the distance the car can travel
on one tank of gas when driven in town and when driven on the highway.
Hint: The following formula can be used to calculate the distance:
Distance 5 Number of Gallons 3 Average Miles per Gallon
12. Weight of Freight
One ton is equivalent to 2240 pounds. Write a program that calculates the
weight, in tons, of freight that weighs 10,158 pounds.
13. Surface Area and Volume of a Sphere
The surface area of a sphere of radius r is calculated by using the formula
A = 4πr2 , and its volume is calculated by using the formula V = (4/3)πr 3.
Write a program that calculates the surface area and volume of a sphere
that has a radius of 8 cm. (Note: π = 3.1415926535)
14. Rainfall Information
Rain is collected in a pluviometer to determine how much rain has fallen
during a certain period of time. Suppose that a pluviometer contained 3
liters at 0:00 and 15 liters at 6:00. Write a program that displays the
following pieces of information, each on a separate line:
The total rain during the observed period
The average per hour
The expected amount for the entire day of 24 hours if the rain continues
with the same intensity.
Use a single cout statement to display all information.
15. Triangle Pattern
Write a program that displays the following pattern on the screen:
*
***
*****
*******

16. Diamond Pattern


Write a program that displays the following pattern:
*
***
*****
*******
*****
***
*
17. Stock Commission
Kathryn bought 750 shares of stock at a price of $35.00 per share. She
must pay her stockbroker a 2 percent commission for the transaction.
Write a program that calculates and displays the following:
• The amount paid for the stock alone (without the commission).
• The amount of the commission.
• The total amount paid (for the stock plus the commission).
18. Energy Drink Consumption
A soft drink company recently surveyed 16,500 of its customers and
found that approximately 15 percent of those surveyed purchase one or
more energy drinks per week. Of those customers who purchase energy
drinks, approximately 58 percent of them prefer citrus-flavored energy
drinks. Write a program that displays the following:
• The approximate number of customers in the survey who purchase
one or more energy drinks per week.
• The approximate number of customers in the survey who prefer
citrus-flavored energy drinks.
19. Annual High Temperatures
The average July high temperature is 85 degrees Fahrenheit in New York
City, 88 degrees Fahrenheit in Denver, and 106 degrees Fahrenheit in
Phoenix. Write a program that calculates and reports what the new
average July high temperature would be for each of these cities if
temperatures rise by 2 percent.
20. How Much Paint
A particular brand of paint covers 340 square feet per gallon. Write a
program to determine and report approximately how many gallons of
paint will be needed to paint two coats on a wooden fence that is 6 feet
high and 100 feet long.
21. Gallons to Liters
Write a program that calculates the price of gasoline. The program should
ask the user to input the volume of gasoline in liters. It should then display
the volume in gallons and the corresponding price. Assume that the price
of gasoline is $3.58 per gallon.
Note that 1 gallon = 4.546 liters.
22. Stadium Seating
There are three seating categories at a stadium. For a softball game, Class
A seats cost $15, Class B seats cost $12, and Class C seats cost $9. Write
a program that asks how many tickets for each class of seats were sold,
then displays the amount of income generated from ticket sales. Format
your dollar amount in fixed-point notation, with two decimal places of
precision, and be sure the decimal point is always displayed.
23. Percentage of Scores
Write a program that asks for the test scores of six subjects. Each subject
can have a maximum score of 100. The program should calculate and
display the total score and the percentage obtained out of 600, formatted
in fixed-point notation, with two decimal points of precision.
24. Average Rainfall
Write a program that calculates the average rainfall for three months. The
program should ask the user to enter the name of each month, such as June
or July, and the amount of rain (in inches) that fell each month. The
program should display a message similar to the following: The average
rainfall for June, July, and August is 6.72 inches.
25. Battery Charge Consumption
Battery consumption is a major issue for portable electronics, especially
smartphones. A full battery may contain 3000 mAh, but if a component
requires 300 mA of current, after only 10 hours the battery will be
completely drained. Suppose that using GPS consumes 148 mA, WiFi
uses 352 mA, and the display uses 197 mA at full brightness. Write a
program that lets the user input the time spent using GPS, on WiFi with
the display on full brightness, and calculates the battery consumption.
26. Surface Area and Volume of a Cylinder
The surface area A of a cylinder is given by the following formula:
𝐴 = 2𝜋𝑟ℎ + 2𝜋𝑟 2
The volume V of a cylinder is given by the following formula:
𝑉 = 𝜋𝑟 2 ℎ
The term r is the radius and h is the height of the cylinder. Write a program
that asks the user for the radius and height of the cylinder and displays the
area and volume. Assume that value of π is 3.1415926535.
27. Box Office
A movie theater only keeps a percentage of the revenue earned from ticket
sales. The remainder goes to the movie distributor. Write a program that
calculates a theater’s gross and net box office profit for a night. The
program should ask for the name of the movie, and how many adult and
child tickets were sold. (The price of an adult ticket is $10.00 and a child’s
ticket is $6.00.) It should display a report similar to:
Movie Name: “Wheels of Fury”
Adult Tickets Sold: 382
Child Tickets Sold: 127
Gross Box Office Profit: $ 4,582.00
Net Box Office Profit: $ 916.40
Amount Paid to Distributor: $ 3,665.60
NOTE: Assume the theater keeps 20 percent of the gross box office profit.
28. How Many Widgets?
The Yukon Widget Company manufactures widgets that weigh 12.5
pounds each. Write a program that calculates how many widgets are
stacked on a pallet, based on the total weight of the pallet. The program
should ask the user how much the pallet weighs by itself and with the
widgets stacked on it. It should then calculate and display the number of
widgets stacked on the pallet.
29. How Many Calories?
A bag of cookies holds 30 cookies. The calorie information on the bag
claims there are 10 “servings” in the bag and that a serving equals 300
calories. Write a program that asks the user to input how many cookies he
or she actually ate, then reports how many total calories were consumed.
30. Guess the Number
Write a program that asks the user for two values and calculates a random
number between the two values. Then print a message that informs the
user that a number between the given inputs has been selected and ask the
user to guess the actual number. Display the correct answer and the
difference between the guess and the correct answer.
31. Automobile Costs
Write a program that asks the user to enter the monthly costs for the
following expenses incurred from operating his or her automobile: loan
payment, insurance, gas, oil, tires, and maintenance. The program should
then display the total monthly cost of these expenses, and the total annual
cost of these expenses.
32. Sum of Two Fractions
The formula to find the sum of two fractions a/b and c/d is:
𝑎 𝑐 𝑎𝑑 + 𝑏𝑐
+ =
𝑏 𝑑 𝑏𝑑
Write a program that asks for the numerator and denominator of each
fraction and displays the sum in fractional form.
33. Currency
Write a program that will convert U.S. dollar amounts to Japanese yen
and to euros, storing the conversion factors in the constants
YEN_PER_DOLLAR and EUROS_PER_ DOLLAR. To get the most up-
to-date exchange rates, search the Internet using the term “currency
exchange rate”. If you cannot find the most recent exchange rates, use the
following:
1 Dollar = 98.93 Yen
1 Dollar = 0.74 Euros
Format your currency amounts in fixed-point notation, with two decimal
places of precision, and be sure the decimal point is always displayed.
34. Temperature in the Mountains
As one goes higher up the mountains, the temperature decreases. The rate
at which this occurs is called the lapse rate. The actual value depends on
the humidity of the air. We can easily use the typical value of around
5°C/km or 2.7°F/1000 ft. Write a program that asks the user for the
temperature at sea level in degrees Celsius and displays the following:
The temperature at sea level (for reference)
The temperature at 1000, 2000 and 3000 m
The temperature at the top of Mount Everest (8.848 m)
The height at which the temperature is 0°C
As an additional exercise, show also the temperatures in degrees
Fahrenheit and the height in feet. To convert temperatures in degrees
Celsius to degrees Fahrenheit, multiply by 1.8 (or 9/5) and add 32; to
convert meters to feet, multiply by 3.28.
35. Container Space
Containers are used when shipping large amounts of goods between
countries. The shipping cost depends on the number of containers, not on
how much they are filled. The capacity of a container is typically
expressed in liters. Write a program that asks for the capacity of a
container in liters and the amount of goods to be shipped (also in liters).
Display the number of containers needed and the amount of free space
remaining.
36. Rectangular to Polar Coordinates
A point in a rectangular coordinate system is represented by (x,y), where
x is its position along the x-axis and y is its position along the y-axis. The
point can be represented in a polar coordinate system by (r, u), where r is
the distance of the point from the origin and u is the angle in radians
between the x-axis and the line joining the point with the origin.
To convert from the rectangular to the polar coordinates, the following
formulas are used:
𝑟2 = 𝑥 2 + 𝑦2
𝜃 = tan−1 𝑦/𝑥
Write a program that asks the user for the position of a point in the
rectangular coordinate system and displays the point in the polar
coordinate system. (Use library function atan for finding θ).
37. Math Tutor
Write a program that can be used as a math tutor for a young student. The
program should display two random numbers to be added, such as
247
+129
The program should then pause while the student works on the problem.
When the student is ready to check the answer, he or she can press a key
and the program will display the correct solution:
247
+129
376
38. Interest Earned
Assuming there are no deposits other than the original investment, the
balance in a
savings account after one year may be calculated as
𝑅𝑎𝑡𝑒 𝑇
𝐴𝑚𝑜𝑢𝑛𝑡 = 𝑃𝑟𝑖𝑛𝑐𝑖𝑝𝑎𝑙 × (1 + )
𝑇
Principal is the balance in the savings account, Rate is the interest rate,
and T is the number of times the interest is compounded during a year (T
is 4 if the interest is compounded quarterly).
Write a program that asks for the principal, the interest rate, and the
number of times the interest is compounded. It should display a report
similar to:
Interest Rate: 4.25%
Times Compounded: 12
Principal: $ 1000.00
Interest: $ 43.34
Amount in Savings: $ 1043.34
39. Monthly Payments
The monthly payment on a loan may be calculated by the following
formula:
𝑅𝑎𝑡𝑒 × (1 + 𝑅𝑎𝑡𝑒)𝑁
𝑃𝑎𝑦𝑚𝑒𝑛𝑡 = ×𝐿
((1 + 𝑅𝑎𝑡𝑒)𝑁 − 1)
Rate is the monthly interest rate, which is the annual interest rate divided
by 12. (12 percent annual interest would be 1 percent monthly interest.)
N is the number of payments, and L is the amount of the loan. Write a
program that asks for these values then displays a report similar to:
Loan Amount: $ 10000.00
Monthly Interest Rate: 1%
Number of Payments: 36
Monthly Payment: $ 332.14
Amount Paid Back: $ 11957.15
Interest Paid: $ 1957.15

40. Pizza Pi
Joe’s Pizza Palace needs a program to calculate the number of slices a
pizza of any size can be divided into. The program should perform the
following steps:
A) Ask the user for the diameter of the pizza in inches.
B) Calculate the number of slices that may be taken from a pizza of that
size.
A) Display a message telling the number of slices.
To calculate the number of slices that may be taken from the pizza, you
must know the following facts:
• Each slice should have an area of 14.125 inches.
• To calculate the number of slices, simply divide the area of the
pizza by 14.125.
• The area of the pizza is calculated with this formula:
Area = πr2
NOTE: π is the Greek letter pi. 3.14159 can be used as its value. The
variable r is the radius of the pizza. Divide the diameter by 2 to get the
radius.
Make sure the output of the program displays the number of slices in
fixed-point notation, rounded to one decimal place of precision. Use a
named constant for pi.
41. How Many Pizzas?
Modify the program you wrote in Programming Challenge 20 (Pizza Pi)
so it reports the number of pizzas you need to buy for a party if each
person attending is expected to eat an average of four slices. The program
should ask the user for the number of people who will be at the party, and
for the diameter of the pizzas to be ordered. It should then calculate and
display the number of pizzas to purchase.
42. Angle Calculator
Write a program that asks the user for an angle, entered in radians. The
program should then display the sine, cosine, and tangent of the angle.
(Use the sin, cos, and tan library functions to determine these values.)
The output should be displayed in fixed-point notation, rounded to four
decimal places of precision.
43. Stock Transaction Program
Last month Joe purchased some stock in Acme Software, Inc. Here are
the details of
the purchase:
• The number of shares that Joe purchased was 1,000.
• When Joe purchased the stock, he paid $45.50 per share.
• Joe paid his stockbroker a commission that amounted to 2 percent
of the amount he paid for the stock.
Two weeks later, Joe sold the stock. Here are the details of the sale:
• The number of shares that Joe sold was 1,000.
• He sold the stock for $56.90 per share.
• He paid his stockbroker another commission that amounted to 2
percent of the amount he received for the stock.
Write a program that displays the following information:
• The amount of money Joe paid for the stock.
• The amount of commission Joe paid his broker when he bought the
stock.
• The amount that Joe sold the stock for.
• The amount of commission Joe paid his broker when he sold the
stock.
• Display the amount of profit that Joe made after selling his stock
and paying the two commissions to his broker. (If the amount of
profit that your program displays is a negative number, then Joe lost
money on the transaction.)
44. Planting Grapevines
A vineyard owner is planting several new rows of grapevines, and needs
to know how many grapevines to plant in each row. She has determined
that after measuring the length of a future row, she can use the following
formula to calculate the number of vines that will fit in the row, along
with the trellis end-post assemblies that will need to be constructed at each
end of the row:
𝑅 − 2𝐸
𝑉=
𝑆
The terms in the formula are:
V is the number of grapevines that will fit in the row.
R is the length of the row, in feet.
E is the amount of space, in feet, used by an end-post assembly.
S is the space between vines, in feet.
Write a program that makes the calculation for the vineyard owner. The
program
should ask the user to input the following:
• The length of the row, in feet
• The amount of space used by an end-post assembly, in feet
• The amount of space between the vines, in feet
Once the input data has been entered, the program should calculate and
display the number of grapevines that will fit in the row.
45. Word Game
Write a program that plays a word game with the user. The program
should ask the
user to enter the following:
• His or her name
• His or her age
• The name of a city
• The name of a college
• A profession
• A type of animal
• A pet’s name
After the user has entered these items, the program should display the
following story, inserting the user’s input into the appropriate locations:
There once was a person named NAME who lived in CITY. At the age of
AGE, NAME went to college at COLLEGE. NAME graduated and went
to work as a PROFESSION. Then, NAME adopted a(n) ANIMAL named
PETNAME. They both lived happily ever after!

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