 CPP All : Structures passing/returning Concept Learning Code Sheets #### Passing Structure variables to a function #2955

Demonstration of how structure variables can be passed to function as pass-by-value or as pass-by-reference method

#### Passing structure to a function pass-by-value #2969

A program to demonstrate passing of structure to a function using pass by value method,

#### Structure passed as a reference #2979

A program to demonstrate how an structure is passed as a reference argument to a function.

Solved Problems #### Slope of line -using structure Point passed to a function #2973

Write a program by declaring a structure Point with two integer values for i

Write a program by declaring a structure Point with two integer values for its position x and y. Now write a function that finds slope of a line drawn out of two points that are passed as structure argument to this function. Show implementation of this function and structure in the main routine assuming suitable values of x and y being initialised for two points.

#### Output Writing Structure pass by value/reference #2984

Write the output of the following program depicting structure instances being

Write the output of the following program depicting structure instances being called as value and called as reference to a function.

```struct Sale {int ID; float value;};
void sc(Sale a,Sale &b)
{
a.ID=a.ID+1;
a.value=a.value+100;
b=a;
}
int main()
{
Sale zone1={1,400.50},zone2;
sc(zone1,zone2);
cout<<"Zone 1 (ID, value) = "<<zone1.ID<<", "<<zone1.value<<endl;
cout<<"Zone 2 (ID, value) = "<<zone2.ID<<", "<<zone2.value<<endl;
return 0;
}```

#### Output Writing – Pixel structure passed by reference #2987

Write down the output of the program and give steps in arriving at such outpu

Write down the output of the program and give steps in arriving at such output.

```struct Pix {int x,y;};
void show(Pix &p)
{
cout<<p.x++<<","<<++p.y<<endl;
}
int main()
{
Pix P={50,60},Q,R;
R=P;
show(R);
P.x+=10;P.y+=30;
Q=R;
show(P); show(Q); show(R);
return 0;
}```

#### Output Writing – Three dimensions in structure passed by reference #5596

Write down the output of the program.

```struct three_d{int x,y,z;};

```

Write down the output of the program.

```struct three_d{int x,y,z;};

void movein(three_d &t,int step=1)
{
t.x+=step; t.y-=step; t.z+=step;
}
void moveout(three_d &t,int step=2)
{
t.x-=step; t.y+=step; t.z-=step;
}

int main()
{
three_d t1={10,20,5},t2={30,10,40};
movein(t1);
moveout(t2,5);
cout<<t1.x<<","<<t1.y<<","<<t1.z<<endl;
cout<<t2.x<<","<<t2.y<<","<<t2.z<<endl;
movein(t2,10);
cout<<t2.x<<","<<t2.y<<","<<t2.z<<endl;
return 0;
}

```

#### Array of Structure – Output Writing #7663

Find and write the output of the following C++ program code:
Note: Assu

Find and write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.

```struct Score {
int Year;float Topper;
};
void change(Score *s,int x=10)
{
s->Topper=(s->Topper+15)-x;
s->Year++;
}
int main()
{
Score Arr[]={{2006,100},{2007,85}};
Score *point=Arr;
change(point,40);
cout<<Arr.Year<<'#'<<Arr.Topper<<endl;
change(++point);
cout<<Year<<'#'<<Topper<<endl;
return 0;
}

```

Code Sheets:3  Solved Problems:5
×