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));
return str.at(0) + changePi(str.substr(1)); }
int main() {
string stra;
cout << "Enter a string: ";
cin >> stra;
string temp = "pi";
string result = changePi(temp);
cout << "changePi" << "(" << stra << ")" << " --> " << result;
return 0;
}
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
I need help with this program. C++ Given a string, compute recursively (no loops) a new...
Can you please translate this code from Java to C++;
These are the only libraries i am allowed to use
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
using namespace std;
1 /* Given a string, compute recursively (no loops) a new string where all * appearances of "pi" have been replaced by "3.14". public String changepi(String str) { if(str.length() <= 1) return str; if(str.substring(0, 2).equals("pi")) return "3.14" + changepi(str.substring(2)); 11 12 return str.charAt(0) + changepi(str.substring(1)); }
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...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. #include <iostream> #include <string> using namespace std; //Write a recursive function 'void reverse(string &str)' that reverses the given input string. void reverse(string &str) { /*Code needed*/ } int main() { string name = "sherry"; reverse(name); cout << name << endl; //should...
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);...
I need to add a for or a while loop to the following code. please help needs to be in c++. #include <iostream> #include <string.h> using namespace std; int main() { char input[100]; cout << "Please enter a character string: "; cin >> input; char *head = &input[0], *tail = &input[strlen(input) - 1]; char temp = *head; *head = *tail; *tail = temp; tail--; head++; cout << "CString = " << input << "\n"; }
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>...
Hi, I need to change the conversion where stack is into a class stack and add a template <class type> PROMPT: write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. if the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. #include #include #include #include #include using namespace std; double conversion(string); int...
C++ NEED HELP WITH MY REVERSE STRING FUNCTION IN LINK LIST A function Reverse, that traverses the linked list and prints the reverse text to the standard output, without changing the linked list. ( Pass the linked list by value, you have the freedom to create a doubly linked list that is a copy of the original list in your program before you call the function) #include "pch.h" #include <iostream> #include <string.h> #include <string> using namespace std; #define MAX 512...
Flatten Text: Write a function to implement simple string flatten operation with the help of number of occurrence of characters. For example, the string xxyzzzzzxxx results in x2ylz5x3. In case the "flattened" string doesn’t result in becoming shorter than what we started with, then the function simply returns the starting string. The string should use only uppercase and lowercase letters (a through z). #include <iostream> using namespace std; string flattenText(string str) { string flattenedText = ""; return flattenedText;...
my program wont run on my computer and im not understanding why. please help. #include<iostream> #include<iomanip> #include<string> #include "bookdata.h" #include "bookinfo.h" #include "invmenu.h" #include "reports.h" #include "cashier.h" using namespace std; const int ARRAYNUM = 20; BookData bookdata[ARRAYNUM]; int main () { bool userChoice = false; while(userChoice == false) { int userInput = 0; bool trueFalse = false; cout << "\n" << setw(45) << "Serendipity Booksellers\n" << setw(39) << "Main Menu\n\n" << "1.Cashier Module\n" << "2.Inventory Database Module\n" << "3.Report Module\n"...