1 |
On Monday 20 March 2006 16:15, Cyrill Helg wrote: |
2 |
> > ich werd es mal in c++ probieren |
3 |
> > weiss aber noch nicht ob es klappt |
4 |
> |
5 |
> Wäre cool, dann könnte ich es vielleicht schaffen das in kopete zu |
6 |
> integrieren ;) |
7 |
> |
8 |
|
9 |
|
10 |
stelle gerade fest das alles doch nicht so einfach ist ;) |
11 |
|
12 |
habe es aber inzwischen geschaft ein wort aus dem text auszulesen jetzt muss |
13 |
ich nur noch das mixen einbauen und auch dafuer sorgen das bei "alle" und |
14 |
anderen woertern keine probleme gibt :) |
15 |
|
16 |
aber hier mal das was ich schon hab vlt regt es ja jemanden es selbst zu |
17 |
probieren und zu verbessern :) |
18 |
|
19 |
#include <iostream> |
20 |
#include <string> |
21 |
|
22 |
using namespace std; |
23 |
|
24 |
class MixWords |
25 |
{ |
26 |
private: |
27 |
string msg_; |
28 |
unsigned short int max_; |
29 |
public: |
30 |
MixWords(string str, int max); |
31 |
void setMsg(string str, int max); |
32 |
void setMsg(string str); |
33 |
string mixStr(void); |
34 |
}; |
35 |
|
36 |
MixWords::MixWords(string str, int max=5) |
37 |
{ |
38 |
msg_=str; |
39 |
max_=max; |
40 |
} |
41 |
|
42 |
void MixWords::setMsg(string str) |
43 |
{ |
44 |
msg_=str; |
45 |
} |
46 |
|
47 |
void MixWords::setMsg(string str, int max) |
48 |
{ |
49 |
msg_=str; |
50 |
max_=max; |
51 |
} |
52 |
|
53 |
string MixWords::mixStr(void) |
54 |
{ |
55 |
if(msg_.length()<=3){ |
56 |
// Keine Aenderung moeglich |
57 |
return msg_; |
58 |
} |
59 |
|
60 |
string mixed(""); |
61 |
|
62 |
int start = msg_.find(" ",0); |
63 |
|
64 |
// Copy Word |
65 |
for(int i=0;i<start;++i){ |
66 |
mixed+=msg_[i]; |
67 |
} |
68 |
cout << mixed << endl; // enthaelt nun das 1. wort aus msg_ |
69 |
} |
70 |
|
71 |
int main(int argc, char *argv[]) |
72 |
{ |
73 |
MixWords funny("Hallo Welt",5); |
74 |
|
75 |
cout << funny.mixStr() << endl; |
76 |
|
77 |
return(0); |
78 |
} |
79 |
|
80 |
viel spass damit ;) |
81 |
|
82 |
es fehlt leider noch einiges aber ich denke es ist ein guter anfang :) |
83 |
|
84 |
daniel |
85 |
|
86 |
-- |
87 |
gentoo-user-de@g.o mailing list |