Skip to content

Instantly share code, notes, and snippets.

@bitwiser
Last active August 29, 2015 13:56
Show Gist options
  • Save bitwiser/9224032 to your computer and use it in GitHub Desktop.
Save bitwiser/9224032 to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
/* Part (i) */
struct Rectangle{
int width;
int height;
};
// Part (iii)
int Area(Rectangle r){
return r.width*r.height;
}
/* Program 3 */
void Rotate(Rectangle &r){
int a;
a = r.width;
r.width = r.height;
r.height =a;
}
int main(){
int l = 15;
/* Part (ii) */
int H[15] = {761, 186, 198, 243, 698, 279, 391, 885, 542, 718, 339, 408, 308, 172, 482};
int W[15] = {174, 354, 114 , 884, 156, 396, 926, 398, 771, 432, 801, 972, 978, 583, 726};
Rectangle R[15];
for(int i=0;i<l;i++){
R[i].width = W[i];
R[i].height = H[i];
}
/* Part (iv) */
int ar_max = 0, ind = 0;
for(int i=0;i<l;i++){
int ar;
ar = Area(R[i]);
if(ar>ar_max){
ind = i;
ar_max = ar;
}
}
cout<<"Rectangle with max area is at index "<<ind<<" and area "<<ar_max<<endl;
/* program 2 */
int w,h;
cout<<"Enter the index of rectangles to check fitting: ";
cin>>w>>h;
if(R[w].width<=R[h].width && R[w].height<=R[h].height){
cout<<"Yes. The rectangles fit\n";
}else{
cout<<"No. The ractangles don\'t fit\n";
}
/* Program $ part */
cout<<"Enter the index of rectangles to check fitting with rotation: ";
cin>>w>>h;
if((R[w].width<=R[h].width && R[w].height<=R[h].height)){
cout<<"Yes. The rectangles fit\n";
return 0;
}
Rotate(R[w]);
if((R[w].width<=R[h].width && R[w].height<=R[h].height)){
cout<<"Yes. The rectangles fit\n";
}else{
cout<<"No. The ractangles don\'t fit\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment