The assignment is to write our own string function; not a big deal. However I dont think that I am declaring everything correctly as I am getting 20-some nearly identical errors that I cant get to go away. Any insight into the issue here would be greatly appreciated.
mystring.h
mystring.cppCode:#include <iostream> using namespace std; class String { public: void string(); void assign(const char s[]); void append(const String &str); int compare_to(const String &str); void print() const; int length() const; char element(int i); private: int lngth; char strng[100]; }
Code:#include "mystring.h" #include <iostream> using namespace std; void String() { for (int i=0;i<100;i++) { strng[i]='\0'; } } void assign(const char s[]) { lngth=0; for (int i=0;i<100;i++) { strng[i]=s[i]; lngth++; } } void append(const String &str) { int i,n; for (i=0;i<100 && strng[i]!='\0';i++) { } for (n=0; *(str+n)=!'\0'; n++,i++) { strng[i]=*(str+n); lngth++; } } int compare_to(const String &str) { int i, n, check=0; for (i=0;(i<100 && strng[i]!='\0')&&(n<100 && *(str+n)!='\0')&& check=0;i++) { if (strng[i]<*(str+n)) check=-1; if (strng[i]>*(str+n)) check=1; } return check; } void print() const { for (int i=0; strng[i]!='\0';i++) cout<<strng[i]; } int length() const { return lngth; } char element(int i) { if (i<100 && strng[i]=!'\0') return strng[i]; else cerr<<"Element out of range"; return '\0'; }
....error messages
the above errors were all attributed to mystring.cpp. The driver file was provided, and I am confident It it error-free.Code:1>mystring.cpp error C2143: syntax error : missing ';' before 'using' (11) : error C2065: 'strng' : undeclared identifier (16) : error C2065: 'lngth' : undeclared identifier (19) : error C2065: 'strng' : undeclared identifier (20) : error C2065: 'lngth' : undeclared identifier (24) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (24) : error C2143: syntax error : missing ',' before '&' (27) : error C2065: 'strng' : undeclared identifier (30) : error C2065: 'str' : undeclared identifier (32) : error C2065: 'strng' : undeclared identifier (32) : error C2065: 'str' : undeclared identifier (33) : error C2065: 'lngth' : undeclared identifier (37) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (37) : error C2143: syntax error : missing ',' before '&' (40) : error C2143: syntax error : missing ';' before 'for' (40) : error C2065: 'strng' : undeclared identifier (40) : error C2065: 'str' : undeclared identifier (42) : error C2065: 'strng' : undeclared identifier (42) : error C2065: 'str' : undeclared identifier (44) : error C2065: 'strng' : undeclared identifier (44) : error C2065: 'str' : undeclared identifier (53) : error C2270: 'print' : modifiers not allowed on nonmember functions (54) : error C2065: 'strng' : undeclared identifier (55) : error C2065: 'strng' : undeclared identifier (59) : error C2270: 'length' : modifiers not allowed on nonmember functions (60) : error C2065: 'lngth' : undeclared identifier (65) : error C2065: 'strng' : undeclared identifier (66) : error C2065: 'strng' : undeclared identifier




Reply With Quote