标题:请教老师大师们:基类,派生类的用法和窗体的输出
取消只看楼主
wudics
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-12-27
 问题点数:0 回复次数:0 
请教老师大师们:基类,派生类的用法和窗体的输出
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

         
        public class auto
        {
            public int _wheels; //车轮
            public double _weight; //车重
            public auto(int wheels, double weight)
            {
                _wheels = wheels ;
                _weight = weight ;
            }
            int getwheels()
            {
                return _wheels ;
            }
            double getweight()
            {
                return _weight ;
            }
        }

         class car : auto
         {
             public car(int wheels, double weight)
                 : base(wheels, weight)
             {
             }
         }
        
        class truck: auto
        {
            public truck(int wheels, double weight)
                : base(wheels, weight)
            {            
            }

        }

        class bike: auto
        {
             public bike(int wheels, double weight)
                : base(wheels, weight)
            {
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "轿车")
            {
                new car(4, 1000);
                textBox1.Text = "轿车" ;
                textBox2.Text = "4";
                textBox3.Text = "1000";
            }
            else if (comboBox1.Text == "卡车")
            {
                new truck(12, 6000);
                textBox1.Text = "卡车";
                textBox2.Text = "12";
                textBox3.Text = "6000";
            }
            else if (comboBox1.Text == "自行车")
            {
                new bike(2, 60);
                textBox1.Text = "自行车";
                textBox2.Text = "2";
                textBox3.Text = "60";
            }
            else MessageBox.Show ("请选择你要查询的项目。");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }
  
    }
}


这是我的课题要求
设计一个汽车类族
要求:一个基类AUTO;
若干个派生类分别描述轿车、卡车、自行车等等。
设计相应Windows界面用于选择性地输出各种信息。

对于赋于派生类的值怎么在textbox中输出了?
要是和汉字一起输出,即把3个textbox合并成一个.不知道如何是好...
搜索更多相关主题的帖子: class public double wheels 
2011-12-27 12:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-358713-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.475801 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved