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 squares footage for a house. The very f

ID: 3810876 • Letter: W

Question

Write a program in C that calculates the squares 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 rooms. 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 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 upon which location was sent. The smallest room in the house is tie 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 out moodle class online.

Explanation / Answer

#include<stdio.h>
#define myName "sambis" //change the data within quotation
int calcArea(int x, int y) {
   return x*y; //simple area calculateion
}

void printRoom(int i){ //print using switch case
   switch(i) {
       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 Bathroom");
           break;
   }
}

void findValues(int *arr, int *max, int *min) { //find minimum and maximum at same time
       int i;
       *max = *min = arr[0];
       for (i=1; i<5; i++)
           if (arr[i] > max)
               *max = i;
           else if(arr[i] < min)
               *min = i;
}

void main() {
   int area[5], totalArea, i, len, bre, minPos, maxPos;
   totalArea = 0; //initialize total area to zero
   printf(myName);
   printf(" ");
   printf("Enter 5 length breadth pair ");
   for (i=0; i<5; i++) {
       scanf("%d %d",&len, &bre); //scan 5 pair of length and breadth
       area[i] = calcArea(len,bre); //calculate and store area
       totalArea += area[i]; //and update totalArea
   }

   printf("The total square footage for this house is %d sq.ft. ",totalArea);
   findValues(area, &maxPos, &minPos);//get min and max pos
   printf("The largest room in this house is the");
   printRoom(maxPos); //print largest room
   printf(" ");
   printf("The smallest room in this house is the");
   printRoom(minPos);
   printf(" ");
}

I kept the program as simple as possible just for you. Hope you like it.

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