-
Notifications
You must be signed in to change notification settings - Fork 95
/
volume of boxes.cpp
68 lines (59 loc) · 1.19 KB
/
volume of boxes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
#include"box.h"
using namespace std;
void sortArray(Box* bptr, int size)
{
Box temp=bptr[0];
for (int i = 0; i < size; i++)
{
for (int j = i+1; j < size; j++)
{
if (bptr[i].getvolume() > bptr[j].getvolume())
{
temp = bptr[i];
bptr[i] = bptr[j];
bptr[j] = temp;
}
}
}
for (int i = 0; i < size; i++)
{
cout << bptr[i].getvolume();
cout << "\t";
}
}
int main()
{
int size;
cout << "Enter the size of array : ";
cin >> size;
Box *bptr = new Box[size];
for (int i = 0; i < size; i++)
{
int le;
cout << "Enter of length of box " << i + 1 << " : ";
cin >> le;
bptr[i].setlength(le);
int w;
cout << "Enter the width of box " << i + 1 << " : ";
cin >> w;
bptr[i].setwidth(w);
int h;
cout << "Enter the height of box " << i + 1 << " : ";
cin >> h;
bptr[i].setheight(h);
}
cout << endl;
for (int i = 0; i < size; i++)
{
cout << "Volume of box " << i + 1 << " : ";
cout << bptr[i].getvolume() << endl;
cout << endl;
}
cout << endl;
cout << " Sorted array in ascending order : ";
sortArray(bptr, size);
cout << endl;
delete[]bptr;
return 0;
}