Computer Programming theory quiz 3
|
|
QUIZ NO. 03
|
|
||||||
|
Date: 08 /05/2017
|
Time:
20 Minutes
|
Total
Marks: 10
|
Obtained
Marks: _______
|
|||||
|
Enrollment No:
|
___________
|
Student_Name:
|
____________________________________
|
|||||
1.
What will be the output of following program
[2 mark]
|
#include<iostream>
#include<cmath>
#include<iomanip>
using
namespace std;
void
traceMe(double x , double y);
int
main()
{
double
one , two ;
cout<<”enter
two numbers:”;
cin>>one>>two;
cout<<endl;
traceMe(one
, two);
traceMe(two,
one);
return
0;
}
void
traceMe(double x , double y)
{
double
z;
if(x!=0)
z
= sqrt(y) /x;
else
{
cout<<”enter
a non zero number:”;
cin>>x;
cout<<endl;
z
= floor(pow(y , x));
}
//cout<<fixed<<showpoint<<setprecision(2);
cout<<
x << “,” << y <<” , “ <<z<<endl;
}
|
a) What
is the output if the input is 3 625? 3,
625 , 8.33333 625, 3 , 0.00277128
b)
What is the output if the input is 24
1024? 24,1024 ,
1.33333 1024,24 , 0.00478416
2.
Write the output of the following code
blocks. [3
marks]
a.
|
CODE
BLOCK
|
|
#include<iostream>
using namespace std;
void find(int &a ,int b , int &c);
int main()
{
int one = 1, two = 2,
three =3;
find(one ,two ,three);
cout<<one <<”,” << two <<”,”<<three<<endl;
find(two,one,three);
cout<<one <<”,” <<
two<<”,”<<three<<endl;
find(two,three,one);
cout<<one <<”,” <<
two<<”,”<<three<<endl;v
return 0;
}
void find(int&a ,int b , int&c)
{
int temp;
c = a * b + 2;
temp = c;
if(b == 0)
a = c/ ( b+1);
a = a + c –b;
c = b* temp;
}
|
OUTPUT :
3,2,8
3,7,24
4080,153,24
b.
|
CODE
BLOCK
|
|
#include<iostream>
using namespace std;
void tryMe(int
&v);
int main()
{
int x = 8;
for(int count = 1 ;
count<5; count++)
tryMe(x);
return 0;
}
void tryMe(int
&v)
{
int num = 2;
if(v % 2 == 0)
{
num++;
v = v+3;
}
else
{
num--;
v = v + 5;
}
cout<<v<<”,”<<num<<endl;
}
|
OUTPUT:
11,3
16,1
19,3
24,1
3.
State whether true or false . Provide
answers in given answer sheet.
[5 marks]
a. The
function definition contains the code for the function.
b. When
array is passed to a function. C++ uses pass by reference.
c. Variable
define in a function block have a global
scope.
d. To
use a predefined function in a program, you need to know only the name of the
function and how to use it.
e. A
value – returning function returns only one value.
f. If a c++ function does not use parameters, parenthesis around the
empty parameter list are still required.
g. Parameters
allow you to use different values each time the function is called.
h. Whenever
the value of reference parameter is changes, the value of the actual parameter
is changes.
i.
The concept of declaring same function name with
multiple definition is function overloading.
j.
C++ provides
inline functions to reduce function call
overhead , mainly for large functions.
|
ANSWER
SHEET FOR QUESTION NO. 3
|
|
Q.No
|
Answer
|
|
a.
|
T
|
|
b.
|
T
|
|
c.
|
F
|
|
d.
|
T
|
|
e.
|
T
|
|
f.
|
T
|
|
g.
|
T
|
|
h.
|
T
|
|
i.
|
F
|
|
j.
|
F
|
Comments
Post a Comment