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

Atılım University Computer Engineering Department

The document is a midterm exam for a Computer Programming course containing 5 questions. Question 1 has 10 multiple choice questions about C programming concepts. Question 2 has 5 expressions to evaluate. Question 3 asks to trace a C program and write the output. Question 4 asks to rewrite an if/else statement using a switch statement. Question 5 asks to write a C program that calculates salary increases for employees based on certain rules.

Uploaded by

Burak Baggins
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views

Atılım University Computer Engineering Department

The document is a midterm exam for a Computer Programming course containing 5 questions. Question 1 has 10 multiple choice questions about C programming concepts. Question 2 has 5 expressions to evaluate. Question 3 asks to trace a C program and write the output. Question 4 asks to rewrite an if/else statement using a switch statement. Question 5 asks to write a C program that calculates salary increases for employees based on certain rules.

Uploaded by

Burak Baggins
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Atılım University

Computer Engineering Department

Name and Surname:


CMPE 102 - Computer Programming
2017-2018, Fall ID Number:
Instructors: Bilge Say, Ekrem Çağlar Yılmaz, Fügen Selbes,
Meltem Eryılmaz, Serhat Peker Section:
Midterm Exam-1
Date: 26.10.2017 Signature:
Duration: 60 Minutes
Number of Pages: 5 pages

WARNINGS
 It is forbidden to bring electronic data storage equipments (e.g. mobile phone, MP3 player, flash disk etc.)
to exams.
 Students who either cheat, attempt to cheat or provide a help to other(s) in cheating, get 0 (zero) grade
from the entered examination. Also, based on the regulations, a disciplinary action will be taken.

Q1 Q2 Q3 Q4 Q5 Total
(50pts.) (15 pts.) (10 pts.) (10 pts.) (15 pts.) (100pts.)

1
Q1 (50 pts / 5 pts. each). Multiple-choice questions, mark all the answers to the first page.

1. Which standard library is included to use input/output functions?


a) stdlib.h √b) stdio.h c) math.h d) ctype.h

2. Which of the following is not a valid identifier?


a) MAAS √b) time&place c) avg_num d) xyz123

3. What type of punctuation marks are used to form and enclose compound statements?
√a) {} b) () c) [] d) /* */

4. Which of the following is a valid constant name?


a) void √b) MY_CONSTANT c) 3rdconstant d) sabit_değer

5. Which of the following is not a relational operator?


a) > b) <= √c) = d) !=

6. Which of the following logical expressions has the value false if a and b have been declared as
follows ?
int a=5, b=2;
a) (a >= b)&&(b != 0) b) (a % b)||(b == 0) √c) (b - 2 != 0) d) 1 || !0

7. Which of the following relational expressions in C represents


“num is greater than 10 or is less than -15”?
a) num != -15 b) num > 10 && num < -15 √c) (num > 10) || (num < -15)
d) -15<num<10

8. Which of the following is not a reserved word?


a) return √b) ent c) double d) void

9. The format identifier %d is used for _____ data type.


a) double b) float √c) int d) char

10. The format identifier %lf is used for _____ data type.
a) loaf b) int c) char √d) double

2
Q2 (3 pts. each). Evaluate each of the following expression. (4 marks for each correct answer. True or
false is acceptable in place of 1 and 0 respectively)

int a=12, b=52;


float c=4.5;

1) ! ((4+a) >= (b*5-a%2)) Answer: 1

2) a<b || c-2 Answer: 1

3) b%5-4 && !(c/3<3) Answer: 0


4) !(c!=a%5) || a-b==4 Answer: 0
5) c>=b%2 || b<62&&c Answer: 1

Q3 (10 pts). Trace the following C program and write down the output into the output area. (Hint: Each
character or digit should be written in a single cell).

#include <stdio.h>
Output:
#include <math.h>
#include <stdlib.h>
8 4
#define MAX 8.768
4 5 . 6 7 0
int main(void) 8 . 7 7
{ int m = 84; 3 . 0
char my_ch = 'a';; a
double p = 45.67;

printf("%-5d\n", m);
printf("%7.3f\n", p);
printf("%5.2f\n", MAX);
printf("%0.1f\n", sqrt(9));
printf("%5c\n", my_ch);

system("PAUSE");
return(0);
}

3
Q4 (10 pts.) Rewrite the following code segment using “switch” statement.

if(ch=='A' || ch=='a')
{
area=side*side;
printf("Area is %d", area);
}

else if(ch=='P' || ch=='p')


{
perimeter=4*side;
printf("Perimeter is %d", perimeter);
}

else
printf("Wrong input!");

switch (ch)
{
case 'A':
case 'a':
area=side*side;
printf("Area is %d", area);
break;
case 'P':
case 'p':
perimeter=4*side;
printf("Perimeter is %d", perimeter);
break;
default:
printf ("Wrong input!");
}

Q5 (15 pts). A company gives 5% salary increase to its workers whose salaries are less than 1500 TL, and
3% salary increase to the other workers. The workers who have been working in the company for at least 5
years get an extra 1.5% increase on their current salary regardless of the amount of their pay.
Write a complete C program for this problem using appropriate selection statements. Assume all salary-
related variables to be used are real numbers.

Sample Run:
Please enter current salary in TL: 1000.0
Please enter number of years worked: 6
The new salary with increase is calculated as 1065.00 TL

4
/* Variations of this solution are possible using different conditional
statements */

#include <stdio.h>
#include <stdlib.h>
int main (void)
{
double salary, /* input salary */
new_salary; /* output increased salary */
int num_years; /*num of years worked */

// Get the salary


printf ("Please enter current salary in TL: ");
scanf ("%lf", &salary);
// Get the years worked
printf ("Please enter number of years worked: ");
scanf ("%d", &num_years);

// test and raise salary acc to num of years worked


if (num_years >= 5)
new_salary = salary + salary*0.015;
else
new_salary = salary;
// test and raise acc to existing salary
if (salary < 1500)
new_salary = new_salary + salary*0.05;
else
new_salary = new_salary + salary*0.03;

// Display the raised salary


printf ("The new salary with increase is calculated as %0.2f
TL \n", new_salary);
system (“PAUSE”);
return(0);
}

You might also like