Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in C that calculates the square footage for a house. The very fi

ID: 3810847 • Letter: W

Question

Write a program in C that calculates the square footage for a house. The very first thing your program should do is to print your full name using a printf(). The main() function should ask the user for the dimensions of 5 rooms (length and width) using a for loop. For each room, the main() function will call a function called calcArea() which will calculate and return the area for a room, given the length and width. The returned area will then be loaded into an array called room. The rooms that the user will be entering, in order, are as follows: Kitchen, Bathroom, Living Room, Master Bedroom and Second Bedroom. (You do not need to tell them this - assume they already know - See output on next page!) Once the areas for all five rooms have been loaded into the array, the main() function will call a function called calcSquareFeet() which will add up the total areas of all the rooms and return the total square footage of the house. Your main() function will then print out the following message: The total square footage for this house is 1575 sq.ft. Next, your program should call a function called findValues() that will find the location in the array of the largest room in the house and the location in the array of the smallest room in the house. This information (the array locations of the largest and smallest) is to be returned to the main function. Your main() function will then send the location of the largest room in the house to a function called printRoom() which will print the following message depending upon which location was sent. The largest room in the house is the Kitchen. Your main() function will then send the location of the smallest room in the house to the same function called printRoom() which will then print the following message depending upon which location was sent. The smallest room in the house is the Bathroom. Your code is expected to be commented and written professionally (indent, readable) but you do NOT need data validation for this program. You must print a copy of your source code AND upload your .c or .cpp file to our moodle class online.

Explanation / Answer

#include <stdio.h>
float calcArea(float,float);//area method declartn
float calcSquareFeet(float []);//sqrfootage method
void printRoom(int,int);//print Room details
int * findValues(float arr[]){ //findvalue method to return highest Aad lowest area as values we are using functn to return array pointer in *
int static values[2];//static array to store highest and lowest areas
int lindex,hindex,j;//store index of high annd low areas
float high,low;
high=low=arr[0];
for(j=0;j<5;j++){//loop to read all arrays elems and store the vavlues
if(arr[j]>high){
high=arr[j];
hindex=j;
}
if(arr[j]<low){
low=arr[j];
lindex=j;
}
}
//printf("%d %d",lindex,hindex);
values[0]=lindex;
values[1]=hindex;
return values;//return the array
}
int main()
{
printf("My full name is <> "); //enter ur name
float length,width; //variables for len and width
int i,j; //for loop variables
float rooms[5]; //rooms array to store areas
for(i=0;i<5;i++){ //for loop to read len and wdth of rooms
length=width=0.0;
printf("Enter the length and breadth of Room #%d ",i+1);
scanf("%f",&length);
scanf("%f",&width);
rooms[i]=calcArea(length,width); //calcArea for each room
}
float sq_footage=calcSquareFeet(rooms);
printf("The total square footage of this house is %0.2f sq.ft",sq_footage);
int *p; ///* a pointer to an int */
p= findValues(rooms);
int lowarea= *(p + 0);//get array values
   int higharea=*(p + 1);
printRoom(lowarea,0);//call print room to print lowest and it is indicated using 0
printRoom(higharea,1);//using 1
/*for(j=0;j<5;j++){
printf("%f ",rooms[j]);
}*/
return 0;
}
float calcArea(float len,float wdth){
return len*wdth;
}
float calcSquareFeet(float arr[]){
int p;
float total_Area=0.0;
for(p=0;p<5;p++){
total_Area=total_Area+arr[p];
}
return total_Area;
  
}
void printRoom(int val,int areaval){
   if(areaval==0){//check here for whether smallest or //largest room
       printf("The smallest room in the house is ");
   }else{
       printf("The largest room in the house is ");
   }
   switch(val){//use switch case to print the room
       case 0:
       printf("Kitchen ");
       break;
       case 1:
       printf("BathRoom ");
       break;
       case 2:
       printf("Living Room ");
       break;
       case 3:
       printf("Master Bedroom ");
       break;
       case 4:
       printf("Second Bedroom ");
       break;
   }
}
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote