OOOOPPPPP

#include <iostream>
#include <cmath>
#include <iomanip>
#define pi acos(-1);
using namespace std;
class Shape
{
public:
	virtual void area() {};
	
};
class Circle : public Shape
{
private:
	double r;
public:
	Circle(double rr)
	{
		r = rr; 
	}
	Circle() {};
	virtual void area()
	{
		double ans = pow(r, 2) * pi;
		cout << fixed << setprecision(2) << ans << endl;
	}
};
class Square : public Shape
{
private:
	double a;
public:
	Square() {};
	Square(double aa) { a = aa; }
	virtual void area()
	{
		cout << fixed << setprecision(2) << pow(a, 2) << endl;
	}
};
class Rectangle : public Shape
{
private :
	double n, m;
public:
	Rectangle() {};
	Rectangle(double nn, double mm) { n = nn, m = mm; }
	virtual void area()
	{
		cout <<fixed << setprecision(2)<< n * m << endl;
	}
};

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		double r, n, m, a;
		cin >> r >> a >> n >> m;
		Circle one(r);
		Square two(a);
		Rectangle three(n, m);
		Shape* p;
		p = &one;
		p->area();
		p = &two;
		p->area();
		p = &three;
		p->area();
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
using namespace std;
class Vehicle
{
protected:
	string no;
public:
	virtual void display() = 0;
};
class Car :public Vehicle
{
private:
	int number, weight;
public:
	Car(string nono, int n, int w)
	{
		no = nono, number = n, weight = w;
	}
	virtual void display()
	{

		cout << number * 8 + weight * 2 << endl;
	}
};
class Truck :public Vehicle
{
private:
	int number, weight;
public:
	Truck(string nono, int w)
	{
		no = nono, weight = w;
	}
	virtual void display()
	{
		cout << weight * 5 << endl;
	}
};
class Bus :public Vehicle
{
private:
	int number, weight;
public:
	Bus(string nono, int n)
	{
		no = nono, number = n;
	}
	virtual void display()
	{
		cout << number * 30 << endl;
	}
};
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		Vehicle* p;
		int n;
		string no;
		int number, weight;

		cin >> n;

		if (n == 1)
		{
			cin >> no >> number >> weight;
			Car a(no, number, weight);
			p = &a;
			cout << no << " ";
			p->display();
		}
		else if (n == 2)
		{
			cin >>no >>  weight;
			Truck b(no, weight);
			p = &b;
			cout << no << " ";
			p->display();
		}
		else
		{
			cin >>no >> number;
			Bus c(no, number);
			p = &c;
			cout << no << " ";
			p->display();
		}
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
class Animal
{
protected:
	string name ;
	string type;
	int age;
public:
	virtual void speak() = 0;
};
class tiger : public Animal
{
public:
	tiger(string ty , string na , int ag) 
	{
		type = ty , name = na , age = ag;
	}
	virtual void speak()
	{
		cout << "Hello,I am " << name << ",AOOO."<< endl; 
	}
};
class dog: public Animal
{
public:
	dog(string ty , string na , int ag) 
	{
		type = ty , name = na , age = ag;
	}
	virtual void speak() 
	{
		cout << "Hello,I am " << name << ",WangWang."<< endl; 
	}
};
class duck : public Animal
{
public:
	duck(string ty , string na , int ag) 
	{
		type = ty , name = na , age = ag;
	}	
	virtual void speak()
	{
		cout << "Hello,I am " << name << ",GAGA."<< endl; 
	}
};
class pig : public Animal
{
public:
	pig(string ty , string na , int ag) 
	{
		type = ty , name = na , age = ag;
	}
	virtual void speak()
	{
		cout << "Hello,I am " << name << ",HENGHENG."<< endl; 
	}
};
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		Animal * p ;
		string name , type;
		int age;
		cin >> type >> name >> age;
		if(type == "Tiger")
		{
			tiger a(type,name, age);
			p = &a;
			p->speak();
		}
		else if(type == "Pig")
		{
			pig b(type,name,age);
			p = &b;
			p->speak();
		}
		else if(type == "Duck")
		{
			duck c(type , name , age);
			p = &c;
			p->speak();
		}
		else if(type == "Dog")
		{
			dog d(type , name , age );
			p = & d;
			p->speak();
		}
		else
		{
			cout << "There is no " << type << " in our Zoo." << endl;
		}

	}
	return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值