⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 application1.cpp

📁 对于特定长度的高速公路
💻 CPP
字号:
#include <iostream.h>

/*     Classes   */

class Spark_plug
{
	private:
		double gap_size;
	public:
		Spark_plug();
		void ignite();
};

class Engine
{
	private:
		Spark_plug  spark_plug[6];
		int horsepower;
	public:
		Engine();
		void begin_ignition();
};


class Wheel
{
	private:
		double size;
	public:
		Wheel();
		void inflate_tires();
		void turn_right();
};

class Steering_wheel
{
	private:
		Wheel* wheel_ptr[4];
		double diameter;
	public:
		Steering_wheel( Wheel* );
		void rotate_clockwise();
};

class Car
{
	private:
		Wheel  wheel[4];
		Engine  the_engine;
		Steering_wheel  the_steering_wheel;  

	public:
		Car();
		void prepare_tires();
		void turn_ignition_key();
		void drive_to_right();
};


/*      Car functions   */

Car::Car() 
       : the_steering_wheel (wheel)
{
}

void Car::prepare_tires()
{
	int i;
	for (i=0; i<4; i++) wheel[i].inflate_tires();
}

void Car::turn_ignition_key()
{
	the_engine.begin_ignition();
}


void Car::drive_to_right()
{
	the_steering_wheel.rotate_clockwise();
}

/*   Steering_wheel functions   */


Steering_wheel :: Steering_wheel ( Wheel*  wheel_var ) 
                           : diameter(40)
{
	int i;
	for(i=0; i<4; i++)   wheel_ptr[i] = wheel_var + i;
}

void Steering_wheel :: rotate_clockwise( )
{
	int i;
	for (i=0; i<4; i++)  wheel_ptr[i]->turn_right();
}

/*  Engine functions   */

Engine::Engine() 
            : horsepower(400)
{
}


void Engine::begin_ignition()
{
	int i;
	for (i=0; i<6; i++) spark_plug[i].ignite();
}

/*  Wheel functions */
Wheel::Wheel() 
           : size(15)
{
}

void Wheel::inflate_tires()
{
		cout<<"Tire inflated."<<endl;
}

void Wheel::turn_right()
{
		cout<<"Wheel turned right."<<endl;
}



/*   Spark_plug functions   */
Spark_plug::Spark_plug() 
                   : gap_size(1.2)
{
}

void Spark_plug::ignite()
{
	cout<<"Spark plug ignited."<<endl;
}

/*     main   */

int main ( )
{
	Car ford1950;
	ford1950.prepare_tires();
	ford1950.turn_ignition_key();
	ford1950.drive_to_right();

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -