InterviewSolution
| 1. |
Given here is a structure defilation:struct Box { char maker[21];float height,width,length,volume;};Write a function that passes the address of a Box structure and that sets the volume member to the product of the other three dimensions. |
|
Answer» #include<iostream.h> struct box { char maker[40]; float height; float width; float length; float volume; }; box yours; float boxer_dimensions (const box * compute ); void display_box (const box make); int main() { box yours ={"Apple", 10.0, 5.0,7.5};// to initialize a record char name[40]; float dia; dia= boxer_dimensions (&yours); //function call yours.volume = dia;// assigning results to volume member record display_box (yours);// function call return 0; } float boxer_dimensions (const box *compute )// specs calls for passing address of the structure { float Vol; Vol= ((compute->height)*(compute->length)*(compute->width)); //computation for volume here return Vol; } void display_box (const box make)/// display all results here { cout << make.maker <<endl; cout << make.height <<endl; cout << make.width <<endl; cout << make.length<< endl; cout << make.volume<<endl; } |
|