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

Write a C++ program that has a case changing function that is called in the main

ID: 3831285 • Letter: W

Question

Write a C++ program that has a case changing function that is called in the main function. The case changing function should return a string, i.e. have a return data type of string. This case changing function should have two input parameters both strings. This case changing function should return a new string in which the case of the letters in a user-entered string (first input parameter) are to be changed according to the desired case - uppercase or lowercase (second parameter), defined by the user as well. The main function should prompt the user to enter a word and prompt the user to enter which case they want the word to be returned in, pass the word and desired case as two strings to the function, and display the user-entered word in the user-specified case. Give the code and the screenshot of the code working for user input and displayed output printed to the command line by the program.

Explanation / Answer

#include <iostream>
using namespace std;

int main()
{
string str, caseChange;
int i=0;
  
   cout << "Enter the word: ";
getline(cin, str);
  
cout << "Enter the case you want to change to (Uppercase/lowercase) ";
getline(cin, caseChange);
  
string change(str, caseChange);
  
if(caseChange[0]=='u'||'U')
  
{
    while(str[i]!=''){
           if(str[i]>96 && str[i]<123)
           str[i]=str[i]-32;
           i++;
       }
   }
   else if(caseChange[0]=='l'||'L'){
       i=0;
       while(str[i]!=''){
           if(str[i]>64 && str[i]<91)
           str[i]=str[i]+32;
           i++;
       }
      
   }
cout << "The word after changing case " << str << endl;

}

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