Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c programming, mutiple files You are to create a program that reads the dimensio

ID: 3689772 • Letter: C

Question

c programming, mutiple files

You are to create a program that reads the dimensions of geometric shapes trom command line and computes and outputs the area of the shape. Your program will consist of multiple files as follows. Create a header file geometry.h and add to it the following: A marcro definition for the constant P A prototype definition for the function computeCircleArea. This function takes as input the radius of a circle and returns its area . A prototype definition for the function computeRectancleArea. This function takes as input the length and width of a rectangle and outputs its area. . Create a source file geometry.c and add to it the definition of the two functions. Create your main program areas.c so it reads the parameters from command line. If the shape is a circle, the command line parameter should be the letter C followed by the radius. If the shape is a rectangle, the command line parameters should be the letter R followed by the length and the width. The following is an example oTVaila parameers. >a.out R 12.5 14.2 >a.out C 3.6 >a.out C 10.2 Your program should compute the area according to the parameters given. If the program is given invalid parameters, it should display an error message to the user and exit. The outputs corresponding to the previous examples are: C 40.7 C 326.8

Explanation / Answer

#include <stdio.h>

void main()
{
int fig_code;
float side, base, length, breadth, height, area, radius;

printf("------------------------- ");
printf(" 1 --> Circle ");
printf(" 2 --> Rectangle ");
printf(" 3 --> Triangle ");
printf(" 4 --> Square ");
printf("------------------------- ");
printf("Enter the Figure code ");
scanf("%d", &fig_code);
switch(fig_code)
{
case 1:
printf("Enter the radius ");
scanf("%f", &radius);
area = 3.142 * radius * radius;
printf("Area of a circle = %f ", area);
break;
case 2:
printf("Enter the breadth and length ");
scanf("%f %f", &breadth, &length);
area = breadth * length;
printf("Area of a Reactangle = %f ", area);
break;
case 3:
printf("Enter the base and height ");
scanf("%f %f", &base, &height);
area = 0.5 * base * height;
printf("Area of a Triangle = %f ", area);
break;
case 4:
printf("Enter the side ");
scanf("%f", &side);
area = side * side;
printf("Area of a Square=%f ", area);
break;
default:
printf("Error in figure code ");
break;
}
}

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