Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<cmath>
- #include<ctime>
- using namespace std;
- typedef struct box
- {
- double width;
- double height;
- double lenght;
- 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()%101+1;
- newbox->width=rand()%101+1;
- newbox->lenght=rand()%101+1;
- }
- double volume_over(BOX *start, double biggest)
- {
- BOX *t1=start;
- double b=0;
- while(1)
- {
- if(t1->height*t1->width*t1->lenght>biggest) b=b+1;
- if(t1->next == NULL) break;
- t1=t1->next;
- }
- return b;
- }
- int main()
- {
- srand(time(NULL));
- BOX *box0 = new BOX;
- box0 -> width = 12;
- box0 -> lenght = 4;
- box0 -> height = 8;
- box0 -> next = NULL;
- for (int i = 0; i < 10; i++) addbox(box0);
- cout << "Boxes with ovlume over 100mm^3: " << volume_over(box0, 100) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement