Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- typedef struct box {
- double length;
- double width;
- double height;
- box *next;
- }
- BOX;
- void addbox(BOX *start)
- {
- BOX *t1 = start;
- while(1)
- {
- if (t1 -> next == NULL) break;
- t1 = t1-> next;
- }
- BOX *newbox = new BOX;
- t1 -> next = newbox;
- newbox -> next = NULL;
- newbox -> height = rand()%81+20;
- newbox -> length = rand()%120+10;
- newbox -> width = rand()%90+4;
- }
- double volumebig(BOX *start)
- {
- BOX *t1 = start;
- double big = 0;
- while(1)
- {
- if (t1->next == NULL) break;
- t1 = t1->next;
- if ((t1->height * t1->width * t1->length)>big) big=(t1->height * t1->width * t1->length);
- }
- return big;
- }
- double volume_over_given(BOX *start, double biggest)
- {
- BOX *t1 = start;
- int n=0;
- while(1)
- {
- if (t1->next == NULL) break;
- t1 = t1->next;
- if ((t1->height * t1->width * t1->length)>biggest) n++;
- }
- return n;
- }
- void display_parameters(BOX *start)
- {
- BOX *t1 = start;
- while(1)
- {
- if (t1->next == NULL) break;
- t1 = t1->next;
- }
- cout<<""<<t1->height<<endl;
- cout<<""<<t1->width<<endl;
- cout<<""<<t1->length<<endl;
- cout<< ""<<(t1->height * t1->width * t1->length)<<endl;
- }
- int main()
- {
- srand(time(NULL));
- BOX *box0 = new BOX;
- for (int i = 0; i < 10; i++) {
- addbox(box0);
- display_parameters(box0);
- }
- cout<<"Biggest volume="<< volumebig(box0)<<endl;
- cout<<"volume over given number="<<volume_over_given(box0,100000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement