Advertisement
Guest User

biggest volume of box in list and given number

a guest
Jan 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. typedef struct box {
  9. double length;
  10. double width;
  11. double height;
  12. box *next;
  13. }
  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.  
  25. BOX *newbox = new BOX;
  26. t1 -> next = newbox;
  27. newbox -> next = NULL;
  28. newbox -> height = rand()%81+20;
  29. newbox -> length = rand()%120+10;
  30. newbox -> width = rand()%90+4;
  31. }
  32.  
  33.  
  34.  
  35. double volumebig(BOX *start)
  36. {
  37. BOX *t1 = start;
  38. double big = 0;
  39. while(1)
  40. {
  41. if (t1->next == NULL) break;
  42. t1 = t1->next;
  43. if ((t1->height * t1->width * t1->length)>big) big=(t1->height * t1->width * t1->length);
  44. }
  45. return big;
  46. }
  47.  
  48.  
  49.  
  50. double volume_over_given(BOX *start, double biggest)
  51. {
  52. BOX *t1 = start;
  53. int n=0;
  54. while(1)
  55. {
  56. if (t1->next == NULL) break;
  57. t1 = t1->next;
  58. if ((t1->height * t1->width * t1->length)>biggest) n++;
  59. }
  60. return n;
  61. }
  62.  
  63. void display_parameters(BOX *start)
  64. {
  65. BOX *t1 = start;
  66. while(1)
  67. {
  68. if (t1->next == NULL) break;
  69. t1 = t1->next;
  70. }
  71. cout<<""<<t1->height<<endl;
  72. cout<<""<<t1->width<<endl;
  73. cout<<""<<t1->length<<endl;
  74. cout<< ""<<(t1->height * t1->width * t1->length)<<endl;
  75. }
  76.  
  77. int main()
  78. {
  79. srand(time(NULL));
  80. BOX *box0 = new BOX;
  81.  
  82.  
  83.  
  84. for (int i = 0; i < 10; i++) {
  85. addbox(box0);
  86. display_parameters(box0);
  87. }
  88. cout<<"Biggest volume="<< volumebig(box0)<<endl;
  89. cout<<"volume over given number="<<volume_over_given(box0,100000);
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement