I'm behind and need IMMEDIATE help

Apr 28, 2017 at 9:04pm
So I'm at a loss for my current assignment. I've missed some classes and so I've lost my knowledge on how to go about it but basically the problem is this.

Create a base class Music, a class Genre derived from Music, and a class Performer derived from Genre. Class Music only has a string title, Genre adds string type and Performer has string name.
Interview the user for their favorite artist, their genre and title of the music they like best. Then call a Performer class display function that shows all the information. Inheritance must be used.

I'm not sure how to even start this as I said I am behind and have forgotten a lot. If I could get help on even just a dummy way to make the class and then call it for the interview I would be greatful
Apr 28, 2017 at 9:30pm
You could create the classes like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Music
{
  string title;
};

class Genre : public Music
{
  string type;
};

class Performer : public Genre
{
public:
  void display();
  string name;
};

How shall they be used? Passing the data in the constructor or defining setters and getters?
Apr 28, 2017 at 9:38pm
Sorry I've lost my knowledge of much of the vocab as well so I'm not sure what you mean. Basically I want to have it so that it asks the genre and music individually and asks the user for the input instead of a pre created lists. Not sure if that answered your question or not.
Apr 29, 2017 at 12:36am
So here is what I have for the main function of these classes.
1
2
3
4
5
6
7
8
9
10
int main()
{
    Genre("What is your favorite genre of music?");
cout<<endl;
    Music("Who is your favorite musician in that genre?");
cout<<endl;
    Performer.display();

    return 0;
}

I am not sure how to call classes or display them or anything, someone please help.
Apr 29, 2017 at 1:42am
You don't "call" classes: classes only describe things - e.g., class Genre only describes what a Genre is. It's the job of an object or instance of class Genre which represents a particular Genre, for example, an instance of Genre named rock should represent specifically Rock and Roll.

the interview...

If you're going to be discussing the problem, I would consider mentioning that the problem specification implies that a Performer is a Genre (inheritance implies that a subclass is-a base class.) This is nonsense at worst, or at least counter-intuitive.

Slightly more in-depth:
http://www.cplusplus.com/forum/beginner/213266/#msg995536
Also, the tutorial:
http://www.cplusplus.com/doc/tutorial/structures/
http://www.cplusplus.com/doc/tutorial/classes/

Last edited on Apr 29, 2017 at 1:43am
Apr 29, 2017 at 7:36am
A quick implementation on how to use the classes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Music
{
public:
  Music(string title)
  {
    this->title = title;
  }
  string getTitle() {return title;}
private:
  string title;
};

class Genre : public Music
{
public:
  Genre(string type, string title): Music(title)
  {
    this->type = type;
  }
  string getType() {return type;}
private:
  string type;
};

class Performer : public Genre
{
public:
  Performer(string name, string type, string title):Genre(type, title)
  {
    this->name = name;
  }
  void display()
  {
    cout << "Performer info" << "\n\nTitle: " << getTitle()
         << "\nGenre: " << getType()
         << "\nName: " << name << "\n\n";
  }
private:
  string name;
};


int main()
{
  Performer p("Some Name", "Some type", "Some title");
  p.display();
  system("pause");
  return 0; 
}
Apr 29, 2017 at 4:22pm
what does the
system("pause");
part mean as I'm not sure how to implement it. Also how do I use the class in a way that it asks the user for the title and genre? Would it be a simple cin or something else?
Apr 29, 2017 at 8:10pm
welp pause wasn't needed. Anyway I figured it out thanks a bunch.
Topic archived. No new replies allowed.