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

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

  • Write two functions: Main should call the first function. The first function should use getline to...

    Write two functions: Main should call the first function. The first function should use getline to read a line of data: getline(cin,variableToHoldLineOfData); It should then call the second function, sending the line of data it just read. The second function should determine the number of CAPITAL letters, the number of lowercase letters, and the number of everything else (that's not capital or lower case). Count the length of the string and then use a for loop to go through each...

  • In C++ write a program that will read three strings from the user, a phrase, a...

    In C++ write a program that will read three strings from the user, a phrase, a letter to replace, and a replacement letter. The program will change the phrase by replacing each occurrence of a letter with a replacement letter. For example, if the phrase is Mississippi and the letter to replace is 's' the new phrase will be "miizzizzippi". in the function, replace the first parameter is a modifiable string, the second parameter is the occurrence of a letter...

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