STRUCTURE:BUILDING
Structures : Building
Create a structure called Building.
struct Building
{
char name[100];
float length;
float width;
float height;
float ratePerSqFt;
};
Write a program to get the details of 'n' buildings and to display the name, area and rate for painting the inner side of the building per square feet of each building, sorted by name in ascending order. Length, width and height of the building are given in feet.
The flooring is also done with the same rate.
Input and Output Format:
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.
Sample Input and Output:
Enter the number of buildings
2
Enter the details of building 1
Enter name
Vikram
Enter length
200
Enter width
150
Enter height
10
Enter rate per square feet
650.5
Enter the details of building 2
Enter name
Ganesh
Enter length
1050.5
Enter width
700
Enter height
12
Enter rate per square feet
800
Details of building 1
Name : Ganesh
Area : 1512712.00
Value : 1210169600.00
Details of building 2
Name : Vikram
Area : 67000.00
Value : 43583500.00
#include
#include
struct Building
{
char name[30];
float length;
float width;
float height;
float ratePerSqFt;
}b[10];
int i,j,n;
char nt[20];
float lt,wt,ht,rt,a[30],v[30];
int main()
{
printf("Enter the number of buildings\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the details of building %d\n",i);
printf("Enter name\n");
scanf("%s",b[i].name);
printf("Enter length\n");
scanf("%f",&b[i].length);
printf("Enter width\n");
scanf("%f",&b[i].width);
printf("Enter height\n");
scanf("%f",&b[i].height);
printf("Enter rate per square feet\n");
scanf("%f",&b[i].ratePerSqFt);
}
for(i=1;i<=n;i++)
{
for(j=i+1;i0)
{
strcpy(nt,b[i].name);
strcpy(b[i].name,b[j].name);
strcpy(b[j].name,nt);
lt=b[i].length;
b[i].length=b[j].length;
b[j].length=lt;
wt=b[i].width;
b[i].width=b[j].width;
b[j].width=wt;
ht=b[i].height;
b[i].height=b[j].height;
b[j].height=ht;
rt=b[i].ratePerSqFt;
b[i].ratePerSqFt=b[j].ratePerSqFt;
b[j].ratePerSqFt=rt;
}
}
}
for(i=1;i<=n;i++)
{
a[i]=2*((b[i].length*b[i].width)+(b[i].width*b[i].height)+(b[i].height*b[i].length));
v[i]=a[i]*(b[i].ratePerSqFt);
}
for(i=1;i<=n;i++)
{
printf("Details of building %d\n",i);
printf("Name : %s\n",b[i].name);
printf("Area : %0.2f\n",a[i]);
printf("Value : %0.2f\n",v[i]);
}
return 0;
}
Comments
Post a Comment