Question

In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the...

In C code

1. Write and submit the algorithm OR flowchart to indicate you understand the problem

2. Create a project and name the source code lastname_firstname_prog5.c

3. Use the prog5.c as a guide, copy/ paste into your project source code

*** build run and test, the outline code - You will need to declare an integer variable called again and initialize it

4. Add the function prototype and implement the function definition for the Greeting function

5. Add the function call to Greeting in the main function

*** build run and test Now it is time to Implement the UserDecision function

6. Add the function prototype and Implement the function definition for the UserDecision function

7. Function definition: a. Declare an integer b. Use printf statements to ask the user what they want to enter (1), (2), (0) c. Scan into the integer d. Return the integer value

8. Call the function twice from the main function a. before the while loop(initialization) b. inside the while loop(update)

9. The integer that is returned from this function will be assigned to the variable again

*** build run and test (try entering a 1, a 2, and a 0)

SAMPLE OUTPUT AT THIS STEP: Welcome to the number/ character converter! This program converts characters to numbers and numbers to characters --You may enter any single character on the keyboard --You may enter any integer value, negative or positive --You may be surprised by the output!! ------------------------------------------------------------------------- Would you like to enter a character or a number? (ENTER (1) to enter a character, (2) to enter a number, (0) to quit) >> 1 ------------------------------------------------------------------------- Would you like to enter a character or a number? (ENTER (1) to enter a character, (2) to enter a number, (0) to quit) >> 2 ------------------------------------------------------------------------- Would you like to enter a character or a number? (ENTER (1) to enter a character, (2) to enter a number, (0) to quit) >> 0 Press any key to continue . . .

10. Now add the message for the user if anything other than a 0, 1, or 2 is entered (the else inside the while loop)

***build/run and test

11. Now it is time to implement the GetCharacter function, add the prototype and definition,

12. Function definition: a. Declare a character b. Prompt for the character c. Read (scanf) the character – REMEMBER TO ADD the space between “ and % scanf(“ %c”, &tempchar); d. Return the character

13. Add the function call (inside the block of code if again == 1)

***build/run and test – Add a printf statements to test that everything is working as instructed

14. The next function to implement will be the ProcessCharacterInput function, add the prototype and definition

15. Function definition: a. Declare 2 characters and 2 integer variables b. Use toupper and tolower functions to assign an uppercase version and a lowercase version of the characterInput function argument variable c. Use (int) type casting to assign the numerical value for the 2 characters (upper and lower) d. Print all 4 results onto the screen

16. Add the function call and pass the character that was returned from GetCharacter function

***build/run and test

17. Now it is time to implement the GetInt function, add the prototype and definition.

18. Function definition: a. Declare an integer b. Prompt for the integer c. Read (scanf) the integer – DO NOT ADD A SPACE for an integer d. Return the integer

19. Add the function call (inside the block of code if again == 2)

***build/run and test – Add a printf statements to test that everything is working as instructed

20. The next function to implement will be the ProcessIntegerInput function, add the prototype and definition

21. Function definition: a. Declare 1 character b. Use (char) type casting to assign the character version of the integer argument c. Return the character

22. Add the function call and pass the character that was returned from GetInteger function

23. Print the original integer and the character onto the screen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C program to implement an application for Character and Integer conversion

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

// function declaration

void Greeting();

int UserDecision();

char GetCharacter();

void ProcessCharacterInput(char ch);

int GetInt();

char ProcessIntegerInput(int in);

int main(void) {

               int choice;

               Greeting();

               choice = UserDecision();

               while(choice != 0) //loop that continues till the user quits

               {

                              if(choice == 1) // character to integer

                              {

                                             ProcessCharacterInput(GetCharacter());

                              }else if(choice == 2) // integer to character

                              {

                                             int in = GetInt();

                                             char ch = ProcessIntegerInput(in);

                                             printf(" Integer : %d Character : %c",in,ch);

                              }else if(choice == 0) // quit

                                             break;

                              else

                                             printf(" Invalid choice. Valid choices are 0,1 or 2");

                              choice = UserDecision();

               }

               return EXIT_SUCCESS;

}

// function to display greetings to user

void Greeting()

{

               fflush(stdout);

               printf(" Welcome to the number/ character converter! This program converts characters to numbers and numbers to characters");

               printf(" --You may enter any single character on the keyboard --You may enter any integer value, negative or positive --You may be surprised by the output!! ");

               printf(" ------------------------------------------------------------------------- ");

}

// function to get the input for user's choice

int UserDecision()

{

               int choice;

               printf(" Would you like to enter a character or a number? (ENTER (1) to enter a character, (2) to enter a number, (0) to quit) : ");

               fflush(stdout);

               scanf("%d",&choice);

               return choice;

}

// function to get and return an input character

char GetCharacter()

{

               char ch;

               printf(" Enter a character : ");

               fflush(stdout);

               scanf(" %c",&ch);

               return ch;

}

// function to convert the character to integer and print them

void ProcessCharacterInput(char ch)

{

               char chUpper, chLower;

               int inUpper, inLower;

               chUpper = toupper(ch);

               chLower = tolower(ch);

               inUpper = (int)chUpper;

               inLower = (int)chLower;

               printf(" Upper Character : %c Integer value : %d Lower Character : %c Integer value : %d",chUpper,inUpper,chLower,inLower);

}

// function to get and return an input integer

int GetInt()

{

               int in;

               printf(" Enter an integer : ");

               fflush(stdout);

               scanf("%d",&in);

               return in;

}

// function to convert an integer to character

char ProcessIntegerInput(int in)

{

               char ch;

               ch = (char)in;

               return ch;

}

//end of program

Output:

Add a comment
Know the answer?
Add Answer to:
In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the...
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
  • Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To...

    Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To compile, build, and execute an interactive program with a simple loop, conditions, user defined functions and library functions from stdio.h and ctype.h. You will write a program that will convert characters to integers and integers to characters General Requirements • In your program you will change each letter entered by the user to both uppercase AND lowercase– o Use the function toupper in #include...

  • Must Follow Example code //Add name, date, and description here //preprocessor directives #de fine CRT SECURE...

    Must Follow Example code //Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS #includestdio.h> - //Calculate the cost of the gas on a trip /Ideclare, ask, and get the price per gallon and the mpg /Icalculate and return (by reference) the cost of gas for the number of miles passed to the function void GasCost (double miles, double *gasTotalPtr) //using a 70 MPH speed limit and the miles passed to the function //calculate and return...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • In basic c develop the code below: (a) You will write a program that will do...

    In basic c develop the code below: (a) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘X’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘X’. Example input mJ0*5/]+x1@3qcxX The ‘X’ should not be included when computing the statistics...

  • //Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS ...

    Complete the incomplete code provided //Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS #includestdio.h> - //Calculate the cost of the gas on a trip /Ideclare, ask, and get the price per gallon and the mpg /Icalculate and return (by reference) the cost of gas for the number of miles passed to the function void GasCost (double miles, double *gasTotalPtr) //using a 70 MPH speed limit and the miles passed to the function //calculate and...

  • Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int...

    Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...

  • The cosine function is analytically defined as follows: m 1. x² + x6 (-1)" x2m COS...

    The cosine function is analytically defined as follows: m 1. x² + x6 (-1)" x2m COS X = (-1)" x2n (2n)! 2!*4!- 6 + ... + (2m)! Write a complete C program that has three functions: main, cosine, and factorial. The cosine function receives a real number x and returns a real number representing the cosine of x. The cosine function also receives another integer m that determines the number of terms that will be used in computing the cosine...

  • Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string"...

    Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string" is a sequence of characters. In the C language anything within double quotes is a "string constant" so you have been seeing strings all semester. But we can also have string variables. In the C language these are implemented as an array of char, e.g. char name (10]: In order to make these variables easier to work with, it has been universally agreed that...

  • Working in C, modify the algorithm created in the Topic 1 assignment "Non-Linear Flow Chart" to...

    Working in C, modify the algorithm created in the Topic 1 assignment "Non-Linear Flow Chart" to instead compute the nth term in the series by calling a recursive function. Note that the value of "n" will need to be an input argument, along with the two starting values of the series. Discuss the efficiency of this method versus the iterative logic that you wrote previously. Previous Code: //main.c #include<stdio.h> #include<limits.h> int main() {    //declare a integer data type variales...

  • ****Using C and only C**** I have some C code that has the function addRecord, to...

    ****Using C and only C**** I have some C code that has the function addRecord, to add a record to a linked list of records. However, when I run it, the program exits after asking the user to input the address. See picture below: Here is my code: #include<stdio.h> #include<stdlib.h> struct record { int accountno; char name[25]; char address[80]; struct record* next; }; void addRecord(struct record* newRecord) //Function For Adding Record at last in a SinglyLinkedList { struct record *current,*start,*temp;...

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