#define _USE_MATH_DEFINES

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>

#ifndef M_PI
#define M_PI acos(-1.0)
#endif

// our first use of the function prototype to provide adeclaration before use.
// note the function implementation is placed after usage inmain.
// function prototype or declarations is considered good form, eventhough the language doesnt require such
void PrintExitBanner(const char *, const char *);

_Bool bHasError = false;

// note the use of the const specifier on these fourstrings
// these are literals that should not change during the lifetime ofthe program execution
//
// try adding this to the program and observe the output generatedduring compilation phase
// dueDate[0]=’S’; dueDate[1]=’u’; dueDate[2]=’n’;
const char *assignmentID = “Project 02”;
const char *classId = “CSC-250 Computer Science II (a.k.a. C II)Spring 2017”;
const char *programmerName = “Roy Fine”;
const char *dueDate = “Monday AM, February 6, 2017”;

void print_usage(void)
{
printf(“usage:n”
” Project 02 compute area/volume for common geometricshapesn”
” area calcualtors:n”
” square widthn”
” circle radiusn”
” annulus inner_radius outer_radiusn”
” volume calculators:n”
” square_prism width heightn”
” cylinder radius heightn”
” torus minor_radius major_radiusn”
” example:n”
” square_prism 4 12n”
” cylinder 32 320n”
” torus 17 45n”);
}

_Bool HasSilentFlag(int argc, char *argv[])
{
for (size_t n = 1; n < (unsigned int)argc; n++)
{
if (0 == strcmp(“-quiet”, argv[n]))
return true;
}
  
return false;
}

void PrintEntryBanner(const char *sAssignID, const char*sClassID, const char *sDate, const char *sDeveloper)
{
// Is the multiline C string literal a new form?
// Adjacent string literal tokens are concatenated (during phase 6)into a single literal token
// See 6.4.5 String literals, paragraph 5 (Semantics) of C 2011Language Standard (N1570.pdf draft)
  
// It is not until compilation phase 6 that the C string nullterminator char is appended,
// and that is why the following produces one C string and not5…
printf(“n————————————————————————–n”
“Project ID: %sn”
“Class ID: %sn”
“Program Due Date: %sn”
“Programmer ID: %snn”, sAssignID, sClassID, sDate,sDeveloper);
}

//===============================================================
// main – this is where all of the action occurs…
//===============================================================
int main(int argc, char *argv[])
{
// dueDate[0] = ‘S’; dueDate[1] = ‘u’; dueDate[2] = ‘n’;
  
if (argc < 2)
{
print_usage(); // if no args, then show usage and quit early
return 0;
}

if (!HasSilentFlag(argc, argv))
{
PrintEntryBanner(assignmentID, classId, dueDate,programmerName);
}

char *completionStatus = “Success”; // set this to Success here.on error we will reset it to appropriate messaging

// C is missing the case insensitive compare – so we coerce inputarg to lower case, and compare on that
// OH MY – we are modifying a string that we do not have ownershipof. In general, that is a very very very bad thing to do
// If the modifying of arguments stings would result in eitherundefined or unspecified behavior as covered in Annex J of C 2011Language Standard (draft as of N1570), then you must fix this
// Hint — check Section 5.1.2.2.1, paragraph 2 of C 2011 LanguageStandard (N1570.pdf draft)
for (char *p = argv[1]; *p; p++)
{
if (isalpha(*p) && isupper(*p))
{
*p = (char)tolower(*p);
}
}

// step throug hthe possible candidates – test for each
// if we find a request that we handle, we do so, else we move tothe end
// if we get to the end and find we have not handled the request(e.g. the final else)
// we treat that as as error and report

// for each case that we handle, do a modest amount of inputvalidation
// make sure width, widsth, radius are non-negative
// where appropriate, validate relationships

if (0 == strcmp(argv[1], “square”) && (argc >=3))
{
double base = atof(argv[2]);
if (base >= 0.0)
{
double area = base * base;
printf(“%18s: base: %.2lf area: %.2fn”, “square”, base,area);
}
else
{
printf(“%18s: base: %.2lf ***> error <*** Bad Datan”,”square”, base);
bHasError = true;
completionStatus = “***> error <*** square(bad data)”;
}
}
else if (0 == strcmp(argv[1], “circle”) && (argc >=3))
{
double radius = atof(argv[2]);
if (radius >= 0.0)
{
double area = radius * radius * M_PI;
printf(“%18s: radius: %.2lf area: %.2fn”, “circle”, radius,area);
}
else
{
printf(“%18s: radius: %.2lf ***> error <*** Bad Datan”,”circle”, radius);
bHasError = true;
completionStatus = “***> error <*** circle(bad data)”;
}
}
else if (0 == strcmp(argv[1], “annulus”) && (argc >=4))
{
double inner_radius = atof(argv[2]);
double outer_radius = atof(argv[3]);
if ((inner_radius >= 0.0) && (outer_radius >= 0.0)&& (inner_radius <= outer_radius))
{
double area = (outer_radius*outer_radius -inner_radius*inner_radius) * M_PI;
printf(“%18s: inner radius: %.2lf outer radius: %.2lf area:%.2fn”, “annulus”, inner_radius, outer_radius, area);
}
else
{
printf(“%18s: inner_radius: %.2lf outer_radius: %.2lf ***> error<*** Bad Datan”, “annulus”, inner_radius, outer_radius);
bHasError = true;
completionStatus = “***> error <*** annulus(bad data)”;
}
}
else if (0 == strcmp(argv[1], “square_prism”) && (argc>= 4))
{
double width = atof(argv[2]);
double height = atof(argv[3]);
if ((width >= 0.0) && (height >= 0.0))
{
double volume = (width*width) * height;
printf(“%18s: width: %.2lf height: %.2lf volume: %.2fn”,”square_prism”, width, height, volume);
}
else
{
printf(“%18s: width: %.2lf height: %.2lf ***> error <*** BadDatan”, “square_prism”, width, height);
bHasError = true;
completionStatus = “***> error <*** square_prism(baddata)”;
}
}
else if (0 == strcmp(argv[1], “cylinder”) && (argc >=4))
{
double radius = atof(argv[2]);
double height = atof(argv[3]);
if ((radius >= 0.0) && (height >= 0.0))
{
double volume = height * radius * radius * M_PI;
printf(“%18s: radius: %.2lf height: %.2lf volume: %.2fn”,”cylinder”, radius, height, volume);
}
else
{
printf(” cylinder: radius: %.2lf height: %.2lf ***> error<*** Bad Datan”, radius, height);
bHasError = true;
completionStatus = “***> error <*** cylinder(baddata)”;
}
}
else if (0 == strcmp(argv[1], “torus”) && (argc >=4))
{
double minor_radius = atof(argv[2]);
double major_radius = atof(argv[3]);
if (minor_radius <= major_radius)
{
if ((minor_radius >= 0.0) && (major_radius >=0.0))
{
double volume = (minor_radius*minor_radius * major_radius) * M_PI *M_PI * 2;
printf(“%18s: minor radius: %.2lf major radius: %.2lf volume:%.2fn”, “torus”, minor_radius, major_radius, volume);
}
else
{
printf(“%18s: minor radius: %.2lf major radius: %.2lf ***> error<*** Bad Data(negative data)n”, “torus”, minor_radius,major_radius);
bHasError = true;
completionStatus = “***> error <*** torus(bad data)”;
}
}
else
{
printf(” torus: minor radius: %.2lf major radius: %.2lf ***>error <*** Bad Data(invalid radii)n”, minor_radius,major_radius);
bHasError = true;
completionStatus = “***> error <*** torus(bad data)”;
}
}
else
{
printf(” unknown or unhandled shape: %sn”, argv[1]);
bHasError = true;
completionStatus = “***> error <*** unknown shape”;
}

if (!HasSilentFlag(argc, argv) || bHasError)
PrintExitBanner(assignmentID, completionStatus);

return 0;
}

void PrintExitBanner(const char * sAssignID, const char *sComplStatus)
{
printf(“nProject ID: %sn”
“Compeletion Status: %sn”, sAssignID, sComplStatus);
}

We are supplied a program in source form that computes Areas and volumes for a set of shapes. The program is called Project 02 To compute the area of a shape, enter the name of the 2 dimensional geometric shape along wit the relevant dimensions Circle radius Project 02 circle 100 Project 02 annulus 10 100 To compute the volume of a shape, enter the name of the 3 dimensional geometric shape along wit the relevant dimensions torus Show transcribed image text We are supplied a program in source form that computes Areas and volumes for a set of shapes. The program is called Project 02 To compute the area of a shape, enter the name of the 2 dimensional geometric shape along wit the relevant dimensions Circle radius Project 02 circle 100 Project 02 annulus 10 100 To compute the volume of a shape, enter the name of the 3 dimensional geometric shape along wit the relevant dimensions torus