Midterm Code 03

You might also like

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

MIDTERM EXAMINATION

Code: 03
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 sin(2x) as the below expression: (2
points)
(2𝑥)3 (2𝑥)5 (−1)𝑛
sin(2𝑥) = 2𝑥 − + + (2𝑥)2𝑛+1
3! 5! ( )
2𝑛 + 1 !
Question 2. (25 points)
Develop a C function that accepts an array of letter and reverses it. After reversing, the
function should print the array.
For example: Input array: ['C', 'k', 'd', 'i', 'p', 'g'] Output: gpidkC

Question 3. (50 points)


Assume that you are developing a program to manage laptops in a store. The information
of a laptop is described as a struct as following:
struct laptop {
char laptop_name[20];
char laptop _code[6];
char category[10];
float price;};
- The laptop _name is the name of laptops such as: “Lenovo thinkpad T60”, “HP
Probook 14”
- The laptop _code is the code of laptops such as: “LV6001”, “HP1402”

1
- The category is to classify the laptops with countries such as: “China”, “America”
- The last attribute is the price of laptops such as: 800.0, 600.0
The program that has the interface as follows: (5 points)
Please choose:
1. Enter laptop’s information.
2. Print/show information of all laptops
3. Search laptops by code.
0. Exit
When the user chooses:
1. Allow the user to enter N laptops. The N laptops will be store in an array. The
code of the laptop (laptop_code atrribute) should be distinct. (10 points)
2. Display all laptops in the array out. (10 points)
3. Allow to search for a laptop by a given code (laptop_code) from the user. (15
points)
0. The program will quit and release all the resources. (5 points)

You might also like