Question

a. Ask the user for the input of a letter (char type). Write a function that...

a. Ask the user for the input of a letter (char type). Write a function that takes a char as the argument (parameter) and returns the ASCII value of that char back to the caller. Call the function using the char variable and taking input from the user (no validation required). Display the value in ASCII.

b. Write a program that takes a char as the argument (parameter) and uses a loop to interrogate the char, calling a function that is looking for characters with the ASCII code of 97 through 122. Create a loop that goes for 10 times. Display any characters that are not in that range and include a small message.

c. write a program that takes a char as the argument (parameter) and checks to see if it (the char) is a punctuation mark. From within the function display “the character was (was not) a punctuation mark!”.

/*Please answer a,b and c. C++ please. Thank you so much*/

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

#include<iostream>
using namespace std;
//a
int getAscii(char c)
{
   return (int)c;
}
//b
//function that checks whether the given char is in range 97 to 122
//and display message if not in the range
void check(char c)
{
   if(97<=c && c<=122)
   cout<<"Yes "<<c<<" in range 97 to 122\n";
   else
   cout<<"No "<<c<<" is not in range 97 to 122\n";
}
//c
//method to check entered char is a punctuation mark
void check_punct()
{
       char c;
       char p[] ={'.','?','!',',',';',':','-','{','}','[',']','(',')','\'','\"'};
   cout<<"Enter a char:";
   cin>>c;
   for(int i=0;i<15;i++)
   if(c==p[i])
   {
       cout<<"yes "<<c<<" is punctuation mark\n";return;
   }
   cout<<"no "<<c<<" is not a punctuation mark\n";
}
int main()
{
   //a
   char c;
   cout<<"Enter a char:";
   cin>>c;
   //calling method to find ascii value
   cout<<"Ascii value of "<<c<<" is "<<getAscii(c)<<endl;
  
   //b
   int i=0;
   while(i<10)
   {cout<<"Enter a char:";
   cin>>c;
   check(c);
      
       i++;  
   }
  
   //c
   check_punct();
   return 0;
}

output:

Enter a char:c
Ascii value of c is 99
Enter a char:a
Yes a in range 97 to 122
Enter a char:b
Yes b in range 97 to 122
Enter a char:c
Yes c in range 97 to 122
Enter a char:d
Yes d in range 97 to 122
Enter a char:A
No A is not in range 97 to 122
Enter a char:e
Yes e in range 97 to 122
Enter a char:Q
No Q is not in range 97 to 122
Enter a char:$
No $ is not in range 97 to 122
Enter a char:@
No @ is not in range 97 to 122
Enter a char:1
No 1 is not in range 97 to 122
Enter a char:2
no 2 is not a punctuation mark


Process exited normally.
Press any key to continue . . .

Add a comment
Know the answer?
Add Answer to:
a. Ask the user for the input of a letter (char type). Write a function that...
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
  • in C++ Write a program that will take a sentence from the user and uses a...

    in C++ Write a program that will take a sentence from the user and uses a ​for loop​ to convert all lowercase characters to uppercase characters. Then output the converted sentence. Example, if the user enters “Hello World”, your program should output “HELLO WORLD”.​ Recall that the ASCII value of ‘A’ is 65 and the ASCII value of ‘a’ is 97. The ASCII value of ‘Z’ is 90 and the ASCII value of ‘z’ is 122. in c++… we can...

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

  • In the space below, write a C function definition for a function named StrLower, which will...

    In the space below, write a C function definition for a function named StrLower, which will receive one parameter, a pointer to a null-terminated string (i.e., pointer to char), convert each character in the string to lowercase (using the tolower function from <ctype.h>), and return nothing to the caller. Inside the function definition, you may use a for loop or a while loop. If you use any variables other than the incoming parameter, you must define them locally in the...

  • please use pythom Write a program that ask the user for a string as input. It...

    please use pythom Write a program that ask the user for a string as input. It should duplicate of all the characters in the string and print it back out to the user. For example: AbC123 would be printed out as AAbbCC112233 Write a program that takes two lists and displays the items that occur in both lists. For example: ["a", "b", "c"] ["c", "a", "d"] would display a and c

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • Write a function called smallestLetter that takes in a string argument and returns a char. The...

    Write a function called smallestLetter that takes in a string argument and returns a char. The char that is returned by this function is the character in the string with the lowest ASCII integer code. For example: smallestLetter("Hello") returns ‘H’ which is code 72, and smallestLetter("Hello World") returns ‘ ’ (The space character) which is code 32

  • MIPS programming question Problem 1: Write a program that asks the user to input a string...

    MIPS programming question Problem 1: Write a program that asks the user to input a string (or no more than 50 characters). Your program should then output the length of the string. The string length should be determined using a separate function strlen that will accept the address of the string and return its length. For the purposes of this exercise, the length of a string will be defined as the number of non-null and non-newline characters until either the...

  • Write a simple C/C++ function named int match_content(char * file1, char *file2) that would take two...

    Write a simple C/C++ function named int match_content(char * file1, char *file2) that would take two text file name as a parameter, and return 1, if the content is same in both the files, 0 otherwise. Your program should be case insensitive and should support all the ascii characters.

  • 21 Write a program that asks the user to input the length and breadth of a...

    21 Write a program that asks the user to input the length and breadth of a soccer field, and then computes and returns the number of square meters of grass required to cover the field The formula for the area is the product of length and breadth (5) 22 The following program uses the break statement to terminate an infinite while loop to print 5 numbers Rewrite the program to use a while loop to display numbers from 1 to...

  • 14.3: More Sentences Write a program that allows a user to enter a sentence and then...

    14.3: More Sentences Write a program that allows a user to enter a sentence and then the position of two characters in the sentence. The program should then report whether the two characters are identical or different. When the two characters are identical, the program should display the message: <char> and <char> are identical! Note that <char> should be replaced with the characters from the String. See example output below for more information. When the two characters are different, 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