google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: C++ Programs Questions and answers Solve it

Saturday, January 26, 2019

C++ Programs Questions and answers Solve it



Solve C++ programs 
Questions and answers:
 

1)Which C++ header file(s) will be essentially required to be included to run /execute the following C++ code:
 void main()
{
     char Msg[ ]="Sunset Gardens";
     for (int I=5;I<strlen(Msg);I++)
     puts(Msg);
 }

Ans : stdio.h, string.h

 

2) Name the header files that shall be need for the following code:
  void main() 
            {
                char text[] =”Something”
               cout<<”Remaining SMS chars: ”<<160-strlen(text)<<endl; 
            }
 
 Ans: iostream.h/iomanip.h , string.h


3) Rewrite the following program after removing the syntactical error(s) if any.

 #include<iostream.h>
Class Item
{ long IId, Qty; public: void Purchase
{ cin>>IId>>Qty;}
 void Sale()
{ cout<<setw(5)<<IId<<”Old:”<< Qty<<endl; cout<< “New :”<<Qty<<endl; }
};
void main()
 { Item I; Purchase(); I.Sale() }

Ans : #include<iostream.h>
class Item // C capital
 { long IId, Qty; public: void Purchase ( ) { cin>>IId>>Qty;}
 // ( ) after function name void Sale( )
{
cout<<setw(5)<<IId<<”Old:”<< Qty<<endl; cout<< “New :”<<Qty<<endl;
}
};
 void main()
{ Item I; I. Purchase(); // object missing I.Sale() ; // ; is missing }


4) Find the output of the following program:
 #include<iostream.h>
#include<ctype.h>
typedef char Str80[80];
 void main()
 {char *Notes;
 Str80 str= “ vR2GooD”;
int L=6;
Notes =Str;
 while(L>=3)
{ Str[L]=(isupper(Str[L])? tolower(Str[L]) : toupper(Str[L]));
cout<<Notes<<endl;
L--;
 Notes++;
}
}

Either the statement is removed or header file included as #include<iomanip.h>

Ans : vR2Good R2GoOd 2GOOd gOOd


5) Observe the following program and find out, which output(s) out id (i) to (iv) will not be expected from program?
 What will be the minimum and maximum value assigned to the variables Chance?
 #include<iostream.h>
 #include<stdlib.h>
void main()
{ randomize();
 int Arr[] = {9,6};, N;
int Chance = random(2)+10;
 for(int c=0;c<2;c++)
 { N= random(2);
 cout<<Arr[N];
 }
}
i) 9#6# ii) 19#17# iii) 19#16# iv) 20#16#

Ans: The output not expected from program are (i),(ii) and (iv) Minimum value of Chance =10
Maximum value of Chance = 11

6) Find the output of the following program:
#include<iostream.h>
class METRO
{ int Mno, TripNo, PassengerCount;
public: METRO(int Tmno=1) { Mno =Tmno; PassengerCount=0;} void Trip(int PC=20) { TripNo++, PassengerCount+=PC};
void StatusShow() { cout<<Mno<< “:”<<TripNo<< “ :”<<PassengerCount<<endl;} };
 void main() { METRO M(5), T; M.Trip(); M.StatusShow(); T.StatusShow(); M.StatusShow(); }
Ans : 5: 1: 20 1: 1: 50 5: 2: 50



7) Find the output for the following program:
 #include<iostream.h>
 #include<ctype.h>
void Encript ( char T[ ])
 { for( int i=0 ; T[i] != ‘ \0’ ; i += 2)
if( T[i] = = ‘A’ || T[i] = = ‘E’ ) T[i] = ‘#’ ;
 else if (islower (T[i] )) T[i] = toupper(T[i]);
 else T[i] = ‘@’;
}
void main()
{ char text [ ] = “SaVE EArTh in 2012”;
encrypt(text);
 cout<<text<<endl;
 }

8) Find the output of the following program:
 #include<iostream.h>
void main( )
{
 int U=10,V=20;
 for(int I=1;I<=2;I++)
{
cout<<”[1]”<<U++<<”&”<<V  5 <<endl;
 cout<<”[2]”<<++V<<”&”<<U + 2 <<endl;
}
 }


9)In the following program, find the correct possible output(s)from the options:
#include<stdlib.h>
 #include<iostream.h>
void main( )
 {
randomize( );
 char City[ ][10]={“DEL”, “CHN”, “KOL”, “BOM”, “BNG”};
int Fly;
for(int I=0; I<3;I++)
{
Fly=random(2) + 1;
cout<<City[Fly]<< “:”;
 }
}
 Outputs: (i) DEL : CHN : KOL: (ii) CHN: KOL : CHN: (iii) KOL : BOM : BNG: (iv) KOL : CHN : KOL:

10)In the following C++ program what is the expected value of Myscore from options (i) to (iv) given below.
 Justify your answer.
#include<stdlib.h>
#include<iostream.h>
 void main( )
{
 randomize( );
 int Score[ ] = {25,20,34,56,72,63},Myscore;
 cout<<Myscore<<endl;
 }

 i) 25 (ii) 34 (iii) 20 (iv) Garbage Value.

Function overloading in C++
A function name having several definitions that are differentiable by the number or types of their arguments is known as function overloading.
Example :

 A same function print() is being used to print different data types:
#include <iostream.h>
class printData { public: void print(int i) { cout << "Printing int: " << i << endl; }
void print(double  f) { cout << "Printing float: " << f << endl; }
void print(char* c) { cout << "Printing character: " << c << endl; }
};
int main(void) { printData pd;
// Call print to print integer pd.print(5);
 // Call print to print float pd.print(500.263);
 // Call print to print character pd.print("Hello C++");
return 0;
}
When the above code is compiled and executed, it produces following result:
Printing int: 5 Printing float: 500.263 Printing character: Hello C++

रामायण

रामायण दशरथ की तीन पत्नियाँ – कौशल्या, सुमित्रा , कैकेयी दशरथ के चार पुत्र – राम,लक्ष्मण,भरत,शत्रुघ्न दशरथ: राम के पिता और कौशल के राजा कौशल...