Question

Write a parameterized function that calculates and returns the cost per square inch of a rectangular...

Write a parameterized function that calculates and returns the cost per square inch of a rectangular pizza, given its width, height and price as parameters. The formula for area of a rectangle is width * height.

Homework Answers

Answer #1
//Solution in C++
#include<iostream>
using namespace std;
double calculateCostperSquare(double width,double height,double price){
        double area=width*height;
        double costperSq=area/price;
        return costperSq;
}
int main(){
        double width,height,price;
        cout<<"Enter Width and Height in inches:";
        cin>>width>>height;
        cout<<"Enter Price:";
        cin>>price;
        double costperSq=calculateCostperSquare(width,height,price);
        cout<<"Cost per Square Inch "<<costperSq<<endl;
}
/*
Output
Enter Width and Height in inches:5 6
Enter Price:12
Cost per Square Inch 2.5

--------------------------------
Process exited after 6.477 seconds with return value 0
Press any key to continue . . .
*/
//Solution in C
#include<stdio.h>
double calculateCostperSquare(double width,double height,double price){
        double area=width*height;
        double costperSq=area/price;
        return costperSq;
}
int main(){
        double width,height,price;
        printf("Enter Width and Height in inches:");
        scanf("%lf%lf",&width,&height);
        printf("Enter Price:");
        scanf("%lf",&price);
        double costperSq=calculateCostperSquare(width,height,price);
        printf("Cost per Square Inch %lf ",costperSq);
}
/*
Output
Enter Width and Height in inches:5 6
Enter Price:12
Cost per Square Inch 2.500000
--------------------------------
Process exited after 2.734 seconds with return value 0
Press any key to continue . . .
*/
//Solution in Java
import java.util.Scanner;//import Scanner class
public class CalculateRate {
    static double calculateCostperSquare(double width,double height,double price){
        double area=width*height;
        double costperSq=area/price;
        return costperSq;
}
    public static void main(String[] args) {
           double width,height,price;
            Scanner input=new Scanner(System.in);//input is object of Scanner class which takes System.in as argument.
            System.out.print("Enter Width and Height in inches:");
            width=input.nextDouble();
            height=input.nextDouble();
            System.out.print("Enter Price:");
            price=input.nextDouble();
            double costperSq=calculateCostperSquare(width,height,price);
            System.out.println("Cost per Square Inch "+costperSq);
                   
    }
}
/*
Output
Enter Width and Height in inches:5 6
Enter Price:12
Cost per Square Inch 2.500000
--------------------------------
Process exited after 2.734 seconds with return value 0
Press any key to continue . . .
*/
#Solution in Python
def calculateCostperSquare(width,height,price):
    area=width*height
    costperSq=area/price
    return costperSq

print("Enter Width and Height in inches:")
width=(float(input("")))
height=(float(input("")))
print("Enter Price:");
price=(float(input("")))
costperSq=calculateCostperSquare(width,height,price);
print("Cost per Square Inch {} ".format(costperSq))

'''
output
Enter Width and Height in inches:
5
6
Enter Price:
12
Cost per Square Inch 2.5 



'''
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Java class called Rectangle that represents a rectangular two-dimensional region. It should have following...
Write a Java class called Rectangle that represents a rectangular two-dimensional region. It should have following 4 fields: int x (x-coordinate for its top left corner) int y (y coordinate for its top left corner) double height (height of the rectangle) double width (width of the rectangle) Your rectangle objects should have the following methods: public Rectangle(int newx, int newy, int newwidth, int newheight) Constructor that initializes the x-coordinate, y-coordinate for the top left corner and its width and height....
Write a function name as 'square' that returns the square of input value. For example, the...
Write a function name as 'square' that returns the square of input value. For example, the main function is given: int main(){     cout << "The square of " << n << " is " << square(n) << endl;     return 0; } In c++ simple code.
A rectangular storage container with an open top has a volume of 10 m3 . The...
A rectangular storage container with an open top has a volume of 10 m3 . The length of the base is twice its width. Material for the base costs $10 per sqaure meter and material for the sides costs $6 per square meter. (a) Find an equation for the volume of the box, relating the variables of the height of the box and the width of the base of the box. (b) Use the previous equation to solve for the...
Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum...
Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at least...
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
Part 3. Write a function called totalCost that takes three parameters (shipping cost, cost of one...
Part 3. Write a function called totalCost that takes three parameters (shipping cost, cost of one box, and number of boxes purchased) and returns the total cost which is computed using the following formula: shipping cost + (number of boxes purchased) * (cost of one box). Default values for the parameters are the following: shipping cost is 0, cost of one box is $4, number of boxes is 1. In the main function test your totalCost function with no arguments,...
Call your project as CarpetCost Write a Java to calculate the cost of installing carpeting into...
Call your project as CarpetCost Write a Java to calculate the cost of installing carpeting into a new room. Your program should ask the user to enter a value for the room width (in metres), the room length (in metres) and then calculate and print the cost of the carpeting, the cost of installation, the taxes to be paid (PST (8%) , GST (7%)) and the final overall cost. The carpet cost is $24.95 per square yard and the installation...
Python Jupyter Notebook Write a python function called profit that takes the number of meals (n)...
Python Jupyter Notebook Write a python function called profit that takes the number of meals (n) sold by a restaurant in a month and calculates the monthly profit given the following information: The selling price of each meal is 12 USD (same for all meals) There is a fixed cost of 2500 USD per month regardless of the number of meals sold. There is a variable cost of 6 USD per each meal sold profit= total revenue- total cost =...
5. A competitive firm has a production function described as follows. “Weekly output is the square...
5. A competitive firm has a production function described as follows. “Weekly output is the square root of the minimum of the number of units of capital and the number of units of labor employed per week.” Suppose that in the short run this firm must use 16 units of capital but can vary its amount of labor freely. a) Write down a formula that describes the marginal product of labor in the short run as a function of the...
A competitive firm has a production function described as follows. “Weekly output is the square root...
A competitive firm has a production function described as follows. “Weekly output is the square root of the minimum of the number of units of capital and the number of units of labor employed per week.” Suppose that in the short run this firm must use 16 units of capital but can vary its amount of labor freely. a. Write down a formula that describes the marginal product of labor in the short run as a function of the amount...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT