Question

Prompt the user to enter two character strings. The program will then create a new string which has the string that appears second, alphabetically, appended to the end of the string that shows up first alphabetically. Use a dash (-) to separate the two strings. You must implement the function string appendStrings(string, string), where the return value is the combined string. Display the newly created string. Your program must be able to handle both uppercase and lowercase characters. You are allowed to convert all the input characters to lowercase Example: If dog and bird have been entered then bird-dog is returned then displayed. Sample code for string case conversion ? i++) < mystring, size(); - tolower(mystring[i]); for i # 0; (int mystring[i]
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

using namespace std;

string appendString(string a, string b){

   string str1 = a;
   string str2 = b;
   string str = "";

   //str = str + (char)tolower(a[0]);
  
   for (int i = 0; i<a.size(); i++){
       str1 = str1 + (char)tolower(a[i]);
   }
   for (int i = 0; i<b.size(); i++){
       str2 = str2 + (char)tolower(b[i]);
   }
   if (str1 >=str2){
      str = b + "-" + a;
   }
   else {
      str = a + "-" + b;
   }
  
   return str;
}


int main(){

   cout << appendString("dog","bird") << endl;
   return 0;
}

C I Chegg.com G adding a character to string w H ow would I add a characte E -) O 숲 Owww.HomeworkLib.com/homework help expertquesti

Add a comment
Know the answer?
Add Answer to:
Prompt the user to enter two character strings. The program will then create a new string...
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
  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • Create a program that performs the following operations: 1. Prompt for and accept a string of...

    Create a program that performs the following operations: 1. Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 #create space for string input The syscall to place input into the buffer looks like: li $v0,8 # code for syscall read_string la $a0, buffer #tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer is syscall 2....

  • Using the Arduino IDE, write a program for an Arduino board that will perform the following three...

    Using the Arduino IDE, write a program for an Arduino board that will perform the following three tasks: 1. Input: Prompt the user to enter a character string. Read the character string from your computer through the Arduino's serial interface. 2. Processing: Convert lowercase characters to uppercase and uppercase characters to lowercase, and 3. Output: Return the processed string through the serial output and display it on your computer screen. Example: If the input character string is, “Here I am”,...

  • Your program must prompt the user to enter a string. The program must then test the...

    Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....

  • Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

    Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...

  • Create a program that performs the following operations: Prompt for and accept a string of up...

    Create a program that performs the following operations: Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 # create space for string input • The syscall to place input into the buffer looks like: li $v0, 8 # code for syscall read_string la $a0, buffer # tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer...

  • Implement a program that requests from the user a list of words (i.e., strings) and then...

    Implement a program that requests from the user a list of words (i.e., strings) and then prints on the screen, one per line, all four-letter strings in the list. >>> Enter word list: ['stop', 'desktop', 'top', 'post'] stop post An acronym is a word formed by taking the first letters of the words in a phrase and then making a word from them. For example, RAM is an acronym for random access memory. Write a function acronym() that takes a...

  • Design a program that prompts the user to enter a string, and displays the character that...

    Design a program that prompts the user to enter a string, and displays the character that appears most frequently in the string. (Please read the problem above carefully. I'm asking this question for the second time because the last answer I received wasn't even paying attention to what the question asked for.) Answer MUST be using Flowgorithm with screenshots. Please attach a screenshot of the program successfully running in flowgorithm as well to confirm proper output. Thanks for understanding!

  • Write a program that uses String method regionMatches to compare two strings input by the user....

    Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the user to enter two strings, the starting index in the first string, the starting index in the second string, and the number of characters to be compared. The program should print whether or not the strings are equal, (Ignore the case of the characters during comparison.) 四SAMPLE RUN #1: java StringCompare Highlight: None D Show Highlighted Only Interactive Session...

  • Assembly program: NASM assembler write a program to print the location of character "i" from a input string from left to right. User inputs a strings upto 40 characters.

    Assembly program: NASM assembler write a program to print the location of character "i" from a input string from left to right. User inputs a strings upto 40 characters.

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