Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

Hello, I am working on a C++ assignment and I'm trying to create an array inside of a class. This class incorporates a linked list and the different index in that array will take on a certain value from this link list. This is my code from my class called word: class word{ public: string name; string words; int numTimes; word(int i){ words[i]; } word(string n){ numTimes=0; name=n; } word* next; word* previous; }; What I'm trying to do in my int main is print out the words using the array word(int i) parameter, below is my attempt. Will give medal.

OpenStudy (anonymous):

This is my attempt: for(int i=0; i<=185; i++){ cout << words.name<<" "; i++; }

OpenStudy (anonymous):

Any help would be great thank you@

OpenStudy (anonymous):

for (int i=0; i<=185; i++) { cout << words[i].name; i++; }

OpenStudy (anonymous):

Thank you! This was the correct way. However, it didn't work at first because I had to include other things in my class definition(making a change in my array definition and adding an empty constructor) Afterwords I added some different things in my int main() and incorporated the "[i]" you added in my code.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!