#include <iostream>
#include <cmath>
#include <cstdlib>
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 !!!! -------------------
{ const int SIZE=1000;
PIPE pipes[SIZE];
for (int i=0; i<SIZE; i++){
create_pipe(&pipes[i]);
display_pipe(pipes[i]);
}
return 0;
} // --------------------------------------
double pipe_volume(PIPE pipe0){
double vol, s1, s2;
s1 = M_PI*pow(pipe0.diameter,2)/4;
s2 = M_PI*pow(pipe0.diameter-2*pipe0.thickness,2)/4;
return vol=(s1-s2)*pipe0.length/1000000;
}
double pipe_mass(PIPE pipe0){
double mass, density=1000;
if(pipe0.material="Steel") density=7800;
if(pipe0.material="Cast iron") density=7800;
if(pipe0.material="Al") density=2700;
if(pipe0.material="PVC") density=3200;
if(pipe0.material="Cu") density=8900;
return mass= density*pipe_volume(pipe0);
}
void create_pipe(PIPE *pipe0){
pipe0->length = (rand()%61+10)/10.+1.; // 1.-7. [m]
pipe0->diameter = rand()%(5+1)*10;
pipe0->thickness = pipe0->diameter*0.1;
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;
cout << " mass " <<pipe_mass(pipe0) <<" kg "<< endl;
cout << endl;
} // ----------------------------------------------
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}