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

Write a program in C++ to perform the following: 1. Prompt the user to input a s

ID: 3671857 • Letter: W

Question

Write a program in C++ to perform the following:

1. Prompt the user to input a string - "Enter a string " Input a string using getline Extract the second character of the string and store it in a char variable, say c Examine c using switch branching operations with the following classification: a. if c is 'A', print the entire string b. if c is 'c' , print the string twice (concatenated) c. if c is '0' print half of the string d. if c is '!' replace the second and third character with string "he" and print the new string e. if none of the above, print "some other character" Extract the last character of the string (say stored in char variable t) and do the following classification with if-else constrcuct: a. if t is a lower case alphabet - print "lower case" b. if t is an upper case alphabet - print "upper case" c. if t is a number - print "number" d. if t is a space - print "space" e. if none of the above, print "some special character"

Explanation / Answer

Please find the required program below :

// Example program
#include <iostream>
#include <string>

int main()
{
std::string s;
std::cout << "Enter a string"<<std::endl;;
getline (std::cin, s);

char c = s[1];

switch(c){

case 'A' : std::cout << s << std::endl; break;

case 'c' : std::cout << s << s << std::endl; break;

case '0' :

for(int i=0; i<s.length()/2;i++){
std::cout << s[i] << std::flush;
}
std::cout << "" << std::endl;
break;

case '!' :

s[1] = 'h';
s[2] = 'e';
std::cout << s << std::endl;
break;
  
default :
std::cout << c << std::endl;
break;
  
}

}

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