前些时候做过的一份面试试题

题目不算太简单,但因为开卷,所以稍为查了一下资料还是轻松完成。提交过去后,即得面试的机会,但当知道没有.Net实际开发经验时,三两下打发我了,没有音信!不过也是的,像我这样的程序员,只出道那么一年时间,有更多的不确定因素,凭什么给你机会呢。战战兢兢几个月了,都做了不少题,发觉有些企业会出一些手册性的题目,就是说太细,内容这么多太细谁记得住啊?真晕!今天想重ghost机器,差点把这删了,贴出来看看也好。

XX软件程序员测试题目

测试人姓名: _ _ Kemin _ _____

测试日期: ___ 2004-11-2 _____ 完成测试时间: _____ 2004-11-2 _________

本次测试共三道题目,要求如下:

** 1. ** ** 请用 ** ** C# ** ** 完成 ** ** **

** 2. ** ** 开卷独立完成,可以看书,上网等任何方式查找资料,但必须保证独立完成。一旦发现有不诚实行为,本公司将不予录取,后果自负。 ** ** **

题目一:

1. 编写冒泡排序程序

要求:

1) 请用 C#编写一个冒泡排序的程序,

2) 要求排序的数据从文件 C:\DATA.DAT中读取,数据间用逗号分隔。

解:

using System;

using System.IO;

class Test{

static void BubbleSort(int[] ai) {

for (int j = ai.Length - 1; j > 0; j--){ // outer loop (backward)

for (int i = 0; i < j; i++) // inner loop (forward)

if (ai[i] > ai[i+1]) Swap(ref ai[i], ref ai[i+1]);

}

}

static void Swap(ref int x,ref int y) {

x = x + y;

y = x - y;

x = x - y;

}

static void Main (string[] args) {

int[] ai = getData();

BubbleSort(ai);

foreach (int i in ai) Console.WriteLine(i);

Console.ReadLine();

}

public static int[] getData(){

try{

StreamReader sr = new StreamReader("data.dat");

string sLine;

sLine = sr.ReadLine();

string[] astr = sLine.Split(new Char[]{','});

int[] ai = new int[astr.Length];

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

ai[i] = Convert.ToInt32(astr[i]);

return ai;

}

catch (Exception e) {

// Let the user know what went wrong.

Console.WriteLine("The file could not be read:");

Console.WriteLine(e.Message);

return null;

}

}

}

2.完成下面函数

public static string Left(string sSource, int iLength)

{

// 完成类似于 VB 的 Left 函数的功能(返回字符串 sSource 的左 iLength 位的字符串)。

}

解:

using System;

class Test{

public static void Main (){

// 完成类似于 VB 的 Left 函数的功能(返回字符串 sSource 的左 iLength 位的字符串)。

Console.WriteLine("Please enter a string to treaded:");

string s = Console.ReadLine();

int i = 0;

bool bInputValid = false;

while(!bInputValid){

try{

Console.WriteLine("Please enter the length from left most:");

i = Convert.ToInt32(Console.ReadLine());

if(i > s.Length) throw new Exception("");

}

catch(Exception e){

Console.WriteLine("It seen that your input data is not a integer or over flow, try again!");

Console.WriteLine(e.Message);

continue;

}

bInputValid = true;

}

Console.WriteLine("The left part string is {0} ", Left(s, i));

}

public static string Left(string sSource, int iLength){

char[] ac har = new char[iLength];

for(int i = 0; i < iLength; i++)

ac har [i] = sSource[i]; // 直接可字串中的单个字符,关键在这儿了

string sLeftPart = new string(ac har ); // 直接构造回一个 string

return sLeftPart;

}

}

2. 动物 (animals) 中的猫 (cat) 和狗 (dog) 都有咬 (bit) 的动作。请运用 .net 中对象的多态性技术展示猫咬和狗咬的动作。要求用 C# 代码实现。

解:

u sing System;

public class animals{

//string sName;

public virtual void bit(){

Console.Write("i am animals");

}

}

public class dog : animals{

public override void bit(){

Console.Write("bit by a dag!");

}

}

public class cat : animals{

public override void bit(){

Console.Write("bit by a cat!");

}

}

public class Test{

public static void Main (){

animals[] aa = new animals[2];

aa[0] = new dog();

aa[1] = new cat();

foreach(animals a in aa) a.bit();

}

}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus