Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- class human{
- protected:
- string name,surname;
- int age;
- public:
- human(string x,string y){
- name=x;
- surname=y;
- age=0;
- }
- human(string x,string y,int age_1){
- name=x;
- surname=y;
- age=age_1;
- }
- void say_hello(){
- if(age>0){
- cout<<"hello my name is "<<name<<" "<<surname<<endl<<age<<" years old"<<endl;
- }
- else{
- cout<<"hello my name is "<<name<<" "<<surname<<endl;
- }
- }
- };
- class worker : public human{
- protected:
- float salary;
- string jobname;
- public:
- worker(string x, string y, float z,string job) : human(x, y), salary(z),jobname(job){}
- worker(string x, string y,int age_1, float z,string job) : human(x, y, age_1), salary(z),jobname(job){}
- void say_hello(){
- human::say_hello();
- cout << "\t salary - "<<salary<<" job name is "<<jobname << endl;
- }
- };
- class animal{
- public:
- virtual void print()=0;
- };
- class cat:public animal{
- public:
- void print(){
- cout<<"cat"<<endl;
- }
- };
- class dog:public animal{
- public:
- void print(){
- cout<<"dog"<<endl;
- }
- };
- class shape{
- public:
- virtual float S() = 0;
- };
- class square:public shape{
- public:
- float a,s;
- square(float x){
- a=x;
- }
- float S(){
- s=a*a;
- return s;
- }
- };
- class rectangle:public shape{
- public:
- float a,b,s;
- rectangle(float a1,float b1):a(a1),b(b1){
- }
- float S(){
- s=a*b;
- return s;
- }
- };
- class circle:public shape{
- public:
- float p=3.1415;
- float r;
- circle(float r1):r(r1){
- }
- float S(){
- float s=p*(r*r);
- return s;
- }
- };
- class triangle:public shape{
- public:
- float a,b,c;
- triangle(float a1,float b1,float c1):a(a1),b(b1),c(c1){}
- float S(){
- float p=(a+b+c)/2;
- float s=sqrt(p*(p-a)*(p-b)*(p-c));
- return s;
- }
- };
- int main()
- {
- shape *a=new square(5);
- cout << a->S() << endl;
- shape *b=new rectangle(5,10);
- cout<< b->S()<<endl;
- shape *c=new circle(12);
- cout<< c->S()<<endl;
- shape *t=new triangle(3,4,5);
- cout<<t->S()<<endl;
- }
Add Comment
Please, Sign In to add comment