Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<cmath>
  4. #include<ctime>
  5.  
  6. using namespace std;
  7.  
  8. typedef struct box
  9. {
  10. double width;
  11. double height;
  12. double lenght;
  13. box *next;
  14. }BOX;
  15.  
  16. void addbox(BOX *start)
  17. {
  18. BOX *t1=start;
  19. while(1)
  20. {
  21. if(t1->next==NULL) break;
  22. t1=t1->next;
  23. }
  24. BOX *newbox = new box;
  25. t1->next=newbox;
  26. newbox->next=NULL;
  27. newbox->height=rand()%101+1;
  28. newbox->width=rand()%101+1;
  29. newbox->lenght=rand()%101+1;
  30. }
  31. double volume_over(BOX *start, double biggest)
  32. {
  33. BOX *t1=start;
  34. double b=0;
  35. while(1)
  36. {
  37. if(t1->height*t1->width*t1->lenght>biggest) b=b+1;
  38. if(t1->next == NULL) break;
  39. t1=t1->next;
  40. }
  41. return b;
  42. }
  43. int main()
  44. {
  45. srand(time(NULL));
  46. BOX *box0 = new BOX;
  47.  
  48. box0 -> width = 12;
  49. box0 -> lenght = 4;
  50. box0 -> height = 8;
  51. box0 -> next = NULL;
  52.  
  53. for (int i = 0; i < 10; i++) addbox(box0);
  54. cout << "Boxes with ovlume over 100mm^3: " << volume_over(box0, 100) << endl;
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement