Odd ICP Terminal Exam V2

You might also like

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

ELECTRICAL & COMPUTER ENGINEERING DEPT.

COMSATS UI, Islamabad


Introduction to Computer Programming (CSC 141)
Terminal Exam (SP2020) (2)
Max Marks: 50 Date: August 19th, 2020
Instructor: Dr. Shaista Jabeen Section: BEE- 2D
Time: 3h & 30 minutes

Instructions:
• Read the questions carefully and try to attempt/answer to the point.
• To understand the questions is the part of exam, read multiple times if required.
• Honesty is of prime importance; no credit will be given to the copied material.
• Marks distribution as : 10+10+30 = viva + objectives + subjective

Q1. Write a C function named calculations( ) that computes the mean and standard deviation of
the sample data given below using arrays. The function is called through the main( ) which finally
prints the result i.e. mean and standard deviation.
−6, −12, 2 , 9 , 10 , 11 , 8 ,13, 11, 6, 7, 2, −6, −9, −10
Hints:
∑(𝑥𝑖 − 𝜇)2
𝑠𝑡𝑑 𝑑𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛 = √
𝑛

Where 𝜇 𝑖𝑠 𝑡ℎ𝑒 𝑚𝑒𝑎𝑛 𝑜𝑓 𝑑𝑎𝑡𝑎 𝑠𝑎𝑚𝑝𝑙𝑒.


Program Format:
int main ( )
{ int sample_data………………
…………
calculations ( );……………….. // Function Call
printf(“the mean and standard deviation of data is %d and %d \n……)
return 0;
}
Q2. Write a C program that takes 10 (cartesian coordinate)points in a 2D array. It then computes
the distance of last point from the first point (sum of distances between consecutive points). The
distance is computed using a function named as func_distance( ) and it returns the distance to
main. The main function prints the result.
Hint: Cartesian Coordinate Points are usually as given in the figure below. (Take P1 – P10 as 2D array)
Q3.Create a structure to specify the data on address as given below:
• HouseNumber
• Street
• City
• Country
• Postalcode

a) Initialize a structure variable struct address ad* in main function. (by any means you want)
b) Write a C code that writes the above structure data to a file on your PC hard disk.(using file
handling)
c) Then write a code to read the data that was written to the file in part (b) above.

Q4. Write a C program that passes the string (taken from user) as an argument to the function
reverse_str( ) and reverses the string characters. The function returns the number of characters
that have been reversed and the length of the string.
Hint: No built-in function like strrev( ) should be used, but you can only use strlen( ) function.

GOOD LUCK

You might also like