Question

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 <ctype.h>

o Use the function tolower in #include <ctype.h>
• You will create a numerical version of both the upper- and lower-case versions of the character

o NOTE: for characters that are not letters both upper and lower will be the sameo Example:

  • int upperNumber = (int)upper;

  • int lowerNumber = (int)lower;

• You will create a character version each integer entered by the user (positive or negative)

o Example:
• char CharacterN = (char)numberInput;

  • You will ask the user if they want to Enter a (1) to enter a character --- (2) to enter a number or --- (0) to Quit

  • You must have at least 6 user defined functions as follows:

o No modifications may be made to the functions

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <ctype.h>


//greets the user

void Greeting();
//Asks, gets, and returns the users option (1, 2, or 0)

int UserDecision();

//Declare a character
//Ask, get, and return the characterchar GetLetter();

//Declare an integer
//Ask, get, and return the integerint GetInt();

//input: a character
//creates a lowercase and uppercase version of the character //finds the numerical versions of the characters
//prints the results onto the screen
void ProcessCharacterInput(char characterInput);

//input: an integer
//finds a corresponding character for the integer (if there is one) //returns the character version of the integer
char ProcessIntegerInput(int numberInput);

Additional Requirements:

  • Use function prototypes.

  • Write comments for each function that will appear in the file before each prototype and again before each

    function definition.

  • Be sure to comment your code adequately.

  • Be sure to indent properly. Check your textbook and lecture code examples to see how it should be done.

  • Use meaningful variable names

    **PLEASE MAKE SURE CODE MATCHES SAMPLE OUTPUT**

  • SAMPLE OUTPUT:   

    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 Enter a character: k
    The capital letter is K and the numerical value is 75
    The lowercase letter is k and the numerical value is 107 -------------------------------------------------------------------------

    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

    Enter a character: &

    The capital letter is & and the numerical value is 38

    The lowercase letter is & and the numerical value is 38

    ------------------------------------------------------------------------- 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 Enter a number: -32

    The corresponding character for -32 is α-------------------------------------------------------------------------

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 Enter a number: 241

The corresponding character for 241 is ± ------------------------------------------------------------------------- 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 . . .

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

//C program

#include <stdio.h>

#include <ctype.h>


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


int UserDecision(){
   int choice;
   printf("Would you like to enter a character or a number? ");
   printf("(ENTER (1) to enter a character, (2) to enter a number, (0) to quit) >> ");
   scanf("%d",&choice);
   return choice;
}
//Declare a character
//Ask, get, and return the character
char GetLetter(){
   char ch;
   printf("Enter a character: ");
   scanf(" %c",&ch);
   return ch;
}

//Declare an integer
//Ask, get, and return the integer
int GetInt(){
   int n;
   printf("Enter a number: ");
   scanf("%d",&n);
   return n;
}

//input: a character
//creates a lowercase and uppercase version of the character //finds the numerical versions of the characters
//prints the results onto the screen
void ProcessCharacterInput(char characterInput){
   char upper = toupper(characterInput);
   char lower = tolower(characterInput);
   printf("The capital letter is %c and the numerical value is %d ",upper ,(int)upper);
   printf("The lowercase letter is %c and the numerical value is %d ",lower ,(int)lower);
}

//input: an integer
//finds a corresponding character for the integer (if there is one) //returns the character version of the integer
char ProcessIntegerInput(int numberInput){
   printf("The corresponding character for %d is %c ",numberInput ,(char)numberInput);
}

int main(){
   Greeting();
   int choice ;
   do{
       choice=UserDecision();
       switch(choice){
           case 1:{
               char ch=GetLetter();
               ProcessCharacterInput(ch);
               break;
           }
           case 2:{
               int n =GetInt();
               ProcessIntegerInput(n);
               break;
           }
           case 0:{
               printf("Goodbye! ");
               break;
           }
           default:{
               printf("Invalid input ");
               break;
           }
       }
      
   }while(choice!=0);
   return 0;
}

//sample output

Add a comment
Know the answer?
Add Answer to:
Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To...
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
  • General Requirements . . . Write a program that reads letters from a file called "letters.txt"....

    General Requirements . . . Write a program that reads letters from a file called "letters.txt". Your program will open the letters.txt file read in one character at a time For this assignment the test file will contain at least 30 letters, uppercase OR lowercase In your program you will change each letter (solution) to uppercase Use the function toupper in #include <ctype.h> You create a numerical version of the uppercase letter from the file . o Use int numberSolution...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Please create the following program in C format with Visual Studio Declare any variables needed Print...

    Please create the following program in C format with Visual Studio Declare any variables needed Print “Hello my name is (add your name here)” onto the screen. Ask the user for a number. Scan the number from the user. Multiply the number by 123. Print the original number and the product back onto the screen. Ask the user for a letter. Scan the letter from the user. Make an uppercase and a lowercase version of the letter (use toupper and...

  • 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...

  • Python Ask the user to enter a character and find out if the character is numeric...

    Python Ask the user to enter a character and find out if the character is numeric (a digit from 0-9), an uppercase letter, a lowercase letter, or none of these. Remember that all characters are defined by ASCII codes, and you do not need to convert the input to int or float. You can just compare it with other values. For example, if the entered character is between 'a an d 'z, the character is a lowercase letter.

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • 6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you...

    6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...

  • I need help programming this program in C. 1.) Write a program that reads a message,...

    I need help programming this program in C. 1.) Write a program that reads a message, then checks whether it's a palindrome (the letters in the message are the same from left to right as from right to left), example is shown below: Enter a message: He lived as a devil, eh? Palindrome Enter a message: Madam, I am Adam. Not a Palindrome 2.) Ignore all characters that aren't letters. Use integer variables to keep track of positions in the...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

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