Você está na página 1de 5

//C++ Concept programing--- btm

#include <iostream>
using namespace std;
class CDimensions //class
{
public: //Encapsulation
float width,length,height,fourthdim;
int oper;
CDimensions(); //Costructor

};
CDimensions::CDimensions() //Scope resolution operator
::
{
width=1;
length=1;
height=1;
fourthdim=1;
}

class CCircle: public CDimensions //Inheritance


{
public:
CCircle() //Default Constructor
{
cout<<"Enter Radius\n";
cin>>fourthdim;
cout<<"Select operation\n";
cout<<"1.area\n";
cout<<"2.cicumference\n";
cin>>oper;

if(oper==1)
circarea(fourthdim);
else if(oper==2)
circumf(fourthdim);
else
cout<<"You have choosen WRONG choice \n";
}

void circarea(float val)


{
cout<<"Circle Area is: "<< 3.14*val*val<<'\n';
}
void circumf(float val)
{
cout<<"Circle Circumference is: "<< 2*3.14*val<<'\n';
}
friend class CUnknown; //Friend class

};

class CRect: public CDimensions


{
public:

CRect() //Default Constructor


{
cout<<"Enter Length\n";
cin>>length;
cout<<"Enter Width\n";
cin>>width;
cout<<"Select operation\n";
cout<<"1.area\n";
cout<<"2.cicumference\n";
cin>>oper;

if(oper==1)
rectarea(length,width);
else if(oper==2)
rectcircum(length,width);
else
cout<<"You have choosen WRONG choice \n";
}

CRect(int squ) //Constructor Overloading


{
cout<<"Enter Side\n";
cin>>length;
cout<<"Select operation\n";
cout<<"1.area\n";
cout<<"2.cicumference\n";
cin>>oper;
if(oper==1)
rectarea(length);
else if(oper==2)
rectcircum(length);
else
cout<<"You have choosen WRONG choice \n";
}

void rectarea(float len,float wid)


{
cout<<"Rectangle Area is: "<< len*wid<<'\n';
}
void rectcircum(float len,float wid)
{
cout<<"Rectangle Circunference is: "<< 2*len*wid<<'\n';
}

void rectarea(float len) //function overloading


{
cout<<"Square Area is: "<< len*len<<'\n';
}
void rectcircum(float len) //function Overloading
{
cout<<"Square Circunference is: "<< 4*len<<'\n';
}

};
class CTriangle: public CDimensions
{
public:
CTriangle()
{
cout<<"Enter base length\n";
cin>>length;
cout<<"Enter Height\n";
cin>>width;
cout<<"Select operation\n";
cout<<"1.area\n";
cout<<"2.cicumference\n";
cin>>oper;

if(oper==1)
triarea(length,width);
else if(oper==2)
tricircum();
else
cout<<"You have choosen WRONG choice \n";
}
void triarea(float len,float heig)
{
cout<<"Triangle Area is: "<< 0.5*len*heig<<'\n';
}
void tricircum()
{
cout<<"Enter 3 sides value\n";
cin>>length>>width>>height;

cout<<"Triangle Circunference is: "<<length+width+height <<'\n';


}
};

class CUnknow: public CDimensions


{
public:
int n;
int ch;

CUnknow()
{
cout<<"How many dimension data U have?\n";
cin>>n;
switch (n)
{
case 1:
{
cout<<"Which one is best suits for ur object\n";
cout<<"1.Circle\n";
cout<<"2.square\n";
cin>>ch;
if(ch==1)
CCircle cir; //friend class object creation
else
CRect squ(1); //friend class object creation

break;

}
case 2:
{
CRect rect;
break;
}
case 3:
{
CTriangle tri;
break;
}
default:
cout<<"Sorry for inconvience we are not able to idendify the shape\n ";

}
}
};

int main ()
{
int choice;
int shape=0;
cout<<"This application is for geomentric calculation"<<endl;
cout<<"Choose your Geomentric"<<endl;
do
{
cout<<"----------------\nChoose Shape"<<endl;
cout<<"1.Circle \n";
cout<<"2.Square \n";
cout<<"3.Rectangle \n";
cout<<"4.Triangle \n";
cout<<"5.Don't Know the Shape \n";
cin>>shape;

switch (shape)
{
case 1:
{
CCircle cir; //Object creation
break;

}
case 2:
{
CRect squ(1); //Object will parametrized constructor
break;
}
case 3:
{
CRect rect; //Object will calldefault constructor
break;
}

case 4:
{
CTriangle tri;
break;
}

case 5:
{
CUnknow element;
break;
}

default:
cout<<"Sorry for inconvience u selected wrong option\n";

}while(1);

return 0;
}

Você também pode gostar