一道C#题; 50

一道C#题;建立三个类:居民,成人,官员。居民包含身份证号,姓名,出生日期,而成人继承自居民,包含学历包含学历,职业两项数据;官员则继承自成人,包含党湃,职务两项数据。要... 一道C#题;建立三个类:居民,成人,官员。居民包含身份证号,姓名,出生日期,而成人继承自居民,包含学历
包含学历,职业两项数据;官员则继承自成人,包含党湃,职务两项数据。要求每个类中都提供数据输入输出的功能。
展开
 我来答
woshifotuo
2011-03-29 · TA获得超过701个赞
知道小有建树答主
回答量:249
采纳率:0%
帮助的人:266万
展开全部
三个类都在这里了,给你写完了,一定要看完哦,也不枉我给你费了半天的劲.
我是新建了一个控制台应用程序,调试通过,希望对你有帮助.祝你好运!!!
//Person.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenNotePad
{
public class Person
{
public String identity = String.Empty;
public String name = String.Empty;
public DateTime birthday;

}
}
//Adult.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenNotePad
{
public class Adult:Person
{
public String educationBackground = String.Empty;
public String profession = String.Empty;
}
}
//Officer.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenNotePad
{
public class Officer:Adult
{
public String group = String.Empty;
public String job = String.Empty;

}
}
//测试主程序Program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenNotePad
{
class Program
{
static void Main(string[] args)
{
//System.Diagnostics.Process.Start("winword.exe");
Person person = new Person();
Adult adult = new Adult();
Officer officer = new Officer();
Console.WriteLine("请输入Person类的基本信息:");
Console.WriteLine("身份证号:");
person.identity = Console.ReadLine();
Console.WriteLine("姓名:");
person.name = Console.ReadLine();
Console.WriteLine("出生日期:");
person.birthday =DateTime.Parse(Console.ReadLine());

Console.WriteLine("请输入Adult类的基本信息:");
Console.WriteLine("身份证号:");
adult.identity = Console.ReadLine();
Console.WriteLine("姓名:");
adult.name = Console.ReadLine();
Console.WriteLine("出生日期:");
adult.birthday = DateTime.Parse(Console.ReadLine());
Console.Write("学历:");
adult.educationBackground= Console.ReadLine();
Console.Write("职业:");
adult.profession= Console.ReadLine();

Console.WriteLine("请输入Officer类的基本信息:");
Console.WriteLine("身份证号:");
officer.identity = Console.ReadLine();
Console.WriteLine("姓名:");
officer.name = Console.ReadLine();
Console.WriteLine("出生日期:");
officer.birthday = DateTime.Parse(Console.ReadLine());
Console.WriteLine("学历:");
officer.educationBackground = Console.ReadLine();
Console.WriteLine("职业:");
officer.profession = Console.ReadLine();
Console.Write("党派:");
officer.group = Console.ReadLine();
Console.Write("职业:");
officer.job = Console.ReadLine();
Console.WriteLine("Person类输入信息:身份证号:{0},姓名:{1},出生日期:{2}",person.identity,person.name,person.birthday);
Console.WriteLine("Adult类输入信息:身份证号:{0},姓名:{1},出生日期:{2},学历:{3},职业:{4}", adult.identity, adult.name, adult.birthday,adult.educationBackground,adult.profession);
Console.WriteLine("Officer类输入信息:身份证号:{0},姓名:{1},出生日期:{2},学历:{3},职业:{4},党派:{5},职务:{6}", officer.identity, officer.name, officer.birthday,officer.educationBackground,officer.profession,officer.group,officer.job);
Console.ReadKey();
}
}
}
上面是建立的一个控制台应用程序,如果你用在构架网站等的项目上的话,三个类如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Person
{
public String identity { get;set;}
public String name{get;set;}
public DateTime birthday{get;set;}
/// <summary>
/// 设置属性值
/// </summary>
/// <param name="args">参数数组,identity,name,birthday</param>
public virtual void SetBasicInfo(Object[] args)
{
this.identity = args[0].ToString();
this.name = args[1].ToString();
this.birthday = DateTime.Parse(args[2].ToString());
}
public virtual String GetBasicInfor()
{
return String.Format("identity:{0},name:{1},birthday:{2}",this.identity,this.name,this.birthday);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
/// <summary>
/// Adult继承Person
/// </summary>
class Adult:Person
{
public String educationBackground { get; set; }
public String profession { get; set; }
/// <summary>
/// Set Basic Information
/// </summary>
/// <param name="args">params array</param>
public override void SetBasicInfo(object[] args)
{
this.identity = args[0].ToString();
this.name = args[1].ToString();
this.birthday =DateTime.Parse(args[2].ToString());
this.educationBackground = args[3].ToString();
this.profession = args[4].ToString();
}
/// <summary>
/// Get Basic Information
/// </summary>
/// <returns></returns>
public override string GetBasicInfor()
{
return String.Format("identity:{0},name:{1},birthday:{2},eduationbackground:{3},profession:{4}",this.identity,this.name,this.birthday,this.educationBackground,this.profession);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
/// <summary>
/// Officer 继承 Adult
/// </summary>
class Officer:Adult
{
public String group { get; set; }
public String job { get; set; }
/// <summary>
/// Get Basic Infomation
/// </summary>
/// <returns>format info</returns>
public override String GetBasicInfor()
{
return base.GetBasicInfor();
}
public override void SetBasicInfo(object[] args)
{
return string.Format("identity:{0}, name:{1} ,birthday: {2}, educationBackground:{3}|,profession:{4},group:{5},job:{6}",
this.identity, this.name, this.birthday, this.educationBackground, this.profession, this.group,this.job);

}
}
}
郏鸿祯C6
2011-03-24 · TA获得超过4548个赞
知道小有建树答主
回答量:1601
采纳率:50%
帮助的人:1193万
展开全部
二楼的估计没有看清题目,题目要求在类的内部实现数据的输入和输出,二楼的完全没有实现啊
,不写成方法就算了,连属性都没有封装/// <summary>
/// 居民类
/// </summary>
public class Inhabitant
{
public string ID { get; set; }//身份证号码
public string Name { get; set; }//姓名
public DateTime Birthday { get; set; }//生日
/// <summary>
/// 输入
/// </summary>
/// <param name="args">参数数组</param>
public virtual void SetValues(params object[] args)
{
this.ID =args[0].ToString();
this.Name = args[1].ToString();
this.Birthday = Convert.ToDateTime(args[2]);
}
/// <summary>
/// 输出
/// </summary>
/// <returns>按一定的格式返回所有的属性</returns>
public virtual string GetValues()
{
return string.Format("Inhabitant| ID:{0}| Name:{1}| Birthday: {2}",
this.ID, this.Name, this.Birthday);
}
}
/// <summary>
/// 成人类(继承自居民类)
/// </summary>
public class Adult : Inhabitant
{
public string Degree { get; set; }//学历
/// <summary>
/// 输入
/// </summary>
/// <param name="args">参数数组</param>
public override void SetValues(params object[] args)
{
this.ID = args[0].ToString();
this.Name = args[1].ToString();
this.Birthday = Convert.ToDateTime(args[2]);
this.Degree = args[3].ToString();
}
/// <summary>
/// 输出
/// </summary>
/// <returns>按一定的格式返回所有的属性</returns>
public override string GetValues()
{
return string.Format("Inhabitant| ID:{0}| Name:{1}| Birthday: {2}| Degree:{3}",
this.ID, this.Name, this.Birthday, this.Degree);
}
}
/// <summary>
/// 官员类(继承自成人类)
/// </summary>
public class Official : Adult
{
public string Party { get; set; }//党派
public string Position { get; set; }//职位
/// <summary>
/// 输入
/// </summary>
/// <param name="args">参数数组</param>
public override void SetValues(params object[] args)
{
this.ID = args[0].ToString();
this.Name = args[1].ToString();
this.Birthday = Convert.ToDateTime(args[2]);
this.Degree = args[3].ToString();
this.Party = args[4].ToString();
this.Position = args[5].ToString();
}
/// <summary>
/// 输出
/// </summary>
/// <returns>按一定的格式返回所有的属性</returns>
public override string GetValues()
{
return string.Format("Inhabitant| ID:{0}| Name:{1}| Birthday: {2}| Degree:{3}| Party:{4}| Position:{5}",
this.ID, this.Name, this.Birthday, this.Degree, this.Party, this.Position);
}
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
我想做好孩子cV
2018-04-17 · TA获得超过312个赞
知道小有建树答主
回答量:368
采纳率:74%
帮助的人:63.2万
展开全部
Console.readline()是C#控制台应用程序(编程)的读取,也即是接收你的键盤输入,以按回车作为结束标志,一般用Console.Writeline()来读取。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友5982c66ea
2011-03-25
知道答主
回答量:27
采纳率:100%
帮助的人:11.9万
展开全部
不识台北路正解.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式