zoukankan      html  css  js  c++  java
  • 类的小练习

    《高级程序设计语言原理》实 验 报 告 ( 5 )

    实验名称:面向对象编程,继承机制

    实验地点:信息楼318

    所使用的工具软件及环境:VS2013

    一、实验目的:

    1、面向对象编程语言

    2、类定义

    二、实验内容:

    定义一个名为Box的类,有三个实例变量:length, widh height, 同时定义一个设置长方体长、宽、高值的方法setlwh( )和计算长方体面积area ()和体积volumn( )的方法

    主要程序代码:

    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("面积为");

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

            }

            public void volumn()

            {

                Console.WriteLine("体积为");

                Console.WriteLine(length * widh * height);

            }

        }

        class program

        {

            static void Main(string[] args)

            {

                Box b = new Box();

                b.setlwh(1,2,3);

                b.area();

                b.volumn();

                Console.ReadLine();

            }

        }

       

    }

    三、程序运行结果示例

  • 相关阅读:
    Java学习笔记-Lambda表达式
    Java学习笔记-枚举类
    Java学习笔记-枚举类
    Java学习笔记-包装类
    js 递归 汉诺塔的例子
    js 用 hasOwnProperty() 判定属性是来自该对象成员,还是原型链
    正则,js函数math()提取混乱字符串中多个字符串内容
    封装好的cookie的三个常用函数 cookie的添加、删除、提取操作函数
    解决ie6下png背景不能透明bug
    ie6下标签定义的高失效,显示的高不受设定的height值影响
  • 原文地址:https://www.cnblogs.com/to-creat/p/4945065.html
Copyright © 2011-2022 走看看