0% found this document useful (0 votes)
33 views5 pages

Lab 1 - Getting Started With C++

This document provides an introduction to C++ and covers several programming concepts including input/output using cin and cout, selection statements like if/else and switch/case, and repetition statements like for, while, and do/while loops. It includes examples for each concept and homework problems applying these ideas. The homework involves calculating meal costs, tracking daily weather, and printing a diamond pattern using loops.
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)
33 views5 pages

Lab 1 - Getting Started With C++

This document provides an introduction to C++ and covers several programming concepts including input/output using cin and cout, selection statements like if/else and switch/case, and repetition statements like for, while, and do/while loops. It includes examples for each concept and homework problems applying these ideas. The homework involves calculating meal costs, tracking daily weather, and printing a diamond pattern using loops.
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/ 5

CT077-3-2-DSTR Getting Started with C++

Lab 1: Getting Started with C++

Part A: Learn how to use the cin and cout in C++

1. Write a program that to display the following output:

[Estimate Finish Time: 5 minutes]

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:

[Estimate Finish Time: 5 minutes]

Test yourself questions for Part A:

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:

Please enter your elapsed time (in HH:MM:SS format) = 00:02:44


Elapsed time in seconds = 164 seconds
[Estimate Finish Time: 15 minutes]

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

Area in rectangle B is bigger rectangle A.

[Estimate Finish Time: 15 minutes]

Level 3 Asia Pacific University of Technology & Innovation Page 1 of 5


CT077-3-2-DSTR Getting Started with C++

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:

[Estimate Finish Time: 10 minutes]

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]

Test yourself questions for Part B:

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:

if the average score =90% =>grade=A


if the average score >= 70% and <90% => grade=B
if the average score>=50% and <70% =>grade=C
if the average score<50% =>grade=F

Output sample:

[Estimate Finish Time: 15 minutes]

Level 3 Asia Pacific University of Technology & Innovation Page 2 of 5


CT077-3-2-DSTR Getting Started with C++

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

[Estimate Finish Time: 10 minutes]

Test yourself questions for Part C:

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.

Input validation: Do not accept a negative number.


[Estimate Finish Time: 15 minutes]

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.

[Estimate Finish Time: 15 minutes]

Level 3 Asia Pacific University of Technology & Innovation Page 3 of 5


CT077-3-2-DSTR Getting Started with C++

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).

Your program should display:

The total cost of the meal BEFORE GST and tipping


The total cost of the meal AFTER GST
The total cost of the meal AFTER GST and tipping

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:

Level 3 Asia Pacific University of Technology & Innovation Page 4 of 5


CT077-3-2-DSTR Getting Started with C++

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:

Level 3 Asia Pacific University of Technology & Innovation Page 5 of 5

You might also like