Class of small exercises

Source: Internet
Author: User

Experimental report on the principles of Advanced Programming languages (5)

Experiment name: Object-oriented programming, inheritance mechanism

Experimental location: Information Building 318

The tool software and environment used: VS2013

First, the purpose of the experiment:

1. Object-Oriented programming language

2. Class definition

Second, the experimental content:

Defines a class named box with three instance variables : Length, Widh , and height, and defines a method for setting the length, width, and height of the box SETLWH () and the method for calculating box area areas () and volume volumn () .

Main program code:

Using System;

Using System.Collections.Generic;

Using System.Linq;

Using System.Text;

Using System.Threading.Tasks;

Namespace BOX

{

Class Box

{

private double length;

Private double Widh;

private double height;

public void Setlwh (double length,double widh,double height)

{

this.length = length;

This.widh = Widh;

This.height = height;

}

public void Area ()

{

Console.WriteLine (" area is ");

Console.WriteLine (2 * (length * widh + widh * height + length * height));

}

public void Volumn ()

{

Console.WriteLine (" volume is ");

Console.WriteLine (Length * widh * height);

}

}

Class Program

{

static void Main (string[] args)

{

Box B = new box ();

B.SETLWH (a);

B.area ();

B.volumn ();

Console.ReadLine ();

}

}

}

Example of program running results

Class of small exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.