Header Ads

Create a program that will display the following information on multimedia screens for their audience.


Problem Statement




style="display:block; text-align:center;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="ca-pub-7200085558568021"
data-ad-slot="3193586076">




Suppose
you are hired by Pakistan Art Council as a software engineer to work on
different ongoing projects. You are now given a task to create a program for
their multimedia screens which usually contains insights into ongoing events for
the participants. In Islamabad, they are about conduct a Lok Versa musical
night event, 
Pakistan Art Council now wants
you to create a program that will display the following information on multimedia
screens for their audience.



1) Name of Artist

2) Artist  Music Band

3) Artist Music Category

4) Artist's main instrument



Keeping in mind the above scenario, consider
the following class diagram showing the composition, aggregation, and
inheritance relationship among the classes.


Now, you are required to write a C++ program for the above given class diagram.




style="display:block"
data-ad-format="autorelaxed"
data-ad-client="ca-pub-7200085558568021"
data-ad-slot="6426802817">




Guidelines:

Carefully analyze the given class diagram. 


Write a C++ code for the given classes including attributes, functions, and relationships mentioned in the class diagram.

Create one object of each, class Pop and class Classic.

Object of class Pop should print Artist Name as your First Name and Band Name as your Last Name. 

Second object of class Artist should print Artist Name as your Last Name and Band Name as your First Name. 

Composition and inheritance concepts must be included in your code as depicted in the class diagram. 

Sample Output:







Solution :





style="display:block; text-align:center;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="ca-pub-7200085558568021"
data-ad-slot="3193586076">






#include <iostream>
#include <string>

using namespace std;

class Artist {
    private:
        string artistName;
        MusicBand band;
        MusicCategory category;
    public:
        Artist() {};
        void SetArtistName(string name) {
            artistName = name;
        }
        string GetArtistName() {
            return artistName;
        }
        void Display() {
            cout << "Artist name : " << artistName << endl;
            band.Display();
            category.Display();
        }
};

class MusicBand {
    private:
        string bandName;
    public:
        MusicBand() {};
        void SetBandName(string name) {
            bandName = name;
        }
        string GetBandName() {
            return bandName;
        }
        void Display() {
            cout << "Music Band name : " << bandName << endl;
        }
};

class MusicCategory {
    private:
        string categoryName;
        string instrument;
    public:
        MusicCategory() {};
        void SetCategoryName(string name) {
            categoryName = name;
        }
        string GetCategoryName() {
            return categoryName;
        }
        void SetInstrument(string inst) {
            instrument = inst;
        }
        string GetInstrument() {
            return instrument;
        }
        void Display() {
            cout << "Music Category Name : " << categoryName << endl;
            cout << "Instrument Name : " << instrument << endl;
        }
};

class Pop: public MusicCategory {};
class Classic: public MusicCategory {};

int main() {
    string vuid;
    cout << "VUID: ";
    cin >> vuid;

    Artist firstArtist;
    string artistName;
    cout << "Enter Artist name : ";
    cin >> artistName;
    firstArtist.SetArtistName(artistName);

    MusicBand firstBand;
    string bandName;
    cout << "Enter Music Band name : ";
    cin >> bandName;
    firstBand.SetBandName(bandName);

    Pop firstPop;
    string categoryName = "Pop";
    firstPop.SetCategoryName(categoryName);
    string instrument;
    cout << "Enter Instrument Name : ";
    cin >> instrument;
    firstPop.SetInstrument(instrument);

    firstArtist.band = firstBand;
    firstArtist.category = firstPop;

    Artist secondArtist;
    cout << "Enter Artist name : ";
    cin >> artistName;
    secondArtist.SetArtistName(artistName);

    MusicBand secondBand;
    cout << "Enter Music Band name : ";
    cin >> bandName;
    secondBand.SetBandName(bandName);

    Classic secondClassic;
    categoryName = "Classic";
    secondClassic.SetCategoryName(categoryName);
    cout << "Enter Instrument Name : ";
    cin >> instrument;
    secondClassic.SetInstrument(instrument);

    secondArtist.band = secondBand;
    secondArtist.category = secondClassic;

    cout << "Data of First Artist" << endl << endl;
    firstArtist.Display(); 
    cout << endl << "Data of Second Artist" << endl << endl; 
    secondArtist.Display();
 
    return 0;

}




style="display:block"
data-ad-format="autorelaxed"
data-ad-client="ca-pub-7200085558568021"
data-ad-slot="6426802817">

No comments

Powered by Blogger.