Professional Documents
Culture Documents
sodapdf-converted (1)
sodapdf-converted (1)
Read Carefully the Question It is NOT Allowed to use any digital media It is NOT Allowed to use the
internet
Required
1.Name in English:
void main()
{
Test t(1);
t.print();
Test x(t);
x.print();
t.print();
}
What is the output of the previous program?
(2 Points)
121
122
222
233
20.What will be the output of the following C++ code? #include <iostream.h> int main() { int a[2][4] = {3, 6,
9, 12, 15, 18, 21, 24}; cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]]; return 0; }
(2 Points)
a) 15 18 21
b) 21 21 21
c) 24 24 24
d) Compile time error
21.What will be the output of the following C++ code? #include <iostream.h> int main () { int numbers[5];
int * p; p = numbers; *p = 10; p++; *p = 20; p = &numbers[2]; *p = 30; p = numbers + 3; *p = 40; p =
numbers; *(p + 4) = 50; for (int n = 0; n < 5; n++) cout << numbers[n] << ","; return 0; }
(2 Points)
a) 10,20,30,40,50,
b) 1020304050
c) compile error
d) runtime error
22.What will be the Output of the following Code:
int * GetMin(int ar[5]);
int main ()
{
int *ptr;
int X[5] = {12, 18, -11, -20, 3};
ptr = GetMin(X);
printf(%d, *ptr);
return 0;
}
int * GetMin(int ar[5])
{
int min, I;
min = ar[0];
for(I = 1 ; I < 10 ; I++)
{
if(ar[I] < min)
{
min = ar[I];
}
}
return &min;
}
(2 Points)
a) -20
b) Function cant return address
c) No value will be printed
d) There is a value that we dont know appear on the screen
23.What will be the output of the following C++ code? #include <iostream.h> void swap(int &a, int &b); int
main() { int a = 5, b = 10; swap(a, b); cout << "In main " << a << b; return 0; } void swap(int &a, int &b) { int
temp; temp = a; a = b; b = temp; cout << "In swap " << a << b; }
(2 Points)
a) In swap 105 In main 105
b) In swap 105 In main 510
c) In swap 510 In main 105
d) In swap 510 In main 510
24.What is the difference between references and pointers?
(2 Points)
a) References are an alias for a variable whereas pointer stores the address of a variable
b) References and pointers are similar
c) References stores address of variables whereas pointer points to variables
d) Pointers are an alias for a variable whereas references stores the address of a variable
25.#include
int f(int &x, int c)
{
c = c - 1;
if (c == 0)
return 1;
x = x + 1;
return f(x, c) * x;
}
int main()
{
int a = 4;
cout<<f(a,a);
(2 Points)
a) 343
b) 336
c) 120
d) 840
26.What will be the output of the following C++ code? #include <iostream.h> struct Time { int hours; int
minutes; int seconds; }; int toSeconds(Time now); int main() { Time t; t.hours = 5; t.minutes = 30;
t.seconds = 45; cout << "Total seconds: " << toSeconds(t) << endl; return 0; } int toSeconds(Time now) {
return 3600 * now.hours + 60 * now.minutes + now.seconds; }
(2 Points)
a) 19845
b) 20000
c) 15000
d) 19844
27.#include <iostream>
class Person
{
protected:
int id;
public:
Person(int i)
{
id = i;
}
Person(Person &p)
{
id = p.id;
}
int GetId()
{
return id;
}
void SetId(int m)
{
id = m;
}
};
Employee FillEmp()
{
Employee em(3, 4);
return em;
}
int main()
{
Employee emp(7, 8);
emp = FillEmp();
cout << emp.GetId() ;
cout << emp.GetSalary() << endl;
return 0;
}
What is the output of the previous program?
(2 Points)
34
78
Compile error
Non of the above
28.What will be the output of the following C++ code? #include <iostream.h> int main () { int n; for (n = 5;
n > 0; n--) { cout << n; if (n == 3) break; } return 0; }
(2 Points)
a) 543
b) 54
c) 5432
d) 53
29.What will be the output of the following C++ code? #include <iostream.h> void Sum(int a, int b, int & c)
{ a = b + c; b = a + c; c = a + b; } int main() { int x = 2, y =3; Sum(x, y, y); cout << x << " " << y; return 0; }
(2 Points)
a) 2 3
b) 6 9
c) 2 15
d) compile time error
30.What will be the output of the following C++ code? #include <iostream.h> int func(int m = 10, int n) { int
c; c = m + n; return c; } int main() { cout << func(5, 6); return 0; }
(2 Points)
a) 15
b) 10
c) compile time error
d) 30
31.What will be the output of the following C++ code? #include <iostream.h> int func(int m , int n = 10) {
int c; c = m + n; return c; } Int func(int a) { return (a*a); } int main() { cout << func(5); return 0; }
(2 Points)
a) 15
b) 11
c) compile time error
d) 30
32.What will be the output of the following C++ code? #include <iostream.h> class rect { int x, y; public:
void val (int, int); int area () { return (x * y); } }; void rect::val (int a, int b) { x = a; y = b; } int main () { rect
Rect; Rect.val (3, 4); cout << "rect area: " << Rect.area(); return 0; }
(2 Points)
a) rect area: 24
b) rect area: 12
c) compile error
d) rect area: 56
33.What will be the output of the following C++ code? #include <iostream.h> class CDummy { public: int
isitme (CDummy& param); }; int CDummy::isitme (CDummy& param) { if (¶m == this) return 1; else
return 0; } int main () { CDummy a; CDummy *b = &a; if (b->isitme(a)) { cout << "execute"; } else {
cout<<"not execute"; } return 0; }
(2 Points)
a) execute
b) not execute
c) error
d) both execute & not execute
34.Which of the following, when used as the /* body */ of method sum, will enable
that method to compute 1 + 2 + + n correctly for any n > 0?
//return 1 + 2 + ... + n
int sum(int n)
{
/* body */
}
I) return n + sum(n - 1);
II) if (n == 1)
return 1;
else
return n + sum(n - 1);
III) if (n == 1)
return 1;
else
return sum(n) + sum(n - 1);
(2 Points)
a) I only
b) II only
c) III only
d) I and II only
e) I, II, and III
Never give out your password.Report abuse
This content is created by the owner of the form. The data you submit will be sent to the form owner.
Microsoft is not responsible for the privacy or security practices of its customers, including those of this
form owner. Never give out your password.
Powered by Microsoft Forms
|
The owner of this form has not provided a privacy statement as to how they will use your response data.
Do not provide personal or sensitive information.
| Terms of use