Please do Realization, Directed Association, Reflexive Association, and Multiplicity........
To define 4 different object relationships with proper syntax with no compilation error.
Here is the information regarding the above assignment:
Below is an example of different types of Object Relationships and its corresponding UML notations:
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
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:
//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;
}
COMMENT DOWN FOR ANY QUERIES,
AND LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.
Please do Realization, Directed Association, Reflexive Association, and Multiplicity........ To define 4 different object relationships with...
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,...