Advertisement
Guest User

11.1

a guest
Dec 14th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include<stdlib.h>
  4. using namespace std;
  5. typedef struct Pipe {
  6. double diameter ;//[mm]
  7. double length;//[m]
  8. double thickness ; //[mm]
  9. char *material; // "cast iron" "steel" "Cu" "PVC" "Al"
  10.  
  11. } PIPE;//====================
  12. void display_pipe(PIPE pipe0);
  13. void create_pipe(PIPE *pipe0);
  14. int main() //how to use structures!!!!---------------
  15. { PIPE pipe1 = {50., 1.5, 5, "steel"};
  16. PIPE pipe2,pipe3;
  17. pipe2.diameter = 30.;//alternative way of declaring struct--------------------------
  18. pipe2.thickness = 2.;
  19. pipe2.length = 5.;
  20. pipe2.material= "cast iron";
  21. PIPE *p1= &pipe3;//pointer to structure PIPE//alternative way of declaring struct--------------------------
  22. p1->diameter = 40.;
  23. p1->length=6.;
  24. p1->thickness = 3.;
  25. p1->material="Cu";
  26. display_pipe(pipe1);
  27. display_pipe(pipe2);
  28. display_pipe(pipe3);
  29. create_pipe(&pipe1);
  30. display_pipe(pipe1);
  31. return 0;
  32. }//---------------------------------
  33. void create_pipe(PIPE *pipe0){
  34. pipe0->length = (rand()%(61+10)/10.+1.);//range 1 to 7 metres[m]
  35. pipe0->diameter = rand()%61+10; //10-70[mm]
  36. pipe0->thickness = rand()%11+1;//1-10[mm]
  37. int a = rand()%5+1;//1-5
  38. if (a==1)pipe0->material="steel";
  39. if (a==2)pipe0->material="Cu";
  40. if (a==3)pipe0->material="cast iron";
  41. if (a==4)pipe0->material="PVC";
  42. if (a==5)pipe0->material="Al";
  43. }
  44. void display_pipe(PIPE pipe0){
  45. cout<<"Pipe parameters"<<endl;
  46. cout<<" diameter "<<pipe0.diameter<<endl;
  47. cout<<" length "<<pipe0.length<<endl;
  48. cout<<" thickness "<<pipe0.thickness<<endl;
  49. cout<<" material "<<pipe0.material<<endl<<endl;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement