}
class mobile {
string company; static string model; void mobile1() {
company = \; model = \; }
static void mobile2() {
company = \; model = \; } } }
12. 以下程序段的功能是从键盘输入9个整数,组成一个3行3列的矩阵,在这个矩阵中找出矩阵的鞍点。所谓鞍点,是指矩阵中某个数是它所在行的最大值,所在列的最小值。矩阵中可能没有鞍点,最多只有一个鞍点。请仔细阅读该段程序,并填空。 namespace 鞍点 {
class Program {
static void Main(string[] args) {
int[,] a = new int[3, 3]; int max, max_col=0; int min, min_row=0; int flag = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
a[i, j] = Convert.ToInt16(Console.ReadLine()); } }
for (int i = 0; i < 3; i++) {
max = a[i, 0];
for (int j = 1; j < 3; j++) {
if (max < a[i, j]) {
max = a[i, j]; max_col = j; } }
min = a[0, max_col];
for (int k = 1; k < 3; k++) {
if (min > a[k, max_col]) {
min = a[k, max_col]; min_row = k; }
}
if (min_row == i) {
flag = 1; break; } }
if(flag==1)
Console.WriteLine(\鞍点是a[{0},{1}]的元素,值|为{2}\, min_row, max_col, a[min_row, max_col]); else
Console.WriteLine(\这个矩阵没有鞍点\); } } }
12. 定义一个类triangle, 该类有三个公有静态变量a,b,c 分别表示三角形的三条边长,在该类
中定义方法girth(),用于计算三角形的周长;定义方法area(),用于计算三角形的面积。并在main()方法中,提示用户输入三个数据,判断这三个数据是否可以构成一个三角形,若可以,调用triangle类中的方法,计算三角形的周长和面积,并屏幕输出;若不可以,则提示用户重新输入数据。
13. sealed关键字能与Abstract关键字同时使用吗?为什么?
14. 编写一个程序,定义三个float类型的变量,分别从键盘上输入值给他们,然后用if??else 语句找出他们中的最小数,最后输出。
15. 编写程序,统计100以内所有能被3整除的自然数的个数。
16. 什么是继承,派生类的定义格式是什么?
17. 什么是多态,多态可以分为哪几类,各自的实现途径是什么? 18简述ADO.NET的架构。
19. 以下程序段是否有错误,若有错误,请改正,并写出程序的运行结果。 static void Main(string[] args) {
int s = 0;
for (int i = 1; ; i++) {
if (s > 20) break;
if (i % 2 == 0) s += i; }
Console.WriteLine(\,i,s); }
20. 已知有一个main()程序,代码如下:
class Program {
static void Main(string[] args) {
int a;
Console.WriteLine(\调用方法,绘制三角形,请输入三角形的边长:\); a = int.Parse(Console.ReadLine()); triangle.dengbian(a); } }
运行时,从键盘输入3,则程序的运行结果如图所示。现在请你定义triangle类,该类中有一个方法dengbian(),用于实现三角形的打印。
21.编写代码,实现在f盘根目录下创建文件夹”我的文档”,若文件夹已经存在,则屏幕输出“文件夹已经存在”。
22.编写代码,实现在以上文件夹中创建文本文件1.txt, 并在文件中写入文字“我是中国人!”
23. 编写代码,在查看f盘根目录下的“我的文档”文件夹是否存在,若存在,则将该文件夹删除,否则,屏幕输出“文件夹不存在!”。
24. 阅读以下代码,该程序段中共有4出错误,请找出并并给出错误原因。最后给出程序的输出结果。
class Program {
static void Main(string[] args) {
test t1 = new test(100,200); t1.x = 40; t1.cnt = 0; int z = t1.y; z = test.intmax; Console.WriteLine(z); } }
public class test {
public const int intmax=int.MaxValue ; public int x = 0;
public readonly int y = 0; public static int cnt = 0; public test(int x1, int y1) {
x = x1; y = y1; cnt++; }
public void modify(int x1, int y1)
{
intmax = 0; x = x1; cnt = y1; y = 10;
} }
25写出下列代码的运行结果。
class Program {
static void Main(string[] args) {
A a = new B(); a.fun(); } }
public abstract class A {
public A() {
Console.WriteLine('A'); }
public virtual void fun() {
Console.WriteLine(\); } }
public class B : A {
public B() {
Console.WriteLine('B'); }
public override void fun() {
Console.WriteLine(\); }