Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

MIDTERM EXAMINATION

Code: 04
Course Code: INS 2020 – Semester II 2023/2024 Lecturer’s Signature
Course Title: Programming 1
Time allowed: 60 mins. Closed-book exam.
Full name: Marks
Student ID:
Code number: . Class:

Question 1. (25 points)


Write a program to calculate the aproximation of cos(2x) as the below expression:
(2𝑥)2 (2𝑥)4 (−1)𝑛
cos(2𝑥) = 1 − + + (2𝑥)2𝑛
2! 4! (2𝑛)!
Question 2. (25 points)
Write a C function to count the number of vowels and consonants in a given string. The function
should accept a string as a parameter and return the count of vowels and consonants.
For example: Input string: "Hello World" Output: Vowels: 3, Consonants: 7

Question 3. (50 points)


Assume that you are developing a program to manage Magazine information in a store. The
information of a book is described as a struct as following:
struct Magazine{
char Magazine_id[8];
char Magazine_title[50];
char year[4];
int quantity;};
- The Magazine_id is the ID of books such as: “BKJ00001”, “BKA00003”
- The Magazine_title is the tittle of books such as: “Journey to the East”, “A brief history of
time”
- The year is the published year such as: 1894, 1998
- The last attribute is the quantity of products such as: 20, 24

1
The program that has the interface as follows: (10 points)
Please choose:
1. Enter Magazine’s information.
2. Print/show information of all Magazines
3. Search products by ID
0. Exit
When the user chooses:
1. Allow the user to enter N Magazines. The N Magazines will be store in an array. The ID
of the Magazine (Magazine_id atrribute) should be distinct. (10 points)
2. Display all Magazines in the array out. (10 points)
3. Allow to search for a Magazine by a given ID (Magazine _id) from the user. (15 points)
0. The program will quit and release all the resources. (5 points)
Note: The program is written in functions

You might also like