多个文件中,用到的关键字是() a) extern b) partial internal d interface 程序阅读题 1、阅读下面代码,写出输出结果 public class a public static void Methodl(out int x, params object[] objs foreach (object obj in objs x + int Parse(obj. ToString) public class Test static void Maino A Methodl(out x, 1, 2, 3, 4, 5) Console. WriteLine(x) 输出结果 2、阅读下面代码,写出输出结果 public class A public static void Methodl (ref int x, int y) int mp 11
11 多个文件中,用到的关键字是()。 a) extern b) partial c) internal d) interface 2.程序阅读题 1、阅读下面代码,写出输出结果: using System; public class A { public static void Method1(out int x, params object[] objs) { x = 0; foreach (object obj in objs) x += int.Parse(obj.ToString()); } }; public class Test { static void Main() { int x; A.Method1(out x, 1, 2, 3, 4, 5); Console.WriteLine(x); } } 输出结果: ______________________________ 2、阅读下面代码,写出输出结果: using System; public class A { public static void Method1(ref int x, int y) { int temp = x; x = y; y = temp;
public class Test static void Maino y A Methodl (ref x, y) Console. WriteLine( x=10), y=(ll", x, y) 输出结果: 3、阅读下面代码,写出输出结果: using System public class a public void funl (int n) Console. Writeline("{0}的2倍={1}",n,2*n) public void fun (int n) Console. Writeline("{0}的3倍={1}",n,3*n) public delegate void mydelegate(int n) public class Test static void Main O aa new Ao mydelegate p new mydelegate(a fun1) p + a fun (1); 输出结果: 3.设计题
12 } }; public class Test { static void Main() { int x = 1, y = 2; A.Method1(ref x, y); Console.WriteLine("x={0},y={1}", x, y); } } 输出结果: ______________________________ 3、阅读下面代码,写出输出结果: using System; public class A { public void fun1(int n) { Console.WriteLine("{0}的2倍={1}", n, 2 * n); } public void fun2(int n) { Console.WriteLine("{0}的3倍={1}", n, 3 * n); } }; public delegate void mydelegate(int n); public class Test { static void Main() { A a = new A(); mydelegate p = new mydelegate(a.fun1); p += a.fun2; p(1); } } 输出结果: ______________________________ ______________________________ 3.设计题
阅读下面说明和代码,在(n)处填充代码。 (1)【说明】 单件模式( Singleton)在某种程度上来说是限制而不是促进类的创建。单件模式 确保类有且仅有一个实例,并提供了一个对该实例的全局访问点。在实际程序 中,有很多类是需要确保有且仅有一个实例的 【代码】 using System; class SingletonDemo private static Singleton Demo theSingleton null private (1) public (2) SingletonDemo Instance O if (null = theSingleton) the Singleton return theSingleton static void Main(string[] args) SingletonDemo sl SingletonDemo Instanceo SingletonDemo s2= SingletonDemo Instance o if (sl Equals(s2)) Console. WriteLine(See, Only One Instance! 【程序输出结果】 on. C: Windows\system3.oDe ee, Only One Instance 青按任意键继续
13 阅读下面说明和代码,在(n)处填充代码。 (1)【说明】 单件模式(Singleton)在某种程度上来说是限制而不是促进类的创建。单件模式 确保类有且仅有一个实例,并提供了一个对该实例的全局访问点。在实际程序 中,有很多类是需要确保有且仅有一个实例的。 【代码】 using System; class SingletonDemo { private static SingletonDemo theSingleton = null; private (1) () { } public (2) SingletonDemo Instance() { if (null == theSingleton) { theSingleton = (3) ; } return theSingleton; } static void Main(string[] args) { SingletonDemo s1 = SingletonDemo.Instance(); SingletonDemo s2 = SingletonDemo.Instance(); if (s1.Equals(s2)) { Console.WriteLine("See, Only One Instance!"); } } } 【程序输出结果】
(2)【说明】 某高校的部门组织结构如图3-1所示,现采用组合 ( Composition)设计模式来设计,得到如图3-2所示的类图。 其中 Department为抽象类,定义了在组织结构图上添加(add) 删除( delete)部门和获取子部门列表的方法接口以及部门名称字段 和封装部门名称字段的属性。类 ConcreteDepartment表示具体的系 部,各系部下还可以设置不同的子部门或教研室。类 HRDepartment 和类 FinanceDepartment分别表示人事处和财务处。 简述组合( Composition)设计模式的特征? 福建工程学院 人事处 计算机与信息科学系 财务处 软件工程教研室 信息管理教研室 计算机基础教研室 计算机 计算机二 级教研组 级教研组 图3-1组织结构图
14 (2)【说明】 某 高 校 的 部 门 组 织 结 构 如 图 3-1 所 示 , 现 采 用 组 合 (Composition)设计模式来设计,得到如图 3-2 所示的类图。 其中 Department 为抽象类,定义了在组织结构图上添加(add)、 删除(delete)部门和获取子部门列表的方法接口以及部门名称字段 和封装部门名称字段的属性。类 ConcreteDepartment 表示具体的系 部,各系部下还可以设置不同的子部门或教研室。类 HRDepartment 和类 FinanceDepartment 分别表示人事处和财务处。 简述组合(Composition)设计模式的特征? 福建工程学院 人事处 计算机与信息科学系 财务处 软件工程教研室 信息管理教研室 计算机基础教研室 计算机一 级教研组 计算机二 级教研组 图 3-1 组织结构图
tr delete Name o Children o HRDepartment FinanceDepartment ConcreteDepartment + add 0) HaddO addo deleted delete o +deleted +getChildrenO getChildren o getChildren O 图3-2类图 【代码】 using System. Collections. Generic using System. Text namespace Composition public(1 class Department ted stri public string Name [(2)( return this name;)) public abstract void add (Department d) public abstract void delete(Department d) public abstract List(Department> getChildrenO public class ConcreteDepartment: Department private List<Department>children new List<Department>O public ConcreteDepartment(string name)I this name name; I public override void add(Department d) public override void delete(Department d)
15 +add() +delete() +Name() +getChildren() #name : string Department +add() +delete() +getChildren() HRDepartment +add() +delete() +getChildren() FinanceDepartment +add() +delete() +getChildren() ConcreteDepartment 图 3-2 类图 【代码】 using System; using System.Collections.Generic; using System.Text; namespace Composition { public (1) class Department { protected string name; public string Name { (2) { return this.name; } } public abstract void add(Department d); public abstract void delete(Department d); public abstract List<Department> getChildren(); } public class ConcreteDepartment : Department { private List<Department> children = new List<Department>(); public ConcreteDepartment(string name) { this.name = name; } public override void add(Department d) { (3) ; } public override void delete(Department d) {