0% found this document useful (0 votes)
113 views

Cs-111 Introduction To Programming: Terminal Exam 8 July 2021

This document provides instructions and questions for a CS-111 Introduction to Programming terminal exam. It consists of 5 multiple part questions testing a variety of programming concepts. Students are given 160 minutes to complete and submit their exam responses as a single PDF document with their name and registration number. They are warned that any similarity between responses will result in zero marks.

Uploaded by

Aamar shahzad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

Cs-111 Introduction To Programming: Terminal Exam 8 July 2021

This document provides instructions and questions for a CS-111 Introduction to Programming terminal exam. It consists of 5 multiple part questions testing a variety of programming concepts. Students are given 160 minutes to complete and submit their exam responses as a single PDF document with their name and registration number. They are warned that any similarity between responses will result in zero marks.

Uploaded by

Aamar shahzad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS-111 INTRODUCTION TO PROGRAMMING

Terminal Exam

8th July 2021

Total Marks: 50 Time Allowed: 160 minutes


Instructions:
• Submissions are included within the time allowed.
• Any kind of similarity will lead to zero marks.
• Your answers should be submitted in a single PDF document.
• Your Full Name, Registration Number, and Class should be written on the files.
• Save your files with your Full Name.

Question No:1 (2+2+2+4)

A. Comment on a local and global variable. What is the precedence when there are a Global
variable and local variable in the program with the same name?

B. Suppose that you have the declaration int *numPtr;. What is the difference between the
expressions *numPtr and &numPtr?

C. Explain the difference between formal and actual parameters during the call by reference and
call by value with the help of an example.

D. Consider the following statements to identify valid or invalid statements along with a reason.

i.
char string15[16];
if(string15 >= "Nice day")
cout << string15;

ii.
int myList[5] = {0, 4, 8, 12, 16};
int yourList[5];
yourList = myList;

Question No:2 (4+6)


A. Write C++ statements for a print function printArray. It should print the elements of an int
array with no return value. The array to be printed the number of elements is passed as
parameters. The parameter listSize specifies the number of elements to be printed.

B. Write a C++ function, power(), that takes as parameters two integers x and y such that x is
nonzero and returns 𝑥 𝑦 . You can use the following definition to calculate 𝑥 𝑦 . If y ≤ 0:

𝑝𝑜𝑤𝑒𝑟(𝑥, 𝑦) = 1 𝑖𝑓 𝑦 = 0,
𝑥 𝑖𝑓 𝑦 = 1,
𝑥 𝑥 𝑝𝑜𝑤𝑒𝑟( 𝑥, 𝑦 − 1) 𝑖𝑓 y > 1

Question No:3 (10)


Given the declaration:
char name[8] = "QAU";

mark the following statements as “Yes” if they output QAU. Otherwise, mark the statement as
“No” and explain why it does not output QAU.
A. cout << name;
B. cout<<name[];
C. for (int j = 0; j < 6; j++)
cout << name[j];
D. int j = 0;
while (name[j] != '\0')
cout << name[j++];
E. int j = 0;
while (j < 8)
cout << name[j++];

Question No:4 (6+4)


A. Write a C++ code to declare an array of maximum integer pointers. The maximum values should be
computed via a function having input and output. The array should contain at least five values. It
should print all the values and a Max number of an array.
B. Write the C++ statements for the given the declaration:
char myStr[26];
char yourStr[26] = "Arrays and Strings";

i. Write statement that stores "Summer Vacation" in myStr.


ii. Write a statement that outputs the length of yourStr.
iii. Write a statement that copies the value of yourStr into myStr.
iv. Write a statement that compares myStr with yourStr and stores the result into an int
variable compare.

Question No:5 (5+5 )


A. Write the output for the following programs with its logical execution (dry run)

void test(int first, int& second);


int main(){
int num=5;
test(num + num, num);
cout << "num+num,num: "<<num << endl;
return 0; }
void test(int first, int& second){
int third;
third = first + second * second + 2;
first = second + first;
second = 2 * second;
cout << "First:"<<first << "Second:"<<second <<"Third"<< third <<
endl; }

B. Identify and correct the errors in the following codes.

int N = 2,137;
main (){
int a, b, c, d:
a := 3;
b = 5;
c = c + d;
N = a + n;
for (i = 3; i <= N; i++){
cout << setw(5) << i;
i = i + 1; }
return 0; }

GOOD LUCK

You might also like