class in c 2b 2b

Solutions on MaxInterview for class in c 2b 2b by the best coders in the world

showing results for - "class in c 2b 2b"
María
02 Mar 2018
1public class Car
2{  
3    // fields
4    public bool isDriving = false;
5    
6    // constructor
7    public Car( string make )
8    {
9        Make = make;
10    }
11	
12    // properties
13    private string _make = string.Empty;
14    public string Make
15    {
16        get { return _make; }
17        set { _make = value; } 
18    }
19    
20    // methods
21    public void drive()
22    {
23        if( isDriving )
24        {
25			// Car is already moving
26        }
27        else
28		{
29            // start driving the car
30            isDriving = true;
31    	}        
32    }
33
34    public void stop()
35    {
36		if( isDriving )
37		{
38			// stop the car 
39			isDriving = false;
40		}
41        else
42        {
43			// car is already not moving
44        }        
45    }      
46}
47
48// ---
49// An example of using this class in a console app
50
51using System;
52					
53public class Program
54{
55	public static void Main()
56	{		
57        // construct a new class of type Car and set the Make
58      	// property to "VW" using the constructor.
59		Car newCar = new Car( "VW" );
60		
61      	// display the make of our new car
62		Console.WriteLine( newCar.Make );
63		
64      	// call the drive method of the car class
65		newCar.drive();		
66		
67      	// display the value of the isDriving property to
68		Console.WriteLine( newCar.isDriving );
69		
70      	// call the stop method of the car class
71		newCar.stop();
72		
73      	// display the value of the isDriving property
74		Console.WriteLine( newCar.isDriving );
75	}
76}
77
78// the class 
79public class Car
80{  
81    // fields
82    public bool isDriving = false;
83    
84    // constructor w
85    public Car( string make )
86    {
87        Make = make;
88    }
89	
90    // properties
91    private string _make = string.Empty;
92    public string Make
93    {
94        get { return _make; }
95        set { _make = value; } 
96    }
97    
98    // methods
99    public void drive()
100    {
101        if( isDriving )
102        {
103        		// Car is already moving
104        }
105        else
106		{
107            // start driving the car
108            isDriving = true;
109    	}        
110    }
111
112    public void stop()
113    {
114		if( isDriving )
115		{
116			// stop the car 
117			isDriving = false;
118		}
119        else
120        {
121			// car is already not moving
122        }        
123    }      
124}
Johanna
02 Oct 2017
1class Rectangle 
2{
3	int width, height;
4public:
5	void set_values (int,int);
6    int area() {return width*height;}
7};
8
9void Rectangle::set_values (int x, int y)
10{
11	width = x;
12	height = y;
13}
Clara
10 Nov 2020
1class Exemple
2{
3  private:
4  	/* data */
5  public:
6  	Exemple(); //Constructor
7  	~Exemple(); //Destructor
8};
Lilly
02 Mar 2018
1class Rectangle {
2    int width, height;
3  public:
4    void set_values (int,int);
5    int area (void);
6} rect;
Anna
23 Mar 2020
1public abstract class GraphicObject {
2
3   abstract void draw();
4}
Oberon
17 Jun 2017
1class Name {
2  private:
3  	int data;
4  
5  public:
6  
7    // Constructor
8  	Name() {
9		// Code      
10    }
11  	int id;
12  	void fun1(int a) {
13        // Some instructions here 
14    }
15 	 
16}
similar questions
queries leading to this page
class in c 2b 2b