So for this project I have to change all the characters in a picture we drew. Well rather the program needs to prompt the user to choose a character to change each character in the picture to. Here is the picture. How could i do this, at least get me started on the right path.
Yea just each one to one other character. For example, turning all the stars into @ symbols or something. You'll have to forgive me i am super new to programming and C++ in particular so i still dont fully understand how to do this.
oh, that is much easier.
you can make a string that holds the entire output above including its end of lines, and then replace the chars in a single statement. looks like
string starship = " * \n *** \n * \n \n * \n \n * \n \n * \n \n * \n \n * * \n *** \n *** * \n ***** \n ***** \n ***** \n ******* \n *********** \n *************** \n ***************** \n ********************* \n ******************* \n ******* \n ********* \n *********** \n **** **** \n * * \n * * \n * \n \n";
std::replace( starship.begin(), starship.end(), '*', '@');
The string is messy in code. You could also do a vector of strings and manage it one line at a time to look better in code but its less efficient and needs a loop of replaces for each row.
When dealing with things like this, there are many ways, I used notepad++ to convert your couts to the string.
Awesome thank you, so yea your string works. Now I have to prompt the user to ask which character it would like to change. So would I just cout and cin to get the character they want the starship changed to. Then how would i implement that. Then after that i would just print the changed string.
Well I was leaving a little of it for you to do... try it...
roughly..
cout a prompt to the user
char input;
cin input
replace as above but change '@' to input
do that first, and replace the *s with what is put in. once that is working,
repeat that same idea to replace anything with anything, this time change '*' for an input (a different one, you need 2) character.
Your teacher may not like you doing it this way, seems like a lot of them want hand-rolled code instead of built-in code. If so, you may find you have to write your own version of replace. once its all done, you may do that just to do it, for practice, though the built in function is the right thing to do.