Question

Please do Realization, Directed Association, Reflexive Association, and Multiplicity........

To define 4 different object relationships with proper syntax with no compilation error.

  • Select 4 different types of object relationship out of 8 listed (in the picture below)
  • For each of the 4 relationships you may create any tow objects and these classes can be use for different relationships.
  • The class of objects can be reused in other relationship. That brings the max count, not min, of classes required is eight (8).
  • Create the Class declaration header and place ahead of a main app
  • Save the whole file as one .cpp file for all classes used in each of the 4 object relationships
  • You must provide the necessary information in your comment on the relationship between objects.

Here is the information regarding the above assignment:

Below is an example of different types of Object Relationships and its corresponding UML notations:

Passengers Passengers Passengers Airline Staff 0 Airplane Airplane Airplane Association Directed Asscoation Reflexive Assciat

In this lab, we’ll explore the nuances of the relation types “part-of”, “has-a”, “uses-a”, “depends-on”, “member-of”,... etc. We will show how these relationship can be useful in the context of C++ classes.

Come up four (4) pair of related Classes with their simple definition (i.e. declaration only) out of the above listed eight (8) relationships. The pair of classes in relationship maybe nested declared inside of another class or individually declared, depending on their relationship. (Please do Realization, Directed Association, Reflexive Association, and Multiplicity)

The class of objects can be reused in other relationship. That brings the max count, not min, of classes required is eight (8).

For example, a Customer is associated with a Store:

*note: You are to come up any pair of objects that you like to demonstrate your chosen object relationships.

#include 
#include 
#include 

using namespace std;
class Store;

class Customer
{
private:
        std::string m_name;
        std::vector m_customer; 
        void addStore(Store *rhs);
 
public:
        Customer(std::string name) : m_name(name) { }
        std::string getName() const { return m_name; }
        friend std::ostream& operator<<(std::ostream &out, const Customer &rhs);
        friend Store;
};
 
class Store {
private:
        std::string m_name;
        std::vector m_customer;
 
public:
        Store(std::string name): m_name(name) { }
        void addCustomer(Customer *rhs) { }
        std::string getName() const { return m_name; }
        friend std::ostream& operator<<(std::ostream &strm, const Store &rhs);
};

int main() { }; // an empty main to turn off compiler noise

Again, You are to

  • demonstrate four (4) C++ syntax Object (Class) relationships syntax!
  • select any four different relationship out of the above eight (8) object relationship.
  • come up a pair of related Object Classes to demonstrate the relationship as you declared, with minimum but sufficient features.

There should be minimum of 4 pair of class declarations for the 4 relationship. We may use these class declarations for a future assignment.

Submit:

  • lab_object_relationship.cpp (with appropriate object relationship C++ syntax)
  • test run: compiled with no error!
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//a code to show directed association between class using Home and Room
//A Home can have rooms but a room cannot have a Home.

//include header files
#include<iostream>
#include<string.h>

using namespace std;

class Home;

class Room
{
public:

    Room()
    {
    };

    static void createRoom_v(Room* (&room), Home* hse, char* name)
    {
      room = new Room(hse, name);
    }
  
    Room(Home* hse, char* myName)
    {
      cout<<"Room::ctor\n";
      p_myHouse = hse;
    
      if(NULL != p_myHouse)
      {
        name_of_person = new char(sizeof(strlen(myName)));
        name_of_person = myName;
      }
      else
      {
        cout<<"Oops Home itself is not Created Yet ...\n";
      }
    };

    ~Room()
    {
      cout<<"Room:dtor\n";
      p_myHouse = NULL;
      delete (name_of_person);
    };

    void disp()
    {
      cout<< name_of_person;
      cout<<"\n";
    }
  
    static void initList_v(Room *(& roomsList_p)[3])
    {
      roomsList_p[3] = new Room[3];
    }

private:
    Home * p_myHouse;
    char * name_of_person;
};

class Home
{
public:

    Home(char *myName)
    {
      cout<<"Home::ctor\n";
      name_of_person = new char(sizeof(strlen(myName)));;
      name_of_person = myName;

      Room::initList_v(roomsList_p);

      Room* mine_room;
      Room::createRoom_v(mine_room, this, "KITCHEN");
      roomsList_p[0] = mine_room;
    
      Room::createRoom_v(mine_room, this, "BedRoom");
      roomsList_p[1] = mine_room;

      Room::createRoom_v(mine_room, this, "Drawing Room");
      roomsList_p[2] = mine_room;
    }
  
    ~Home()
    {
      cout<<"Home:dtor\n";
      unsigned int i;
    
      cout<<"Delete all the Rooms ...\n";
      for(i=0; i<3; ++i)
      {
        if(roomsList_p[i] != NULL)
        {
          delete (roomsList_p[i]);
        }
        
      }
      delete [] roomsList_p;
      delete (name_of_person);
    }

    void disp()
    {
      cout<<"\n\nName of the Home :"<<name_of_person;
    
      if(roomsList_p != NULL)
      {
        unsigned int i;
        cout<<"\n\nRooms details...\n";
        for(i=0; i<3; ++i)
        {
          if(NULL != roomsList_p[i])
          {
            roomsList_p[i]->disp();
          }
        }
        cout<<"\n\n";
      }
    }

private:
    char* name_of_person;
    Room* roomsList_p[3];
};

int main()
{

cout<<"\nShowing example of Directed Relationship\n";
cout<<"-----------------------------------------\n\n";
Home hse("Tahir Abbas");

cout<<"\n\nShowing description of Home\n";
hse.disp();

cout<<"Home Creates room and then deletes based on itself\n";

return(0);
}

//A code to show multiple relationship since each Emp in a company can have only 1 manager
//butt a manager have multiple emploryees
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Emp {
private:
   string id, add, no;
   string initial_name, Name_last;


public:
   Emp(string firstNameArg, string Name_lastArg) :initial_name(firstNameArg), Name_last(Name_lastArg){}
   Emp() {}


   string getName() const { return this->initial_name + " " + Name_last; } // changed name to getName and made the function return the persons full name


};

class Manager {
private:
   //string manager1;
   vector<Emp> Empe;
public:
   void addEmp(Emp Emp) {
       Empe.push_back(Emp);
      
   }
};

int main() {
//Main function to display
   Emp Emp("Abbaas", "Tahir");
   cout << Emp.getName() << endl;
}

//Code for Realization Implementation

#include<iostream>
using namespace std;

class Class_For_Mammals{
public:
    virtual void running() = 0;
};


class Cats: public Class_For_Mammals {
public:
    void running() {
        cout<< "A running cat is seen" << endl;
    }
};

class Dogs: public Class_For_Mammals {
public:
    void running(){
        cout<< "A running dog is seen." << endl;
    }
};

int main(void) {
    Cats Cat_object;
    Dogs Dog_object;
    Class_For_Mammals *Mammals_pointer = NULL;

    Mammals_pointer = &Cat_object;
    Mammals_pointer->running();

    Mammals_pointer = &Dog_object;
    Mammals_pointer->running();

    return 0;
}

//A code to show reflexive relationships since Components can be made from further subcomponents

#include<iostream>
using namespace std;

class Components{
public:
   char * c;
   char* sub_components(){
       //subcomponents
       c="Subcomponents";
       return c;
   }
  
};

int main(void) {

   Components c1,c2;
   printf("Components of c1 are %s",c1.sub_components());

    return 0;
}

D:Freelancer WorksleLearner Task 9 Elearnerkdirected Association.exe Room:ctor Room: :ctor Room:ctor Home details.. Name of t

D:Freelancer WorksleLearnertTask 9 Elearnerlmultiplicity.exe Abbaas Tahir Process exited after 1.944 seconds with return valu

D:\Freelancer Works\eLearner!Task 9 Elearn errealization.exe A running cat is seen running dog is seen Process exited after 5

DAFreelancer WorksteLearner Task 9 Elearnerreflexive_Association.exe Components of c1 are Subcomponents Process exited after

COMMENT DOWN FOR ANY QUERIES,

AND LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.

D:Freelancer WorkstelearnerTask 9 Elearner directed Association.exe Home: :ctor Room: :ctor Room: ctor Room: :ctor Showing de

Add a comment
Know the answer?
Add Answer to:
Please do Realization, Directed Association, Reflexive Association, and Multiplicity........ To define 4 different object relationships with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE HELP ASAP Object Relationship In Module 6 Object Relationship, we have learned to construct relationships between...

    PLEASE HELP ASAP Object Relationship In Module 6 Object Relationship, we have learned to construct relationships between objects use proper C++ syntax. Here are two different Object Relationship the Car class is relating to two other objects Composition: CarEngine Aggregation: Car<-Passenger(s) To be precise, here is the illustration in UML representation Engine Car Composition: every car has an engine Car Passengers Aggregation: cars may have passengers, they come and go Below is the Class Definition without embedding the above relationships,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT