Professional Documents
Culture Documents
#include <iostream.h>
int max (int &x, int &y, int &z)
{
if (x >y && y > z)
{
y ++;
z ++;
return x;
}
else
if (y >x)
return y;
else
return z;
}
void main ( )
{
int a = 10, b = 13, c = 8 ; a = max (a, b, c);
cout << a << b << c << endl; b = max (a, b, c);
cout << ++ a << ++ b << ++ c << endl; c = max (a, b, c);
cout << a++ << ++b << ++c << endl;
}
3.Give the output of the following program (Assuming all required header
files are included
in the program ).
2
void swap(char &c1,char &c2)
{ char temp;
temp=c1;
c1=c2;
c2=temp;
}
void update(char *str)
{
int k,j,l1,l2;
l1 = (strlen(str)+1)/2;
l2=strlen(str);
for(k=0,j=l1-1;k<j;k++,j--)
{
if(islower(str[k]))
swap(str[k],str[j]);
}
for(k=l1,j=l2-1;k<j;k++,j--)
{
if(isupper(str[k]))
swap(str[k],str[j]);
}
}
void main()
{
char data[100]={"gOoDLUck"};
cout<<"Original Data : "<<data<<endl;
update(data);
cout<<"Updated Data "<<data;
}
(5) Find the output of the following program:
#include<iostream.h>
struct MyBox
{
int Length, Breadth, Height;
};
void Dimension (MyBox M)
{
cout<<M.Length<<"x"<<M.Breadth<<"x";
cout<<M.Height<<endl;
}
void main ()
{
MyBox B1={10,15,5}, B2, B3;
++B1.Height;
Dimension(B1);
B3 = B1;
++B3.Length;
B3.Breadth++;
Dimension(B3);
B2 = B3;
B2.Height+=5;
B2.Length--;
Dimension(B2);
}
13. Find the output of the following program:
#include<iostream.h>
#include<ctype.h>
void main( )
{
char Mystring[ ] = "what@OUTPUT!";
for(int I=0; Mystring[I]!='\0';I++)
{
if(!isalpha(Mystring[I]))
Mystring[I]='*';
else if(isupper(Mystring[I]))
Mystring[I]=Mystring[I]+1;
else
Mystring[I] =Mystring[I+1];
}
cout<<Mystring;
}
14. Find the output.
#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;
}
}
15. Give the output of the following program segment(Assuming
all required header files are included in the program):
char *NAME=a ProFiLe;
for(int x=0;x<strlen(NAME);x++)
if(islower(NAME[x]))
NAME[x]=toupper(NAME[x]);
else
If(isupper(NAME[x]))
If(x%2!=0)
NAME[x]=tolower(NAME[x-1]);
else
NAME[x]--;
cout<<NAME<<endl;
16)Write the output of the following program:
#include<iostream.h>
int func(int &x,int y=10)
{ if(x%y==0) return ++x;else return y- -; }
void main( )
{
int p=20,q=23;
q=func(p,q);
cout<<p<<q<<endl;
p=func(q);
cout<<p<<q<<endl;
q=func(p);
cout<<p<<q<<endl;
}
17) Find the output of the following program:
#include<iostream.h>
#include<conio.h>
main( )
{
int number[10],a,b,c,d;
clrscr( );
for(int i=0;i<10;i++)
{
number[i]=i+i;
}
clrscr( );
for(int j=0;j<9;j++)
{
for(int k=j+1;k<10;k++)
{
if (number[j]>number[k])
{
a=number[j];
number[j]=number[k];
number[k]=a;
}
}
}
cout<<endl;
for(i=0;i<10;i++)
cout<<number[i]<<\t;i++;
getch( );
return 0;
}
18. Find the output of the following program:
#include <iostream.h>
struct Game
{
char Magic[20];int Score;
};
void main()
{
Game M={Tiger,500};
char *Choice;
Choice=M.Magic;
Choice[4]=P;
Choice[2]=L;
M.Score+=50;
cout<<M.Magic<<M.Score<<endl;
Game N=M;
N.Magic[0]=A;N.Magic[3]=J;
N.Score-=120;
cout<<N.Magic<<N.Score<<endl;
}
19.
point u = {20,10},V,W;
v=u;
v.x+=20;
w=v;
u.y+=10;
u.x+=5;
w.x-=5;
show(u);
show(v);
show(w);
}
Q 2(c)Consider the following and answer the following questions given below:
class School
{
int A;
protected:
int B,C;
public:
void INPUT(int);
void OUTPUT( );
};
class Dept:protected School
{
int X,Y;
protected:
void IN(int, int);
public:
void OUT( );
};
class Teacher:public Dept
{
int P;
void DISPLAY(void);
public:
void ENTER( );
};
(i) Name the base class and derived class of the class Dept.
(ii) Name the data member(s) that can be accessed from function OUT( ).
(iii) Name the private member function(s) of class Teacher.
(iv) Is the member function OUT( ) accessible by the objects of Dept?