Chapter – 2. STRUCTURES

Ans:

#include<iostream.h>
#include<string.h>
struct Supergym
{
int membernumber;
char membername[20];
char membertype[4];
};
void main( )
{
Supergym person1,person2;
cin>>"Member Number: ";
cin>>person1.membernumber;
cout<<"Member Name: ";
cin>>person1.membername; strcpy(person1.membertype,"MIG"); person2=person1;
cin>>"Member Number;">>person2.membernumber;
cin>>"Member Name">>person2.membername;
cin>>"Member Number:">>person2.membertype;
}

2003 :

1.d. Give the output of the following program:

#include<iostream.h>
struct Pixel
{ int C,R;
};
void Display(Pixel P)
{
cout<<”col”<<P.C<<”Row”<<P.R<<endl;
}
void main( )
{
Pixel X={40,50},Y,Z;
Z=X; X.C+=10;
Y=X; Y.R+=20;
Z.C-=15; Display(X);
Display(Y);
Display(Z);
}

Output:

col50Row50
col50Row70
col25Row5

2001 :

1.e. Give the output of the following program. (3)

#include<iostream.h>
#include<conio.h>
int g=20;
void func(int &x,int y)
{
x=x-y; y=x*10;
cout<<x<<’,’<<y<<’\n’;
}
void main( )
{
int g=7; func(g,::g);
cout<<g<<’,’<<::g<<’\n’; func(::g,g);
cout<<g<<’,’<<::g<<’\n’;
}

Ans:

-13, -130
-13, 20
-13, 33