Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the below c++ program such that if one of the whitespaces is entered, it

ID: 3669433 • Letter: M

Question

Modify the below c++ program such that if one of the whitespaces is entered, it displays a message and tells what the character was.

// P54.cpp - This program reads one character from the keyboard and will

// convert it to uppercase, if it is lowercase

// convert it to lowercase, if it is uppercase

// display a message, if it is a digit

#include<iostream>

#include<ctype>

using namespace std;

int main()

{

char c;

cout << "Enter a character ";

cin >> c;

if (isalpha(c))

{ //check to see if it is a letter of alphabet

if (isupper(c)) //check to see if it is uppercase

{

c = tolower(c);

cout << "Your character " << c << " is in uppercase.";

cout << "Its lowercase case is " << c << endl;

}

else

{

c = toupper(c);

cout << "Your character " << c << " is in lowercase.";

cout << "Its uppercase is " << c << endl;

}

}

else

{

cout << "Your character " << c << " is a digit. ";

}

return 0;

Explanation / Answer

#include <iostream>
#include <ctype.h>
#include <stdio.h>

using namespace std;

int main()
{

char c;
cout << "Enter a character ";
c = getchar();

if (isalpha(c))
    { //check to see if it is a letter of alphabet
      if (isupper(c)) //check to see if it is uppercase
        {
          cout << "Your character " << c << " is in uppercase. ";
          c = tolower(c);
          cout << "Its lowercase case is " << c << endl;
        }

      else
        {
          cout << "Your character " << c << " is in lowercase. ";
          c = toupper(c);
          cout << "Its uppercase is " << c << endl;
        }
    }
else if( c >= '0' && c<='9' )
    {
      cout << "Your character " << c << " is a digit. ";
    }
else if(isspace(c))
{
    cout<<"Your character is a whitespace character ";
    if(c==' ')
      cout<<"Your character " <<c<<" is a space character ";
    else if(c==' ')
      cout<<"Your character " <<c<<" is a tab character ";
    else if(c==' ')
      cout<<"Your character " <<c<<" is a carriage return character ";
    else if(c==' ')
      cout<<"Your character " <<c<<" is a newline character ";
    else if(c==' ')
      cout<<"Your character " <<c<<" is a vertical tab character ";
    else if(c==' ')
      cout<<"Your character " <<c<<" is a formfeed character ";

}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote