Question

In: Computer Science

C++ Question: write a program that prompts the user for the length and width of a...

C++ Question:

write a program that prompts the user for the length and width of a rectangle in inches.  The program then uses functions to compute the perimeter and area of the rectangle and to convert those to meters and square meters respectively.

Sample output

from one instance of the program is shown below:

```html

Welcome to the Foot-To-Meter Rectangle Calculator

=================================================

Enter the rectangle length in feet: 2

Enter the rectangle width in feet: 3

The rectangle dimensions are: 0.61 meters by 0.91 meters.

The rectangle perimeter is: 3.05 meters.

The rectangle area is: 0.56 square meters.

Your solution to this problem must meet the following criteria.

1. You must prototype and define three functions.  

Examples of the function prototypes are shown below.  

Within the `feetToMeters` function, declare a constant

with value 0.3048 (the number of meters in a foot) to assist with the conversion.

```c++

// return the perimeter of a rectangle with a given length (1st parameter)

//  and width (2nd parameter)

float perimeter(float, float);

// return the area of a rectangle with a given length (1st parameter)

//  and width (2nd parameter)

float area(float, float);

// return the number of meters of a given dimension (2nd parameter) that

//  corresponds to a number of feet (1st parameter) of the same dimension

//  (dimension 1 = linear, 2 = square, 3 = cubic, etc.)

float feetToMeters(float,short);

Solutions

Expert Solution

// Program to compute the perimeter and area of the rectangle and to convert those to meters and square meters respectively by using functions.

#include <iostream>
#include <cmath>

using namespace std;
float mtrlength,mtrbreadth;
float feetToMeters(float l,float b)
{
//float

mtrlength=l*0.3048;
mtrbreadth=b*0.3048;
cout<<"the rectangle dimensions are" <<mtrlength<<"meter"<<mtrbreadth<<"meter";
//return mtrbreadth;
}

float perimeter(float mtrlength,float mtrbreadth)
{
float p=2*(mtrlength+mtrbreadth);
return p;
}

double area(float mtrlength,float mtrbreadth)
{
double a=mtrlength*mtrbreadth;
return a;
}
int main()
{
float length,breadth;
cout<<"Enter the rectangle length in feet";
cin>>length;
cout<<"Enter the rectangle width in feet";
cin>>breadth;

float finallength=feetToMeters(length,breadth);

float peri=perimeter(mtrlength,mtrbreadth);
cout<<"\nthe rectangle perimeter is"<< peri;

double are=area(mtrlength,mtrbreadth);
cout<<"\nthe rectangle area is"<< are;


return 0;
}

Screen Shot:

Another Example:


Related Solutions

write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
Write a program in C that prompts the user for a number of seconds and then...
Write a program in C that prompts the user for a number of seconds and then converts it to h:m:s format. Example: 5000 seconds should display as 1:23:20 (1 hour, 23 minutes, 20 seconds.) Test with several values between about 100 seconds and 10,000 seconds. use unint and remainders for this and keep it as simple as possible.
1. Write a Python program that will ask the user length and width of the right...
1. Write a Python program that will ask the user length and width of the right triangle and find the area of the right-angled triangle. The formula for finding the area of a right-angle triangle is ab/2. Also, find out the result if you calculate as (ab)/2. Is it the same? If it is same, why it is the same. If it is not the same, why it is not the same.
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
C++ Program: Write a program that prompts the user for two numbers and stores them in...
C++ Program: Write a program that prompts the user for two numbers and stores them in signed integers. The program should then add those two numbers together and store the result in a signed integer and display the result. Your program should then multiply them by each other and store the result in another integer and display the result. Then do the same but with dividing the first number by the second. Display an error message to the screen if...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT