DOEACC Society 2004 DOEACC A Level C Lanaguage - Question Paper
A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE
NOTE:
1. There are TWO PARTS in this Module/paper. PART ONE contains FOUR questions and PART TWO contains FOUR questions.
2. PART ONE is to be answered in the TEAR-OFFANSWER SHEET only, attached to the question paper, as per the instructions contained therein. PART ONE is NOT to be answered in the answer book.
3. Maximum time allotted for PART ONE is ONE HOUR. Answer book for PART TWO will be supplied at the table when the answer sheet for PART ONE is returned. However, candidates who complete PART ONE earlier than one hour, can collect the answer book for PART TWO immediately after handing over the answer sheet for PART ONE.
TOTAL TIME: 3 HOURS TOTAL MARKS: 100
(PART ONE-40; PART TWO 60)
PART ONE
(Answer all the questions)
1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter in the tear-off answer sheet attached to the question paper, following instructions therein. (1 x 10)
1.1 Assume that variable x resides at memory location 100, y at 200 and ip at 1000.
int x=1; y=2; int *ip;
ip=&x
y=*ip
What will be the value of y after execution of above code?
A) 1
B) 2
C) 100
D) 1000
1.2 What will be the output of the following program?
main() { int i=1,j,k;
if(i>=2)
j=2;
k=3;
printf(\n%d%d,j,k);
}
A) 2,3
B) 0,0
C) 0,3
D) 3,2
1.3 Which of the following keyword is used to jump out of a loop without waiting to get back to the conditional test?
A) break
B) continue
C) while
D) exit
1.4 Pick up the odd one out from the following.
A) a=a+1;
B) a+=1;
C) a++;
D) a=+1;
1.5 Which of the following is the correct way of declaring an array of integer pointers?
A) int *arr[10];
B) int arr[10];
C) *int arr[10];
D) int *arr;
1.6 The expression, i=30 * 10+27; evaluates to
A) 327
B) -327
C) 810
D) 0
1.7 Which of the following is returned by the function strcmp if the strings that are compared are identical?
A) 0
B) 1
C) 2
D) true
1.8 The statement that correctly defines a character called letter is
A) letter :=char;
B) char letter;
C) letter : char;
D) character letter;
1.9 The statement that defines an input file handle called input_file, which is a pointer to type FILE, is:
A) FILE*input_file;
B) type input _file as FILE;
C) input_file FILE;
D) *FILE input_file;
1.10 Close the file associated with input_file
A) close input_file;
B) fclose(input_files);
C) fcloseall();
D) input_file(fclose);
2. Each statement below is either TRUE or FALSE. Choose the most appropriate one and ENTER in the tear-off sheet attached to the question paper, following instructions therein. (1 x 10)
2.1 Operation between integer and real(float) always yields a real result.
2.2 The while and for loops cannot be nested loops the way if statements can be nested.
2.3 The advantage of switch statement over if is that it leads to more structured program.
2.4 Strings are arrays of characters terminated by the null character.
2.5 A pointer is a variable that points to another variable.
2.6 The variables commonly used in C functions are available to all functions in a program.
2.7 fopen() function returns a pointer to the open file.
2.8 Character data types cannot be declared as unsigned.
2.9 The statement which prints out the value of the integer variable sum, is printf(%s, sum);
2.10 The char variable is used to store the largest number less than 128.
3. Match words and phrases in column X with the closest related meaning/ word(s)/phrases in column Y. Enter your selection in the tear-off answer sheet attached to the question paper, following instructions therein. (1 x 10)
X Y
3.1 |
Several built in functions in 'C' that can be called at any time |
A. |
Library |
3.2 |
A collection of values of the same type |
B. |
An Array |
3.3 |
A decision control structure |
C. |
The if-else statement |
3.4 |
Logical AND operator |
D. |
&& |
3.5 |
Finding length of a string |
E. |
strlen() |
3.6 |
Passing address of variables to a function |
F. |
Call by reference |
3.7 |
Reading formatted data from the standard input stream |
G. |
scanf() |
3.8 |
Preprocessor statement |
H. |
#define |
3.9 |
A data type suitable for grouping data elements together |
I. |
A Structure |
3.10 |
Dynamic memory allocation |
J. |
calloc, sizeof, free |
|
|
K. |
functions |
|
|
L. |
gets() |
4. Each statement below has blank space to fit one of the word(s) or phrases in the list below. Enter your choice in the tear-off answer sheet attached to the question paper, following instructions therein. (1 x 10)
A. |
switch-case-default |
B. |
while |
C. |
5 |
D. |
& |
E. |
linked list |
F. |
#include<stdio.h> |
G. |
main() |
H. |
puts |
I. |
sizeof |
J. |
for |
K. |
20 |
L. |
null |
M. |
getchar() |
N. |
fopen() |
O. |
|
4.1 The statement within the _______ loop would keep on getting executed till the condition being tested remains true.
4.2 The control statement, which allows us to make a decision from the number of choice, is called a(n) _______.
4.3 A string is terminated by a(n) _______ character.
4.4 C provides a special operator _______ which gives the size of basic data types in bytes.
4.5 A(n) _______ is comprised of a series of nodes, each node containing a data element and a pointer to the next node.
4.6 The statement printf(%20.5s\ns) means that the first _______ characters are printed of an arrays.
4.7 The _______ accepts a single character from the keyboard.
4.8 The _______ function, accepts the pathname for the file and the access mode.
4.9 The _______ refers to the address of the variable.
4.10 The _______ acts as a check to make sure you are using the input and output commands properly.
PART TWO
(Answer any four questions)
5.
a) What does the scope of variable refer in C language?
b) Write a program to sort a given list of number using Bubble sort algorithm.
(5+10)
6.
a) What is a Pointer? How can you use pointers with Array if you want to copy elements of array a into array b.
b) We have a Single linked list as following:
Write the C link list program to sum up this list.
([3+5]+7)
7.
a) Create a program that prints a Fahrenheit-to-Celsius conversion with a for loop or a while loop; where Celsius=((f-32) * 5/9); and Fahrenheit is denoted by f.
b) While purchasing certain items a discount of 10% is offered if the quantity purchased is more than 2000. Write a program to calculate the total expenses, if quantity and price per item are entered through keyboard.
(7+8)
8.
a) Write a program to determine whether a number is prime or not.
b) Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In Fibonacci sequence the sum of two successive terms gives the third term. The following are few terms of Fibonacci sequence:
1 1 2 3 5 8 13 21 ....
(7+8)
9. Create a program that reads in a string containing a first name followed by a blank followed by a last name. Write functions to remove any leading or trailing blanks. Write another function that return the last name.
(15)
A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE
NOTE:
1. There are TWO PARTS in this Module/paper. PART ONE contains FOUR questions and PART TWO contains FOUR questions.
2. PART ONE is to be answered in the TEAR-OFFANSWER SHEET only, attached to the question paper, as per the instructions contained therein. PART ONE is NOT to be answered in the answer book.
3. Maximum time allotted for PART ONE is ONE HOUR. Answer book for PART TWO will be supplied at the table when the answer sheet for PART ONE is returned. However, candidates who complete PART ONE earlier than one hour, can collect the answer book for PART TWO immediately after handing over the answer sheet for PART ONE.
TOTAL TIME: 3 HOURS TOTAL MARKS: 100
(PART ONE-40; PART TWO 60)
PART ONE
(Answer all the questions)
1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter in the tear-off answer sheet attached to the question paper, following instructions therein. (1 x 10)
1.1 Consider the following code segment
int a[10], *p1, *p2;
p1 = &a[4];
p2 = &a[6[;
Which of the following is incorrect w.r.t pointers?
A) p1 +2
B) p2 - 2
C) p2 - p1
D) p2 +p1
1.2 The second expression (j k), in the following expression will be evaluated
(i + 5) || (j - k)
A) if the expression (i + 5) is true.
B) if the expression (i + 5) is false.
C) irrespective of whether (i + 5) is true or false.
D) will not be evaluated in any case.
1.3 In the for statement : for (exp1; exp2; exp3 ) { ..}
where exp1, exp2 and exp3 are expressions. What is/are optional?
A) None of the expressions are optional.
B) Only exp1 and exp3 are optional.
C) Only exp1 is optional
D) All the expressions are optional.
1.4 Which of the following statement is not true for register variable?
A) Only a few register variables may be defined in a function.
B) It is not possible to take the address of a register variable.
C) A struct variable can be stored in registers.
D) If a register declaration is not honored, the register variables are treated as auto variables.
1.5 What will be the output of the following code?
#include <stdio.h>
myfunc ( struct test t) {
strcpy(t.s, world);
}
main() {
struct test { char s[10];}t;
strcpy(t.s,Hello )
printf(%s,t.s);
myfunc(t);
printf(%s,t.s);
}
A) Hello Hello
B) Hello world
C) world world
D) the program will not compile
1.6 Which of the following is false for goto statement?
A) Use of the goto statement should generally be avoided.
B) A goto statement transfers the control to a labeled statement.
C) No two statements in a function can have same label.
D) With a goto statement, the control can be transferred to any statement of other program.
1.7 The output of the following code segment will be
char x = B;
switch ( x ) {
case A : printf(a);
case C : printf(c);
}
A) B
B) b
C) BC
D) bc
1.8 How many values at the most can be returned to the calling function through a single return statement?
A) 0
B) 1
C) 2
D) any number of values
1.9 A constant cannot be used except
A) for assigning initial value to a variable.
B) with ++ operator.
C) as a formal argument.
D) on LHS of an assignment operator.
1.10 Which of the following preprocessor directives is used to create marcos
A) #include
B) #ifdef
C) #define
D) #undef
2. Each statement below is either TRUE or FALSE. Choose the most appropriate one and ENTER in the tear-off sheet attached to the question paper, following instructions therein. (1 x 10)
2.1 The size of a pointer to an integer is same as the size of a pointer to a struct variable having four integer data members.
2.2 The contents of a file opened in r+ cannot be changed.
2.3 The mod operator (%) can operate on float data.
2.4 Every if statement can be converted into an equivalent switch statement.
2.5 The only property of a recursive function is that it calls itself again and again.
2.6 All members of a union are allocated contiguous memory locations.
2.7 The main() function can call itself recursively.
2.8 No two constants in an enum can have same value.
2.9 (i + j)++ is illegal.
2.10 The statement struct s { int j; float f;}; tells the compiler to reserve the space for its data members j and f.
3. Match words and phrases in column X with the closest related meaning/ word(s)/phrases in column Y. Enter your selection in the tear-off answer sheet attached to the question paper, following instructions therein. (1 x 10)
X Y
3.1 |
A homogeneous data structure |
A. |
declaration |
3.2 |
A non-linear data structure |
B. |
register |
3.3 |
a return in main( ) |
C. |
int *p[10] |
3.4 |
Logical AND |
D. |
gets |
3.5 |
Left to right precedence operator |
E. |
static variable |
3.6 |
Space allocation |
F. |
& |
3.7 |
Retains value across the function calls |
G. |
?: |
3.8 |
Pointer to a function |
H. |
structure |
3.9 |
Returns a pointer to an integer |
I. |
array |
3.10 |
To read a line from standard input |
J. |
getline |
|
|
K. |
terminate program |
|
|
L. |
int (*p)[10]; |
|
|
M. |
linked llist |
|
|
N. |
int *p(void); |
|
|
O. |
auto |
|
|
P. |
definition |
|
|
Q. |
int (*p)(void); |
|
|
R. |
&& |
4. Each statement below has blank space to fit one of the word(s) or phrases in the list below. Enter your choice in the tear-off answer sheet attached to the question paper, following instructions therein. (1 x 10)
A. |
2.5 |
B. |
extern |
C. |
value |
D. |
variable |
E. |
*p |
F. |
char *s[10]; |
G. |
a[1][2] |
H. |
3 |
I. |
struct s *p |
J. |
&a[1][2] |
K. |
all except first |
L. |
reference |
M. |
P |
N. |
char (*s)[10]; |
O. |
expression |
P. |
2 |
Q. |
5 |
R. |
first |
S. |
struct s p; |
T. |
&p |
U. |
static |
4.1 The arrays are always passed by __________.
4.2 &(*p) is equivalent to __________.
4.3 *(*(a+1)+2) is equivalent to __________.
4.4 __________ defines an array of pointers to strings.
4.5 A(n) __________ cannot be a part of formal argument list.
4.6 Within a multifile program, a(n) __________ variable can be defined in one file and accessed in another.
4.7 A self referential structure, s, has __________ as a member.
4.8 Let f be a float variable, then after execution of the statement f = 5 / 2; the value of f will be __________.
4.9 Let str be a string of 5 characters, then printf(%3s, str); will display __________ characters.
4.10 The subscript positions(s) __________ need not be included in the formal argument declaration of an array.
PART TWO
(Answer any FOUR questions)
5. Write a C program to copy only those lines from one file to another that have more than 80 characters. Also print the line numbers in the new file. The line numbers must be with respect to the original file. Assume there are at the most 100 characters in a line.
(15)
6.
a) Write a C function, str_search, that takes two strings, as arguments and returns a pointer to the first occurrence of 1st string in 2nd string, or NULL if it is not present.
b) Write a recursive C function, power (, b) to compute ab. Assume a and b are non-negative integers.
(9+6)
7.
a) Write a C function to remove duplicates from an ordered array. For example, if input is 1,1,1,3,4,4,5,8,8,10 then output should be 1,3,4,5,8,10.
b) Write a recursive C function to print the reverse of a string.
(9+6)
8. Write a C program to generate a triangle with fibonacci numbers (series given below) as elements of every row. For example, for m = 5, the output should be
1
1 1
1 1 2
1 1 2 3
1 1 2 3 5.
Given, fibo(n) = fibo (n 1) + fibo (n 2), for n >= 3
= 1 for n= 1, 2
(15)
9.
a) Define a structure of anode of a linked list having an integer data member x.
b) Use the above structure in (a) and write the functions for the following parts;
i) a function which takes a pointer to the head of linked list, which is in ascending order and an integer, x to be inserted in the linked list, as arguments. The node must be inserted in such a way that the linked list remains in ascending order after insertion.
ii) a function which takes a pointer to the head of a linked list and an integer, x to be removed from the linked list, as arguments. If x is not found in the linked list, then it should display an appropriate message.
(3+[6 + 6])
Earning: Approval pending. |