Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include<stdlib.h>
- using namespace std;
- typedef struct Pipe {
- double diameter ;//[mm]
- double length;//[m]
- double thickness ; //[mm]
- char *material; // "cast iron" "steel" "Cu" "PVC" "Al"
- } PIPE;//====================
- void display_pipe(PIPE pipe0);
- void create_pipe(PIPE *pipe0);
- int main() //how to use structures!!!!---------------
- { PIPE pipe1 = {50., 1.5, 5, "steel"};
- PIPE pipe2,pipe3;
- pipe2.diameter = 30.;//alternative way of declaring struct--------------------------
- pipe2.thickness = 2.;
- pipe2.length = 5.;
- pipe2.material= "cast iron";
- PIPE *p1= &pipe3;//pointer to structure PIPE//alternative way of declaring struct--------------------------
- p1->diameter = 40.;
- p1->length=6.;
- p1->thickness = 3.;
- p1->material="Cu";
- display_pipe(pipe1);
- display_pipe(pipe2);
- display_pipe(pipe3);
- create_pipe(&pipe1);
- display_pipe(pipe1);
- return 0;
- }//---------------------------------
- void create_pipe(PIPE *pipe0){
- pipe0->length = (rand()%(61+10)/10.+1.);//range 1 to 7 metres[m]
- pipe0->diameter = rand()%61+10; //10-70[mm]
- pipe0->thickness = rand()%11+1;//1-10[mm]
- int a = rand()%5+1;//1-5
- if (a==1)pipe0->material="steel";
- if (a==2)pipe0->material="Cu";
- if (a==3)pipe0->material="cast iron";
- if (a==4)pipe0->material="PVC";
- if (a==5)pipe0->material="Al";
- }
- void display_pipe(PIPE pipe0){
- cout<<"Pipe parameters"<<endl;
- cout<<" diameter "<<pipe0.diameter<<endl;
- cout<<" length "<<pipe0.length<<endl;
- cout<<" thickness "<<pipe0.thickness<<endl;
- cout<<" material "<<pipe0.material<<endl<<endl;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement