You are on page 1of 4

Department of Higher Education

University of Computer Studies (Sittway)


First Year (B.C.Sc./B.C.Tech)
Final Examination
Computer Programming Technique (CS-201)
September, 2019
Answer All questions: Time allowed:3 hours
Part I
1. What are the outputs of the program? (12 marks)
(a) void countdown(int n)
{
cout<<n<<endl;
n--;
if(n>0)
{
countdown(n); //The function calls itself! Recursion!
}
}
int main()
{
countdown(10);
return 0;
}
Please answer as follow:
The output of the program are: …………………………..

(b) int main()


{
int var1,var2;
int* ptr;
ptr=&var1;
*ptr=37;
var2=*ptr;
cout<<var2<<endl;
return 0;
}
Please answer as follow:
The output of the program are: …………………………..

(c) enum days_of_week{Sun,Mon,Tue,Wed,Thur,Fri,Sat};


int main()
{

Page 1 of 4
days_of_week d1,d2;
d1=Mon;
d2=Fri;
cout<<d1<<” “<<d2;
if(d1>d2)
cout<<”\n day2 comes before day1”;
return 0;
}
Please answer as follow:
The output of the program are: …………………………..

2. Which of the following lines are correct and which have errors? If error, correct them. (12 marks)
(a) Line 1: char ch=a;
Line 2: cout<<”She said that, “ I am character a.” ”<<endl;
Line 3: if(ch!=56) ch=48;
Line 4: else (ch ==56) ch=’*’;
Line 5: cout>>ch>>endl;
Please answer as follow:
Line ( ) is correct.
Line ( ) is error. Correct syntax is = …………………………… //Answer correct

(b) Line 1: int age{4}


Line 2: for(int i=0,i<n,i++);
Line 3: {cout<<”Enter age’
Line 4: cin>>age{i};
Please answer as follow:
Line ( ) is correct.
Line ( ) is error. Correct syntax is = …………………………… //Answer correct

(c) Line 1: int constant x=10


Line 2: char c= static cast(int)<x>
Line 3: cout<<”Constant value ‘ = x;
Line 4: char ch=a
Please answer as follow:
Line ( ) is correct.
Line ( ) is error. Correct syntax is = …………………………… //Answer correct

3. Describe the concerned header file for the following instructions to run properly. (12 marks)
(a) srand(time(NULL));
(b) char ch=getche( );
(c) cout<<setw(2)<<numb;
(d) strcpy(str,s);
(e) islower(ch);
(f) fprintf(fp,”%d\t%d\n”,var1,var2);

Page 2 of 4
Please answer as follow:
Header file for rand(time(NULL))=>#include<………………>

4. Write a short code segments for the given instruction. (12 marks)

(a) Declare variable total and currentValue of type int. Assign 5 to currentValue and total. Divide
total by currentValue, then increase currentValue by 1. Print total is now, followed by the value
of variable total.

(b) Create a structure called Rainfall that contains three members: City-ID (type int), year (type int)
and Rate (type double). Write a program that creates two structure variables of Rainfall. Initialize
one and have the user input value for the other one. Then display their contents.

(c) Write a program to reverse the element of a C string (an array of char).

Part II

5. (a) Write a program that inputs a character from user and test the character is vowel or not. When it
finishes the calculation the program should ask whether the user wants to do another character. The
response can be ‘y’ or ‘n’. Continue this process until the user input ‘n’. After all input, the program
output the total count of vowel and total count of not vowel. (8 marks)

(b) Write a program that prints the following outputs on the screen.

1 2 3 1
2 4 6 2
3 6 9 3
4 8 12 4
5 10 15 5
(8 marks)

6. (a) Write a program that accepts 10 integers from keyboard and stores in an array and then search a
number in that array. If the number is found, display the message “FOUND”, otherwise display
“NOT FOUND”. (8 marks)

(b) Write a program to find if a given sting is palindrome or is not palindrome. (Some examples of
palindrome sentence: “deed”, “level”). (8 marks)

7. Answer ANY TWO of the following: (20 marks)


(a) Write a function called displayReverse() that should take an argument of type int and print the
reverse of the value of argument. Write a main() function that gets an integer value from the user,
to print the reverse of user input number call displayReverse().

Page 3 of 4
For example: displayReverse(123), then the result is 321.

(b) Write a program that reads data from input file “mark.txt” as follows. This includes 4 data:
rollNo and three subjects’ marks. Your program should read student data from that file and
counts the number of pass students and fail students and then display it. (Hint: if all subjects’
marks are greater than or equal to 50, the student will pass the exam.)

(c) Write a function called upit() that converts the string to all uppercase. You can use the toupper()
library function, which take single character as an argument and returns a character that has been
converted (if necessary) to uppercase. The library function uses the <ctype.h> header file.
Include a main() program that accepts a string from the user call upit() and display the uppercase
string.

Page 4 of 4

You might also like