CSE102 – Computer Programming Solved

$ 20.99
Category:

Description

Homework #2
Hand in: A student with number 20180000001 should hand in a file named 20180000001_partx.c for each part of this homework and compress it into a .zip file which is named 20180000001.

Part 1. [30pts]

Write a complete program describing all the tasks below. In the main () function, the 3 integer values requested from the user will represent the lengths of the sides of a triangle, and the 4 functions specified below will be called from the main ( ) function, ensuring that all tasks are performed completely.

• Determining whether the triangle can be drawn according to the triangle inequality theorem.
o If the triangle cannot be drawn;
– “According to the triangle inequality theorem, this triangle cannot be drawn. ” message should be printed on the screen and the process should end.

o If the triangle can be drawn;
– “According to the triangle inequality theorem, this triangle can be drawn.” message should be printed on the screen
– the type of triangle should be determined
– the perimeter of the triangle should be calculated – the area of the triangle should be calculated

1. Write a function that determines whether the triangle can be drawn according to the triangle inequality theorem and returns 1 if it can be plotted and 0 if it cannot be drawn.

“The Triangle Inequality Theorem states that the sum of any 2 sides of a triangle must be greater than the measure of the third side.”

Function prototype is int draw_triangle(int side1,int side2, int side3)

2. Write a function that determines the type of the triangle (equilateral, isosceles or scalene) and prints on the screen, without returning value.
Function prototype is void type_triangle(int side1,int side2, int side3)

3. Write a function that calculates the perimeter of the triangle and returns this value.
Function prototype is int perimeter_triangle(int side1,int side2, int side3)

4. Write a function that calculates the area of the triangle according to the formula below and returns this value.

Function prototype is double area_triangle(int side1,int side2, int side3,int perimeter)

Tip: When calculating the area of the triangle, take root by using the sqrt () function of the math library. You can find detailed information about using this function here.

Part 2. [50pts]

In the main ( ) function, ask the user to enter a maximum of 6 digits and consider this number written 100 times next to each other. Write a complete program that tries to find the number in an index to be determined by the user in this large series of numbers.

Please note that the integer array and loops will not be used in the question.

You are expected to use 2 functions except the main function while performing the desired operations in the question.
1. A function that finds the length of the number entered by the user on the command screen and returns the integer value expressing the length should be defined.
Function prototype is int number_length(int number)
Hint : You can use the logarithm to find out how many digits the number is. You can access log functions and their uses in the math library for logarithm operation from here.
2. According to the index value entered by the user on the command screen, define a function that finds the number in the specified index and returns that integer value.
Function prototype is int find_digit(int number, int index)

Part 3. [20pts]

Write a currency converter program in the Main () function. You do not have to define functions for this part.

Exchange rate information will be accepted as follows.
1 Euro = 6.69 Turkish Lira
1 Dollar = 6.14 Turkish Lira

As you can see the screen output below, the user must first be greeted with the message “***** Welcome to ABC Exchange Office *****”.

Then the user should be asked to write the amount of money he/she has on the command screen. The menu in the screenshot below should be created in order to select the currency that the user has.

By using the ‘switch case’ structure according to the user’s choice;

For example, if the user chose 1, ‘You have xxx Turkish Liras’ message should be printed on the screen.

Then, the user should be asked to choose the rate he / she wants to convert according to the menu above.

Currency exchange calculations should be completed depending on the user’s choice again.

Please note that when the user makes a wrong choice (for example, if he makes a choice of 5), ‘Your selection is invalid.’ message should be printed.

General Rules:

1. Obey and don’t broke the function prototypes that are shown on each part, otherwise, you will get zero from the related part.
3. Note that if any part of your program is not working as expected, then you can get zero from the related part, even it’s working in some way.
4. Upload your .zip file on to Moodle to deliver your homework. The zip file must consist of one .c file that contains your solutions. Name format can be found on the top of this homework sheet.
5. You can ask any question about the homework by sending an email to bbuluz@gtu.edu.tr .

Reviews

There are no reviews yet.

Be the first to review “CSE102 – Computer Programming Solved”

Your email address will not be published. Required fields are marked *