Advertisement
Guest User

STRUCTURE OF ARRAY

a guest
Jan 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdlib>
  4. using namespace std;
  5. typedef struct Pipe
  6. {
  7. double diameter;
  8. double lenght;
  9. double thickness;
  10. char *material;
  11. } PIPE;
  12. void display_pipe(PIPE pipe0);
  13. void create_pipe(PIPE *pipe0);
  14. double TotalMassPipes(PIPE pipe[],int ArraySize);
  15. double TotalMassPipesCu(PIPE pipe[], int ArraySize, char *material);
  16. double LenghtPipeline(PIPE pipe[], int ArraySize, char*material);
  17. int main()
  18. {const int SIZE = 1000;
  19. PIPE pipe[SIZE];
  20.  
  21. for(int i=0; i<SIZE; i++){
  22. create_pipe(&pipe[i]);
  23. display_pipe(pipe[i]);
  24.  
  25.  
  26. }
  27.  
  28. cout<< " total mass of pipe :" << TotalMassPipes(pipe, SIZE) << endl;
  29. cout<< " total mass of Cu :" << TotalMassPipesCu(pipe, SIZE, "Cu") << endl;
  30. cout<< " Longest lenght of Cu :" << LenghtPipeline(pipe, SIZE, "Cu") << endl;
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. return 0;
  39. }
  40. double pipe_volume(PIPE pipe0){
  41. double vol, s1, s2;
  42. s1 = M_PI* pow(pipe0.diameter,2)/4;
  43. s2 = M_PI*pow(pipe0.diameter-2*pipe0.thickness,2)/4;
  44. return vol = (s1-s2)*pipe0.lenght/1000000;
  45. }
  46. double pipe_mass(PIPE pipe0){
  47. double mass,density=1000;
  48. if(pipe0.material=="steel") density=7800;
  49. if(pipe0.material=="cast iron") density= 7800;
  50. if(pipe0.material=="Al") density= 2700;
  51. if(pipe0.material=="PVC") density= 3200;
  52. if(pipe0.material=="Cu") density= 8900;
  53. return mass = density*pipe_volume(pipe0);
  54. }
  55. void create_pipe(PIPE *pipe0){
  56. pipe0 ->lenght = (rand()%61+10)/10.+1;
  57. pipe0 ->diameter = (rand()%5+1)*10;
  58. pipe0 ->thickness = pipe0->diameter*0.1;
  59. int a = rand()%5 + 1;
  60. if (a==1) pipe0 ->material = "steel";
  61. if (a==2) pipe0 ->material = "Cu";
  62. if (a==3) pipe0 ->material = "cast iron";
  63. if (a==4) pipe0 ->material = "PVC";
  64. if (a==5) pipe0 ->material = "Al";
  65. }
  66.  
  67.  
  68. void display_pipe(PIPE pipe0)
  69. {
  70.  
  71. cout <<"PIPE parameters" << endl;
  72. cout << " diameter " <<pipe0.diameter<< endl;
  73. cout << " lenght " <<pipe0.lenght<< endl;
  74. cout << " thickness " <<pipe0.thickness<< endl;
  75. cout << " material " <<pipe0.material<< endl << endl;
  76. cout << " mass " <<pipe_mass(pipe0)<< " kg " << endl;
  77.  
  78. }
  79. double TotalMassPipes(PIPE pipe[],int ArraySize){
  80. double Total_mass=0, SIZE;
  81. for(int i=0; i<SIZE; i++){
  82. Total_mass = Total_mass + pipe_mass(pipe[i]);
  83. }
  84.  
  85. return Total_mass;
  86. }
  87. double TotalMassPipesCu(PIPE pipe[], int ArraySize, char *material){
  88. double Total_mass_Cu=0, SIZE;
  89. for(int i=0; i<SIZE; i++){
  90.  
  91. Total_mass_Cu = Total_mass_Cu + pipe_mass(pipe[i]);
  92. }
  93. return Total_mass_Cu;
  94.  
  95. }
  96.  
  97. double LenghtPipeline(PIPE pipe[], int ArraySize, char*material){
  98. double Longest_lenght_Cu=0, SIZE;
  99. for(int i=0; i<SIZE; i++){
  100.  
  101. Longest_lenght_Cu = Longest_lenght_Cu + (pipe[i].lenght);
  102. }
  103. return Longest_lenght_Cu;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement