Super Easy, but alas I am clueless

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;

int main()
{
   
   cout << "                  *         " << endl;
   cout << "                 ***        " << endl;
   cout << "                  *         " << endl;
   cout << "                            " << endl;
   cout << "                  *         " << endl;
   cout << "                            " << endl;
   cout << "                  *         " << endl;
   cout << "                            " << endl;
   cout << "                  *         " << endl;
   cout << "                            " << endl;
   cout << "                  *         " << endl;
   cout << "                            " << endl;
   cout << "               *  *         " << endl;
   cout << "              ***           " << endl;
   cout << "              *** *         " << endl;
   cout << "             *****          " << endl;
   cout << "             *****          " << endl;
   cout << "             *****          " << endl;
   cout << "            *******         " << endl;
   cout << "          ***********       " << endl;
   cout << "        ***************     " << endl;
   cout << "       *****************    " << endl;
   cout << "     *********************  " << endl;
   cout << "      *******************   " << endl;
   cout << "            *******         " << endl;
   cout << "           *********        " << endl;
   cout << "          ***********       " << endl;
   cout << "           **** ****        " << endl;
   cout << "             *   *          " << endl;
   cout << "              * *           " << endl;
   cout << "               *            " << endl;
   cout << "                            " << endl;

   
                   
   return 0;
}
each one? That will get tedious ...

for(# of chars) //does this include the spaces??
{
cout and what should this one be..
cin char
store char for later
}

write all the chars / strings out after all the I/O to draw it

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.
1
2
3
4
5
6
7
8
9
10
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.
Last edited on
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.
Last edited on
Topic archived. No new replies allowed.