Question

In: Computer Science

I wrote this code and just realized I need to put it into at least 6...

I wrote this code and just realized I need to put it into at least 6 different functions and I don't know how. No specific ones but recommended is: Read Data, Calculate Installation Price, Calculate Subtotal, Calculate Total, Print -> 1) Print Measurements & 2) Print Charges. Can somebody help?


#include <stdio.h>

// Function Declarations

int length, width, area, discount;


int main ()
{
// Local Declarations
double price, cost, charge, laborCharge, installed, amtDiscount, subtotal, amtTax, total;
const double tax = 8.5;
const double labor = .35;

printf("Enter length in feet: ");
scanf("%d", &length);
printf("Enter width in feet: ");
scanf("%d", &width);
printf("Enter the percentage discount: ");
scanf("%d", &discount);
printf("Enter carpet price per foot: ");
scanf("%lf", &price);

area = length * width;
charge = price * area;
laborCharge = labor * area;
installed = charge + laborCharge;
amtDiscount = installed * (discount / 100.);
subtotal = installed - amtDiscount;
amtTax = tax / 100. * subtotal;
total = subtotal + amtTax;

printf("\n\t\tMEASUREMENT\n\n");
printf("Length \t%4d feet\n", length);
printf("Width \t%4d feet\n", width);
printf("Area \t%4d sq. ft\n", area);

printf("\n\t\tCHARGES\n\n");
printf("DESCRIPTION COST/SQ.FT. CHARGE/ROOM\n");
printf("----------- ----------- -----------\n");

printf("Carpet %5.2f $%7.2f\n", price, charge);
printf("Labor %.2f $%7.2f\n", labor, laborCharge);
printf("\t\t\t-----------\n");

printf("INSTALLED PRICE \t$%7.2f\n", installed);
printf("Discount %2d%% \t\t$%7.2f\n", discount, amtDiscount);
printf("\t\t\t-----------\n");

printf("SUBTOTAL \t\t$%7.2f\n", subtotal);
printf("Tax \t\t\t$%7.2f\n", amtTax);
printf("TOTAL \t\t\t$%7.2f\n", total);
return 0;
}

Solutions

Expert Solution

#include <stdio.h>

double GetArea(double length, double width)
{
return length * width;
}

double GetCharge(double price, double area)
{
return price * area;
}

double GetLaborCharge(double labor, double area)
{
return labor * area;
}

double GetInstalled(double charge, double laborCharge)
{
return charge + laborCharge;
}

double GetDiscountAmount(double installed, double discount)
{
return installed * (discount / 100.0);
}

double GetSubtotal(double installed, double discountAmount)
{
return installed - discountAmount;
}

double GetTaxAmount(double tax, double subtotal)
{
return tax / 100.0 * subtotal;
}

double ReadData()
{
double data;
scanf("%lf", &data);
return data;
}

void PrintMeasurment(double length, double width, double area)
{
printf("\n\tMEASUREMENT\n\n");
printf("Length \t\t%4d feet\n", (int)length);
printf("Width \t\t%4d feet\n", (int)width);
printf("Area \t\t%3.2lf sq. ft\n", area);
}

void PrintCharges(double price, double charge, double labor, double laborCharge)
{
printf("\n\tCHARGES\n\n");
printf("DESCRIPTION COST/SQ.FT. CHARGE/ROOM\n");
printf("----------- ----------- -----------\n");
printf("Carpet       %5.2f        $%7.2f\n", price, charge);
printf("Labor         %.2f        $%7.2f\n", labor, laborCharge);
printf("\n");
}

double CalculateInstallationPrice(double area, double price, double labor)
{
return GetInstalled(GetCharge(price, area), GetLaborCharge(labor, area));
}

double CalculateDiscount(double area, double price, double labor, double discount)
{
return GetDiscountAmount(CalculateInstallationPrice(area, price, labor), discount);
}


int main ()
{
int length, width, discount;
double price;
double area, charge, laborCharge;
double installed, amtDiscount, subtotal, amtTax, total;
const double tax = 8.5;
const double labor = .35;

printf("Enter length in feet: ");
length = (int)ReadData();
printf("Enter width in feet: ");
width = (int)ReadData();
printf("Enter the percentage discount: ");
discount = (int)ReadData();
printf("Enter carpet price per foot: ");
price = ReadData();

area = GetArea(length, width);
charge = GetCharge(price, area);
laborCharge = GetLaborCharge(labor, area);

PrintMeasurment(length, width, area);
PrintCharges(price, charge, labor, laborCharge);

installed = CalculateInstallationPrice(area, price, labor);
amtDiscount = CalculateDiscount(area, price, labor, discount);
subtotal = GetSubtotal(installed, amtDiscount);
amtTax = GetTaxAmount(tax, subtotal);
total = subtotal + amtTax;

printf("\t\t\t-----------\n");
printf("INSTALLED PRICE \t$%7.2f\n", installed);
printf("Discount %2d%% \t\t$%7.2f\n", discount, amtDiscount);
printf("\t\t\t-----------\n");

printf("SUBTOTAL \t\t$%7.2f\n", subtotal);
printf("Tax \t\t\t$%7.2f\n", amtTax);
printf("TOTAL \t\t\t$%7.2f\n", total);
return 0;
}

/*
output:-

Enter length in feet: 12
Enter width in feet: 78
Enter the percentage discount: 34
Enter carpet price per foot: 75

        MEASUREMENT

Length            12 feet
Width             78 feet
Area            936.00 sq. ft

        CHARGES

DESCRIPTION COST/SQ.FT. CHARGE/ROOM
----------- ----------- -----------
Carpet       75.00        $70200.00
Labor         0.35        $ 327.60

                        -----------
INSTALLED PRICE         $70527.60
Discount 34%            $23979.38
                        -----------
SUBTOTAL                $46548.22
Tax                     $3956.60
TOTAL                   $50504.81

*/


Related Solutions

Files I need to be edited: I wrote these files and I put them in a...
Files I need to be edited: I wrote these files and I put them in a folder labeled Project 7. I am using this as a study tool for a personal project of mine. //main.cpp #include <iostream> #include "staticarray.h" using namespace std; int main( ) {    StaticArray a;    cout << "Printing empty array -- next line should be blank\n";    a.print();    /*    // Loop to append 100 through 110 to a and check return value    // Should print "Couldn't append 110"...
I just wrote Python code to solve this problem: Write a generator that will return a...
I just wrote Python code to solve this problem: Write a generator that will return a sequence of month names. Thus gen = next_month('October') creates a generator that generates the strings 'November', 'December', 'January' and so on. If the caller supplies an illegal month name, your function should raise a ValueError exception with text explaining the problem. Here is my code: month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] def next_month(name: str) -> str:...
When I wrote this code in the Eclipse program, I did not see a output .....
When I wrote this code in the Eclipse program, I did not see a output .. Why? _______ public class AClass { private int u ; private int v ; public void print(){ } public void set ( int x , int y ) { } public AClass { } public AClass ( int x , int y ) { } } class BClass extends AClass { private int w ; public void print() { System.out.println (" u + v...
I have a product I need to market in the Kingdom of Saudi Arabia I wrote...
I have a product I need to market in the Kingdom of Saudi Arabia I wrote most of the main points but it remains only for me: Marketing Mix (4 P’s ) Analysis Describe each of the 4Ps of your chosen company. Product or Service Identify the product or service by what it is, who will buy it, how much they will pay for it and how much it will cost for the company to produce it, why a consumer...
In writing the background for this weekend’s homework assignment, I realized that I didn’t need to...
In writing the background for this weekend’s homework assignment, I realized that I didn’t need to spend much time with the introduction of the company. Everyone knows Amazon, as a matter of fact, most of us shop on Amazon for many things that we use in our daily life. The company is one of the largest in the world and has over 500,000 employees. The CEO and founder of Amazon, Jeff Bezos, was interviewed at an awards ceremony in 2016...
(i just need an answer for question 4) (i just need an answer for just question...
(i just need an answer for question 4) (i just need an answer for just question 4) you have two facilities, one in Malaysia and one in Indonesia. The variable cost curve in the Malaysian plant is described as follows: VCM = q­ + .0005*q2 , where q is quantity produced in that plant per month. The variable cost curve in the Indonesian plant is described by VCI = .5q + .00075q2, where q is the quantity produced in that...
Respond to at least two classmates with substantial posts. i just need you to respond A...
Respond to at least two classmates with substantial posts. i just need you to respond A diet that is high I protein can be beneficial for many reasons. One benefit of a high protein diet is that it promotes weight loss.To loose weight, one must burn more calories than what they take in. Since protein is a macronutrient, it promotes weight loss. While this seems like a good way to loose weight, it can be problematic for people with kidney...
pls, I need Matlab code for, OFDM modulation (Matlab demo by at least 4 carriers)
pls, I need Matlab code for, OFDM modulation (Matlab demo by at least 4 carriers)
I have completed the first 5 parts just need 6&7 Need to complete it by noon...
I have completed the first 5 parts just need 6&7 Need to complete it by noon pacific time Thanks Problem 6-23 (Algo) Make or Buy Decision [LO6-3] Silven Industries, which manufactures and sells a highly successful line of summer lotions and insect repellents, has decided to diversify in order to stabilize sales throughout the year. A natural area for the company to consider is the production of winter lotions and creams to prevent dry and chapped skin. After considerable research,...
C++ Code (I just need the dieselLocomotive Class) Vehicle Class The vehicle class is the parent...
C++ Code (I just need the dieselLocomotive Class) Vehicle Class The vehicle class is the parent class of the derived class: dieselLocomotive. Their inheritance will be public inheritance so reflect that appropriately in their .h files. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +getSize():int +setName(s:string):void +getName():string +getMap():char** +setMap(s: string):void +getMapAt(x:int, y:int):char +~vehicle() +operator--():void +determineRouteStatistics()=0:void The class variables are as follows: map: A 2D array of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT