c55.cpp
来自「大量的C++语言代码,可以快速的学习C++的相关知识」· C++ 代码 · 共 79 行
CPP
79 行
// c55.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
// --------------------------------------------------------------------------
// class Description
class Description
{
public:
Description( char* info ) : information(info) {}
public:
virtual void Print() { cout << endl << information << endl; }
private:
char* information;
};
// --------------------------------------------------------------------------
// class Sphere
class Sphere : public Description
{
public:
Sphere( char* info, float rad ) : Description(info), radius(rad) {}
public:
void Print()
{
Description::Print();
cout << "radius = " << radius << endl;
}
private:
float radius;
};
// --------------------------------------------------------------------------
// class Cube
class Cube : public Description
{
public:
Cube( char* info, float edge ) : Description(info), edgeLength(edge) {}
public:
void Print()
{
Description::Print();
cout << "edge length = " << edgeLength << endl;
}
private:
float edgeLength;
};
// --------------------------------------------------------------------------
Sphere smallBall( "mini", 1.0 );
Sphere beachBall( "plastic", 24.0 );
Sphere planetoid( "moon", 24 );
Cube crystal( "carbon", 24 );
Cube ice( "party", 1.0 );
Cube box( "cardboad", 16.0 );
Description* shapes[] = { &smallBall, &beachBall, &planetoid, &crystal, &ice, &box };
// --------------------------------------------------------------------------
// entrance to main
int main(int argc, char* argv[])
{
for ( int i = 0; i < sizeof( shapes ) / sizeof( shapes[0] ); ++i )
shapes[i]->Print();
cout << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?