Answers for "class in c++"

C++
4

class in c#

public class Car
{  
    // fields
    public bool isDriving = false;
    
    // constructor
    public Car( string make )
    {
        Make = make;
    }
	
    // properties
    private string _make = string.Empty;
    public string Make
    {
        get { return _make; }
        set { _make = value; } 
    }
    
    // methods
    public void drive()
    {
        if( isDriving )
        {
			// Car is already moving
        }
        else
		{
            // start driving the car
            isDriving = true;
    	}        
    }

    public void stop()
    {
		if( isDriving )
		{
			// stop the car 
			isDriving = false;
		}
        else
        {
			// car is already not moving
        }        
    }      
}

// ---
// An example of using this class in a console app

using System;
					
public class Program
{
	public static void Main()
	{		
        // construct a new class of type Car and set the Make
      	// property to "VW" using the constructor.
		Car newCar = new Car( "VW" );
		
      	// display the make of our new car
		Console.WriteLine( newCar.Make );
		
      	// call the drive method of the car class
		newCar.drive();		
		
      	// display the value of the isDriving property to
		Console.WriteLine( newCar.isDriving );
		
      	// call the stop method of the car class
		newCar.stop();
		
      	// display the value of the isDriving property
		Console.WriteLine( newCar.isDriving );
	}
}

// the class 
public class Car
{  
    // fields
    public bool isDriving = false;
    
    // constructor w
    public Car( string make )
    {
        Make = make;
    }
	
    // properties
    private string _make = string.Empty;
    public string Make
    {
        get { return _make; }
        set { _make = value; } 
    }
    
    // methods
    public void drive()
    {
        if( isDriving )
        {
        		// Car is already moving
        }
        else
		{
            // start driving the car
            isDriving = true;
    	}        
    }

    public void stop()
    {
		if( isDriving )
		{
			// stop the car 
			isDriving = false;
		}
        else
        {
			// car is already not moving
        }        
    }      
}
Posted by: Guest on February-18-2020
8

how to write a class in c++

class Rectangle 
{
	int width, height;
public:
	void set_values (int,int);
    int area() {return width*height;}
};

void Rectangle::set_values (int x, int y)
{
	width = x;
	height = y;
}
Posted by: Guest on October-24-2020
3

classes c++

class Rectangle {
    int width, height;
  public:
    void set_values (int,int);
    int area (void);
} rect;
Posted by: Guest on August-01-2020
2

class cpp

class Exemple
{
  private:
  	/* data */
  public:
  	Exemple(); //Constructor
  	~Exemple(); //Destructor
};
Posted by: Guest on January-14-2021
2

abstract class in java

public abstract class GraphicObject {

   abstract void draw();
}
Posted by: Guest on April-29-2020
0

class in c++

class Name {
  private:
  	int data;
  
  public:
  
    // Constructor
  	Name() {
		// Code      
    }
  	int id;
  	void fun1(int a) {
        // Some instructions here 
    }
 	 
}
Posted by: Guest on May-30-2020

Browse Popular Code Answers by Language