edelossantos
asked on
Anagrams
Does not compile, please advise. Del
class Ana {
public:
Ana(){};
~Ana(){};
int getArraySize(char []);
void printAnagrams ( char [], int );
private:
char str[256];
char *nWord;
int Counter = 0;
};
#endif
*******************
// ana.cpp
// Sheet 2
#include<iostream>
#include<cctype>
#include<string>
#include "ana.h"
using namespace std;
int Ana::getArraySize(char a[]) {
int sz = 0;
int x = 0;
do {
x = a[sz];
sz++;
}
while(x != 0);
sz-=1;
return (sz);
}
void Ana::printAnagrams ( char a[], int len ) {
if(len <= 1) {
nWord = a;
cout << nWord << endl;
Counter++;
}
else {
int i;
char temp;
for (i = 0; i < len; i++) {
temp = a[i];
a[i] = a[len-1];
a[len-1] = temp;
printAnagrams(a, len-1);
temp = a[i];
a[i] = a[len-1];
a[len-1] = temp;
}
}
}
#include "ana.h"
int main() {
Ana = a;
cout <<"Enter Word: ";
cin >> str;
cout << endl;
int Len = getArraySize(str);
a.printAnagrams(str,Len);
cout << endl << Counter <<" Anagrams";
cout<< endl;
return 0;
system("pause");
}
Output:
In file included from ana.cpp:8:
ana.h:29: error: ISO C++ forbids initialization of member `Counter'
ana.h:29: error: making `Counter' static
ana.h:29: error: ISO C++ forbids in-class initialization of non-const static
member `Counter'
ana.cpp: In function `int main()':
ana.cpp:63: error: parse error before `=' token
ana.cpp:66: error: `str' undeclared (first use this function)
ana.cpp:66: error: (Each undeclared identifier is reported only once for each
function it appears in.)
ana.cpp:68: error: `getArraySize' undeclared (first use this function)
ana.cpp:70: error: `a' undeclared (first use this function)
ana.cpp:71: error: `Counter' undeclared (first use this function)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Alex,
When I made the mistake of taking a quarter off from CS, I forgot alot of the simple concepts. I am playing catchup, and I can see now that taking any time off from progamming is a big mistake. Del
When I made the mistake of taking a quarter off from CS, I forgot alot of the simple concepts. I am playing catchup, and I can see now that taking any time off from progamming is a big mistake. Del
Del, I didn't want to blame you. Just wondered.
Thanks for the points ;-)
Regards, Alex
Thanks for the points ;-)
Regards, Alex
you are an EE member since 2 years. In all the time you have seen hundreds of C++ samples and should know the very basics of C++. The errors you posted above easily can be solved by a beginner. The compiler showed you the lines that were wrong and the error messages were quite clearly.
I wonder why you need to post a 500 points question for something like that.
Regards, Alex