0% found this document useful (0 votes)
148 views6 pages

SENG 102 Midterm Exam Overview

Here is a C program that reads a customer database file, creates two output files based on the criteria specified in the question: #include <stdio.h> #include <string.h> struct customer { char first_name[20]; char last_name[20]; char birthday[20]; float amount_owed; }; int main() { FILE *cust_file, *owes_file, *bdays_file; cust_file = fopen("CustDB.txt", "r"); owes_file = fopen("Owes.txt", "w"); bdays_file = fopen("Bdays.txt",

Uploaded by

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

SENG 102 Midterm Exam Overview

Here is a C program that reads a customer database file, creates two output files based on the criteria specified in the question: #include <stdio.h> #include <string.h> struct customer { char first_name[20]; char last_name[20]; char birthday[20]; float amount_owed; }; int main() { FILE *cust_file, *owes_file, *bdays_file; cust_file = fopen("CustDB.txt", "r"); owes_file = fopen("Owes.txt", "w"); bdays_file = fopen("Bdays.txt",

Uploaded by

cixefit398
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Faculty of Engineering

Department of Software Engineering

SENG 102 Object Oriented Programming

MIDTERM EXAM

Asst. Prof. Dr. Sadık Eşmelioğlu


2021-2022 Spring Semester
22.03.2022 - 11:00
Student’s Information
Name and Surname:

Student ID: Signature:

Instructions:
• Read the questions carefully and repeatedly. Writing with clarity will make it possible to assess
your answers correctly.
• Any form of cheating, intention of cheating, or disruption of the exam will subject you to a
disciplinary action as specified by the university’s regulations.

Before starting, DO:


1. Put your student ID on your desk and clear your desk
2. Turn off your mobile phone and put on your desk
3. Put your name, student number, and signature in the space provided above
4. Read each question carefully
5. Make sure all the pages are there

During the exam, DO NOT:


1. Ask any questions about the exam questions. If you think something is wrong or missing, write your
opinion on your paper.
2. Pass anything (Paper, Pen, Eraser, etc.) to your friends.
3. Look at anybody’s paper and allow anybody to look at your paper.
4. Use any scrap paper
5. Leave the classroom within the first 20 minutes #of Max
PO Score
Q. Marks
Exam Room: YA2 1 PO1, P02, PO3 10
Duration: 90 min 2 PO1, P02, PO3 5
Total pages
6 3 PO1, P02, PO3 25
(inc. cover page):
Total points: 100 4 PO1, P02, PO3 10
5 PO1, P02, PO3 15
6 PO1, P02, PO3 15
7 PO1, P02, PO3 20
Total
SENG 102 Midterm Spring 2021 - 22

10 1. What will each of the printf statement display? Put your answers in the table provided.

#include <stdio.h> Output


int main(void)
{
int x[] = {10, 20, 30}; //Starting Address:1000 No Output
char y[6] = "John"; //Starting Address:2000
int *xp = x; //Starting Address:3000 1
char *yp = y; //Starting Address:4000 2

printf("%d\n", x); // 1. Line 3


printf("%d\n", y); // 2. Line 4
printf("%d\n", xp); // 3. Line
printf("%d\n", yp); // 4. Line 5
printf("%d\n", *(xp + 2)); // 5. Line 6
printf("%d\n", *xp + 2); // 6. Line
printf("%d\n", *xp); // 7. Line 7
printf("%d\n", yp + 2); // 8. Line 8
printf("%d\n", &yp + 2); // 9. Line
printf("%d\n", (x + 1)); //10. Line 9
return(0); 10
}

5 2. What will each of the printf statement display? Put your answers in the table provided.

#include <stdio.h> Output

struct x {
int a; No Output
int b;
}; 1
2
int main(void)
{ 3
struct x y = { 11, 22 }; //Starting Address:1000 4

printf("%d\n", &y); // 1. Line 5


printf("%d\n", y.a); // 2. Line
printf("%d\n", &y.a); // 3. Line
printf("%d\n", y.b); // 4. Line
printf("%d\n", &y.b); // 5. Line
return(0);
}

Page 2 of 6
SENG 102 Midterm Spring 2021 - 22
3. Write a complete C program that will ask the user to enter a string, then will print the
25 upper case, lower case, and all other characters as shown in the example.
a. main function: gets string from user, calls brkup function (call by reference), and
prints the results onto the screen.
b. brkup function: Breaks the string into three other strings (upper case, lower case,
and other). You need to use isupper and islower functions which are in the ctype.h
library).

Please enter a string:


AAss''../,,adf;AbCC
Upper case letters are: AAACC EXAMPLE
Lower case letters are: ssadfb
Other characters are : ''../,,;

Page 3 of 6
SENG 102 Midterm Spring 2021 - 22
4. What will each of the printf statement display? Put your answers in the table provided.
10
#include <stdio.h> Output
#include <string.h>
#define N 40
No Output
int main(void) {
char s1[N] = "Hello"; 1
char s2[N] = "My name"; 2
char s3[N], s4[N];
3
printf("%d\n", strlen(s2)); //Line 1
strcpy(s3, s1); 4
printf("%s\n", s3); //Line 2 5
strncpy(s4, s1, 4);
s4[4] = '\0';
printf("%s\n", s4); //Line 3
strcat(s1, ", ");
strcat(s1, s2);
printf("%s\n", s1); //Line 4
strcat(s1, " is Can");
printf("%s\n", s1); //Line 5

return(0);
}

5. Write a complete C program that will ask the user to enter three names, then prints them in
15 ascending alphabetical order.
Please enter three names:
EXAMPLE Caner Can Ahmet
Ordered names are:
Ahmet Can Caner

Page 4 of 6
SENG 102 Midterm Spring 2021 - 22
6. Given the C program below, fill in the empty lines in boxes, appropriate to the comments
15 and the example shown below.

Enter name, no, area 1: Susan 12 135.23


Enter name, no, area 1: John 15 138.44
Greater apartment: EXAMPLE
John(No:15, area=138.44 m2)

#include <stdio.h>
/* struct definition */
struct apt {
char name[20];
int no;
double area;
};

/* function prototype */
void greater(struct apt a1, struct apt a2, struct apt *a);
/* main function */
int main() {
struct apt apt1, apt2, grt;

printf("Enter name, no, area 1: ");


scanf("%s%d%lf", [Link], &[Link], &[Link]);

printf("Enter name, no, area 1: ");


scanf("%s%d%lf", [Link], &[Link], &[Link]);

greater(apt1, apt2, &grt );

printf("Greater apartment:\n");
printf("%s(No:%d, area=%.2f m2)\n", [Link], [Link], [Link]);
return(0);
}
// returns struct with greater area using call by reference.
void greater(struct apt a1, struct apt a2, struct apt *a) {

if ([Link] > [Link]) *a = a1;


else *a = a2;
}

Page 5 of 6
SENG 102 Midterm Spring 2021 - 22
7. Write a complete C program (using structures) that will read [Link] file which contains
on each line, first name, last name, birthday, and money owed. After reading each customer
20 information, it will create a file called [Link] for customers who owe any money (>0),
and it will create another file called [Link] for customers who have birthdays in April.
Example files are shown below:
[Link]
[Link]
Hasan Topcuoglu 150.25
Ayse Cantez 12.12.1975 0 Canan Hepten 252.75
Hasan Topcuoglu 31.04.1955 150.25
Caner Hepten 22.04.1993 0 [Link]
Canan Hepten 17.08.1963 252.75
Hasan Topcuoglu
Caner Hepten

Page 6 of 6

You might also like