$29
Hand in: A student with number 20180000001 should hand in a file named 20180000001.c for this homework.
Part 1. [50pts] Write a complete program implementing a simple calculator program. The calculator should have the usual binary operators: addition (+), substraction (-), multiplication (*), division (/), power (**) and modulo (%). The users of the program enter the operation they want to carry out in prefix notation.For example, the following input
+ 10 2
adds 10 and 2 returning 12. If the operator has only one argument, it takes the result of the previous operation as the first argument. If there is no previous operation (e.g., at the very beginning), 0 will be used.
An example run of the program follows:
10 2
12
** 8 2 64 / 2 32 * 10 320 % 10 0
10
10 - 8 2
You are additionally asked to define and use a function called doit. This function accepts three arguments: a function to represent the desired operator and two integer inputs. You are not allowed to apply the operator directly. This will require you to define at least 7 functions in your code and also menu function . Example use of doit function is given below:
int add(number1, number2);
int sub(number1, number2);
...
doit (add, first_number, second number);
doit (sub, first_number, second_number);
Part 2. [30pts] Write a program that takes three arrays. The size of the first array should be 10 and it has to include homework grades. The size of the second array should be 10 and it has to include lab grades. The size of the third array should be 2 and it represents midterm and final grades. The grades will be taken from the user and will be assigned to the each cell of the arrays. Firstly you should calculate the average of the lab and homework grades, seperately. Then you should calculate the weighted average all of grades. To calculate the weighted average, you should take 10% of the average homework grade, 20%of the average lab grade, 30% of the midterm grade and %40 of the final grade. You should use these functions;
Page 1 of 3
int take_grades(int [] );
int take_exam_grades(int[]);
double calculate_homework(int[]);
double calculate_lab(int[]);
double calculate_all(int ,int[],int);
Part 3. [20pts] In this part , you should take height of the shape from user. For example user enters the height number x, will press * character twice. Then should add 4 times and 6 times until the number of * will be (x-1)2. A triangle must be created from the combination of stars, triangle should be surrounded by the shape of / , \characters. After the first triangle formed by expanding towards the bottom, the second triangle should be narrowing towards the bottom. Shapes must be look like that;
Output Example:
Input=3
Input=4
Input=5
Input=6
Input=7
Input=8
Page 2 of 3
General Rules:
Obey and don’t broke the function prototypes that are shown on each part, otherwise, you will get zero from the related part.
The program must be developed on Linux based OS and must be compiled with gcc compiler, any problem which rises due to using another OS or compiler won’t be tolerated.
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.
Upload your .zip file on to Moodle to deliver your homework. The zip file must
consist of one .c file that contains the code of your solutions. Name format can be found on the top of this homework sheet.
You can ask any question about the homework by sending an email to ferdaabbasoglu@gtu.edu.tr.
Page 3 of 3