• No results found

CSIS 202: Introduction to Computer Science Spring term Midterm Exam

N/A
N/A
Protected

Academic year: 2021

Share "CSIS 202: Introduction to Computer Science Spring term Midterm Exam"

Copied!
10
0
0

Loading.... (view fulltext now)

Full text

(1)

German University in Cairo April 7, 2016 Media Engineering and Technology

Prof. Dr. Slim Abdennadher Dr. Hisham Othman

CSIS 202: Introduction to Computer Science

Spring term 2015-2016

Midterm Exam

Bar Code

Instructions: Read carefully before proceeding. 1) Duration of the exam: 2 hours (120 minutes). 2) No books or other aids are permitted for this test.

3) This exam booklet contains 9 pages, including this one. Three extra sheets of scratch paper are attached and have to be kept attached. Note that if one or more pages are missing, you will lose their points. Thus, you must check that your exam booklet is complete.

4) Write your solutions in the space provided. If you need more space, write on the back of the sheet containing the problem or on the three extra sheets and make an arrow indicating that. Scratch sheets will not be graded unless an arrow on the problem page indicates that the solution extends to the scratch sheets. 5) When you are told that time is up, stop working on the test.

Good Luck!

Don’t write anything below;-)

Exercise 1 2 3 4 5 P

Possible Marks 10 8 8 10 10 46 Final Marks

(2)

Exercise 1 Tracing (2+2+2+4= 10 Marks) a) What does the following program display. Show your workout:

• print(2 + 3 * 6) Solution: 3*6 = 18 2+18 = 20 • print(2 == 3 or not (1 > 4)) Solution: 2 == 3 True not (1 > 4) True True or True = True

• print((2 % 10) * 6) Solution:

2 % 10 = 2 2*6 = 12

b) Given the following algorithm x = eval(input()) y = eval(input())

print(x%10 == y//100 and y%10 == x//100 and (x//10)%10 == (y//10)%10)

1. What is the output of the algorithm above forx = 143andy = 341? Solution:

True

2. What does the algorithm do for any two integers consisting of three digits? Express it with one single English statement.

Solution:

(3)

Exercise 2 Sequential Algorithms (8 Marks) Write a Python program that given a number of days displays the equivalent number of weeks and remaining days. For example, if the user enters18, the program should display the following:

Number of weeks is 2 Number of extra days is 4

Solution:

days = eval(input()) weeks = days // 7

remainingDays = days % 7

print("Number of weeks", weeks)

(4)

Exercise 3 Sequential Algorithms (8 Marks) Managing inventory levels is important for most businesses and this is especially true for retailers and any com-pany that sells physical goods. The inventory turnover ratio is a key measure for evaluating just how efficient management is at managing company inventory and generating sales from it.

Like a typical turnover ratio, inventory turnover details how much inventory is sold over a period of time. It is calculated as:

Inventory Turnover = Cost of Goods Sold / Average Inventory

Where the average inventory corresponds to a adding the beginning inventory and ending Inventory and dividing the result by 2.

For example, assume a company has cost of goods sold totaling150 000with beginning inventory of75 000 and ending inventory of12 000. your program should display:

Inventory turnover rate is 3.4482

Solution:

cost = eval(input()) begInv = eval(input()) endInv = eval(input())

averageInv = (begInv + endInv)/2 invTurnOver = cost/averagInv

(5)

Exercise 4 Conditional Algorithms (10 Marks) In Germany, the pay regulation regulates the salaries of federal and state employees. The pay regulation W is applied for professors, lecturers and assistants.

The monthly basic salary for W-Professors is structured according to their pay grade: Pay Grade Monthly Basic Salary

1 4105 Euro

2 4681 Euro

3 5672 Euro

A family allowance could be added to the basic salary:

• 105 Euro for the first child

• 90 Euro for the second child

• 230 Euro for the third or more children

Write a Python program that given the pay grade and the number of children calculates the income which corre-sponds to basic salary plus family allowance. Make sure to display the corresponding message if the user enters a number out of range.

For example,

• If the user enters a pay grade 1 and number of children 0 then the program should output Your salary is 4105

• If the user enters a pay grade 2 and number of children 2 then the program should output Your salary is 4876

• If the user enters a pay grade 3 and number of children 7 then the program should output Your salary is 6097

Solution:

grade = eval(input()) children = eval(input()) if (grade > 3 or grade < 1):

print("Error! Input out of range!") else: if(grade == 1): basicSalary = 4105 elif (grade == 2): basicSalary = 4681 elif (grade == 3): basicSalary = 5672 if (children == 0):

print("Your salary is ", basicSalary) elif (children == 1):

print("Your salary is ", basicSalary + 105) elif (children == 2):

(6)

elif (children >= 3):

(7)

Exercise 5 Conditional Algorithms (10 Marks) The German income tax is a progressive tax, which means that the tax rate increases monotonically with increasing taxable income.

Your task is to write an algorithm that given your salary, calculates the income tax. Please note the following:

• A salary consists of a basic allowance which is 8354 Euro. No income tax is charged on the basic allowance.

• Therest of the salaryis a taxable income where the tax rate increases linearly: a) 20%for ataxable incomeuntil 13469 Euro.

b) In the subsequent interval up to a taxable income of 52881 Euro, the marginal tax rate increases to 42%.

c) The last change of rates occurs at a taxable income more than 52,881 Euro when the marginal tax rate to45%.

Write a Python program that given the salary computes the tax that should be paid. For example, if the salary is 50000 Euro, then the program should output:

The tax that you have to pay is 17491.32

Solution:

salary = eval(input())

restOfSalary = salary - 8354 if (salary <= 8354):

print("No income tax is charged") elif (restOfSalary <=13469):

print("The tax that you have to pa is", restOfSalary*0.2) elif (restOfSalary <=52881):

print("The tax that you have to pa is", restOfSalary*0.42) elif (restOfSalary > 52881):

(8)
(9)
(10)

References

Related documents

Franklin and Associates Ltd.’s study, Comparative Energy Evaluation of Plastic Products and Their Alternatives for the Building and Construction and Transportation Industries,

Other readings (not required): Pearson, Neil D., 2002, Risk Budgeting: Portfolio Problem Solving With Value-at-Risk (New York: John Wiley &amp; Sons), Chapters 11, 12, and 13;

With the establishment of the Philippine Commonwealth in 1935, various reforms such as the Rice Share Tenancy Act (RA 1199) established the farmer’s rights to the land, and

• Speed of weaning: induction requires care, but is relatively quick; subsequent taper is slow • Monitoring: Urinary drug screen, pain behaviors, drug use and seeking,

However, in participants experiencing less financial strain, those living in neighbourhoods with a greater amount of change in the built environment experi- enced significantly

Thank you for participating in this study, titled “The effects o f situation awareness, event serial position, and the isolation effect on standardized patients’

Results revealed that the ability of student teachers as measured by the Ability to Use ICT in Researching, Preparing, and Assessing Teaching Materials (category A) and the Ability

Berdasarkan hasil wawancara dengan informan Koordinator Pengelola PKM- K dan mahasiswa penerima beasiswa Bidikmisi yang lolos seleksi PKM-K mengenai dana yang diberikan pada