Itp Final Obj Fall17

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Capital University of Science and Technology

Department of Computer Science


CS1133 – Introduction to Programming
Final Term Exam (BS CS/SE)
Semester: Fall 2017 Max Marks: 50
Date: Jan 16, 2017 Time: 60 Min
Instructors: Dr. Tanvir Afzal(S1), Dr. Azhar Iqbal (S3), Mr. Salman Ahmed (S4),
Mr. Usman Rafiq (S7), Ms. Hajra Klair (S2&S5), Mr. Samir Obaid (S6)
Instructions:
 There are TWO questions in this paper on SIX pages.
 This part will be collected after 60 mins.

Name: Reg. No.

Part I (Objective)

Question No. 1. (CLO – 1) (20)

Encircle True or False:

i) [4]Consider the following declarations


int x;
int *p;
int *q;

p = q; A) True B) False

p = x; A) True B) False

*p = *q; A) True B) False

*p = q; A) True B) False

ii) [1] A variable for which memory remains allocated as long as the program executes is
called a static variable.
A) True
B) False

CS1133 – Introduction to Programming Page 1 of 6


iii) [1] Value-returning function returns only one value.
A) True
B) False

iv) [1] Parameters allow you to use different values each time the function is called.
A) True
B) False

v) [1] When a return statement executes in a user-defined function, the function


immediately exits.
A) True
B) False

vi) [1] A sequential search of a list assumes that the list elements are sorted in ascending
order.
A) True
B) False

vii) [1] Selection sort tries to sort the array after dividing array into two sub-parts.
A) True
B) False

viii) [1] To search an element from a sorted array, we always need to traverse the whole
array.
A) True
B) False

ix) [1] In C++, a string is any sequence of characters enclosed between double quotation
marks.
A) True
B) False

x) [1] Strings are not compared character by character.


A) True
B) False

xi) [1] Because strings are stored in arrays, individual characters in the string can be
accessed using the array component access notation.
A) True
B) False

CS1133 – Introduction to Programming Page 2 of 6


xii) [1] In C++, strings are null terminated.
A) True
B) False

xiii) [1] All members of a struct must be of same type.


A) True
B) False

xiv) [1] A struct can be a member of another struct.


A) True
B) False

xv) [1] 25 elements are reserved in 2-D array with the following statement?
int ara[5][6];.
A) True
B) False

xvi) [1] To access an element of a two-dimensional array, you need a pair of indices: one for
the row position and one for the column position.
A) True
B) False

xvii) [1] In a two-dimensional array, the rows are numbered 0 to ROW_SIZE -1 and the
columns are numbered 0 to COLUMN_SIZE -1.
A) True
B) False

CS1133 – Introduction to Programming Page 3 of 6


Question No. 2. (CLO – 2) (30)

Write the output of following questions. Please note that programs are error free.
i)
void main()
{
int beta[3][3];
for (int i = 0; i< 3; i++)
for (int j = 0; j < 3; j++)
beta[i][j] = 5 * (i + j);

for (int i = 0; i< 3; i++)


for (int j = 0; j < 3; j++)
cout << beta[i][j];
}
OUTPUT :

ii)
int mystery(int num)
{
int y = 1;
if (num == 0)
return 1;
else if (num< 0)
return -1;
else
for (int count = 1; count <num; count++)
y = y * num;
return y;
}

void main()
{
cout<<mystery(2) <<endl;
cout<<mystery(0) <<endl;
cout<<mystery(-2) <<endl;
}

OUTPUT :

CS1133 – Introduction to Programming Page 4 of 6


iii)
void main()
{
int x; int y;
int *p = &x;
int *q = &y;
x = 35; y = 46;
p = q; *p = 78;
cout << x << " " << endl;
cout << *p << " " << *q << endl;

OUTPUT :

iv)
void main()
{
string name="Capitaly";
int j = 3;
while (name[j] != '\0')
cout<< name[j++];
cout<<name.length();
cout<<name;
name=name + ”country”;
cout<<name;
}
OUTPUT:

CS1133 – Introduction to Programming Page 5 of 6


v)
void main()
{
Struct addressType
{
String houseNo;
string street;
string city;
};
Struct employeeType
{
Int pID;
addressType address;
string dept;
double salary;
};

employeeType employees[20];
employeeType newEmployee;
newEmployee.address.city = "Islamabad";
newEmployee.pID = 19;
newEmployee.salary = 45000;
employeeType anotherEmployee;
anotherEmployee = newEmployee;
employees[0].salary = 36000;
employees[0].dept = 3;
employees[19] = employees[0];
employees[19].pID = 1019;
int lastpID = employees[19].pID+1;

cout<<anotherEmployee.salary<<endl;
cout<< (employees[19].salary + newEmployee.salary)/2<<endl;
cout<<lastpID<<endl;

if(employees[19].salary<40000)
cout<<"Employee has an average salary."<<endl;
}
cout<<employees[19]. pID;
employees[0].dept

OUTPUT:

CS1133 – Introduction to Programming Page 6 of 6

You might also like