Question

Write a void function called FlipString. It should have 1 string parameter passed by reference. It...

Write a void function called FlipString. It should have 1 string parameter passed by reference. It should replace each capital letter with its lowercase letter, and each lowercase letter with its capital letter. Use the functions toUpper() and toLower() to help you.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

char toLower(char ch) {
   return ch + 32;
}

char toUpper(char ch) {
   return ch - 32;
}

void FlipString(string &s) {
   char ch;
   for(int i = 0; i < s.size(); ++i) {
      ch = s[i];
      if(ch >= 'a' && ch <= 'z') {
         s[i] = toUpper(ch);
      }
      if(ch >= 'A' && ch <= 'Z') {
         s[i] = toLower(ch);
      }
   }
}

int main() {
   string s = "Hello How are YoU?";
   FlipString(s);
   cout << "Flipped strings is: " << s << endl;
   return 0;
}
Add a comment
Know the answer?
Add Answer to:
Write a void function called FlipString. It should have 1 string parameter passed by reference. It...
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
  • Define a function ValidRoom() that passes in a string parameter and returns true if the string...

    Define a function ValidRoom() that passes in a string parameter and returns true if the string parameter obeys all rules for a building's room address, else returns false. The rules are: (1) Must be two or three characters long. (2) First two characters must be digits, (3) If third character exists, must be a letter (upper or lowercase). Examples of strings yielding true: "65", "00", "21L". Examples of strings yielding false: "356", "7", "A23", " 65", "45AB". Recall some available...

  • Complete the get_mid_letter() function which is passed a list of strings as a parameter. The function...

    Complete the get_mid_letter() function which is passed a list of strings as a parameter. The function returns a string made up of the concatenation of the middle letter of each word from the parameter list. The string returned by the function should be in lowercase characters. If the parameter list is an empty list, the function should return an empty string For example Test Result print("1.", get mid_letter"Jess", "Cain", Amity", "Raeann"])) 1. siia Answer (penalty regime: 0 %) 1 -Idef...

  • Homework Question Write a void function called transformArray that takes two parameters - a reference to...

    Homework Question Write a void function called transformArray that takes two parameters - a reference to a pointer to a dynamically allocated array of ints, and the size of that array.  The pointer is passed by referencebecause you want to change the value of the pointer. The function should dynamically allocate an array that is twice as long, filled with the values from the original array followed by each of those values times 2. For example, if the array that was...

  • Create a Python script file called hw.py. Then import the module random: from random import *...

    Create a Python script file called hw.py. Then import the module random: from random import * Thanks in advance! Ex. 1. Write a function called cleanLowerWord that receives a string as a paramcter and retums a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this,...

  • 10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string...

    10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string for all occurrences of string2. When it finds an occurrence of Programming Challenges string2, it should replace it with string. For example, suppose the three arguments have the following values: stringt: "the dog jumped over the fence" string 2 "the" string3: "that" With these three arguments, the function would return a...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • C++ Write a void function called getAge that has no formal parameter. The function should prompt the user for their...

    C++ Write a void function called getAge that has no formal parameter. The function should prompt the user for their age. An example of the call to the function could be as follows getAge();

  • Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the...

    Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the fork function to produce two processes. In the child process print out the lower case version of the string. In the parent process print out the reversed upper case version of the string (e.g. child: “abc”; parent: ”CBA”). You may call the toupper and tolower functions in the header <ctype.h> if you wish. Specify in the output whether the parent or child process is...

  • Write a recursive function called abb pattern with a single parameter astr, which is a string....

    Write a recursive function called abb pattern with a single parameter astr, which is a string. The function returns True if astr is a string of the form a nb 2n (n a-s followed by 2n b-s, where n is a positive integer) and False otherwise. For example, abb pattern("abb"), abb pattern("aabbbb"), and abb pattern("aaaabbbbbbbb") all return True, but abb pattern("") (parameter is an empty string), abb pattern("abbabb"), and abb pattern("aaabbbbb") all return False. you may not use any built-in...

  • General Requirements . . . Write a program that reads letters from a file called "letters.txt"....

    General Requirements . . . Write a program that reads letters from a file called "letters.txt". Your program will open the letters.txt file read in one character at a time For this assignment the test file will contain at least 30 letters, uppercase OR lowercase In your program you will change each letter (solution) to uppercase Use the function toupper in #include <ctype.h> You create a numerical version of the uppercase letter from the file . o Use int numberSolution...

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