编程题
5.1
#include
#define PI 3.14159
using namespace std;
//重载函数
double getGirth(double length, double width)
{
return 2 * (length + width);
}
//重载函数
double getGirth(double radius)
{
return PI * radius * radius;
}
void main( )
{
cout<
5.2
#include
#include
using namespace std;
class Person
{
protected:
string name;
int age;
public:
Person(){}
Person(string n, int a):name(n), age(a){};
~Person(){}
void display()
{
cout<<"姓名:"<
};
class Student : public Person
{
protected:
int sid;
public:
Student(int id, string n, int a)
{
name = n;
age =a;
sid = id;
}
~Student(){}
void display()
{
cout<<"姓名:"<
};
class Teacher : public Person
{
protected:
string title;
public:
Teacher(string t, string n, int a)
{
name = n;
age =a;
title = t;
}
~Teacher(){}
void display()
{
cout<<"姓名:"<
};
void main( )
{
Person p = Person("张三其", 25);
p.display();
Student s = Student(1001, "李师煊", 19);
s.display();
Teacher t = Teacher("副教授", "王五", 39);
t.display();
}