예제 #1
0
 //Step 2: Copy Constructor
 public EngineClass(EngineClass right)
 {
     this.CNoofcylanders = right.GetNoofcylanders();
     this.CVolumeCC      = right.GetVolumeCC();
     this.CEnginetype    = right.GetEnginetype();
     this.CTorque        = right.GetTorque();
     this.CHorsepower    = right.GetHorsepower();
 }
 //Step 2: Copy Constructor
 public CarClass(CarClass right)
 {
     this.CVIN       = right.GetVIN();
     this.CMake      = right.GetMake();
     this.CModel     = right.GetModel();
     this.CColor     = right.GetColor();
     this.CYearbuilt = right.GetYearbuilt();
     this.CCarEngine = right.GetCarEngine();
 }
 //Step 2: Implementing overloaded constructors
 //OPTIONAL
 public CarClass(int VVIN, String VMake, string VModel, string VColor, int VYearbuilt, EngineClass VCarEngine)
 {
     CVIN       = VVIN;
     CMake      = VMake;
     CModel     = VModel;
     CColor     = VColor;
     CYearbuilt = VYearbuilt;
     CCarEngine = VCarEngine;
 }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            TempObject = new EngineClass();


            TempObject.SetNoofcylanders(Convert.ToInt16(textBox1.Text));
            TempObject.SetVolumeCC(Convert.ToInt16(textBox2.Text));
            //TempObject.SetEnginetype(Convert.ToBoolean(radioButton1.Text));
            TempObject.SetTorque(Convert.ToInt16(textBox3.Text));
            TempObject.SetHorsepower(Convert.ToInt16(textBox4.Text));
            MessageBox.Show("Values are set in object");
        }
예제 #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //int x; The compiler allocates memory for the variable in stack
            EngineClass EnginObject;  // it is only a declaration

            CarObject   = new CarClass();
            EnginObject = new EngineClass(); // the compiler allocates memory for variable in heap
                                             // and it is completely reclaimable
                                             // as a side effect of creating this object, constructor will run
            EnginObject.SetNoofcylanders(2);
            EnginObject.SetVolumeCC(5);
            //EnginObject.SetEnginetype(false);
            EnginObject.SetTorque(5);
            EnginObject.SetHorsepower(2200);
            MessageBox.Show(EnginObject.MakeString());
        }
 public void SetCarEngine(EngineClass VCarEngine)
 {
     CCarEngine = VCarEngine;
 }