Download Yeditepe University Department of Computer Engineering ES 112

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Approximations of π wikipedia , lookup

Location arithmetic wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Yeditepe University
Department of Computer Engineering
ES 112 Algorithms and Computer Programming (Spring 2017)
Assignment 1
Due to: 27.02.2017, class hour. (11:00 for sec 3-4; 14:00 for sec 1-2; 16:00 for sec 5-6-7)
1) (30p) Ticket price of an open-air entertainment park is 100TL. However depending on the
day of the week and the weather conditions following discounts are possible:
− 10% discount in the weekdays (Monday to Friday)
− Extra 20% discount if the weather is rainy.
Therefore, there are 4 possibilities:
Rainy
30% discount
Monday to Friday
Saturday & Sunday 20% discount
Shiny
10% discount
no discount
Write the pseuducode of the program to calculate the ticket price. Your program should do the
following:
1. Read the weather condition as a character value: „R‟ for Rainy, „S‟ for Shiny,
2. Read the day of the week as an integer value: 1 for Monday, 2 for Tuesday, ... 7 for
Sunday
3. Calculate the ticket price.
4. Print the discount rate and the ticket price.
Example:
Input:
Enter weather condition? R
Enter day? 2
Output:
Discount rate is: 30% Ticket price is: 70 TL
2) (50p) Draw the flowchart of the program that will print a square of n numbers. The input for the
program will be “n”. You should print a sequence of numbers in each line that will look like a square.
If the number is smaller than 2 or larger than 40 it will not print anything.
Example: If n is 4, the function will print the following:
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
As you can see it consists of 4 rows and 4 columns.
3) (20p) Write a C program which does the following: Read the radius (int) of a circle and calculate
its area (double). You can assume that the user will always enter a positive integer for the radius. Take
π as 3.14 for the calculation (you should use a constant macro for π – name it as PI). Display the area
to the user.
Then, read the area (double) of another circle from the user. This time, find and display the radius of
this circle to the user (as in the example output).
Example:
Enter the radius: 4
The area of the circle is 50.24
Now enter the area of another circle: 20.48
The radius of this circle is equal to the square root of 6.52.
Submission information:
Submit your work on paper during the class hour.