Function Assignment-2
Function Assignment-2
a) 5500.263
b) 500.2635
c) 500.263
d) none of the mentioned
Answer:
5 Overloaded functions are
a) Very long functions that can hardly run
b) One function containing another one or more functions inside it.
c) Two or more functions with the same name but different number of parameters or type.
d) none of the mentioned
Answer:
7. When our function doesn’t need to return anything means what we will as parameter in
function?
a) void
b) blank space
c) both a & b
d) none of the mentioned
Answer:
#include <iostream>
using namespace std;
void copy (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 1, y = 3, z = 7;
copy (x, y, z);
cout<< "x =" << x << ", y =" << y << ", z =" << z;
return 0;
}
a) 2 5 10
b) 2 4 5
c) 2 6 14
d) none of the mentioned
Answer:
12. How many maximum number of arguments can be present in function in c99 compiler?
a) 99
b) 90
c) 102
d) 127
Answer:
17. How many minimum numbers of functions are need to be presented in C++?
a) 0
b) 1
c) 2
d) 3
Answer:
#include <iostream>
using namespace std;
int max(int a, int b )
{
return ( a > b ? a : b );
}
int main()
{
inti = 5;
int j = 7;
cout<< max(i, j );
return 0;
}
a) 5
b) 7
c) either 5 or 7
d) none of the mentioned
Answer:
23. Which of the following function / type of function cannot be overloaded?
a) Member function
b) Static function
c) Virtual function
d) Both B and C
Answer:
24. Which of the following function declaration is/are incorrect?
a) int Sum(int a, int b = 2, int c = 3);
b) int Sum(int a = 5, int b);
c) int Sum(int a = 0, int b, int c = 3);
d) Both B and C are incorrect.
e) All are correct.
Answer:
25. Which of the following statement is incorrect?
a) The default value for an argument can be a global constant.
b) The default arguments are given in the function prototype.
c) Compiler uses the prototype information to build a call, not the function definition.
d) The default arguments are given in the function prototype and should be repeated in the
function definition.
Answer:
26.Implementation of friend function
#include<iostream.h>
#include<conio.h>
class base {
int val1, val2;
public:
void get() {
cout<< "Enter two values:";
cin>> val1>>val2;
}
friend float mean(base ob);
};
int main() {
// Variable Declaration
int counter, n;
class line {
public:
inline float mul(float x, float y) {
return (x * y);
}
inline float cube(float x) {
return (x * x * x);
}
};
void main() {
lineobj;
float val1, val2;
clrscr();
cout<< "Enter two values:";
cin>> val1>>val2;
cout<< "\nMultiplication value is:" <<obj.mul(val1, val2);
cout<< "\n\nCube value is :" <<obj.cube(val1) << "\t" <<obj.cube(val2);
getch();
}
int main()
{
double number, squareRoot;
cout<< "Enter a number: ";
cin>> number;
void display(int);
void display(float);
void display(int, float);
int main() {
int a = 5;
float b = 5.5;
display(a);
display(b);
display(a, b);
return 0;
}
void display(intvar) {
cout<< "Integer number: " <<var<<endl;
}