Splitting into multiple files You are to create a program that reads the dimensi
ID: 3690442 • Letter: S
Question
Splitting into multiple files You are to create a program that reads the dimensions of geometric shapes from command line and computes and outputs the area of the shape.Your program will consist of multiple Sles as follows Create a header file geometry h and add to it the following A marcro definition for the constant Pl . 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 cincle 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 of valid parameters 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 iven invalld parameters, i should display an error message to the user and exit. The outputs comesponding to the previous examples are C 40.7 C 326.8 Note that the numeric values read from command line are read as strings. Use the function atof defined as: double atof foonst char "stz) in stdib h to convert from string to loat as needed Use the following to compile and build your program goc-areas areas.c geonetry.h geometry c Test your program on the given examples as well as some other invalid inputs Using a makefile Create a makefile to build your program: Add the folilowing rule: areas: areas o geometryo gcc -o areas areas.o geometry. Make sure the second line of your rule starts with tab and not spaces Build your program by executing the makefile: Does your program build successfully? The building process needs to know about the dependencies Add the folowing rule to your makefile areas.o: areas.c geonetry.h gce areas-
Explanation / Answer
Geometry.h #include #include #DEFINE pi 3.14 void Computecirclearea(int radius) { int areacir=pi*radius*radius*; return areacir; } void Computerectanglearea(int length,int breadth) { int arearect=length*breadth; return arearect; } #include #include int main(int argc, char *argv[]) { double length,breadth,radius; radius=atof(argv[0]); length=atof(argv[1]); breadth=atof(argv[2]); if(argc==”C”) { double areacircle= areacir(radius); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.