Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdlib>
- using namespace std;
- typedef struct Pipe
- {
- double diameter;
- double lenght;
- double thickness;
- char *material;
- } PIPE;
- void display_pipe(PIPE pipe0);
- void create_pipe(PIPE *pipe0);
- double TotalMassPipes(PIPE pipe[],int ArraySize);
- double TotalMassPipesCu(PIPE pipe[], int ArraySize, char *material);
- double LenghtPipeline(PIPE pipe[], int ArraySize, char*material);
- int main()
- {const int SIZE = 1000;
- PIPE pipe[SIZE];
- for(int i=0; i<SIZE; i++){
- create_pipe(&pipe[i]);
- display_pipe(pipe[i]);
- }
- cout<< " total mass of pipe :" << TotalMassPipes(pipe, SIZE) << endl;
- cout<< " total mass of Cu :" << TotalMassPipesCu(pipe, SIZE, "Cu") << endl;
- cout<< " Longest lenght of Cu :" << LenghtPipeline(pipe, SIZE, "Cu") << endl;
- 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.lenght/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 ->lenght = (rand()%61+10)/10.+1;
- pipe0 ->diameter = (rand()%5+1)*10;
- pipe0 ->thickness = pipe0->diameter*0.1;
- int a = rand()%5 + 1;
- 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 << " lenght " <<pipe0.lenght<< endl;
- cout << " thickness " <<pipe0.thickness<< endl;
- cout << " material " <<pipe0.material<< endl << endl;
- cout << " mass " <<pipe_mass(pipe0)<< " kg " << endl;
- }
- double TotalMassPipes(PIPE pipe[],int ArraySize){
- double Total_mass=0, SIZE;
- for(int i=0; i<SIZE; i++){
- Total_mass = Total_mass + pipe_mass(pipe[i]);
- }
- return Total_mass;
- }
- double TotalMassPipesCu(PIPE pipe[], int ArraySize, char *material){
- double Total_mass_Cu=0, SIZE;
- for(int i=0; i<SIZE; i++){
- Total_mass_Cu = Total_mass_Cu + pipe_mass(pipe[i]);
- }
- return Total_mass_Cu;
- }
- double LenghtPipeline(PIPE pipe[], int ArraySize, char*material){
- double Longest_lenght_Cu=0, SIZE;
- for(int i=0; i<SIZE; i++){
- Longest_lenght_Cu = Longest_lenght_Cu + (pipe[i].lenght);
- }
- return Longest_lenght_Cu;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement