爱问知识人 爱问教育 医院库

请帮忙完成这个c#语言打印正方形的程序

首页

请帮忙完成这个c#语言打印正方形的程序

小弟是刚刚开始学c#的,有一个程序题目,题中给出了程序的框架结构和运行结果,小弟实在是想不出,请大家帮忙完成,提前感谢。题目给出的程序框架是:usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespacec{classPoint{publicintx;publicinty;publicPoint(intnx,intny){}publicPoint(Pointn){}publicvoidSet(intnx,intny){}publicvoidSet(Pointn){}publicintgetx(){}publicintgety(){}}classClass1{privateintside;privatePointlocation;publicClass1(Pointlocation,intlength){}publicvoidClass(Pointcenter,intlength){}publicvoidgraph(Pointcenter,intlength){}publicintgetarea(){}publicintgetperimeter(){}publicintgetlength(){}publicPointgetlocation(){}}classprogram{staticvoidMain(string[]args){intx,y,a;Console.WriteLine("请输入正方形的边长及位置:");Console.WriteLine("边长:");a=int.Parse(Console.ReadLine());Console.WriteLine("位置:");x=int.Parse(Console.ReadLine());y=int.Parse(Console.ReadLine());Class1sd=newClass1(newPoint(x,y),a);Console.WriteLine("Square:");Console.WriteLine("Length="+sd.getlength());Console.WriteLine("Location="+sd.getlocation().getx()+sd.getlocation().gety());Console.WriteLine("Perimeter="+sd.getperimeter());Console.WriteLine("Area="+sd.getarea());}}}要求的运行结果是:请输入正方形的边长及位置:边长:6位置:50******************** ,0Perimeter=24Area=36Pressanykeytocontinue

提交回答
好评回答
  • 2007-09-15 21:54:27
      程序:
    using System; 
    using System。Collections。Generic; 
    using System。Text; 
    namespace c 
    { 
    	class Point 
    	{ 
    		public int x; 
    		public int y; 
    		public Point(int nx, int ny) 
    		{
    			Set(nx, ny);
    		} 
    		public Point(Point n) 
    		{
    			Set(n);
    		} 
    		public void Set(int nx, int ny) 
    		{
    			x = nx;y = ny;
    		} 
    		public void Set(Point n) 
    		{
    			x = n。
      x; y = n。y; } public int getx() { return x; } public int gety() { return y; } } class Class1 { private int side; private Point location; public Class1(Point location,int length) { this。
      side = length; this。location = location; graph(location, length); } public void Class(Point center,int length) { } public void graph(Point center,int length) { for(int i = 0; i = center。
      x * 2 && (j - center。x * 2) % 2 == 0) line+="*"; else line+=" "; } else { if(j == center。
      x * 2 || j == center。x * 2 + length * 2 - 2) line+="*"; else line+=" "; } } Console。WriteLine(line); } } public int getarea() { return side*side; } public int getperimeter() { return side*4; } public int getlength() { return side; } public Point getlocation() { return location; } } class program { static void Main(string[] args) { int x, y, a; Console。
      WriteLine("请输入正方形的边长及位置:"); Console。WriteLine("边长:"); a = int。Parse(Console。ReadLine()); Console。WriteLine("位置:"); x = int。
      Parse(Console。ReadLine()); y = int。Parse(Console。ReadLine()); Class1 sd = new Class1(new Point(x, y), a); Console。
      WriteLine("Square:"); Console。WriteLine("Length=" + sd。getlength()); Console。WriteLine("Location=" + sd。getlocation()。
      getx() + "," + sd。getlocation()。gety()); Console。WriteLine("Perimeter=" + sd。getperimeter()); Console。WriteLine("Area=" + sd。
      getarea()); } } } 疑问: 1、 public void Class(Point center,int length) { } 这个函数不知道有什么用。 2、 函数Class还有下面这个函数 public void graph(Point center,int length) { } 不知道第一个参数叫center有什么用意没有。
       算出中心再做图有什么好处吗? 3、 using System。Collections。Generic; 我的程序里没用上这个命名空间。 不知道这个命名空间是否提供了什么能让程序简化? 4、 x轴上的坐标都是2个字节算1个单位吧?现在是按这样处理的。
       5、 Console。WriteLine("Location=" + sd。getlocation()。getx() + sd。getlocation()。gety()); 这句的输出少了x和y之间的","。

    E***

    2007-09-15 21:54:27

类似问题

换一换
  • C#/.NET 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):