02 Fundamental of Computer Programming Sample Questions
02 Fundamental of Computer Programming Sample Questions
SAMPLE QUESTIONS
In the final examination, there will be 10 questions covering all chapter according to their class weightage.
Two selected questions will have option.
1. Draw the flow chart and write an algorithm for finding smallest of three numbers and explain.]
2. Find the value of “a” in each of the following statements:
int i=5, j=5, k=7;
Float a=3, b=5.5, c=2.5;
a) a=b-i/j+c/j
b) a=(b-c)/j+(j+c)/j
c) a=b-((i+j)/(k+i))*c
d) a=b-i+j/k+i*c
e) a=b+j%2+c
f) a=(b+1)%(c+1)
3. A machine is purchased which will produce earning of Rs.10000 per year while it lasts. The machine
costs Rs.60000 and will have a salvage value of Rs.20000 when it is condemned. If the 12 percent per
annum can be earned on alternative investments what should be the minimum life of the machine to
make it a more attractive investment compared to alternative investments?
4. The interest charged in installments buying is to be calculated by a computer program. A tape recorder
costs Rs.2000. A shopkeeper sells it for Rs.100 down and Rs.100 for 21 more months. What is the
monthly interest charged?
5. Obtain decision tables for simulating an automatic stamp vending machine with the following
specifications:
a) It should dispense 25, 15, and 10 paisa stamps.
b) It should accepts 50, 25, 10, and 5 paisa coins.
c) It cannot accept more than one coin for each transaction.
d) If more than one coin of the same denomination is to be returned as change after dispensing the
stamp, the machine cannot do it. Instead the coin should be returned and a “no change” signal
turned on.
e) The machine should dispense the stamp and the right change and must indicate exceptional
cases such as “insufficient amount tendered”, “no stamp available”, “no change available”, etc.
Write a program to simulate the machine. The input to the program would be: Amount tendered and stamps
requested. The output of the program should be: whether stamp is dispensed or not, the value of the stamp
dispensed, the denomination of the coins returned (if any) and no charge signal if no change is returned and
no stamp if the stamp is not available.
6. Write a program to obtain the product of the following matrices:
[ ] [ ]
4 6 8 9 8
A= 6 −7 2 B= 7 −3
5 6 1 5 2
7. Write a program to transpose the following matrix.
[ ]
−6 8 5 −1 4
A= 12 6 7 2 −5
−7 8 4 7 6
8. Write a program to find the sum of squares of elements on a diagonal of a square matrix.
9. Write a function to add, subtract, multiply and divide two complex numbers (x+iy) and (a+ib).
10. Write a function to multiply a square-matix by a vector. Assume a nn matrix and a n component
vector. The call would give the size of the matrix and the names of the matrix and a vector.
11. Write a function to multiply two nn matrices.
12. Write a function to sort a set on n numbers in ascending order of magnitude. How would this routine
be called?
13. Write a program to detect all vowels from a sentence. Assumes that the sentences is not more than 80
characters long.
14. Write a program to count the number of words in a sentence.
15. Write a program which will read a line and squeeze out all blanks from it and output the line with no
blanks.
16. Write a program which will read a line and delete from it all occurrences of the word “the”.
17. Write a program to count the number of occurrences of any two vowels in succession in a line of text.
For example, in the following sentence:
“Please allow a studious girl to read behavioral science”
Such occurrences are ea, io, ou, ie.
Observe that in a word such as studious we have counted “io” and “ou” as two separate occurrences of
two consecutive vowels.
18. Define a structure. Employee having data members name, address and salary. Take data for n
employee in an array dynamically and find the average salary.
19. Define a structure. Coordinate having data members x and y for x and y coordinates. Take values for
two points and find the distance between them. Use a function to calculate the distance but the result
should be displayed in main function.
20. Define a structure student having data members name, class, section and marks for six subjects. Use
array within structure to represent the marks in different subjects. Take the information for n numbers
of students given by user dynamically and display their percentage.
21. Define a structure. Table having data members length, breadth and height. Represent different
measurement by another structure Measurement having data members meter and centimeter. Take data
for some table and find their volume.
22. Define a structure for Vehicle Owner having data member name, address, telephone number, vechicle
number and license number. Take the data for ten owners write them in file “Own.txt”. Read the data
from the file and display them.
23. Given three variables x,y, and z, write a function to circularly shift their values. In other words if x=g,
y=9, and z=8, after circular shift y=5,z=9 and x=8. Call the function with variables a,b and c to
circularly shift their values.
24. Write a function to solve a quadratic equation ax2+bx+c=0. The input to be the function are the values
a,b, and c and the outputs of the function should be stored in variable names p and q appropriately
declared.
25. Write a function which will take as its input a matix mat of size (mn), where (m<10,n<5) and return
the same matrix with its elements replaced by absolute values.
26. Suppose a store has a number of items in their inventory and that each item is supplied by at most two
suppliers. Create inventory and supplier files. Find the address of all suppliers who supply more than
10 different items. Discuss any changes in the data structure you suggest to simplify solving this
problem.
27. Arrange the master file in descending order of average marks and create a new file.
28. Assume that at the end of the year a set of student join the class and another set leaves. Using the roll
number and an appropriate code to add to add or delete a student, updata the master file. The updated
file should be in ascending order of the roll number.
29. Given a text file, create another text file deleting all the vowels (a,e,i,o,u).