期末考试题
来源:互联网 发布:淘宝触屏版下载安装 编辑:程序博客网 时间:2024/04/29 11:28
(1)根据下面的要求实现人类People
a)人类People的成员变量:
公共成员name表示姓名,为String类型(1分)
公共成员age 表示性别,为int类型(1分)
b)人类People的方法:
1)无参构造函数People ( ),将各成员变量初始化为“unknown”和20 。(1分)
2)构造函数People (string n, int a) (1分)
3)public virtual void disp( ) 将人的姓名、年龄输出到屏幕(1分)
(2)通过继承People类,派生出学生类Student 。要求如下:
a)学生类Student的成员变量:
公共成员department表示所在院系,为String类型(1分)
b)学生类Student的方法:
1)构造函数Student (string n, int a , string dep),用base 关键字调用父类中有两个参数的构造函数(2分)
2)重载覆盖父类中的函数 disp( ) 将学生的姓名、年龄、所在院系输出到屏幕(2分)
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
people p = new people("张三", 18);
p.disp();
student s = new student("李四", 19, "计算机系");
s.disp();
}
}
class people
{
public string name;
public int age;
public people()
{
name = "unknown";
age = 20;
}
/// <summary>
/// 有参构造函数
/// </summary>
/// <param name="n">人的姓名</param>
/// <param name="a">人的年龄</param>
public people(string n,int a)
{
name = n;
age = a;
}
public virtual void disp()
{
Console.WriteLine("姓名:{0},年龄:{1}",name,age);
}
}
class student : people
{
public string department;
public student(string n,int a,string dep):base(n,a)
{
department = dep;
}
public void disp()
{
base.disp();
Console.WriteLine("所在系部为:"+department);
}
}
}
a)人类People的成员变量:
公共成员name表示姓名,为String类型(1分)
公共成员age 表示性别,为int类型(1分)
b)人类People的方法:
1)无参构造函数People ( ),将各成员变量初始化为“unknown”和20 。(1分)
2)构造函数People (string n, int a) (1分)
3)public virtual void disp( ) 将人的姓名、年龄输出到屏幕(1分)
(2)通过继承People类,派生出学生类Student 。要求如下:
a)学生类Student的成员变量:
公共成员department表示所在院系,为String类型(1分)
b)学生类Student的方法:
1)构造函数Student (string n, int a , string dep),用base 关键字调用父类中有两个参数的构造函数(2分)
2)重载覆盖父类中的函数 disp( ) 将学生的姓名、年龄、所在院系输出到屏幕(2分)
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
people p = new people("张三", 18);
p.disp();
student s = new student("李四", 19, "计算机系");
s.disp();
}
}
class people
{
public string name;
public int age;
public people()
{
name = "unknown";
age = 20;
}
/// <summary>
/// 有参构造函数
/// </summary>
/// <param name="n">人的姓名</param>
/// <param name="a">人的年龄</param>
public people(string n,int a)
{
name = n;
age = a;
}
public virtual void disp()
{
Console.WriteLine("姓名:{0},年龄:{1}",name,age);
}
}
class student : people
{
public string department;
public student(string n,int a,string dep):base(n,a)
{
department = dep;
}
public void disp()
{
base.disp();
Console.WriteLine("所在系部为:"+department);
}
}
}
- 期末考试题
- C++期末考试题
- C语言的期末考试题
- sicily 期末考试题 括号匹配
- 清华大学计算机系C++期末考试题及答案
- 数据库原理期末考试题(经典题型)
- 树莓大一下期末C++期末考试题及扩展思考
- 外国某高校的中国歷史科目期末考试题
- 华南理工大学研究生人工智能期末考试题纲整理文档
- 第十六周往年期末考试题I解题报告
- 某大学期末C语言考试题(附加答案和讲解)
- 【复习题】:哈工大软件学院无线传感器网络期末考试题
- sicily 计算二叉查找树的高度 期末考试题
- 考试题
- 考试题
- 考试题
- 考试题
- 期末
- 第四次程序设计作业
- WriteOS: 制作一个 Boot Sector 并使用 Bochs 进行调试
- linux uboot 启动顺序
- 排列与组合读书笔记
- CF - 118A - String Task
- 期末考试题
- Python中super关键字的作用
- Linux编译内核
- WriteOS: 关于操作系统进入保护模式的总结
- 计算机专业相关词汇
- 华为一道笔试题
- 第四次课后作业
- 从零开始打造自己的Linux开发环境(一, 系统)
- 程序编码-软件工程-第五章