Implement the four classes illustrated in the UML class diagram below in a Use i
ID: 3817783 • Letter: I
Question
Implement the four classes illustrated in the UML class diagram below in a Use initialize lists whenever possible the destructor and the "setBeta" function should not cause a memory leak of crash by trying to delete a null pointer In addition to displaying the data in the Alpha object, the Alpha "display" function should also display the data stored in the two related objects Implement a main that instantiates a Delta object, sets a Beta, and then displays the Delta(hard code the test data in main-do not add prompts, loops, or menus)Explanation / Answer
/* save the file with the name Greek.cpp
#include<iostream.h>
#include<conio.h>
public class Alpha
{
public :
char name[20];
char part;
public Alpha(char a_name[20],a_part char,int a_id)
{
name=a_name;
part=a_part;
cout<<"nter the alpha id is"<<a_id<<endl;
}
public ~Alpha()
{
cout<<"the destructor in alpha:"<<endl;
}
public void setBeta(Double a_cost)
{
cout<<"the apha cost is:"<<a_cost<<endl;
}
public void display()
{
cout<<"the alpha name is"<<name<<endl;
cout<<"the apha part is:"<<part<<endl;
}
}
public class Beta
{
public:
double cost;
public Beta(double a_cost)
{
a_cost=cost;
}
public void display()
{
cout<<"the cost is"<<cost;
}
}
public class Gamma
{
int id;
public Gamma(int a_id)
{
id=a_id;
}
public void display()
{
cout<<"the id is"<<id;
}
}
public class Delta : public Alpha
{
public:
char desc[20];
public Delta(char a_name,char a_part,int a_id,char a_desc[20])
{
cout<<"nter the name :"<<a_name<<endl;
cout<<"nter the part:"<<a_part<<endl;
cout<<"nter the id:"<<a_id<<endl
desc=a_desc;
}
public void display()
{
cout<<"the desc is;"<<desc;
}
}
int main()
{
clrscr();
Delta d("dxyz",'x',123,'D');
d.display();
d.setBeta(123.45);
Alpha a1("Axyz",'A',345);
a1.display();
return 0;
}