0% found this document useful (0 votes)
15 views9 pages

W02-Req-Input and Output

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)
15 views9 pages

W02-Req-Input and Output

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/ 9

CSC10001 – Introduction to Programming

Lab 02
Input Output Statement
CS10001 – Introduction to Programming L02 – Input & Output

1
Review

1.1. Programming
It is the process to write a program / an application.
Specificially, programming includes 4 steps:
- Step1: Understanding your problem.
- Step 2: Designing an algorithm.
- Step 3: Writing source code.
- Step 4: Packaging source code files into an executable file, a website, an apk, or an ipa file...
In this lab, we practice to write source code in C++.

1.2. Input and Output


- Basic units: variables/constants, data-types, expressions.
- Input output stream: concepts, stdin/stdout, formatting.
- Text file: file stream, read/write.

2
CS10001 – Introduction to Programming L02 – Input & Output

2
Reading
2.1 Online IDE
Study how to write, run, enter input values and share source codes in ideone.com.
Find other 2 similar websites.

2.2 Offline IDE


Visual studio
- 2022: https://www.youtube.com/watch?v=HS4c3kBEWr4
- 2023: https://www.youtube.com/watch?v=c8OD_O9FE6Q
Visual studio code: https://www.youtube.com/watch?v=U8sSTvuI78w&list=PLw3TVTwwazpq-
3omuVjhNJO5zZjpHnLmf
Xcode: https://www.youtube.com/watch?v=HA-NahwEnyA

2.3 Compiling program


Study and answer the following questions:
a) How to compile a C/C++ program?
https://www.geeksforgeeks.org/compiling-a-c-program-behind-the-scenes/
b) Study at least 2 common C/C++ compilers.
- https://gcc.gnu.org/onlinedocs/gcc/
- https://clang.llvm.org/docs/UsersManual.html
c) Install and compile 3 program in Assignment 1 in gcc compiler.
- https://aroliant.github.io/guides/installation/windows/gcc.html
- https://youtu.be/hSAY50OL_J4

3
CS10001 – Introduction to Programming L02 – Input & Output

3
Requirements
In-class assignment: P02, P05, P13.
Homework: P02, P05, P10, P12, P13, P16, P17, P23, P24, P25.
(Students need to check ‘W01-Problems.pdf’ file for Px)

Students must design at least 3 test cases for each program.

// <YOUR STUDENT ID>


// <YOUR FULL NAME>
// <YOUR CLASS>

// Test case 1
// Input:
// Output:

// Test case 2
// Input:
// Output:

// Test case 3
// Input:
// Output:

int main(){
//your code here

return 0;
}

4
CS10001 – Introduction to Programming L02 – Input & Output

3.1. P02
Write a program that inputs two integers. Calculate the sum of these two integers and print the result on
the screen.
Input data:
A single line containing two integers a and b, separated by a space.
Where -10^9 <= a, b <= 10^9.
Output data:
The sum of the two integers, in the format a + b = c.
Example:
Input Output
35 3+5=8

3.2. P05
Write a program that inputs two integers. Divide the first number by the second and print the result on
the screen.
Input data:
A single line containing two integers a and b, separated by a space.
Where -10^9 <= a, b <= 10^9.
Output data:
The result is in the format a / b = c, rounded to 2 decimal places.
Example:
Input Output
92 9 / 2 = 4.50

3.3. P13
Write a program that inputs the lengths of the three sides of a valid triangle. Calculate the perimeter
and area of that triangle and print them on the screen.
Input data:
A single line containing three positive real numbers, edge1, edge2, edge3, representing the lengths of
the three sides of the triangle.
Where 0 < edge1, edge2, edge3 <= 10^9.
Output data:
The perimeter and area of the triangle on the same line, rounded to two decimal places.

5
CS10001 – Introduction to Programming L02 – Input & Output

Example:
Input Output
3.0 4.0 5.0 12.00 6.00

3.4. P10
Write a program that inputs the electricity meter reading from the previous month and the current
month. Calculate the number of KWh we have consumed and print the result on the screen.
Input data:
A single line containing two positive integers, previous and current, which are the electricity meter
readings for the previous and current months, separated by a space.
Where 0 <= previous <= current <= 10^9.
Output data:
The consumed electricity reading.
Example:
Input Output
1000 1211 211

3.5. P12
Write a program that inputs the quantity and unit price of a product.
Calculate the total amount to be paid = cost of goods + tax.
Cost of goods = quantity * unit price.
Tax = 10% of the cost of goods.
Input data:
Line 1: a positive integer, quantity, representing the quantity of the product.
Line 2: a positive real number, price, representing the unit price of the product.
Where -10^9 <= quantity, price <= 10^9.
Output data:
The total amount to be paid, with 0 decimal places.
Example:
Input Output
7 231000
30000

6
CS10001 – Introduction to Programming L02 – Input & Output

3.6. P16
Write a program that inputs a Vehicle registration plate, which is a positive integer with 5 digits.
Calculate the last digit of the sum of the digits (called "nut") of that license plate number
Input data:
A positive integer plate with 5 digits, where 10000 <= plate <= 99999.
Output data:
The sum of the digits (nut).
Example:
Input Output
12345 5

3.7. P17
Write a program that inputs a positive integer money, which is an even number in the thousands.
Consider the following banknote denominations: 500.000; 200.000; 100.000; 50.000; 20.000; 10.000;
5000; 2000; and 1000. Using a method that prioritizes higher denominations first, print the number of
each banknote needed for the given amount.
Input:
A single positive integer money, representing the amount to be exchanged, where 0 < money <= 10^9.
Output:
9 lines, each indicating the denomination and the number of notes of that denomination, in the format:
denomination: number of notes.
Example:
Input Output
2361000 500.000: 4
200.000: 1
100.000: 1
50.000: 1
20.000: 0
10.000: 1
5000: 0
2000: 0
1000: 0

3.8. P23
Write a program that inputs the side length of an equilateral triangle and the radius of a circle. Calculate
the total area of the gray region.
7
CS10001 – Introduction to Programming L02 – Input & Output

Use the convention PI = 3.14

Input Data:
A single line containing 2 positive real numbers, edge and radius, separated by a space.
Where 0 < edge, radius <= 10^9.
Output Data:
A single number, area, representing the area of the shaded region, rounded to 2 decimal places.
Example:
Input Output
32 17.97

3.9. P24
A promotional program offers a 40% cashback on all transactions, with a maximum cashback limit of
100,000 VND. Determine how much a user should spend to receive the maximum cashback amount.
Input Data:
A single line containing 2 positive real numbers, percent and quota, separated by a space.
Where 0 < percent, quota <= 10^9.

Output Data:
A single number representing the amount to spend to receive the maximum cashback, rounded to 2
decimal places.
Example:
Input Output
40 100000 250000

8
CS10001 – Introduction to Programming L02 – Input & Output

3.10. P25
On 12-10-2019, Eliud Kipchoge completed 42.195 km in 1 hour, 59 minutes, and 40.2 seconds,
becoming the first person to run a marathon distance of 42 km in under 2 hours.
Write a program to calculate the pace (minutes per km) and speed (km/h) with given the distance (km)
and the running time (hours, minutes, seconds).
Input Data:
A single line containing 4 positive real numbers: km, hour, minute, and second, separated by spaces.
Where 0 < km, hour, minute, second <= 10^9.
Output Data:
A single line with two numbers representing the pace and speed, each rounded to 2 decimal places.
Example:
Input Output
42.195 1 59 40.2 21.16 2.84

You might also like