0% found this document useful (0 votes)
30 views

Computer Science Practice Assignement

This document contains 10 practice exercises for an introduction to computer science class. The exercises cover topics like calculating boiling time of water, flight time between cities, minimum air conditioner capacity for a room, the Pythagorean theorem, surface area and cost of wooden boxes, converting time between seconds and hours/minutes, calculating inflation rate using the consumer price index, reversing 3-digit numbers, and calculating theater profit based on ticket prices and reserved seats. Students are instructed to discuss some exercises in class, solve others in lab, and discuss the remaining in tutorials.

Uploaded by

Chantal Ramez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Computer Science Practice Assignement

This document contains 10 practice exercises for an introduction to computer science class. The exercises cover topics like calculating boiling time of water, flight time between cities, minimum air conditioner capacity for a room, the Pythagorean theorem, surface area and cost of wooden boxes, converting time between seconds and hours/minutes, calculating inflation rate using the consumer price index, reversing 3-digit numbers, and calculating theater profit based on ticket prices and reserved seats. Students are instructed to discuss some exercises in class, solve others in lab, and discuss the remaining in tutorials.

Uploaded by

Chantal Ramez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

German University in Cairo

Faculty of Media Engineering and Technology


Prof. Dr. Slim Abdennadher
Dr. Nada Sharaf
Dr. Mohammed Abd El Megeed

Introduction to Computer Science, Winter Semester 2020


Class Practice Assignment 2
Discussion: 31.10.2020 - 5.11.2020

Exercise 2-1
To be discussed in tutorial
Beside each code fragment in the table below, write what is printed when the code fragment is
executed. If the code would cause an error, write ERROR and give a brief explanation.

Code Output or Cause of Error


x = 22
y = 33
x = y
y = x
print(x,y)
s = "two"
v = int(s)
print(v)
x = "1" + 2
print(x)
What is the output of the following code?
x = float(10/4)
print(x)
Consider the two assignment statements
a = 1/2
b = 1.0/2
c = 1.0//2
What are the values in the variables
a,b and c?

Exercise 2-2 Cook in a hurry


To be discussed in tutorial
You want to cook some pasta, but you are short of time. To be sure you can finish cooking before
your next appointment, you need to know how long it takes for the water to boil. At its highest
setting, your stove needs two minutes per liter to reach the boiling point. You use a cylindric pot.
Write a program that, given the diameter of the pot and the hight of the water in it, calculates
the the time needed for the water to boil.

Exercise 2-3 Flight Time


To be solved in lab
Write an algorithm to determine the flying time between two cities given the mileage between them
and the average speed of the airplane.

Exercise 2-4 Air conditioning


You shop for air conditioners. The capacity of the models you find is given in cubic meters per
3
m
minute i. e., min . You know the height, length, and width of your room. Further, you want to
make sure, that your room gets cool within no more than 10 minutes. Write an algorithm that
m3
calculates the minimum capacity of an air conditioner i.e., min . for your room.

Exercise 2-5 Pythagorean Theorem


To be solved in Lab
The Pythagorean Theorem states that the sum of the squares of the two sides of a right angle
triangle is equal to the square of its hypotenuse. For example, 3, 4 and 5 are the sides of a right
angle triangle as they form a Pythagorean Triple (52 = 42 + 32 ). Given 2 numbers, m and n where
m ≥ n, a Pythagorean Triple can be generated by the following formulae:

a = m2 − n2
b = 2×m×n
p
c = a 2 + b2

Write an algorithm that reads in values for m and n and prints the values of the Pythagorean
Triple generated by the formulae above.

Exercise 2-6 Wooden Boxes


To be discussed in tutorial
A factory manufactures wooden boxes (a box is a cuboid with six faces). The price of the wood
is 10LE/m2 . Write an algorithm that, given the three dimensions of the box in meters, calculates
and prints the total surface area of the box and the price of the wood needed.

Exercise 2-7 Get the Time


To be solved in Lab
Write an algorithm that reads the amount of time in seconds and then displays the equivalent
hours, minutes and remaining seconds.

• One hour corresponds to 60 minutes.


• One minute corresponds to 60 seconds.

Exercise 2-8 Consumer Price Index


The formula for calculating the Inflation Rate using the Consumer Price Index (CPI) is relatively
simple. Assume for the sake of simplicity that the index consists of one item and that in 1984 that
item cost 100 dollars. In December of 2014 that same item would probably cost 198 dollars. Let
us calculate the price difference between 1984 and 2014.

• Step 1: Calculate How Much has the Consumer Price Index Increased?
By looking at the above example, common sense would tell us that the index increased (it
went from 100 to 198). The question is how much has it increased? To calculate the change
we would take the second number (198) and subtract the first number (100). The result
would be 98. So we know that from 1984 until 2014 prices increased (Inflated) by 98 points
• Step 2: Comparing the CPI Change to the Original CPI
Since we know the increase in the Consumer Price Index we still need to compare it to
something, so we compare it to the price it started at (100).We do that by dividing the
increase by the first price or 98/100. the result is (.98).
• Step 3: Convert it to a Percentage
This number is still not very useful so we convert it into a percentage. To do that we multiply
by 100. So the result is a 98 increase in prices since 1984.

Write an algorithm that given two prices of the same item in two different years computes the CPI.
The algorithm should display the following for the example above

The price of the item in year 1984 is 100


The price of the item in year 2014 is 198
The CPI is 98%

Exercise 2-9 Reverse Digits


To be solved in lab
Write an algorithm that given a 3-digit number prints out the number in reversed order.
Example: if the number is 425 then the output should be 524.

Exercise 2-10 Theater


To be discussed in tutorial
A theater owner would like to calculate his daily profit. The theater has three classes of tickets;
the price of the first class tickets is 150 LE, second class is 100 LE, and third class is 75 LE. The
profit is 20ticket price. The owner loses 70 LE. for each unreserved seat in the theater. Write an
algorithm that given the total seats in the theater and the reserved seats out of each class calculates
the total profit, total loss, and the difference between them.
Running example: For the following input

Total Number of seats: 300


First class tickets sold: 70
Second class tickets sold: 75
Third class tickets sold: 90

the algorithm should output

Total profit: 4950


Total loss: 4550
Difference: 400

You might also like