This test has a total of three topics, requiring the following:
1. Please use C # to complete
2. Opening is independently completed, you can read, online, etc. to find information, but you must guarantee independently. Once there is no honesty, the company will not be admitted and the consequences are at your own risk.
Topic one:
1. Write a bubbling order
Claim:
1) Please use C # to write a bubble order,
2) The data required to be sorted is read from the file c: /data.dat, and the data is separated by commas.
solution:
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 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 Ai [i] = convert.toint32 (astr [i]); Return Ai; } Catch (Exception E) { // let the user know what wrong. Console.writeline ("The File Could NOT BE READ:"); Console.writeLine (E.MESSAGE); Return NULL; } } } 2. Complete the following functions Public Static String Left (String Ssource, INT ILENGTH) { // Complete the function of the LEFT function similar to the VB (returns the string of the left Ilength bit of the string SSource). } solution: Using system; Class test { Public static void Main () { // Complete the function of the LEFT function similar to the VB (returns the string of the left Ilength bit of the string SSource). Console.writeline ("please enter a string to turned:"); String s = console.readline (); INT i = 0; BOOL BINPUTVALID = FALSE; While (! binputvalid) { Try { Console.writeline ("please enter the length from left mot:"); I = Convert.Toint32 (console.readline ()); IF (i> s.ley) 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 [] achar = new char [inength]; For (int i = 0; i ACHAR [I] = SSource [i]; / / The key characters in the direct strings are here. String SLEFTPART = New String (achar); // Directly construct back to a string Return SLEFTPART; } } 2. Cats (CAT) and Dogs (DOG) in Animals have a bite (BIT). Please use the polymorphism technology of the object in .NET to show the action of the cat bites and dog biting. Require it with a C # code. solution: Using 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 (); } }