23 November 2010, 9:00 Am - 12 Noon: CS101 Computational Engineering Final Exam
23 November 2010, 9:00 Am - 12 Noon: CS101 Computational Engineering Final Exam
23 November 2010, 9:00 Am - 12 Noon: CS101 Computational Engineering Final Exam
Roll No:
Q11
Q12
Q13
Q14
Q15
Q16
Q17
Q18
Q19
Q20
Total
Write your answers in the space provided below each question (use the back of the page if necessary). Answer all questions. Maximum marks: 70 No cellphones! 0. What is one thing learnt in CS101 that will remain with your for the rest of your life? [1]
1. Listed below are a few popular style suggestions as well as characteristics of a well-written program. For each style suggestion identify one desirable characteristic which can result from implementing the suggestion (choose the best one). Use the codes eg. 5 (k). [2] Style Suggestion Desirable Characteristics 1. Indentation a. Legality 2. Meaningful Variable Names b. Understandability 3. Modular Programming c. Storage 4. Use of Data Structures d. Reusability e. Readability 2. Evaluate the following expressions (write your answers in the boxes provided) !(1 && !(0 || 1)) !( ( 1 || 0 ) && 0 ) !( 1 || 1 && 0 ) log(2.7183) (x=20/3+2%3) > 3
[5]
3. Fill in the blanks (a)The range of decimal integers that can be represented in an 8-bit computer in 2's complement notation is ______________
[5]
(b)A computer uses 7 bits to store floating point numbers. The first bit is employed for the sign of the number. The next 3 bits are used for the sign and magnitude of the exponent. The last 3 bits are used for the magnitude of the mantissa. The decimal number represented by 0111100 is ___________
Name:
Roll No:
(c)The smallest positive fractional number that can be represented in the computer described in (b) is ___________ (d)The binary form of the decimal fraction (7.8) 10 in scientific notation is ______________ (normalise with one binary digit to the left of the decimal point). (e) The technically correct term for mantissa in (b) above is 7. The following structure was developed to represent a book
struct book { page frontCover; page backCover; bind bindingType; page initial[10]; page mainPages[1000]; }; struct page { char pageText[1000]; int pageNumber; int fontType; }; struct bind /*1 -Soft bound, 2 Hard bound, 3 Cloth bound */ { int Type;}
The following are statements about the above representation. State if each is true or false (a)The number of characters allotted for the front is too much for an average front cover (b)The number of characters allotted for the back is too much for an average back cover (c)The book can contain only up to 1000 main pages (d)The font type for the whole book has to be the same (e)The same page number can be assigned to different pages (f) The front cover can be assigned a page number (g)The representation of type of binding is practical (h)Each character in the book can be allotted a different font.
[4]
4. A student passes if her attendance is greater than 50% and her total marks are at least 40. In addition, she must get at least 30 in the final exam. However, if her attendance exceeds 75%, she can get 25 in the final exam and still pass. Write a single Boolean expression that is true if and only if the student passes. [2]
5. It is desired to pass an integer array A[] as an argument to a function F(). (a) Write the C function prototype for F() to achieve this:
[3]
(c) Write the statement in F() to add x to the ith element of the array.
Name:
6. What is printed by the code below? Explain your answer in not more than two sentences. int *p; p = 200; p++; printf("The value of p is %u\n", ++p);
7. What will be the values in the 2D array data just before the return statement in the following program? [3] #include <stdio.h> int main(void) { int *p, i, j; int data[3][6] = {{1,2,3,4,5,6}, {2,4,6,8,10,12}, {3,6,9,12,15,18} }; for(i=0; i<3; i++) { p = *(data+i); for(j=0; j<3; j++) { p[j]++; p++; } } return 0; }
8. Given the date of birth dob of a person and the current date current, write a function findAge() that will return the age of the person as of current date. For a person born on 2nd October 1869, the age on 2nd October 1870 will be 1 and will remain 1 till 1st October 1871. The age must be in years and the function must return an integer value only. Assume that all the members have valid values and current date is later than dob. [3] struct date { int day; int month; int year; }; int findAge(struct date dob, struct date current) {
Name:
Roll No:
9. The following function finds and prints all the prime numbers that are less than or equal to N. There are some mistakes in the program: incorrect datatypes, incorrect mixing of operations etc. Make the smallest number of changes to the function to make it work correctly. [5] void primes(int N) { int i,j; int flag; float k; for(i=2;i<=N;i+=1.0) { flag = 0; for(j=2; j<=N-1;j++) { k = j; if(i%k == 0) flag=1; } if(!flag) printf(%d is prime\n,i); } }
10. What is the output of the following program? int main(void) { int a=4, b=3, c=1, d=1; while(d > 0) { int a,b,i; a = c + d; b = c - d; for(i=0; i<a; i++){ int a = i*i; b += a; } printf("%d %d ",a,b); d--; } printf("%d %d ",c,d); }
[3]
Name:
Roll No:
11. The C function below is expected to return a string containing the character ch repeated n times. Eg, GenString('a', 5) returns aaaaa and GenString('b', 0) returns . Fill in the blanks. [3] char *GenString(char ch, int n) {
for (
} 12. One of the methods suggested for finding the approximate value of an integral is to count the number of squares that fall below the function f(x) and between the limits lo and hi. Draw a graph showing a typical function with the limits. Draw a neat flow chart to illustrate the logic of this method to compute the approximate integral of f(x) between the limits lo and hi. [5]
Name:
Roll No:
13. Write a complete C program that takes two positive integers n and m and the name of a file filename as command-line arguments and prints the multiplication table from n x 1 to n x m into the file. Given the command: ./a.out 3 4 three.tab the file three.tab must have the multiplication table in the following format [5] 3x1=3 3x2=6 3x3=9 3 x 4 = 12
14. (a) Arrange the following in ascending order of rate of convergence i. Newton Raphsons Method ii. Bisection Method iii. Regula Falsi Method.
[3]
(b) In the Bisection method, the minimum number of iterations required to get an accuracy of (>0) with given initial interval a, b is ______________________________. (c) The binary value of 4210 is _________________________________.
15. The linear interpolation formula for (xi, yi), i = 1, 2, , n is ______________________ _____________________________________________________________. 16. Write pseudo-code for the regula-falsi method. [2] [3]
17. Perform 3 iterations of the Newton-Raphson Method to find a root of the equation x ex 1 = 0, which is close to 0.5 (do all calculations to 2 decimal places) [3]
18. Given n data points (xi, yi), i = 1, 2, , n, derive te formula for te linear least square fit. [4]
19. Using the Lagrange interpolation formula find the interpolating polynomial f(x) for the following data points and hence find f (0). [4] x y -2 5 -1 0 1 14