Programs (Set - 2)

Question 1 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
long FactFinder(long = 5); 
int main()
{
    for(int i = 0; i<= 0; i++)
        cout<< FactFinder() << endl; 
    return 0;
}
long FactFinder(long x)
{
    if(x < 2)
        return 1; 
    long fact = 1; 
    for(long i = 1; i <= x-1; i++)
        fact = fact * i; 
    return fact; 
}


A). The program will print the output 1.
B). The program will print the output 24.
C). The program will print the output 120.
D). The program will print the output garbage value.
E). The program will report compile time error.
Answer : Option B

Question 2 :

What will be the output of the following program?

#include < iostream . h >
double ParinamFunction(double, double, double = 0, double = 0, double = 0);
int main()
{
    double d = 2.3;
    cout<< ParinamFunction(d, 7) << " ";
    cout<< ParinamFunction(d, 7, 6) << endl;
    return 0; 
}
double ParinamFunction(double x, double p, double q, double r, double s)
{
    return p +(q +(r + s * x)* x) * x;
}


A). 7 20
B). 7 19.8
C). 7 Garbage
D). 7 20.8
Answer : Option D

Question 3 :

What will be the output of the following program?

#include < iostream . h > 
int main()
{
    float Amount;
    float Calculate(float P = 5.0, int N = 2, float R = 2.0);
    Amount = Calculate(); 
    cout<< Amount << endl; 
    return 0;
}

float Calculate(float P, int N, float R)
{
    int Year = 1;
    float Sum = 1 ;
    Sum = Sum * (1 + P * ++N * R);
    Year =  (int)(Year + Sum);
    return Year; 
}


A). 21
B). 22
C). 31
D). 32
E). None of these
Answer : Option D

Question 4 :

What will be the output of the following program?

#include < iostream . h > 
class Parinam
{
    int x, y; 
    public:
    void show(void);
    void main(void);
};
void Parinam::show(void)
{ 
    Parinam b;
    b.x = 2;
    b.y = 4;
    cout<< x << " " << y;
}
void Parinam::main(void)
{
    Parinam b;
    b.x = 6; 
    b.y = 8;
    b.show();
}
int main(int argc, char *argv[])
{
    Parinam run;
    run.main();
    return 0; 
}


A). 2 4
B). 6 8
C). The program will report error on Compilation.
D). The program will report error on Linking.
E). The program will report error on Run-time.
Answer : Option B

Question 5 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class IndiaParinamSample
{
    private:
    int AdditionOne(int x, int y = 1) 
    {
        return x * y;
    }
     
    public:
    int AdditionTwo(int x, int y = 1)
    {
        return x / y;
    } 
}; 
int main()
{
    IndiaParinamSample objParinam;
    cout<< objParinam.AdditionOne(4, 8)<<" "; 
    cout<< objParinam.AdditionTwo(8, 8); 
    return 0;
}


A). The program will print the output 32 0.
B). The program will print the output 32 garbage-value.
C). The program will print the output 32 1.
D). The program will report compile time error.
Answer : Option D