C++: Another example on creating an object

This entry is part 32 of 61 in the series C++

Consider this example where we want to create a warning when a plane is travelling too fast.

We will call this method SpeedCheck.  As we are using this method on a plane, we put this method under the Plane class.

#include <iostream>

using namespace std;

class Plane

	double speed;

	double SpeedCheck(double);

	Plane();  //This is the constructor
	~Plane();  //This is the destructor


double Plane::SpeedCheck(double sp)

	double speed = sp;

	if (speed >= 1000)
		cout << "You are going interstellar";
		cout << "You are doing just fine";

	return 0;



int main()

	double speed = 1001;

	Plane Plane1; // instance declaration
	cout << endl;

Series Navigation<< C++: Work out the method first
C++: Voiding a function >>