Design and write a program, using functions, that calculates the area and perime
ID: 669759 • Letter: D
Question
Design and write a program, using functions, that calculates the area and perimeter of a rectangle whose dimensions (length and width) are provided by a user.
There are 4 components of your submission including:
Program Description- A detailed, clear description of the program you are building.
Analysis- Demonstrates your thought process and steps used to analyze the problem. Be sure to include the required input and output and how you will obtain the required output from the given input? Also, include your variable names and definitions. Be sure to describe the necessary formulas and sample calculations that might be needed. Talk about how your design will allow any number of students and final grades to be possible inputs.
Test plan - Prepare at least 3 sets of input data (Test data) along with their expected output for testing your program. Your test data can be presented in the form of a table as follows (note: feel free to adapt to your design)
Pseudocode- Provide pseudocode of your overall design that fulfills the requirements of the project
All of these components should be placed in word document for submission.
Explanation / Answer
Provided 4 components as per your requirements.
1) Program Description:
C Program Code:
//Header file section
#include<stdio.h>
//Function prototypes
float calcArea(float length, float width);
float calcPerimeter(float length, float width);
//main method
int main()
{
//Declare variables
float length,width;
float resArea,resPer;
//Prompt and read input from the user
printf("Enter length of the rectangle: ");
scanf("%f",&length);
while(length<0)
{
printf("Enter Length Again {Negative Values Not Allowed}: ");
scanf("%f",&length);
}
printf("Enter width of the rectangle: ");
scanf("%f",&width);
while(width<0)
{
printf("Enter Width Again {Negative Values Not Allowed}: ");
scanf("%f",&width);
}
resArea=calcArea(length,width);
resPer=calcPerimeter(length,width);
//Display output
printf("Area of a rectangle = %.2f Perimter of a rectangle= %.2f ",resArea, resPer);
return 0;
}
//Function definition of calcArea to compute the area of a rectangle area =l*b
float calcArea(float length, float width)
{
return length*width;
}
//Function definition of calcPerimeter to compute the perimeter of a rectangle p =2(l+b)
float calcPerimeter(float length, float width)
{
return 2*(length+ width);
}
2) Analysis:
Program contains three modules: main, calcArea, and calcPermiter.
In main:
calcArea function:
calcPermiter function:
3) Test plan:
Prepared three sets of input data (Test data) along with their expected output for testing your program. Your test data can be presented in the form of a table as follows:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.