Character Converter Class

Pages: 123
Nov 19, 2014 at 6:43pm
From what I found online, I see how and why what was done. I just need to know the function codes.
Nov 19, 2014 at 7:14pm
Alright alright, here are teh c0dez

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
44
45
46
47
48
49
50
#include <iostream>
#include <string>

using namespace std;

class leetspeak {
	public: string eleet(string s);
};

string leetspeak::eleet(string s) {
	for (int i = 0; i < s.length(); i++) {
		char x = s.at(i);
		switch (x) {
			case 'a':
				s.replace(i, 1, "4");
				break;

			case 'e':
				s.replace(i, 1, "3");
				break;

			case 'i':
				s.replace(i, 1, "1");
				break;

			case 'o':
				s.replace(i, 1, "0");
				break;

			case 'h':
				s.replace(i, 1, "]-[");
				break;
			case 't':
				s.replace(i, 1, "7");
				break;
		}
	}
	return s;
}

int main() {
	leetspeak myleetspeak;

	string test = "i am the elite";

	test = myleetspeak.eleet(test);
	cout << test << endl;

	return 0;
}


Last edited on Nov 19, 2014 at 7:16pm
Nov 19, 2014 at 7:50pm
What is that?
Nov 19, 2014 at 7:57pm
those are teh secret c0dez!!
Nov 19, 2014 at 8:00pm
lol. it says 1 4m 7]-[3l173 when I run it lol
Nov 20, 2014 at 1:36pm
Please any help on this?
Nov 20, 2014 at 3:09pm
I know that I have to convert what the user puts in to all uppercase if the letter is lowercase. I think I know how to do that. The part that I don't know is 1. How to start the code and 2. The properword function that uppercases the first word after each space. I don't the that function.
Nov 20, 2014 at 5:02pm
OK....I looked it up in my book and found some stuff on the web and here's what I have so far:
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//Chris Cochran
//COP2000.0M2
//Project 7
//This program will uppercase words and sentences

#include <iostream>
#include <cctype>
#include <string>
using namespace std;


class CharConverter
	{
	private:
		string sentence;
		int count;
	public:
		void uppercase(string sentence)
		{
			
			for (int count = 0; count < sentence.length(); count ++)
			{
			sentence[count] = toupper(sentence[count]);
			cout << sentence;
			return;
			}
		}
		void properWords(string sentence)
		{
			
			for (int count = 0; count < sentence.length(); count++)
			{
				sentence[count] = toupper(sentence[count]);
				if (sentence[count] = ' ') 
				{
					count++; 
					sentence[count] = toupper(sentence[count]);
				}
			}
		}

};

int main()
{

	CharConverter mainSentence;
	string choice;
	string sentence;
	
	cout << "Type a word or sentence.\n";
	cin >> sentence;

	mainSentence.uppercase(sentence);
	mainSentence.properWords(sentence);
	
	return 0;
}


It compiles and runs fine, but when I type in a word or sentence, it gives me this error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: ...hris\Desktop\COP2000 Visual C++\Project 7\Debug\Project 7.exe
File: c:\program files (x86)\microsoft visual studio 10.0\vc\include\xstring
Line: 1440

Expression: string subscript out of range

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
---------------------------
Abort   Retry   Ignore   
---------------------------


Is that something to do with something in int main()?
Nov 20, 2014 at 8:13pm
Not sure if this is what caused your error, but look at line 21, where you increment count. Also, when I tried your code it only took the first word of what I typed. I think you might need to use another function other than cin. I'm not sure which one it is in C++, but I've been seeing alot of getline(cin, variable) around.

Is it supposed to turn "hello my username is swp147. your name is lordZedd." into "Hello my username is swp147. Your name is lordZedd" ?
Last edited on Nov 20, 2014 at 8:25pm
Nov 20, 2014 at 8:15pm
what's wrong with it?
Nov 20, 2014 at 8:30pm
How do you increment the variable differently in the next loop? Nevermind, I didn't know you could throw a space in there.
Last edited on Nov 20, 2014 at 8:32pm
Nov 20, 2014 at 8:32pm
If you input hello my name is blah, it's supposed to output HELLO MY NAME IS BLAH and then output Hello My Name Is Blah
Nov 20, 2014 at 8:34pm
Why do you jump out of the loop at line 25 then?
Nov 20, 2014 at 8:35pm
I deleted the return. but i put it because it was the end of that loop.
Nov 20, 2014 at 8:43pm
return will take you out of the function.
Nov 20, 2014 at 8:46pm
oh ok. I deleted it. So how do I make my code do what i need it to do? xD
Nov 20, 2014 at 8:48pm
Did you fix the sentence input?
Nov 20, 2014 at 8:53pm
ya. i just put cin >> sentence;
Nov 20, 2014 at 9:01pm
void uppercase(string sentence)
{
cout << "Type a sentence to see every letter be uppercased\n";
cin >> sentence;
for (int count = 0; count < sentence.length(); count ++)
{
sentence[count] = toupper(sentence[count]);
cout << sentence;
}
}
void properWords(string sentence)
{
cout << "Type a sentence to see the first letter of every word be uppercased\n";
cin >> sentence;
for (int count = 0; count < sentence.length(); count++)
{
sentence[count] = toupper(sentence[count]);
if (sentence[count] = ' ')
{
count++;
sentence[count] = toupper(sentence[count]);
}
}
}
Nov 20, 2014 at 9:27pm
not in there, in main(). For some reason cin >> sentence; only gets one word. I think you have to use getline()
Pages: 123