0% found this document useful (0 votes)
257 views5 pages

XC350 Final Exam Abdullah Khalid

The document is an exam paper for the course "Intro to Computer Programming" at the University of Management and Technology. It contains 9 multiple choice questions worth 1 mark each (Question 1), 2 questions worth 10 marks total (Question 2), 1 question worth 10 marks analyzing code output (Question 3), 1 question analyzing variable values after code segments worth 10 marks (Question 4), 2 questions analyzing code output worth 10 marks total (Question 5), 2 questions drawing code shapes worth 15 marks total (Question 6), 2 questions analyzing code recursion worth 10 marks total (Question 7), 1 question writing a loop to calculate values from an equation worth 10 marks (Question 8), and 1 question writing a function to calculate array sums, products,

Uploaded by

Shahzael Mughal
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)
257 views5 pages

XC350 Final Exam Abdullah Khalid

The document is an exam paper for the course "Intro to Computer Programming" at the University of Management and Technology. It contains 9 multiple choice questions worth 1 mark each (Question 1), 2 questions worth 10 marks total (Question 2), 1 question worth 10 marks analyzing code output (Question 3), 1 question analyzing variable values after code segments worth 10 marks (Question 4), 2 questions analyzing code output worth 10 marks total (Question 5), 2 questions drawing code shapes worth 15 marks total (Question 6), 2 questions analyzing code recursion worth 10 marks total (Question 7), 1 question writing a loop to calculate values from an equation worth 10 marks (Question 8), and 1 question writing a function to calculate array sums, products,

Uploaded by

Shahzael Mughal
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

University of Management and Technology

School of Professional Advancement


Computer Science Department

Student Resource Person: Abdullah Khalid


Name: _____________________ Exam: Final
Student ID: ________________________ Date: 18 Feb 2021
Course Title: Intro to Computer Programming Total Marks: 100 Marks
Course Code: XC350 Time Allowed: 6 PM - 10 PM
Semester: Fall 2020

_______________________________________________________________________

Question # 1 (10 x 1 = 10 marks)

Choose the correct answer


1) The type of variable whose allocated storage is 4 byte and contains values that can be stored are
positive or negative whole numbers
a. float b. int c.bool d. long

2) A procedural set of instruction or statements, that may take argument then perform some work , and
may return a result
a. property b. object c. class d. function

3) Special words or symbol that denotes a special meaning to the compiler and cannot be used for
variable or function names are:
a. language primitives b. subroutines c. header names d. reserved or keywords

4) Variable that can be accessed and altered only within the function in which they are defined is
called:
a. user defined variables b. static variables c. local variables d. global variables

5) The C++ data type that can take on either one of only two possible values is known as
a. binary b. character c. short d. Boolean

6) The modulus operator "%" is used in division to return the


a. dividend b. quotient c. divisor d. remainder

7) The clause in the SWITCH is executed if no CASE statement matches within the "SWITCH/CASE"
block:
a. finally clause b. catch clause c. default clause d. exception routine

8) Passing argument be means of making a copy of the variable's content is known as passing by:
a. value b. name c. reference d. inheritance

9) The function that must always return control to the operating system is known as:
a. private b. header c. initial method d. main

10) The function the return no result is said to have a return value of
a. int b. undeclared c. void d. double

1
Question #2 (2 + 4 + 4 = 10 marks)
1. What type must x, y, z, and w be if we assign them the values 1, 1.0, '1', and "1", respectively.
2. Consider the following code segment:

if ((Balance >= 2000) && (Balance <= 3000))


{
cout << "Your balance is between $2000 and $3000";
cout << "Your interested rate will be 3.5%";
}
else
{
cout << "Your balance is larger than $3000.";
cout << "Your interest rate will be 4.5%";
}

Do you think this code does what the programmer intended? If not, improve this code.

3. Convert the following nested if statement into an equivalent switch statement.

if (Grade == 'A') || (Grade == 'B')


assignPassingWithHonors();
else if (Grade == 'C') || (Grade = 'D')
assignPassingGrade();
else
assignFailingGrade();

Question # 3 (3.3 x 3 = 10 marks)


What is the output of the following code fragment?
Part1
int A =1;
int B =2;
if(((A==1) || (B==2)) && (B==0))
cout<<"This exam was difficult ";
else
cout<< "This exam was easy ";
Part2
int main() {
char *a[] = { "Argentina", "Korea", "Greece", "Nigeria"};
cout << *(a+1) << endl;
cout << *a[0] << endl;
cout << a[3] << endl;
cout << a[3][1] << endl;
return 0;}
Part3
#include <string>
int main() {
string A = "Good morning";
string B = "Good afternoon";
if (A > B)
cout << A;
else
cout << B;
return 0;}

2
Question 4: (6 + 4 = 10 marks)
1. Determine the value of the indicated variable after execution of each program
segment.

int i = 4;
while (I < 8)
{
i += 3;
}

What is i ?

int j;
for (int i = 0; i < 5; i++)
j = 2*i;

What is j ?

int i = 10;
int j = 4;
int k = 10 / 4;
int l = 10 % 4;

What is k and l ?

int j;
switch (i)
{
case 0: j = 2*i; break;
case 1: j = -i; break;
default: j = -2*i;
}

What is j if i = 1 ? What is j if i = -1 ?

2. Consider the following functions:

void What1(int J)
{
J = 3 - J; }
void What2(int& J)
{
J = 3 - J;}
int main(void)
{
I = 1;
J = 15;
What1(J);
What2(I);}

What is the value of J when the main function is finished?

3
Question 5: (2 x 5 = 10 marks)
1. What would be printed by the following Statements?
#include <iostream.h>
int f(int &i)
{
i = 10;
return(5 * i);
}
int main()
{
int n = 5;
f(n);
cout << n << "\n";
return 0;}

2. Given a program as follows, what would be printed?


#include <iostream.h>
int myfunc(double);
int myfunc(float);
int main()
{
cout << myfunc(3.51) << "\n";
return 0;
}
int myfunc(double n)
{
return n * 2.0;
}
int myfunc(float n)
{
return n * 3.0;}

Question 6: (7.5 + 7.5 =15 marks)


Write the C++ code to print the following shapes.

Figure 1

Figure 2
4
Question 7: (5 + 5 = 10 marks)

1. Consider this function.


void myFunction( int counter)
{
if(counter == 0)
return;
else
{
cout <<counter<<endl;
myFunction(--counter);
return;
}
}

This recursion is not infinite, assuming the function is passed a positive integer value. What will
the output be?

2. Consider this function:

void myFunction( int counter)


{
if(counter == 0)
return;
else
{
cout<<"hello"<<counter<<endl;
myFunction(--counter);
cout<<counter<<endl;
return;
}
}

If the function is called with the value 4, what will the output be? Explain.

Question 8: (10 marks)

Write (C++) code , including a loop, required to calculate y(t) from the equation:
for values of t between -9 and 9 in steps of 3. Display each value of t and y(t).

Question 9: (5 x 3 =15 marks)

Write a function that computes the sum, product & maximum of elements of an array. The input
to the function should be an array of an arbitrary size and an integer indicating the length of the
array currently used as input. The function should deliver a single double number that is the
sum of all entries in the array.

You might also like