Question
/* example of command line parsing via getopt usage: getopt [-dmp] -f fname [-s sname] name [name ...] */ #include #include int debug = 0;
/* example of command line parsing via getopt usage: getopt [-dmp] -f fname [-s sname] name [name ...]
*/
#include
int debug = 0;
int main(int argc, char **argv) { extern char *optarg; extern int optind; int c, err = 0; int mflag=0, pflag=0, fflag = 0, sflag=0; char *sname = "default_sname", *fname; static char usage[] = "usage: %s [-dmp] -f fname [-s sname] name [name ...] ";
while ((c = getopt(argc, argv, "df:mps:")) != -1) switch (c) { case 'd': debug = 1; break; case 'm': mflag = 1; break; case 'p': pflag = 1; break; case 'f': fflag = 1; fname = optarg; break; case 's': sflag = 1; sname = optarg; break; case '?': err = 1; break; } if (fflag == 0) { /* -f was mandatory */ fprintf(stderr, "%s: missing -f option ", argv[0]); fprintf(stderr, usage, argv[0]); exit(1); } else if ((optind+1) > argc) { /* need at least one argument (change +1 to +2 for two, etc. as needeed) */
printf("optind = %d, argc=%d ", optind, argc); fprintf(stderr, "%s: missing name ", argv[0]); fprintf(stderr, usage, argv[0]); exit(1); } else if (err) { fprintf(stderr, usage, argv[0]); exit(1); } /* see what we have */ printf("debug = %d ", debug); printf("pflag = %d ", pflag); printf("mflag = %d ", mflag); printf("fname = \"%s\" ", fname); printf("sname = \"%s\" ", sname); if (optind 1. Learn to work with command line options and arguments 2. Gain more experience with Makefiles 3. Gain more experience with Unix Usage: salary [-p] -h hours [- b bonus] hourlyrate In this assignment, you are asked to do a salary calculation. All information needed for this will be passed to the program on the command line. There will be no user input during the execution of the program. You will need a few pieces of information. The hourly rate for the employee and the number of hours worked. Optionally, you can give a bonus and or a percentage increase (if it was a holiday week or something like that.) To figure the salary follow these steps: 1. Multiply the hourly rate by the number of hours. 2. If there is a precentage increase then multiply the previous result by 10%, which is done by multiplying by 0.10. 3. If there is a bonus then add it to the previous result. p is optional so there may or may not be the percentage increase. h is required and indicates the number of hours worked as an integer. It cannot be more than 80 . - b is optional and would give an integer amount for a bonus. It should not be more than 50% of the calculated salary. You will print out the resulting payment amount as follows. Use rounding to keep money to two decimals and percentages to three decimals
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started