Question

In C++ Write a program that will read a string, call 2 functions to modify the...

In C++

Write a program that will read a string, call 2 functions to modify the string, and then print the final result. The first function should take a string parameter and return the string without any vowels. The second function should take a string and double every letter (which should be all consonants at this point). Be sure to: You must use more than [ ] and at You must use erase, insert, replace, find, and/or substr to make a new string.

Here is what I have so far. And I can't figure out why it won't work:

#include<iostream>

#include<string>

using namespace std;

int main()

{

string string;

cin >> string;

string = deleteVowel(string);

string = doublechar(string);

cout << string;

return 0;

}

string deleteVowel(string str)

{

for (int T = 0; T < str.length(); T++)

if (str.at(t) == 'T' || str.at(t) == 'T' || str[t] == 'a' || str.at(t) == 'T' || str.at(t) == 't')

{

str.erase(T, 1);

T--;

}

}

return str;

string doublechar(string str)

{

for (int T = 0; T<str.length(); T++)

{

char m = str[T];

str.insert(T + 1, 1, m);

T++;

}

return str;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

#include <string>

using namespace std;

string deleteVowel(string);
string doublechar(string);

int main()

{

string string;

cin >> string;

string = deleteVowel(string);

string = doublechar(string);

cout << string;

return 0;
}

string deleteVowel(string str)

{

for (int t = 0; t < str.length(); t++)

if (str.at(t) == 'a' || str.at(t) == 'e' || str[t] == 'i' || str.at(t) == 'o' || str.at(t) == 'u')

{

str.erase(t, 1);

t--;
}

return str;
}

string doublechar(string str)

{

for (int T = 0; T < str.length(); T++)

{

char m = str[T];

str.insert(T + 1, 1, m);

T++;
}

return str;
}

Output:

rrnnlldd Process exited after 1.622 seconds with return val Press any key to continue - -

\color{red}Please\; upvote\;the \;solution \;if \;it \;helped.\;Thanks!

Add a comment
Know the answer?
Add Answer to:
In C++ Write a program that will read a string, call 2 functions to modify the...
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
  • Write a program that prompts the user to input a string. The program then uses the...

    Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. #include <iostream> #include <string> using namespace std; void removeVowels(string& str); bool isVowel(char ch);...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • I need help with this program. C++ Given a string, compute recursively (no loops) a new...

    I need help with this program. C++ Given a string, compute recursively (no loops) a new string where all appearances of "pi" have been replaced by "3.14". It should enter a string like: (xpix)--> and print out " x3.14x" (pi)--> and print out " 3.14p" (pipi)--> and print out " 3.143.14" This is what I have so far... #include<iostream> #include<string> using namespace std; string changePi(string str) { string left; if(str.length() < 2) return str; if(str.substr(0, 1).compare("pi")) return "3.14" + changePi(str.substr(2));...

  • Take the following C++ code and add to it the following: Write a program that reads...

    Take the following C++ code and add to it the following: Write a program that reads a string and outputs the number of times each lowercase vowel appears in it. Your program must contain a function with one of its parameters as a char variable, and if the character is a vowel, it increments that vowel's count. #include<iostream> #include<string> using namespace std; int countVowel(char, char); int main(void) { string str1; int countA = 0; int countE = 0; int countI...

  • c++ Consider the following statement string str "Now is the time for the party!" What is...

    c++ Consider the following statement string str "Now is the time for the party!" What is the output of the following statements? (Assume that all parts are independent of each other.) a. cout <str·size ( ) end 1 ; b. Cout << str. substr (7, 8) <<endl: c. string: :size type indstr.find'£') string s str. substr (ind 4, 9); d. cout << str insert (11,"best " <<endl e. str.erase (16, 14) str.insert (16, "to study for the exam? ") cout...

  • // Write a program that determines how many of each type of vowel are in an...

    // Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...

  • 5.9.2: Modify a string parameter. C++ Complete the function to replace any period by an exclamation...

    5.9.2: Modify a string parameter. C++ Complete the function to replace any period by an exclamation point. Ex: "Hello. I'm Miley. Nice to meet you." becomes: "Hello! I'm Miley! Nice to meet you!" #include <iostream> #include <string> using namespace std; void MakeSentenceExcited(string& sentenceText) { /* Your solution goes here */ } int main() { string testStr; getline(cin, testStr); MakeSentenceExcited(testStr); cout << testStr; return 0; }

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • 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