Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An array would be: class bookGenre // Class that will become a composite object.

ID: 3640940 • Letter: A

Question

An array would be:

class bookGenre // Class that will become a composite object.
{
public:
void setX(int i);
...
private:
int x;
...
}

class books
{
public:
bookGenre[b];
private:
int b;
...
}

void main(void)
{
int a;
books book;
for (i = 0; i < 6; i++)
books.bookGenre[i] // Just to fill it with random stuff.
}

Basically I chose this topic because it was simple, books have genres that in reality the user would probably fill themselves. I choose to fill it with 5 genres for no specific reason because there are many many different types of genres.

The real reason that I choose this layout was to ask Prof. Alnaji if this is how you would actually fill a composite object array. I believe the way to fill a normal object array would be:

myClass
{
public:
...
private:
...
}

void main(void)
{
myClass class1[5];
class1[0].member = dataMember;
...
}

1.
The second block of code is excellent bu the line:
bookGenre[b];

what's b?

2. what applications require the use of an array of classes?how?

Explanation / Answer

1. b, in the statement bookGenre[b], is simply the index into the bookGenre array. In other words, it's accessing the b'th element in the array. A lot of times this is an i, or an n. Anything works though, its just a variable. 2. If you had a class named Fiction, and inside that class you had a class called Book, you could make an array of Books inside your Fiction class. The purpose of having an array of classes is just to make it easier to read, and modify your program when you come back to it later on, and also to make it easier on you, the programmer. It's much more natural to access a book from an array of Books, than it is to try to do anything else. Is this what you needed?

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote