Question

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() twice to display the results of the integer values as well as the character values.

showBiggest

Note that the function to display the largest integer has been written. You must write the function to display the largest character. This function considers uppercase letters to be "bigger" than lowercase letters. Note: your program needs to handle the fact that the ASCII values for uppercase are lower than those for lowercase. And finally, this function displays an error message if any of the characters is not alphabetic.

Input Validation

  1. For the purposes of this program, it is OK to assume the user enters valid integers for the first 3 inputs.
  2. For the 3 character inputs, display an error message if the user enters anything other than an alphabetic character for any of the 3 characters.

Hints

  1. Use functions from the library, such as isupper, islower, isalpha.
  2. Keep in mind that the numeric ASCII values for uppercase characters are lower than those for lowercase characters, and make sure your program handles this.
  3. Don't forget to add comments to explain what the code is doing and where control of the program is executing.
  4. Choose variable names and function names that describe the purpose of the variable.

Sample Output

Please enter 3 integers: 89 33 210

The biggest number from the set (89, 33, 210) is 210

Please enter 3 characters: c F z

The biggest character from the set (c, F, z) is F
Please enter 3 integers: 2 3 4

The biggest number from the set (2, 3, 4) is 4

Please enter 3 characters: U 4 e

All characters must be alphabetic
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program code to copy:-

#include <iostream>

using namespace std;

//Function to accept three integer as parameter and prints
//the largest integer
void showBiggest(int n1, int n2, int n3)
{
   //Assuming first integer as biggest integer
   int biggest = n1;
  
   //Comparing second integer with biggest integer
   if(n2>biggest)
       biggest = n2;
   //Comparing third integer with biggest integer
   if(n3>biggest)
       biggest = n3;
      
   //Printing biggest integer
   cout << biggest << endl;
}

//Function to accept three character as parameter and prints
//the largest charcater.
//This function considers uppercase letters to be "bigger" than lowercase letters.
void showBiggest(char c1, char c2, char c3)
{  
   //Assuming first character as biggest character
   char biggest = c1;
  
   //Checking second character with biggest character.
   if(isupper(c2) && isupper(biggest))
   {
       //When both characters are in upper case then no handling is required
       if(c2>biggest)
           biggest = c2;
   }
   else
       if(islower(c2) && islower(biggest))
       {
           //When both characters are in lower case then no handling is required
           if(c2>biggest)
               biggest = c2;
       }
       else
           //When one characters is in lower case and other character is in upper case
           //then considering uppercase letters are "bigger" than lowercase letters.
           if(c2<biggest)
               biggest = c2;

   //Checking third character with biggest character
   if(isupper(c3) && isupper(biggest))
   {
       //When both characters are in upper case then no handling is required
       if(c3>biggest)
           biggest = c3;
   }
   else
       if(islower(c3) && islower(biggest))
       {
           //When both characters are in lower case then no handling is required
           if(c3>biggest)
               biggest = c3;
       }
       else
          //When one characters is in lower case and other character is in upper case
           //then considering uppercase letters are "bigger" than lowercase letters.
           if(c3<biggest)
               biggest = c3;

   //Printing biggest integer
   cout << biggest << endl;
}

int main()
{
   int num1, num2, num3;
   char ch1, ch2, ch3;
  
   //Prompt and read three integers from user
   cout << "Please enter 3 integers: ";
   cin >> num1 >> num2 >> num3;
  
   cout << "The biggest number from the set ("
   << num1 << "," << num2 << "," << num3 << ") is ";
   //calling function to print biggest integer
   showBiggest(num1, num2, num3);
  
   //Prompt and read three characters from user
   cout << "Please enter 3 characters: ";
   cin >> ch1 >> ch2 >> ch3;
  
   //Checking the input for validation
   if(isalpha(ch1) && isalpha(ch2) && isalpha(ch3))
   {
       cout << "The biggest character from the set ("
   << ch1 << "," << ch2 << "," << ch3 << ") is ";
     
   //Calling function to print biggest character
   showBiggest(ch1, ch2, ch3);
   }
      
   else
       cout << "All characters must be alphabetic" << endl;
  
   return 0;
}

Screenshot of output:-

Add a comment
Know the answer?
Add Answer to:
In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...
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 programming please (b) You will write a program that will do the following: prompt...

    In C programming please (b) 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 'O' You will compule 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 'Q' Example input mJ0*5/1+x1@3qcxQ The 'Q' should be included when computing the statistics properties of the input....

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • in C++ please ELET 2300 Programming Assignment # 2 Write a program that generates an array...

    in C++ please ELET 2300 Programming Assignment # 2 Write a program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array, the program displays the following: [P]osition [Reverse, [A]verage, (Search, [Q]uit Please select an option: Then, if the user selects: -P (lowercase or uppercase): the program displays the array elements position and value pairs for all member elements of...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

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

  • Assembly Programming Question. Read keystroke, reverse case and display, stop on ESC. Also relevant: Also relevant:...

    Assembly Programming Question. Read keystroke, reverse case and display, stop on ESC. Also relevant: Also relevant: Also relevant (though you cant use Irvine16.inc): Assembly Programming Question. Read keystroke, reverse case and display, stop on ESC. Assembly Programming Question. Read keystroke, reverse case and display, stop on ESO. 3. Write a program that reads a user keystroke and if it?s an alphabetical character, reverses it case then displays it. The program should stop when the user hits the ESC key (1Bh)....

  • Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the...

    Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the user to enter a string. The string will then be displayed back to the user. This is followed by determining the number of alphabetic characters, numeric characters, lower_case letters, upper_case letters, whitespace characters, and then displaying them. The user should be given additional chances to enter additional strings, and each time a string is entered, the above process is to be performed. The inputting...

  • Using the Arduino IDE, write a program for an Arduino board that will perform the following three...

    Using the Arduino IDE, write a program for an Arduino board that will perform the following three tasks: 1. Input: Prompt the user to enter a character string. Read the character string from your computer through the Arduino's serial interface. 2. Processing: Convert lowercase characters to uppercase and uppercase characters to lowercase, and 3. Output: Return the processed string through the serial output and display it on your computer screen. Example: If the input character string is, “Here I am”,...

  • Write a C++ program that generates an array filled up with random positive integer number ranging...

    Write a C++ program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array , the program displays the following: [P]osition [R]everse, [A]verage, [S]earch, [Q]uit Please select an option: Then, if the user selects: -P (lowercase or uppercase): the program displays the array elements position and value pairs for all member elements of the array. -R (lowercase or uppercase): the...

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

    In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter an integer value. Your program will then display that integer back to the user. Your program should include a function called getInteger that requests an integer value from the user and returns that value back to the caller. Your main () function will call the function getInteger and will then display the value returned by that function....

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