C#基礎(chǔ)試題(附答案).doc_第1頁
C#基礎(chǔ)試題(附答案).doc_第2頁
C#基礎(chǔ)試題(附答案).doc_第3頁
C#基礎(chǔ)試題(附答案).doc_第4頁
C#基礎(chǔ)試題(附答案).doc_第5頁
已閱讀5頁,還剩11頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

一、選擇題1、能作為C#程序的基本單位是( )。A. 字符 B. 語句 C. 函數(shù) D. 源程序文件答案:B2、將變量從字符串類型轉(zhuǎn)換為數(shù)值類型可以使用的類型轉(zhuǎn)換方法是( )。A.Str() B.Cchar C.CStr() D.int.Parse();答案:D3、數(shù)據(jù)類型轉(zhuǎn)換的類是( )。A.Mod B.Convert C. Const D. Single答案:B4、字符串連接運算符包括&和( )。A. + B. - C. * D. /答案:A 5、先判斷條件的當循環(huán)語句是( )。A. do.while B. while C. while.do D. do .loop答案:B6、下面幾個函數(shù),()是重載函數(shù). 1.void f1(int) 2.int f1(int) 3.int f1(int,int) 4.float k(int)A.四個全 B.1 和 4 C.2 和 3 D.3和4答案:C8、以下的C代碼:static void Main(string args)Console.WriteLine(運行結(jié)果: 0,Console.ReadLine();Console.ReadLine();代碼運行結(jié)果為( )。A.在控制臺窗口顯示“運行結(jié)果:”B.在控制臺窗口顯示“運行結(jié)果:0”C.在控制臺窗口顯示“運行結(jié)果:,ConsoleReadLine”D.如果用戶在控制臺輸入“ A”,那么程序?qū)⒃诳刂婆_顯示“運行結(jié)果:A”答案:D9、在C#中定義一個數(shù)組,正確的代碼為( )。A.int arraya = new int5; B.int arraya = new int5;C.int arraya = new int; D.int5 arraya = new int;答案:B10、在C#中,下列代碼運行后,變量Max的值是( )(選擇一項)Int a=5,b=10,c=15,Max=0; Max = ab?a:b; Max = cMax?c:Max;A.0 B.5 C.10 D.15答案:C11、在C#中,關(guān)于continue和break,以下說法正確的是( )A break是中斷本次循環(huán) B continue是中斷本次循環(huán),進入一下次的循環(huán)C break是中斷本次循環(huán),進入一下次的循環(huán) D continue是中斷整個循環(huán)答案:A12、在C#中,關(guān)于while和dowhile,以下說法正確的是( )A while先執(zhí)行然后判斷條件是否成立 B while最少的循環(huán)次數(shù)是1次C dowhile先執(zhí)行然后判斷條件是否成立 D dowhile最少的循環(huán)次數(shù)是0次答案:C13、在C#中,下列變量定義與賦值正確的是( )A int a=同學 B float a=老師 C double a=教室D char a=學答案:D14、表達式 “abcde”= =”abcde”+”2006”的值為( )ATrue2006 B. true C. false D. 0答案:C15、在C#中定義類時,使用的關(guān)鍵字是( )A、interface B、intC、classD、overrides答案:C二.寫出下列程序的結(jié)果 1、 int y = 1,x; if (y!=0) x = 5; else if (y 0 ) x = 4; else x = 3; Console.WriteLine(x=0”, x); 答案:5 2、 int x, y = 0; do x = y+; Console.WriteLine(x); while (y 6); 答案:153、class Test static void Main( ) int x=5; int y=x- -; Console.WriteLine(y=0, y); y=- -x; Console.WriteLine(y=0, y); 答案:5,54、class Test publicstatic void Main() staticint a = 1, 2, 3, 4, 5, 6, 7, 8 ; ints0, s1, s2; s0=s1=s2= 0; for(int i = 0; i 50)break; if (i%2=0) s+=i; Console.writeLine (i, s= + i + , + s); 答案:14,S=2+4+6.+14,566、寫出下列函數(shù)的功能。static float FH() float y=0,n=0; int x = Convert.ToInt32(Console.ReadLine(); /從鍵盤讀入整型數(shù)據(jù)賦給x while (x!=-1) n+; y+=x;x = Convert.ToInt32(Console.ReadLine(); if (n=0) return y; else return y/n; 答案:從鍵盤中輸入輸入整型數(shù)只要不是-1就求和,不輸入數(shù)就返回0,否則求這幾個數(shù)的的平均值。7、using System;class Test public static void Main () int a =2,4,6,8,10,12,14,16,18;for (int i=0; i b ? a : b; max = max c ? max : c; return max; 2、編一個程序,輸入一個字符,如果是大寫字母,就轉(zhuǎn)換成小寫字母,否則不轉(zhuǎn)換。答案: Console.Write(輸入字符:); char c = char.Parse(Console.ReadLine(); char s = Change(c); Console.WriteLine(0, s); Console.ReadKey(); static char Change(char c) if (c = A & c = A & c = a & c = 48 & c = 0) if (a - b = 0.5) b = b + 1; return b; 5、編一個程序,輸入0100之間的一個學生成績分數(shù),用switch語句輸出成績等第(成績優(yōu)秀(90-100),成績良好(80-89),成績及格(60-79)和成績不及格(59以下)。答案:static void Main(string args) Score(); Console.ReadKey(); static void Score() int score = int.Parse(Console.ReadLine(); int s = score / 10; int a; if (s = 9 & s = 8& s = 6 & s 8) a = 2; else a = 3; switch (a) case 0: Console.WriteLine(成績優(yōu)秀); break; break; case 1: Console.WriteLine(成績良好); break; case 2: Console.WriteLine(成績及格); break; default: Console.WriteLine(成績不及格); break; 6、 編一個程序,用while循環(huán)語句來計算1+1/2+2/3+3/4+.+99/100之和。答案: Console.Write(sum=); double sum = 1; Console.WriteLine(0, Sum(); Console.ReadKey(); static double Sum() double sum = 1; double i=1; while ( i = 100) sum += i / (i+1); i=i+1; return sum; 7、編寫一個程序,用while語句,求出1+(1+2)+(1+2+3)+.+(1+2+3+.+10)之和。答案: int sum = 0; Console.Write(和為:); Console.WriteLine(0,Sum(); Console.ReadKey(); static int Sum() int sum = 0; int i = 1; int a = 0; while (i = 10) a = a+i; sum= sum+ a; i = i + 1; return sum; 8、有關(guān)系式1*1+2*2+3*3+.+k*k2000,編一個程序,求出滿足此關(guān)系式的k的最大值。答案: int sum=0; Console.WriteLine(最大值為:0 ,Max(); Console.ReadKey(); static int Max() int sum = 0; int k=1; while(sum2000) sum+=k*k; k+; return k-1; 9、編寫一個程序,要求用while循環(huán)語句,打印1到100的正整數(shù),每行打印5個數(shù),每列右對齊。答案: Quee(); Console.ReadKey(); static void Quee() for (int i = 1; i = 100; i+) Console.Write(0 ,i); if (i % 5 = 0) Console.WriteLine(); i+; return; 10、編一個程序,利用二重for循環(huán)語句,打印出九九乘法口訣表。答案: Chengfabiao(); Console.ReadKey(); static void Chengfabiao() for (int i = 1; i = 9; i+) for (int j = 1; j = i; j+) Console.Write(0*1=2 , j, i, i * j); Console.WriteLine(); return; 11、編一個程序,利用for循環(huán)語句,求出1!+2!+3!+.+10!的和。答案: int sum = 0; Console.WriteLine(0, Sum(); Console.ReadKey(); static int Sum() int sum = 0; int a = 1; for (int i = 1; i = 10; i+) a = a * i; sum = sum + a; return sum; 13、編一個程序,定義一個字符串變量,輸入字符串,然后再輸入一個字符,在字符串中查找該字符出現(xiàn)的次數(shù)。答案: Console.Write(請輸入字符串:); string str = Console.ReadLine(); Console.Write(請輸入字符:); char c = char.Parse(Console.ReadLine(); int s = Str(str, c); Console.WriteLine(0, s); Console.ReadKey(); static int Str(string str, char c) int a = 0; for (int i = 0; i str.Length; i+) if(stri=c) a+; return a; 15、編一個程序,輸入一個整數(shù),判定它為幾位數(shù)。例如,99是2位數(shù),-100是3位數(shù)。答案: Console.WriteLine(0, Math(); Console.ReadKey(); static int Math() int a = int.Parse(Console.ReadLine(); int b=0; int c = 1; if (a 0) b = a; while (b = 10) b = b / 10; c+; return c; 四、面向?qū)ο?、定義一個車輛(Vehicle)基類,具有Run、Stop等方法,具有Speed(速度)、MaxSpeed(最大速度)、Weight(重量)等域。然后以該類為基類,派生出Bicycle、Car等類。并編程對該派生類的功能進行驗證。答案:基類: class Vehicle public double Speed; public double Maxspeed; public double Weight; public void Run() Console.WriteLine(我跑。); public void Stop() Console.WriteLine(我停。); 派生類: class Bicycle:Vehicle class Car:Vehicle 對派生類功能的驗證: static void Main(string args) Bicycle p = new Bicycle(); p.Run(); Car c = new Car(); c.Stop(); Console.ReadKey(); 2、寫一個控制臺應(yīng)用程序,接收一個長度大于3的字符串,完成下列功能:1)輸出字符串的長度。2)輸出字符串中第一個出現(xiàn)字母a的位置。3)在字符串的第3個字符后面插入子串“hello”,輸出新字符串。4)將字符串“hello”替換為“me”,輸出新字符串。5)以字符“m”為分隔符,將字符串分離,并輸出分離后的字符串。答案: Console.Write(輸入字符:); string str=Console.ReadLine(); while (str.Length=0) Console.Write(出現(xiàn)字符a的位置:); Console.WriteLine(0, index); else Console.WriteLine(字符串中不含字符a); string str1 = hello + str.Substring(3); Console.Write(出現(xiàn)新字符串:); Console.WriteLine(str1); str1 = str1.Replace(hello,me); Console.Write(替換后的字符串:); Console.WriteLine(str1); string str2 = str1.Split(m); for (int i = 0; i str2.Length; i+) Console.Write(分割后的字符串:); Console.WriteLine(str2i); Console.ReadKey(); 3、編寫一個控制臺應(yīng)用程序,完成下列功能,并寫出運行程序后輸出的結(jié)果。1)創(chuàng)建一個類A,在A中編寫一個可以被重寫的帶int類型參數(shù)的方法MyMethod,并在該方法中輸出傳遞的整型值后加10后的結(jié)果。2)再創(chuàng)建一個類B,使其繼承自類A,然后重寫A中的MyMethod方法,將A中接收的整型值加50, 3)在Main方法中分別創(chuàng)建A和類B的對象,并分別調(diào)用MyMethod方法。答案:并輸出結(jié)果。class A public virtual void MyMethod(int num) num+=10; Console.WriteLine(0,num); class B:A public override void MyMethod(int num) num += 50; Console.WriteLine(0,num); A a = new A(); a.MyMethod(3); B b = new B(); b.MyMethod(8); Console.ReadKey();4 編寫一個類Calculate1,實現(xiàn)加、減兩種運算,然后,編寫另一個派生類Calculate2,實現(xiàn)乘、除兩種運算。 class Calculate1 public virtual void Mix(int a,int b) Console.Write(運算符為:); string s=Console.ReadLine(); int c; if (s = +) c = a + b; Console.WriteLine(0, c); else if (s = -) c = a - b; Console.WriteLine(0, c); public override void Mix(int a, int b) Console.Write(運算符為:); string s = Console.ReadLine(); int c; if (s = *) c = a * b; Console.WriteLine(0,c); else if (s = /) c = a / b; Console.Writ

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論