云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > C#程序设计期末题库

C#程序设计期末题库

  • 62 次阅读
  • 3 次下载
  • 2025/6/16 1:20:40

Console.WriteLine(\请输入你希望的n的值:\ Console.ReadLine(); int n = int.Parse(Console.ReadLine()); Sum(n);

Console.ReadLine(); }

static void Sum(int n) { int sum = 0;

for (int i = 1; i <= n; i++) { if (i % 2 != 0) {

sum = sum + i; } else

sum = sum - i; }

Console.WriteLine(\值为:{0}\

23.编写一个方法,判断一个三位数是否等于其每位数字的立方和,例如153=13

+53

+33

,要求编写控制台应用程序,来检验方法的正确性。

Console.WriteLine(\请输入一个你想验证的三位数:\

int n = int.Parse(Console.ReadLine()); Li(n);

Console.ReadLine(); }

static void Li(int n) { int a=n/100; int b=n/10; int c=n;

if(a*a*a+b*b*b+c*c*c==n) {

Console.WriteLine(\等于每位数字的立方之和\ }

else Console.WriteLine(\不等于每位数字的立方之和\

24.编写一个方法,判断一个数是否既能被3整除又能被7整除,要求编写控制台应用程序,来检验方法的正确性。

Console.WriteLine(\请输入你想验证的数字:\

double n = double.Parse(Console.ReadLine()); Ch(n);

}

static void Ch(double n) {

if (n % 3 == 0 && n % 7 == 0) { Console.WriteLine(\既可以被3整除也可以被7整除\ } else

Console.WriteLine(\不满足即被3整除也可以被7整除的条件\三、类设计

1.设计雇员类(Employee)及其子类经理类(Manager),雇员类包含私有成员字段name,salary;并包含其属性Name,Salary;经理类还有自己的私有成员字段bonus,及其对应属性

Bonus;雇员类、经理类都要有自己的无参、有参构造方法;

在main中创建一个经理对象并设置其奖金金额,另建立员工数组(经理作为其一个元素),要求打印输出该员工数组的姓名和薪水信息。

class Employee {

private string name;

public string Name {

get { return name; } set { name = value; } }

private int salary;

public int Salary {

get { return salary; } set { salary = value; } }

public Employee() { }

public Employee(string name, int salary) {

this.name = name; this.salary = salary; }

}

class Manager: Employee {

private int bonus;

public int Bonus {

get { return bonus; } set { bonus = value; } }

public Manager() { } public Manager(int bonus) {

this.bonus = bonus; } }

static void Main(string[] args) {

Manager man = new Manager(); man.Bonus = 2000; man.Name=\吴a明??\; man.Salary = 5000;

Employee [] em=new Employee[3]; em[0]=man;

em[1] = new Employee(\张?三¨y\,3000);

em[2] = new Employee(\李¤?四?\, 2500);

for (int i=0; i < em.Length; i++) {

Employee emp = em[i]; Console.WriteLine(\姓?名?为a:êo\+emp.Name +\工?è资á¨o为a:êo\+emp.Salary ); }

Console.ReadLine(); }

2.设计学生类(Student)及其子类研究生类(Graduate),学生类包含私有成员字段name,credit(学分);并包含其属性Name,Credit;研究生类包含自己的私有变量postcredit;并并包含其属性Postcredit,学生类(Student)及其子类

研究生类(Graduate)要有自己的无参、有参构造方法;

现需创建一个研究生对象并设置其postcredit,另建立学生数组(研究生作为其一个元素),要求打印输出该学生数组的姓名和学分信息。

public class Student {

private string name;

private int credit;

public string Name {

get { return name; } set { name = value; } }

public int Credit {

get { return credit; } set { credit = value; } }

public Student() { }

public Student(string _name, int _credit) {

Name = _name; Credit = _credit; } }

public class Graduate : Student {

private string postcredit;

public string Postcredit {

get { return postcredit; } set { postcredit = value; } }

public Graduate() { }

public Graduate(string _postcredit) {

Postcredit = _postcredit; } }

static void Main(string[] args) {

Graduate gd = new Graduate(); gd.Postcredit = \研D究?生|¨2的ì?Postcredit\;

gd.Name = \研D究?生|¨2小?明??\; gd.Credit = 5;

Student[] sds = new Student[3]; sds[0] = new Student(\学?ì生|¨2小?红¨?\, 2);//学?ì生|¨2

sds[1] = gd;//研D究?生|¨2 sds[2] = new Student(\学?ì生|¨2小?强?\, 6);//学?ì生|¨2

for (int i = 0; i < sds.Length; i++) {

Student sdModel = sds[i]; Console.WriteLine(\姓?名?:êo\+sdModel.Name+\学?ì分¤?:êo\+sdModel.Credit); }

Console.Read(); }

3.定义一个名为Vehicles交通工具的基类: 该类中包含私有的string类型的成员字段brand商标和color颜色,并设置其相应的公有属性; 类中包含成员方法Run来模拟交通工具开动,该方法在控制台显示“我已经开动了”信息; 类中包含成员方法和ShowInfo来显示信息,该方法在控制台显示商标和颜色; 完成父类的无参有参构造方法,

编写Car小汽车类继承于Vehicles类,对于此类: 增加int型成员字段seats座位,并设置其相应的

公有属性;

增加成员方法ShowCar,在控制台显示小汽车的信息并编写构造方法。

覆盖父类的Run方法,在控制台显示“汽车开动了的信息”;

完成小汽车类的无参有参构造方法; 在main方法中测试以上各类。 class Vehicles {

private string brand;

public string Brand {

get { return brand; } set { brand = value; } }

private string color;

public string Color {

get { return color; } set { color = value; } }

public Vehicles() { }

public Vehicles(string brand, string color) {

this.brand = brand; this.color = color; }

public virtual void run() {

Console.WriteLine(\我已经开动了\ }

public void ShowInfo(Vehicles ve) {

Console.WriteLine(\商

\颜色:\ }

}

class Car:Vehicles {

private int seats;

public int Seats {

get { return seats; } set { seats = value; } }

public Car() { } public Car(int seats) {

this.seats = seats; }

public void ShowCar( Car c) {

Console.WriteLine(\汽车的品牌:\颜色:\+\座位:\

}

public override void run() {

base.run();

Console.WriteLine(\汽车开动了\

} }

class Program {

static void Main(string[] args) {

Vehicles we = new Vehicles(); we.Brand = \宝马\ we.Color = \银白色\ we.run(); we.ShowInfo(we); Car car = new Car(); car.Brand = \奥迪\ car.Color = \黑色\ car.Seats = 4; car.run(); car.ShowCar(car); car.ShowInfo(car); Console.ReadLine(); } }

4.定义一个名为Vehicles交通工具的基类: 该类中包含私有的string类型的成员字段brand商标和color颜色,并设置其相应的公有属性; 类中包含成员方法run来模拟交通工具开动,该方法在控制台显示“我已经开动了”信息; 类中包含成员方法ShowInfo来显示信息,该方法在控制台显示商标和颜色 完成父类的无参有参构造方法;

编写Truck卡车类继承于Vehicles类对于此类: 增加float型成员字段load载重,并设置其相应的公有属性;

应增加成员方法showTruck在控制台显示卡车的信息;

完成卡车类的无参有参构造方法;

覆盖父类的run方法,在控制台显示“开车开动了的信息”; 并编写构造方法。

在main方法中测试以上各类。 class Vehicles {

private string brand;

public string Brand {

get { return brand; } set { brand = value; } }

private string color;

public string Color {

get { return color; } set { color = value; } }

public Vehicles() { }

public Vehicles(string brand, string color) {

this.brand = brand; this.color = color; }

public virtual void run() {

Console.WriteLine(\我已经开动了

搜索更多关于: C#程序设计期末题库 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

Console.WriteLine(\请输入你希望的n的值:\ Console.ReadLine(); int n = int.Parse(Console.ReadLine()); Sum(n); Console.ReadLine(); } static void Sum(int n) { int sum = 0; for (int i = 1; i <= n; i++) { if (i % 2 != 0) { sum = sum + i;

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com