Lab 1 - Getting Started With C++
Lab 1 - Getting Started With C++
2. Write a program to get an input word from a user. Then, display the given word
together with the sentence of “Hello World” as below:
1. A program is required to prompt for and accept a time and compute the number of
seconds elapsed since midnight. The time should be entered in the format
HH:MM:SS.
Output sample:
2. The area of a rectangle is the rectangle’s length times its width. Write a program that
asks for the length and width of two rectangles. The program should tell the user
which rectangle has the greater area, or if the areas are the same.
Output sample:
Rectangle A:
Width = 2
Height = 4
Rectangle B:
Width = 3
Height = 10
Part B: Learn how to use the Selection control statements (if…else… / switch…case) in
C++
1. Write a program that reads in two integers and determines and prints if the first is a
multiple of the second.
(Hint: use the modulus operator)
Output sample:
2. Write a program that asks the user to enter a number within the range of 1 through 10.
Use a switch statement to display the Roman numeral version of that number.
Input validation: Do not accept a number less than 1 or greater than 10.
[Estimate Finish Time: 10 minutes]
1. Write a program that determines a student’s grade. The program will read three types
of scores in percentage (quiz , mid-term, and final scores) and determine the grade
based on the following rules:
Output sample:
Part C: Learn how to use the Repetition control statements (for, while, do…while)
in C++.
1. Write a program that able to print the even number that in the between of 1 to 50.
Output sample:
2 4 6 8 10
12 14 16 18 20
22 24 26 28 30
32 34 36 38 40
42 44 46 48 50
1. Sum value:
Write a program that asks the user for a positive integer value. The program should use a
loop to get the sum of all the integers from 1 up to the number entered. For example, if
the user enters 50, the loop will find the sum of 1, 2, 3, 4, … 50.
2. Calories Burned:
Running on a particular treadmill you burn 3.9 calories per minute. Write a program that
uses a loop to display the number of calories burned after 10, 15, 20, 25, and 30 minutes.
Part D: Homework.
Submit your answer (in doc / pdf) to the Microsoft Teams. Your answer should include your
code and your program screenshot.
1. Compute the total cost of a meal inclusive of GST (Goods and Service Tax) and
tipping. Assume that the GST is fixed at 6% but the amount to tip will depend on the
customer. Your program should input the cost of the meal (before GST and tipping)
and the tip amount (to be input as a percentage).
2. Develop an interactive program that will keep track of the weather forecast in a
month. On any given day, the weather forecast may be hot, rainy, or cloudy. Your
program should input the weather forecast for each day in the month and should
display the total number of hot, rainy, and cloudy days in a month. You should use a
loop and a conditional structure to develop this program. Do not use arrays in
question.
Output sample:
3. Write a C++ program ask to the user to enter number of rows for diamond dimension
to print the diamond pattern, then display the result on the screen. Note: Must use
loops to print the diamond.
Output sample: