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

Question 6 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    int K; 
    public:
    void ParinamFunction(float, int , char);
    void ParinamFunction(float, char, char);
    
};
int main()
{
    IndiaParinam objIB;
    objIB.ParinamFunction(15.09, 'A', char('A' + 'A'));
    return 0;
}
void IndiaParinam::ParinamFunction(float, char y, char z)
{
    K = int(z);
    K = int(y);
    K = y + z;
    cout<< "K = " << K << endl; 
}


A). The program will print the output M = 130.
B). The program will print the output M = 195.
C). The program will print the output M = -21.
D). The program will print the output M = -61.
E). The program will report compile time error.
Answer : Option D

Question 7 :

What will be the output of the following program?

#include < iostream . h > 
class TestDrive
{
    int x; 
    public:
    TestDrive(int xx)
    {
        x = xx;
    }
    int DriveIt(void);
};
int TestDrive::DriveIt(void)
{
    static int value = 0;
    int m;
    m = x % 2;
    x = x / 2;
    if((x / 2)) DriveIt(); 
    value = value + m * 10; 
    return value;
}
int main()
{
    TestDrive TD(1234);
    cout<< TD.DriveIt() * 10 << endl;
    return 0; 
}


A). 300
B). 200
C). Garbage value
D). 400
Answer : Option D

Question 8 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    int Num; 
    public:
    IndiaParinam(int x)
    {
        Num = x;
    }
    int ParinamFunction(void);
};
int IndiaParinam::ParinamFunction(void)
{
    static int Sum = 0; 
    int Dec;
    Dec = Num % 10; 
    Num = Num / 10; 
    if((Num / 100)) ParinamFunction(); 
    Sum  = Sum * 10 + Dec; 
    return Sum;
}
int main()
{
    IndiaParinam objParinam(12345);
    cout<< objParinam.ParinamFunction();
    return 0; 
}


A). 123
B). 321
C). 345
D). 12345
E). 54321
Answer : Option C

Question 9 :

What is correct about the following program?

#include < iostream . h > 
class Addition
{
    int x; 
    public: 
    Addition()
    {
        x = 0;
    }       
    Addition(int xx)
    {
        x = xx;
    }
    Addition operator + (int xx = 0)
    {
        Addition objTemp; 
        objTemp.x = x + xx; 
        return(objTemp);
    }
    void Display(void)
    {
        cout<< x << endl;
    }
};
int main()
{
    Addition objA(15), objB;
    objB = objA + 5;
    objB.Display();
    return 0; 
}


A). The program will print the output 20.
B). The program will report run time error.
C). The program will print the garbage value.
D). Compilation fails due to 'operator +' cannot have default arguments.
Answer : Option D

Question 10 :

What will be the output of the following program?

#include < iostream . h > 
class AreaFinder
{
    float l, b, h; 
    float result; 
    public:
    AreaFinder(float hh = 0, float ll = 0, float bb = 0) 
    {
        l = ll; 
        b = bb; 
        h = hh;
    }
    void Display(int ll)
    {
        if(l = 0)
            result = 3.14f * h * h; 
        else
            result = l * b; 
        cout<< result; 
    }
};
int main()
{
    AreaFinder objAF(10, 10, 20);
    objAF.Display(0); 
    return 0; 
}


A). 0
B). 314
C). 314.0000
D). 200.0000
Answer : Option A

Question 11 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    public: 
    int x, y;
    IndiaParinam(int xx = 10, int yy = 20)
    {
        x = xx;
        y = yy; 
    }
    void Exchange(int *, int *);
};
int main()
{
    IndiaParinam objA(30, 40); 
    IndiaParinam objB(50); 
    objA.Exchange(&objA.x, &objB.y); 
    cout<< objA.x << " " << objB.y << endl; 
    return 0;
}
void IndiaParinam::Exchange(int *x, int *y)
{
    int t;
    t  = *x;
    *x = *y;
    *y = t ; 
}


A). 20 10
B). 30 20
C). 20 30
D). 30 40
E). 50 30
Answer : Option C

Question 12 :

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

#include < iostream . h > 
class ParinamArray
{
    int Matrix[3][3]; 
    public:
    ParinamArray()
    {
        for(int i = 0; i<3; i++)
           for(int j = 0; j < 3; j++) 
              Matrix[j][i] = i + j; 
    }
    void Display(void)
    {
        for(int i = 0; i < 3; i++)
           for(int j = 0; j < 3; j++) 
              cout<< Matrix[j][i] << " "; 
    } 
}; 
int main()
{
    ParinamArray objParinam;
    objParinam.Display();
    return 0; 
}


A). The program will display the output 4 3 2 3 2 1 2 1 0.
B). The program will display the output 0 1 2 1 2 3 2 3 4.
C). The program will display the output 9 garbage values.
D). The program will report error on compilation.
Answer : Option B

Question 13 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    int x, y, z; 
    public:
    void Apply(int xx = 12, int yy = 21, int zz = 9)
    {
        x = xx;
        y = yy += 10;
        z = x -= 2;
    }
    void Display(void)
    {
        cout<< x << " " << y << endl; 
    } 
    void SetValue(int xx, int yy)
    {
        Apply(xx, 0, yy);
    }
};
int main()
{
    IndiaParinam *pParinam= new IndiaParinam;
   (*pParinam).SetValue(12, 20);
    pParinam->Display();
    delete pParinam;
    return 0; 
}


A). 10 10
B). 12 10
C). 12 21
D). 12 31
E). The program will report compilation error.
Answer : Option A

Question 14 :

What will be the output of the following program?

#include < iostream . h >
#include < string . h > 
class IndiaParinam
{
    char txtMsg[50]; 
    public:
    IndiaParinam(char *str = NULL)
    {
    if(str != NULL)
       strcpy(txtMsg, str);
    }
    int ParinamFunction(char ch);
};
int IndiaParinam::ParinamFunction(char ch)
{
    static int i = 0;
    if(txtMsg[i++] == ch)
        return strlen((txtMsg + i)) - i;
    else
        return ParinamFunction(ch);
}
int main()
{
    IndiaParinam objParinam("Welcome to IndiaParinam.com!");
    cout<< objParinam.ParinamFunction('t');
    return 0;
}


A). 6
B). 8
C). 9
D). 15
E). 16
Answer : Option A

Question 15 :

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

#include < iostream . h >
#include < string . h >
#include < malloc . h >
class ParinamString
{
    char txtName[20]; 
    public:
    ParinamString(char *txtTemp = NULL)
    {
        if(txtTemp != NULL)
        strcpy(txtName, txtTemp);
    }
    void Display(void)
    {
        cout<< txtName;
    }
};
int main()
{
    char *txtName = (char*)malloc(10);
    strcpy(txtName, "IndiaParinam");
    *txtName = 48;
    ParinamString objTemp(txtName);
    cout<< sizeof(txtName);
    return 0; 
}


A). Above program will display IndiaParinam 8.
B). Above program will display IndiaParinam 9.
C). Above program will display size of integer.
D). Above program will display IndiaParinam and size of integer.
E). Above program will display 1.
Answer : Option B