?? c55.cpp
字號:
// 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;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -