| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 633 人关注过本帖
标题:这程序达不到要求,请大家进来帮调试一下
只看楼主 加入收藏
zhaixiang
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-10-14
收藏
 问题点数:0 回复次数:3 
这程序达不到要求,请大家进来帮调试一下

using System;

namespace class1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class Person
{
public string name;
public string sex;
public int age;
public Person(string name,string sex,int age)
{
this.name=name;
this.sex=sex;
this.age=age;
}
public Person()
{
}
public void show()
{
Console.WriteLine("姓名:{0} 性别:{1} 年龄:{2}",name,sex,age);

}

public void get()
{

Console.WriteLine("请分别输入该生的姓名,性别,年龄:");
name=Console.ReadLine();
sex=Console.ReadLine();
age=Int32.Parse(Console.ReadLine());
}

}
public class Student:Person
{

public int nNo;
public string className;
public Student(string name,string sex,int age,int nNo,string className):base(name,sex,age)
{
this.nNo=nNo;
this.className=className;
}
public Student()
{
}
new public void show()
{
Console.WriteLine("学号:{0}\t班级:{1}",nNo,className);
base.show();
}
new public void get()
{
Console.WriteLine("请输入学号和班级:");
nNo=Int32.Parse(Console.ReadLine());
className=Console.ReadLine();
base.get();
}

}
public class PersonArray
{

Person []P=new Person[100];
int num=0;
public void add(Person PP)
{
if(num<100)
{
P[num]=PP;
num++;
}
}
public void show()
{
for(int i=0;i<num;i++)
{
P[i].show();
}
}
public void sort()
{
Person temp;
bool flg=true;
for(int i=0;flg;i++)
{
flg=false;
for(int j=0;j<num-i-1;j++)
{
if(P[j].age>P[j+1].age)
{
temp=P[j];
P[j]=P[j+1];
P[j+1]=temp;
flg=true;
}
}
}
for(int i=0;i<num;i++)
{
P[i].show();
}
}
public void find()
{
Console.WriteLine("请输入你要查找的人的姓名");
string ff;
ff=Console.ReadLine();
for(int i=0;i<num;i++)
{
if(ff==P[i].name)
{
Console.WriteLine("姓名:{0} 性别:{1} 年龄:{2}",P[i].name,P[i].sex,P[i].age);
break;
}
else
Console.WriteLine("对不起,没有你要查找的人");
}
}

}
public class StudentArray
{
Student []G=new Student[100];
int rtc=0;
public void add(Student GG)
{
if(rtc<100)
{
G[rtc]=GG;
rtc++;
}
}
public void show()
{

for(int j=0;j<rtc;j++)
{
Console.WriteLine("姓名:{0} 性别:{1} 年龄:{2} 学号:{3} 班级:{4}",G[j].name,G[j].sex,G[j].age,G[j].nNo,G[j].className);
}
}
public void sort()
{
Student temp;
for(int j=0;j<rtc-1;j++)
for(int h=j+1;h<rtc;h++)
if(G[j].age>G[h].age)
{
temp=G[j];
G[j]=G[h];
G[h]=temp;
}
}
public void find()
{

Console.WriteLine("请输入你要查找人的姓名");
string uu;
uu=Console.ReadLine();
for(int j=0;j<rtc;j++)
{
if(uu==G[j].name)
{
Console.WriteLine("姓名:{0} 性别:{1} 年龄:{2} 学号:{3} 班级:{4}",G[j].name,G[j].sex,G[j].age,G[j].nNo,G[j].className);
}
else
Console.WriteLine("没有你要查找的人");
}
}
}
class class1
{
public static void Main()
{
Person PP=new Person();
Student SS=new Student();
string cmd;
PersonArray PA=new PersonArray();
StudentArray SA=new StudentArray();
do
{
Console.WriteLine("你要记录人还是学生,a人,b学生,c退出");
cmd=Console.ReadLine();
if(cmd=="a")
{
Console.WriteLine("你将要做:write,show,sort,find");
cmd=Console.ReadLine();
if(cmd=="write")
{
PP.get();
PA.add(PP);
}
if(cmd=="show")
PA.show();
if(cmd=="sort")
PA.sort();
if(cmd=="find")
PA.find();

}
if(cmd=="b")
{
Console.WriteLine("你将要做:写入,显示,排序,查找");
cmd=Console.ReadLine();
if(cmd=="写入")
{
SS.get();
SA.add(SS);
}
if(cmd=="显示")
SA.show();
if(cmd=="排序")
SA.sort();
if(cmd=="查找")
SA.find();
}
}while(cmd!="c");
}
}
}

题目:编写一个person类。类中有age ,name,sex三个属性和构造方法。

编写一个student类,要求该类从person类派生。并增加no(学号),(className)班级名称字段。

编写一个PersonArray类。类中至少有一个person数组。在该类中有排序Sor()t方法对数组排序。Show()方法显示数组中所有数据。 查找方法Find(),在数组中查找并显示数据。

编写一个StudentArray类。类中至少有一个Student数组。在该类中有排序Sort ()方法,可以对数组排序。Show()方法显示数组中所有数据。 查找方法Find(),在数组中查找并显示数据。



   这程序能够运行,但不能达到题目要求,现在请高手来调试一下,以至达到题目要求,谢谢.

搜索更多相关主题的帖子: public string age name 
2006-11-25 11:15
guang
Rank: 4
来 自:广东深圳
等 级:贵宾
威 望:13
帖 子:1414
专家分:285
注 册:2006-4-3
收藏
得分:0 
妈的,阿肥,这个也不懂,哈哈

不相信未作牺牲竟先可拥有,只相信靠双手找到我的欲求!!
我的博客:http://liao5930.blog.
2006-11-25 11:39
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
你的程序怎么了。好长,,

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2006-11-25 12:12
zhaixiang
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-10-14
收藏
得分:0 

这程序只能使用"write"和"写入"两个功能,其它不能用.

2006-11-25 18:20
快速回复:这程序达不到要求,请大家进来帮调试一下
数据加载中...
 
   



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

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