| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 738 人关注过本帖
标题:请大家帮忙看一下这段程序哪里不对了?
只看楼主 加入收藏
zjm_sunrise
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-7-25
收藏
 问题点数:0 回复次数:6 
请大家帮忙看一下这段程序哪里不对了?
有这样一个问题:定义一个Shape抽象类,作用它作为基类派生出Rectanle 、Circle等具体形状类,已知具体形状类均具有两个方法,分别用来求形状的面积和周长。运行界面如附件中所示,程序代码编写如下:
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace shape
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();            
        }
        public class Shape
        {
            public virtual double GetArea()
            {
                return (0);
            }
            public virtual double GetPerim()
            {
                return (0);
            }
        }
            class Rectangle : Shape
            {
                public double Width;
                public double Length;
                public Rectangle(double a, double b)
                {
                    Width = a;
                    Length = b;
                }
                public override double GetArea()
                {
                    return (Width * Length);
                }
                public override double GetPerim()
                {
                    return (2 * (Width + Length));
                }
            }
            class Circle : Shape
            {
                public double Radius;
                public Circle(double r)
                {
                    Radius = r;
                }
                public override double GetArea()
                {
                    return (Math.PI * Radius * Radius);
                }
                public override double GetPerim()
                {
                    return (2 * Math.PI * Radius);
                }
            }
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            double a,b;
            a = Convert.ToDouble(textBox1.Text);
            b = Convert.ToDouble(textBox2.Text);
            Rectangle Rect=new Rectangle (a,b);
            textBox3.Text = Rec.GetPerim().ToString();
            textBox4.Text = Rec.GetAera().ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            double r;
            r = Convert.ToDouble(textBox5.Text);
            Circle Cir = new Circle(r);
            textBox6.Text = Cir.GetPerim().ToString();
            textBox7.Text = Cir.GetArea().ToString();
        }
    }
}
但是程序在编译时提示了这样一堆错误:
错误    1    应输入 class、delegate、enum、interface 或 struct    G:\visualstudio\shape\shape\Form1.cs    64    17    shape
错误    2    应输入 class、delegate、enum、interface 或 struct    G:\visualstudio\shape\shape\Form1.cs    69    17    shape
错误    3    应输入 class、delegate、enum、interface 或 struct    G:\visualstudio\shape\shape\Form1.cs    74    32    shape
错误    4    应输入 class、delegate、enum、interface 或 struct    G:\visualstudio\shape\shape\Form1.cs    79    17    shape
错误    5    应输入 class、delegate、enum、interface 或 struct    G:\visualstudio\shape\shape\Form1.cs    83    30    shape
错误    6    应输入类型、命名空间定义或文件尾    G:\visualstudio\shape\shape\Form1.cs    86    9    shape
请大家帮忙看看是哪里出了问题呢?
搜索更多相关主题的帖子: public 
2008-07-28 22:48
KingTam
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-7-29
收藏
得分:0 
在类里面可以定义类的吗?应该是不可以的吧!
2008-07-29 09:34
师妃暄
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:805
专家分:107
注 册:2006-3-1
收藏
得分:0 
类里面不能定义类的

有实力才会有魅力 实力来自坚持不懈的努力
2008-07-29 11:15
xiaoshu838
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-4-20
收藏
得分:0 
您的两个click方法和form_load方法,根本没在类中,肯定要报错啊
2008-07-29 11:59
xyq701830
Rank: 1
来 自:浙江
等 级:新手上路
威 望:2
帖 子:263
专家分:0
注 册:2008-6-24
收藏
得分:0 
类里面可以定义类的吧````

菜猪猪``
2008-07-29 12:37
漏网之雨
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2008-7-19
收藏
得分:0 
类里面是可以定义一个类的  叫子类   不信你定义就知道了!

搂主那里是不是想用textBox.Text输入来实现运算啊!

其实你也不必写的 那复杂!
2008-07-30 00:09
tpriwwq
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-7-24
收藏
得分:0 
少了个}
2008-07-30 13:14
快速回复:请大家帮忙看一下这段程序哪里不对了?
数据加载中...
 
   



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

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