Question

3.1 Specification Develop an ANSI-C program that reads user information from the standard inputs, and outputs the modified ve

uses loop to read inputs (from standard in), one input per line, about the user information in the form of name age wage, whe3.3 Sample Inputs/Outputs: red 118 a.out Enter name, age and wage (exit to quit): si Sue-32-66.600- [66, 67] Sue-32-66.600- [

lab4C.c file contains:

#include <stdio.h>
.....

#define SIZE 10
#define SIZE2 40

int main(int argc, char *argv[])
{

     char input[SIZE2];    
     char name[SIZE];  
     ....
     char resu[SIZE2], resu2[SIZE2], resu3[SIZE2];
        
     printf("Enter name, age and wage (exit to quit): ");
     fgets(input, 40, stdin);
     while (...)
     {    

 

   

        /* use fgets to read again */
        printf("Enter name, age and wage (exit to quit): ");
        fgets(input, 40, stdin);
     } 
      return 0;
}
3.1 Specification Develop an ANSI-C program that reads user information from the standard inputs, and outputs the modified version of the records. 3.2 Implementation Download file 1lab4C.c and start from there. Note that the program
uses loop to read inputs (from standard in), one input per line, about the user information in the form of name age wage, where name is a word (with no space), age is an integer literal, and wage is a floating point literal. See sample input below. uses fgets () to read in a whole line at a time. An brief introduction to fgets is given in problem D2. The program should, after reading each line of inputs, creates a char [40] string resu for the modified version of the input. In the modified version of input, the first letter of name is capitalized, age becomes age 10, and wage has 100% increases with 3 digits after decimal point, followed by the floor and ceiling of the increase wage. The values are separated by dashes and brackets as shown below then duplicate/copy resu to resu2 using a library function declared in (how about strcpy or strcat?) then duplicate/copy resu to resu3 using a library function declared in (how about sprintf?) then output the resulting strings resu, resu2 and resu3 continue reading input, until a line of exit is entered + Hints: When fgets reads in a line, it appends a new line character \n at the end (before \0) Be careful when checking if the input is exit To tokenize a string, consider sscanf To create resu from several variables, consider sprintf If you use math library functions, be aware that the return type is double
3.3 Sample Inputs/Outputs: red 118 a.out Enter name, age and wage (exit to quit): si Sue-32-66.600- [66, 67] Sue-32-66.600- [66, 67] Sue-32-66.600- [66, 67] ue 22 33.3 age and wage (exit to quit): john 60 1.0 Enter name, John-70-2.000- [2,2] John-70-2.000- [2,2] John-70-2.000- [2,2] age and wage (exit to quit): lisa 30 1.34 Enter name, Lisa-40-2.680- [2,3] Lisa-40-2.680- [2,3] Lisa-40-2.680- [2,3 Enter name, age and wage (exit to quit): judy 40 3.2 Judy-50-6.400- [6, 7] Judy-50-6.400- [6,7] Judy-50-6.400- [6,7] Enter name, age and wage (exit to quit): exit red 119 %
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

#include <string.h>

#include <ctype.h>

#include <math.h>

#include <stdlib.h>

int main(void)

{

char name[20];

int age;

float wage;

char newAge[5];

char newWage[5];

char input[40];

char resu[40] = "";

char resu2[40] = "";

char resu3[40] = "";

float floorValue, ceilValue;

char floors[5], ceils[5];

while(strcmp(input, "exit") != 10)

{

printf("Enter name, age and wage (exit to quit): ");

fgets(input, 40, stdin);

if(strcmp(input, "exit") == 10)

{

printf("\nGood Bye!\n");

exit(0);

}

else

{

sscanf(input, "%s %d %f", name, &age, &wage);

name[0] = toupper(name[0]);

age += 10;

wage += wage;

floorValue = floor(wage);

ceilValue = ceil(wage);

strcat(resu, name);

strcat(resu, "-");

sprintf(newAge, "%d", age);

strcat(resu, newAge);

strcat(resu, "-");

sprintf(newWage, "%0.3f", wage);

strcat(resu, newWage);

strcat(resu, "-[");

sprintf(floors, "%d", (int)floorValue);

strcat(resu, floors);

strcat(resu, ", ");

sprintf(ceils, "%d", (int)ceilValue);

strcat(resu, ceils);

strcat(resu, "]");

strcpy(resu2, resu);

sprintf(resu3, resu, "");

printf("%s\n", resu);

printf("%s\n", resu2);

printf("%s\n", resu3);

printf("\n");

strcpy(resu, "");

strcpy(resu2, "");

strcpy(resu3, "");

}

}

return 0;

}

********************************************************************* SCREENSHOT ******************************************************

Enter name, age and wage (exit to quit): sue 22 33.3 Sue-32-66.600- [66, 67] Sue-32-66.600- [66, 67] Sue-32-66.600- [66, 67]

Add a comment
Know the answer?
Add Answer to:
lab4C.c file contains: #include <stdio.h> ..... #define SIZE 10 #define SIZE2 40 int main(int argc, char *argv...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <stdlib.h> #include <stdio.h> #include "main.h" #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc...

    #include <stdlib.h> #include <stdio.h> #include "main.h" #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc < 4) { fprintf(stderr, "usage: %s <input file 1> <input file 2> <output file>\n", argv[0]); exit(EXIT_FAILURE); } } /* This function takes in the two input file names (stored in argv) and determines the number of integers in each file. If the two files both have N integers, return N, otherwise return -1. If one or both of the files do not exist, it...

  • #include <stdio.h> .. int main(int argc, char *argv[]) { int base, power; printf("enter base and power:...

    #include <stdio.h> .. int main(int argc, char *argv[]) { int base, power; printf("enter base and power: "); scanf("%d %d", &base, &power); while (base != -100){ double res = pow(base, power); double res2 = my_pow(base, power); printf("pow: %.4f\n", res); printf("my_pow: %.4f\n", res2); .... } return 0; } // this function should be RECURSIVE // should not use any loop here double my_pow(double base, double p) { } lab4pow.c file contains: 2.1 Specification Write an ANSI-C program that reads input from the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT