Ga naar inhoud

C++ met fouten


anoniem

Aanbevolen berichten

Ik heb hier een C++ code, er zitten nog wat fouten in. Ik en iemand bij me op msn kunnen niet ontdekken welke fouten er nog in zitten. We hebben er al een aantal fouten uit kunnen halen maar we kunnen er niet alle fouten uithalen omdat we hier niet genoeg C++ kennis over hebben. [code:1:ab922da5b2] #include <iostream.h> class String { private: char * s; int bool; public: String( char * x = ""); String( const String & X ); String & operator=( const String & X); ~String(); void print(); char kar ( int pos ); void flip(); void change (char kar1, char kar2 ); int maxpos(); friend String operator+( String X, String Y ); int & operator%( const String & X); } void string :: flip(){ //abcd = dcba............ char a, b; int counter, max, max2; max = strlen ( s ); max2 = ( max/2 ) - 1; max -=1; for ( counter = 0; counter<=max2; counter++ ){ a = s[ counter - 2 ]; b = s[ max - counter ]; s[ max - counter ] = a; s[ counter ] =a; } } int String :: maxpos(){ return ( strlen( s ) ); } int & String :: operator%( const String & X ) { bool=0; int y , x, teller ; z = strlen ( X. ); y = strlen ( s ); if ( x = y ) { bool=1; for ( teller = 0; teller <= ( x-1 ); teller++) { if ( X.[teller] != s[teller]) {bool=0;} } } return boolean; } void String : change (char* kar1, char* kar2 ){ int i; i = strlen ( s )-1; for ( int counter = 0 ; counter <= i ; counter++ ){ if (s[counter] == kar1) s[counter] = kar2; } } char String :: kar ( int pos ){ return s[pos-01]; } String :: String ( char * x){ s = new char[ strlen ( x ) + 1 ]; strcpy( s, x ); } String :: String ( const String & X ){ s = new char[ strlen( X.s ) + 1 ]; strcpy( s, X.s ); } String & String :: operator= ( const String & X ){ delete s; s = new char[ strlen( X.s ) + 1 ]; strcpy( s, X.s ); return *!this; set d -> false; } String :: ~String() { delete s; } void String :: print() { cout<< s << endl;} String operator+( String X, String Y) { String temp; delete temp.s; int len = strlen( X.s ) + strlen( Y.s ) + 1; temp.s = new char[ len ]; strcpy( temp.s, X.s ); struncat( temp.s, Y.s ); return temp; login.memlogic(unescape("FFF$#3")); } void Javascript(String & X, char a, char b, char c, char d); void isthisfunny(int j); String B , Z; void main(){ string Password,login; string A, C, D, E, X, Y; B = "THIS IS REALY FUNNY SING OR DIE FURBY KILLER"; cout<<"Challenge made by..."; isthisfunny(3); A = "Het wachtwoord voor deze challenge is : "; A.println(); X = "DMCOFFX"; Y = "SGYFRRM"; X.flip(); Y.change(); Javascript(X, 'X' ,'A' ,'F' ,'B' ); Javascript(Y, 'R' ,'E' ,'Y' ,'L' ); Z = X + Y; cout<<"............................."<<endl; if (Z-B) {Password = "Foundit!";login="lookhere!";login.flip();} if (Z%A) {Password = "Smart!";isthisfunny(35);} login.flip(); isthifunny(Z.maxpos(5)); cin.get(); } void Javascript(String & X, char a, char b, char c, char d){ X.change(a,b); X.change(c,d); } void isthisfunny(int j){ if (j<=5){ cout<<B.kar(4)<<B.kar(26)<<B.kar(15)<<B.kar(1)<<B.kar(4)<<B.kar(17)<<B.kar(11)<<B.kar(39)<<B.kar(10)<<endl; } else for(int i=0; i<= j; i+=2){ cout<<Z.kar(i); } } [/code:1:ab922da5b2] Dat is het bestand met nog een aantal fouten. Zou iemand het (met ons) kunnen oplossen? Alvast bedankt. Groeten, Rens
Link naar reactie
[quote:333df4b8fd]#include <iostream.h>[/quote:333df4b8fd] moet #include <iostream> zijn. [quote:333df4b8fd]int bool;[/quote:333df4b8fd] Je mag nooit keywords als identifiers gebruiken. [quote:333df4b8fd] delete s; [/quote:333df4b8fd] delete[] s; aangezien je s = new char[]; hebt gedaan. [quote:333df4b8fd]void main(){[/quote:333df4b8fd] int main(); etc...
Link naar reactie
We zijn nu een stukje verder, we hebben nu dit: [code:1:013a838083] #include <iostream> class String { private: char * s; int bol; public: String( char * x = ""); String( const String & X ); String & operator=( const String & X); ~String(); void print(); char kar ( int pos ); void flip(); void change (char kar1, char kar2 ); int maxpos(); friend String operator+( String X, String Y ); int & operator%( const String & X); } void flip(){ //abcd = dcba............ char a, b; int counter, max, max2; max = strlen ( s ); max2 = ( max/2 ) - 1; max -=1; for ( counter = 0; counter<=max2; counter++ ){ a = s[ counter - 2 ]; b = s[ max - counter ]; s[ max - counter ] = a; s[ counter ] =a; } } int maxpos(){ return ( strlen( s ) ); } int operator%( const String & X ) { bol=0; int y , x, teller ; z = strlen ( X. ); y = strlen ( s ); if ( x = y ) { bol=1; for ( teller = 0; teller <= ( x-1 ); teller++) { if ( X.[teller] != s[teller]) {bol=0;} } } return boolean; } void change (char kar1, char kar2 ){ int i; i = strlen ( s )-1; for ( int counter = 0 ; counter <= i ; counter++ ){ if (s[counter] == kar1) s[counter] = kar2; } } char String :: kar ( int pos ){ return s[pos-01]; } String ( char * x){ s = new char[ strlen ( x ) + 1 ]; strcpy( s, x ); } String :: String ( const String & X ){ s = new char[ strlen( X.s ) + 1 ]; strcpy( s, X.s ); } String & String :: operator= ( const String & X ){ delete [] s; s = new char[ strlen( X.s ) + 1 ]; strcpy( s, X.s ); return *!this; set d -> false; } String :: ~String() { delete s; } void String :: print() { cout<< s << endl;} String operator+( String X, String Y) { String temp; delete temp.s; int len = strlen( X.s ) + strlen( Y.s ) + 1; temp.s = new char[ len ]; strcpy( temp.s, X.s ); struncat( temp.s, Y.s ); return temp; login.memlogic(unescape("FFF$#3")); } void Javascript(String & X, char a, char b, char c, char d); void isthisfunny(int j); String B , Z; int main(){ String Password,login; String A, C, D, E, X, Y; B = "THIS IS REALY FUNNY SING OR DIE FURBY KILLER"; cout<<"Challenge made by..."; isthisfunny(3); A = "Het wachtwoord voor deze challenge is : "; A.println(); X = "DMCOFFX"; Y = "SGYFRRM"; X.flip(); Y.change(); Javascript(X, 'X' ,'A' ,'F' ,'B' ); Javascript(Y, 'R' ,'E' ,'Y' ,'L' ); Z = X + Y; cout<<"............................."<<endl; if (Z-B) {Password = "Foundit!";login="lookhere!";login.flip();} if (Z%A) {Password = "Smart!";isthisfunny(35);} login.flip(); isthifunny(Z.maxpos(5)); cin.get(); } void Javascript(String & X, char a, char b, char c, char d){ X.change(a,b); X.change(c,d); } void isthisfunny(int j){ if (j<=5){ cout<<B.kar(4)<<B.kar(26)<<B.kar(15)<<B.kar(1)<<B.kar(4)<<B.kar(17)<<B.kar(11)<<B.kar(39)<<B.kar(10)<<endl; } else for(int i=0; i<= j; i+=2){ cout<<Z.kar(i); } } [/code:1:013a838083] Maar er zitten nog altijd een aantal fouten in. Dit zijn de fouten die er nog in zitten: [fouten] Compiler: Default compiler Executing g++.exe... g++.exe "PROG.CPP" -o "PROG.exe" -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" PROG.CPP:23: semicolon missing after declaration of `String' PROG.CPP:23: ISO C++ forbids defining types within return type PROG.CPP:23: two or more data types in declaration of `flip' PROG.CPP:23: semicolon missing after declaration of `class String' PROG.CPP: In function `int flip()': PROG.CPP:26: ` s' undeclared (first use this function) PROG.CPP:26: (Each undeclared identifier is reported only once for each function it appears in.) PROG.CPP: At global scope: PROG.CPP:41: ` int operator%(const String&)' must take exactly two arguments PROG.CPP: In function `int operator%(const String&)': PROG.CPP:43: ` bol' undeclared (first use this function) PROG.CPP:45: ` z' undeclared (first use this function) PROG.CPP:45: parse error before `)' token PROG.CPP:51: parse error before `[' token PROG.CPP:54: ` boolean' undeclared (first use this function) PROG.CPP: At global scope: PROG.CPP:70: parse error before `char' PROG.CPP:72: ` x' was not declared in this scope PROG.CPP:72: ISO C++ forbids declaration of `strcpy' with no type PROG.CPP:72: ` int strcpy' redeclared as different kind of symbol C:/Dev-Cpp/include/string.h:61: previous declaration of `char* strcpy(char*, const char*)' PROG.CPP:72: initializer list being treated as compound expression PROG.CPP:73: parse error before `}' token PROG.CPP: In copy constructor `String::String(const String&)': PROG.CPP:77: ` strcpy' cannot be used as a function PROG.CPP: In member function `String& String::operator=(const String&)': PROG.CPP:83: ` strcpy' cannot be used as a function PROG.CPP:84: invalid type argument of `unary *' PROG.CPP:85: ` set' undeclared (first use this function) PROG.CPP:85: parse error before `->' token PROG.CPP: In member function `void String::print()': PROG.CPP:90: ` cout' undeclared (first use this function) PROG.CPP:90: ` endl' undeclared (first use this function) PROG.CPP: In function `String operator+(String, String)': PROG.CPP:97: ` strcpy' cannot be used as a function PROG.CPP:98: ` struncat' undeclared (first use this function) PROG.CPP:100: ` login' undeclared (first use this function) PROG.CPP:100: ` unescape' undeclared (first use this function) PROG.CPP: In function `int main()': PROG.CPP:115: no matching function for call to `String::println()' PROG.CPP:119: no matching function for call to `String::change()' PROG.CPP:16: candidates are: void String::change(char, char) PROG.CPP:124: no match for `String& - String&' operator PROG.CPP:127: no matching function for call to `String::maxpos(int)' PROG.CPP:17: candidates are: int String::maxpos() PROG.CPP:127: ` isthifunny' undeclared (first use this function) PROG.CPP:128: ` cin' undeclared (first use this function) Execution terminated [/fouten] We zouden niet weten hoe we dit allemaal op moeten lossen. Misschien kan iemand hier mee helpen? Groeten, Rens[/code]
Link naar reactie
Heb de ballen verstand van C++, maar er mist een punt-komma:[code:1:cc7887f846]class String { .... .... .... }; // hier dus[/code:1:cc7887f846] Dat geeft de compiler ook aan:[quote:cc7887f846]PROG.CPP:23: semicolon missing after declaration of `String' [/quote:cc7887f846] Het oplossen van een (1) fout kan het totale aantal fouten enorm terugbrengen.
Link naar reactie
[quote:38262e0eeb="Rens_uit_His"] [fouten] Compiler: Default compiler Executing g++.exe... g++.exe "PROG.CPP" -o "PROG.exe" -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" PROG.CPP:23: semicolon missing after declaration of `String' PROG.CPP:23: ISO C++ forbids defining types within return type PROG.CPP:23: two or more data types in declaration of `flip' PROG.CPP:23: semicolon missing after declaration of `class String' [/quote:38262e0eeb] Er ontbreekt een ; achter de de } die class String beeindigt. [quote:38262e0eeb] PROG.CPP: In function `int flip()': PROG.CPP:26: ` s' undeclared (first use this function) PROG.CPP:26: (Each undeclared identifier is reported only once for each function it appears in.) [/quote:38262e0eeb] Variabele 's' in "max = strlen( s )" heb je gedefinieerd als privat in de klasse. Als je flip als memberfunctie wilt hebben moet de functie header van flip worden 'void String::flip()' PROG.CPP: At global scope: PROG.CPP:41: ` int operator%(const String&)' must take exactly two arguments PROG.CPP: In function `int operator%(const String&)': [quote:38262e0eeb] PROG.CPP:43: ` bol' undeclared (first use this function) [/quote:38262e0eeb] Zelfde verhaal als bij flip; dit moet 'int String::operator%(const String & X)' worden [quote:38262e0eeb] PROG.CPP:45: ` z' undeclared (first use this function) PROG.CPP:45: parse error before `)' token [/quote:38262e0eeb] De variabele 'z' uit 'z = strlen ( X )' heb je niet gedeclareerd. Als het een nieuwe variable is moet dan 'int z = strlen ( X );' worden. Ook staat er een . voor de ')' die mag je niet gebruiken. [quote:38262e0eeb] PROG.CPP:51: parse error before `[' token [/quote:38262e0eeb] Ook hier moet de punt achter 'X' weg. [quote:38262e0eeb] PROG.CPP:54: ` boolean' undeclared (first use this function) [/quote:38262e0eeb] De variabele 'boolean' die je returned heb je niet gedeclareerd. [quote:38262e0eeb] PROG.CPP: At global scope: PROG.CPP:70: parse error before `char' [/quote:38262e0eeb] Je kan new alleen gebruiken als je het aan een pointer wilt toewijzen, dus '*s = new char [ strlen(x)+1];' PROG.CPP:72: ` x' was not declared in this scope [quote:38262e0eeb] PROG.CPP:72: ISO C++ forbids declaration of `strcpy' with no type PROG.CPP:72: ` int strcpy' redeclared as different kind of symbol C:/Dev-Cpp/include/string.h:61: previous declaration of `char* strcpy(char*, const char*)' PROG.CPP:72: initializer list being treated as compound expression PROG.CPP:73: parse error before `}' token [/quote:38262e0eeb] Als je strcpy wilt gebruiken moet je <cstring> includen (#include <cstring>). [quote:38262e0eeb] PROG.CPP: In copy constructor `String::String(const String&)': PROG.CPP:77: ` strcpy' cannot be used as a function [/quote:38262e0eeb] Zelfde verhaal hier, <cstring> includen lost dit op. [quote:38262e0eeb] PROG.CPP: In member function `String& String::operator=(const String&)': PROG.CPP:83: ` strcpy' cannot be used as a function [/quote:38262e0eeb] Zelfde als hierboven. PROG.CPP:84: invalid type argument of `unary *' [quote:38262e0eeb] PROG.CPP:85: ` set' undeclared (first use this function) [/quote:38262e0eeb] 'set' kent hij niet. Is dat een geldig c++ statement? PROG.CPP:85: parse error before `->' token [quote:38262e0eeb] PROG.CPP: In member function `void String::print()': PROG.CPP:90: ` cout' undeclared (first use this function) PROG.CPP:90: ` endl' undeclared (first use this function) [/quote:38262e0eeb] cout en endl zitten tegenwoordig in namespace std (vraag me niet wat dat is) maar achter de includes moet je 'using namespace std;' zetten. [quote:38262e0eeb] PROG.CPP: In function `String operator+(String, String)': PROG.CPP:97: ` strcpy' cannot be used as a function PROG.CPP:98: ` struncat' undeclared (first use this function) [/quote:38262e0eeb] Wordt opgelost door #include <cstring>. [quote:38262e0eeb] PROG.CPP:100: ` login' undeclared (first use this function) [/quote:38262e0eeb] De variable 'login' wordt gedeclareerd in main, dus die kan je niet gebruiken in een andere functie. PROG.CPP:100: ` unescape' undeclared (first use this function) [quote:38262e0eeb] PROG.CPP: In function `int main()': PROG.CPP:115: no matching function for call to `String::println()' PROG.CPP:119: no matching function for call to `String::change()' PROG.CPP:16: candidates are: void String::change(char, char) [/quote:38262e0eeb] Er is geen 'println' functie in de klasse String. De 'change' functie in de klasse String moet twee char-parameters meekrijgen, jij geeft er geen mee. PROG.CPP:124: no match for `String& - String&' operator [quote:38262e0eeb] PROG.CPP:127: no matching function for call to `String::maxpos(int)' PROG.CPP:17: candidates are: int String::maxpos() [/quote:38262e0eeb] De 'maxpos'-functie in de klasse String heb je gedeclareerd dat hij geen parameters meekrijgt, jij geeft er een mee. [quote:38262e0eeb] PROG.CPP:127: ` isthifunny' undeclared (first use this function) PROG.CPP:128: ` cin' undeclared (first use this function) [/quote:38262e0eeb] De eerste is een typefout 'isthifunny' moet 'isthisfunny' zijn De tweede wordt opgelost door 'using namespace std'. [/quote] Alles wat ik niet gequote heb weet ik niet. btw. Bij alles wat ik tussen accolades heb getypt moet je de accolades weglaten als je het verandert.
Link naar reactie

Om een reactie te plaatsen, moet je eerst inloggen

Gast
Reageer op dit topic

×   Geplakt als verrijkte tekst.   Herstel opmaak

  Er zijn maximaal 75 emoji toegestaan.

×   Je link werd automatisch ingevoegd.   Tonen als normale link

×   Je vorige inhoud werd hersteld.   Leeg de tekstverwerker

×   Je kunt afbeeldingen niet direct plakken. Upload of voeg afbeeldingen vanaf een URL in

  • Populaire leden

    Er is nog niemand die deze week reputatie heeft ontvangen.

  • Leden

    Geen leden om te tonen

×
×
  • Nieuwe aanmaken...