0% found this document useful (0 votes)
77 views8 pages

Programming Basics and Flowcharting Guide

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)
77 views8 pages

Programming Basics and Flowcharting Guide

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

CSC10001 – Introduction to Programming

Lab 01
Programming Overview
CS10001 – Introduction to Programming L01 – Programming overview

1
Content
Algorithm is the core of an application.
Flowchart is a common way to describe an algorithm. (Another way is pseudo-code)
6 fundamental symbols:
- "Start": a eclipse
- "Input": a parallelogram
- "Process": a rectangle
- "Output": a parallelogram
- "End": a rounded rectangle
- And a line with arrow to connect all above elements. In this lab, we practice to draw several
basic flowchart.

2
CS10001 – Introduction to Programming L01 – Programming overview

2
Basic flowchart understanding
Programming is the process to write a program / an application.
Specifically, 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...

You may think step 3 is the most important step. But, actually, step 2 is the most one.
Without step 2, you don't know how to solve a problem manually. Then, you don't know to teach your
computer how to solve it, by writing source code.

For example, do you know an algorithm to find the shortest path from 2 specific locations? If you don't,
how can to implement a C++ / Python source code to find the shortest path?

There are 2 ways to express an algorithm: drawing a flowchart, or writing a pseudo-code.


Here is an example of a flowchart to solve a problem: compute the sum of 2 integers a, b.
(Students can you [Link] application to create flowchart)

3
CS10001 – Introduction to Programming L01 – Programming overview

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

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

4
CS10001 – Introduction to Programming L01 – Programming overview

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

5
CS10001 – Introduction to Programming L01 – Programming overview

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

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

6
CS10001 – Introduction to Programming L01 – Programming overview

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

7
CS10001 – Introduction to Programming L01 – Programming overview

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

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

Common questions

Powered by AI

Prioritizing higher denominations in the context of a program that determines required banknotes for a given amount results in an efficient algorithm by reducing the number of banknotes used. By using the largest denomination first, the algorithm quickly reduces the remaining amount, minimizing the total count of banknotes required. This approach, known as a greedy algorithm, works effectively when denominations are multiples or factors of each other, simplifying the computation and reducing the complexity of the task, leading to faster execution and simpler implementation .

The problem-solving exercise of calculating a triangle's perimeter and area demonstrates algorithm application in geometry by requiring the translation of geometric principles into a series of computational steps. First, the perimeter is determined by summing the lengths of the sides, while the area is calculated using Heron's formula, which involves multiple arithmetic operations and the square root function. This task exemplifies the application of mathematical concepts within an algorithmic framework, allowing students to integrate geometry and programming by converting theoretical concepts into executable instructions .

Input-output relationships in programming assignments enhance understanding of computational processes by requiring learners to comprehend how data is transformed through different stages of an operation. Each problem involves reading inputs, processing the data through calculations or logic, and producing outputs. This flow helps in understanding how programs operate—taking user input, applying algorithms, and generating results. By working on such problems, students develop an intuition for how data flows through a program and the impact of different programming constructs on the result .

Flowcharts play a critical role in programming by visually representing an algorithm, making it easier to understand the logical flow and sequence of operations. They use standard symbols to denote start, input, processing, output, and end steps, with arrows connecting these elements. Compared to pseudo-code, which uses structured natural language to describe the algorithm, flowcharts provide a more graphical approach. Both methods serve the purpose of designing an algorithm before coding, but flowcharts might be preferred for those who benefit from a visual representation .

Converting a real-world event, such as Eliud Kipchoge's marathon run, into a programming problem helps reinforce learning by providing a concrete context for abstract calculations. Students can relate to the well-known event, making the learning more engaging and memorable. By calculating pace and speed for the marathon, learners apply formulae for distance, time, and rate, thus understanding the practical implications of these metrics. This real-world context emphasizes the applicability of mathematical and programming concepts, aiding better retention and comprehension .

Rounding numerical results in programming assignments involving calculations is essential to ensure precision and consistency with expected output, particularly in contexts like financial transactions or scientific computations. Rounding provides clarity, ensuring outputs meet specification requirements and client expectations. Inaccuracies due to improper rounding can have significant implications, resulting in incorrect conclusions, financial losses, and even system failures. Proper handling of rounding reduces the chances of cumulative floating-point errors and provides reliable and valid results .

Understanding problem constraints, such as input size, is crucial for effective programming as it directly impacts algorithm design and implementation. Constraints define the boundaries within which a solution must operate, influencing choices on data structures and algorithms to ensure efficiency and avoid issues such as overflow or excessive computation time. Pragmatically handling input size constraints ensures that programs can process data efficiently, maintain performance, and avoid runtime errors, particularly important when dealing with large datasets or high iteration computation, such as in competitive programming or real-world applications .

Challenges in programming for high precision in financial calculations include handling floating-point arithmetic accurately, as small errors can accumulate and lead to significant discrepancies. Representing decimal numbers accurately in a binary system can lead to rounding errors, impacting precision, especially in tasks like determining cashback limits that involve percentage calculations. Ensuring outputs meet specified precision levels, such as rounding to two decimal places, requires careful handling of data types and arithmetic operations to avoid inaccuracies and ensure financial calculations remain valid and reliable .

When choosing between flowchart and pseudo-code for algorithm representation in educational settings, several factors should be considered. The learning style of students may influence preference, with visual learners benefitting from flowcharts due to their graphical nature, while those who prefer textual format might find pseudo-code more accessible. The complexity of the algorithm is another factor; simpler algorithms may be more effectively displayed in flowcharts, whereas pseudo-code handles complex logic better. Finally, the goal of the exercise matters—if the focus is on understanding logic flow, flowcharts are beneficial, while pseudo-code is more advantageous for strengthening coding skills .

Designing an algorithm is considered more crucial than writing source code because it represents the core solution to a problem. Without a clear algorithm, it is impossible to implement effective source code. During algorithm design, problem-solving strategies are outlined, allowing the programmer to understand the problem deeply and devise a feasible approach to solving it. Implementing source code is then a translation of this well-thought-out plan. Without designing an algorithm, one might not know how to instruct the computer effectively to achieve the desired outcome .

You might also like