版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、判斷是否是閏年 課本63用戶輸入整數(shù)反向顯示 課本67或68乘法表 課本69判斷從鍵盤輸入大于3的整數(shù)是否為素數(shù) 課本70求輸入所以數(shù)其中正數(shù)的和 課本70求 1平方+2平方+n平方 小于等于1000 的最大n 課本71或72讀入一組數(shù)(以0結(jié)束),分別求奇數(shù)和偶數(shù)和static void Main(string args) int n,s1=0,s2=0; do n = int.Parse(Console.ReadLine(); if (n%2=1) s1 += n; else s2 += n; while (n!=0); Console.WriteLine(奇數(shù)之和=0,s1); Cons
2、ole.WriteLine(偶數(shù)之和=0,s2); 輸入正整數(shù)n計算S=1+(1+2)+(1+2+3)+(1+2+.+n)int n,i,j,s=0; Console.Write(n:); n = int.Parse(Console.ReadLine(); for (i = 1; i = n; i+) for (j = 1; j 13) Console.WriteLine(輸入的數(shù)值太大!); else for (i=0;i=n-1;i+) for (j=1;j15-i;j+) Console.Write( ); /每次循環(huán)顯示2個空格 c=1; Console.Write(0 ,c); fo
3、r (j=1;j=i;j+) c=c*(i-j+1)/j; if (c100) if (c10) Console.Write(0 ,c); /顯示3個空格 else Console.Write(0 ,c); /顯示2個空格 else Console.Write(0 ,c); /顯示1個空格 Console.WriteLine(); 計算的值double pi=0.0; int i; for (i=1;i=2000;i+) if (i%2=1) pi=pi+1.0/(2*i-1); else pi=pi-1.0/(2*i-1); pi=4*pi; Console.WriteLine(=0, pi
4、);求水仙花數(shù)static void Main(string args) int i, n, a, b, c; for (i = 100; i a1?a0:a1; max2=a0a1?a1:a0; for (i=2;in;i+) if (max1ai) max2=max1; max1=ai; Console.WriteLine(max1=0,max2=1,max1,max2); 用一個二維數(shù)組存放5個考生4門功課的考試成績,求每位考生的平均成績 課本89頁static void Main(string args) const int Max = 5; /考生數(shù) int Ave = new in
5、tMax; /定義一個一維數(shù)組存儲考生的總成績 int, grade=88,75,62,84,96,85,75,92, /定義二維數(shù)組存儲考生成績 68,63,72,78,95,89,76,98, 76,65,72,63; for(int i=0; iMax; i+) for(int j=0; j4; j+) Avei += gradei,j; /累加考生成績 for (int k = 0; k Max; k+) Console.WriteLine(考生0平均成績=1 ,k+1, Avek/4.0); 用倆個一維數(shù)組分別存放5個學生的學號和姓名,分別按學號和姓名排序 課本89頁上級實驗5cla
6、ss Program const int Max = 5; static void disp(int no,string name,string str) Console.WriteLine(str); Console.Write(學號:t); for (int i = 0; i no.Length; i+) Console.Write(0t,noi); Console.WriteLine(); Console.Write(姓名:t); for (int i = 0; i name.Length; i+) Console.Write(0t, namei); Console.WriteLine(
7、); static void Main(string args) int no = new int 2, 4, 5, 1, 3; string name = new string Smith,John,Mary,Cherr,Tomn; disp(no, name,排序前:); Array.Sort(no, name); disp(no, name,按學號排序后:); Array.Sort(name, no); disp(no, name, 按姓名排序后:); 課本124頁8class Program static void Main(string args) Person p1 = new P
8、erson(2, 50); Animal a1 = new Animal(); p1.show(); a1.show(); public class Person /定義人類public int legs; /腿的只數(shù) protected float weight; /重量 public Person() /默認構(gòu)造函數(shù) public Person(int legs1,float weight1)/自定義方法F legs= legs1; weight = weight1; public void show() Console.WriteLine(某人有0只腿,重量為1kg, legs, wei
9、ght); class Animal /定義動物類 public int num; /腿的條數(shù) private float weight; /重量 public Animal() /Animal類的默認構(gòu)造函數(shù) public Animal(int n,float w) /Animal類帶2個參數(shù)的構(gòu)造函數(shù) num = n; weight = w; public void show() Console.WriteLine(某動物有0只腳,重量為1kg, num, weight); 課本124頁9/定義了一個委托,委托在傳遞方法時,方法必須帶兩個int型的參數(shù)。 public delegate i
10、nt Call(int num1, int num2); /在Delegates類的內(nèi)部定義Math類和TestDelegates類。 class Math public int fun1(int num1, int num2) return num1*num1+num2*num2; public int fun2(int num1, int num2) return num1*num1-num2*num2; class Program static void Main(string args) int result; Call objCall; /委托的對象 Math objMath = n
11、ew Math();/Math類的對象 objCall = new Call(objMath.fun1); result = objCall(5, 3);/將委托實例化 Console.WriteLine(結(jié)果為0, result); objCall = new Call(objMath.fun2); result = objCall(5, 3);/將委托實例化 Console.WriteLine(結(jié)果為0, result); 課本124頁10class List private int Max = 100; /存儲最多元素 private int num = 0; /存儲的實際元素個數(shù) pr
12、ivate object list; /存儲元素數(shù)組 public List() /構(gòu)造函數(shù) list = new objectMax; public void add(object obj) /添加一個元素 listnum = obj; num+; public void delete(int pos) /刪除一個元素 for (int i = pos + 1; i num; i+) listi - 1 = listi; num-; public object get(int pos) /獲取指定位置的元素 if (pos num) return listpos; else return n
13、ull; public int getnum() /獲取實際元素個數(shù) return num; public string disp() /獲取所有元素 string s = ; for (int i = 0; i num; i+) s += listi + ; return s; class Program static void Main(string args) List list = new List(); list.add(abc); list.add(1.23); list.add(2); list.add(a); Console.WriteLine(元素序列:0,list.disp
14、(); Console.WriteLine(元素個數(shù):0,list.getnum(); Console.WriteLine(位置1的元素:0,list.get(1); Console.WriteLine(刪除位置2的元素); list.delete(2); Console.WriteLine(元素序列:0, list.disp(); 課本124頁11public class Student private string name; private int eng, math, sum; public int psum get return sum; public void inscore()
15、Console.Write(姓名:); name = Console.ReadLine(); Console.Write(英語:); eng = int.Parse(Console.ReadLine(); Console.Write(數(shù)學:); math = int.Parse(Console.ReadLine(); sum = eng + math; public void display() Console.WriteLine(t0t1t2t3, name, eng, math, sum); class Program const int Max = 100; static void so
16、rt(int n, params Student p)/采用冒泡排序法排序 int i, j; bool exchange; Student tmp; for (i = 0; i = i; j-) if (pj + 1.psum pj.psum) tmp = pj + 1;/pj+1pj pj + 1 = pj; pj = tmp; exchange = true; if (exchange = false) break; static void Main(string args) int n, i; Student p = new StudentMax; /定義對象引用數(shù)組 Console.
17、Write(n:); n = int.Parse(Console.ReadLine(); for (i = 0; i n; i+) /創(chuàng)建對象引用的實例 pi = new Student(); for (i = 0; i n; i+) Console.WriteLine(輸入第0個學生數(shù)據(jù):, i + 1); pi.inscore(); Console.WriteLine(排序前:); Console.WriteLine(t姓名t英語t數(shù)學t總分); for (i = 0; i n; i+) Console.Write(序號0:, i + 1); pi.display(); sort(n, p
18、); /按總降序排序 Console.WriteLine(排序后:); Console.WriteLine(t姓名t英語t數(shù)學t總分); for (i = 0; i n; i+) Console.Write(第0名:, i + 1); pi.display(); 課本124上機實驗6 class Student /學生類 int sno; /學號 string sname; /姓名 Course course; /Course類對象數(shù)組 int score; /課程成績數(shù)組 double sgpa1; /常見GPA值 double sgpa2; /標準GPA值 public int psno
19、/psno屬性可讀可寫 get return sno; set sno = value; public string psname /psname屬性可讀可寫 get return sname; set sname = value; public void setcourse(params Course course1) /設置課程 course = new Coursecourse1.Length; for (int i = 0; i course1.Length; i+) coursei = course1i; public void setscore(int score1) /設置分數(shù)
20、score = new intscore1.Length; for (int i = 0; i score1.Length; i+) scorei = score1i; public void computegpa() /根據(jù)課程的學分以及學生成績計算GPA int i; double s, sumc = 0, sumgpa1 = 0, sumgpa2 = 0; for (i = 0; i = 90) s = 4.0; /點數(shù) else if (scorei = 80) s = 3.0; else if (scorei = 70) s = 2.0; else if (scorei = 60)
21、s = 1.0; else s = 0.0; sumgpa1 += coursei.pcredits * s; sumgpa2 += coursei.pcredits * scorei; sumc += coursei.pcredits; sgpa1 = sumgpa1 / sumc; sgpa2 = sumgpa2 * 4 / sumc / 100; public void dispstud() /輸出學生信息 Console.WriteLine(學號:0t姓名:1, sno, sname); Console.WriteLine( 課程名t學分t分數(shù)); for (int i = 0; i
22、course.Length; i+) Console.WriteLine( 0t1t2, coursei.pcname, coursei.pcredits, scorei); public void dispgpa() /輸出GPA Console.WriteLine(常見算法GPA=0:n,標準算法GPA=1:n, sgpa1, sgpa2); class Course /課程類 string cname; /課程名 int credits; /課程學分 public Course() public Course(string name, int xf) /構(gòu)造函數(shù) cname = name
23、; credits = xf; public string pcname /pcname屬性,課程名可讀可寫 get return cname; set cname = value; public int pcredits /pcredits屬性,課程學分可讀可寫 get return credits; set credits = value; class Program static void Main(string args) Course course1 = new Course new Course(課程1,4),new Course(課程2,3), new Course(課程3,2)
24、,new Course(課程4,6),new Course(課程5,3); int score1 = new int 92, 80, 98, 70, 89 ; Student s1 = new Student(); s1.psno = 1; s1.psname = 王華; s1.setcourse(course1); s1.setscore(score1); s1aaaputegpa(); s1.dispstud(); s1.dispgpa(); 課本157頁7using System;using System.Collections.Generic;using System.Text;nam
25、espace Proj7_15 public class Employee private double bsalary= 1000; private double psalary; private int n; public int pn get return n; set n = value; public double compsalary() Console.Write(工作年數(shù):); pn = int.Parse(Console.ReadLine(); psalary = bsalary+30*pn; return psalary; public class UEmployee :
26、Employee new public double compsalary() return 1.5 * baseaaapsalary(); class Program static void Main(string args) Employee emp1 = new Employee(); Console.WriteLine(該普通職工工資:0, emp1aaapsalary(); UEmployee emp2 = new UEmployee(); Console.WriteLine(該本科生職工工資:0, emp2aaapsalary(); 課本157頁8public class Empl
27、oyee /普通職工類 private double bsalary = 1000; /基本工資 private double psalary; /實際工資 private int n; /工作年數(shù) public int pn get return n; set n = value; public virtual double compsalary() /計算普通員工工資 Console.Write(工作年數(shù):); pn = int.Parse(Console.ReadLine(); psalary = bsalary + 30 * pn; return psalary; public cla
28、ss UEmployee : Employee /本科生職工類 public override double compsalary() return 1.5 * baseaaapsalary(); public class GEmployee : Employee /研究生職工類 public override double compsalary() return 2 * baseaaapsalary(); class Program static void Main(string args) Employee emp1 = new Employee(); Console.WriteLine(
29、該普通職工工資:0, emp1aaapsalary(); UEmployee emp2 = new UEmployee(); Console.WriteLine(該本科生職工工資:0, emp2aaapsalary(); GEmployee emp3 = new GEmployee(); Console.WriteLine(該研究生職工工資:0, emp3aaapsalary(); 課本157頁9public class Person /人類 private int no; /編號 private string name; /姓名 public void input() Console.Wri
30、te( 編號:); no = int.Parse(Console.ReadLine(); Console.Write( 姓名:); name = Console.ReadLine(); public void disp() Console.WriteLine( 編號:0,no); Console.WriteLine( 姓名:0,name); public class Student : Person /學生類 private string sclass; /班號 private int degree; /成績 public void input() base.input(); Console.
31、Write( 班號:); sclass = Console.ReadLine(); Console.Write( 成績:); degree = int.Parse(Console.ReadLine(); new public void disp() base.disp(); Console.WriteLine( 班號:0,sclass); Console.WriteLine( 成績:0,degree); public class Teacher : Person /教師類 private string prof; /職稱 private string depart; /部門 public vo
32、id input() base.input(); Console.Write( 職稱:); prof = Console.ReadLine(); Console.Write( 部門:); depart = Console.ReadLine(); new public void disp() base.disp(); Console.WriteLine( 職稱:0, prof); Console.WriteLine( 部門:0, depart); class Program static void Main(string args) Student s1 = new Student(); Teacher t1 = new Teacher(); Console.WriteLine(輸入一個學生數(shù)據(jù):); s1.input(); Console.WriteLine(輸入一個教師數(shù)據(jù):); t1.input(); Console.WriteLine(顯示一個學生數(shù)據(jù):); s1.disp(); Console.WriteLine(顯示一個教師數(shù)據(jù):); t1.disp(); 課本157頁10public class Student:IC
溫馨提示
- 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 洪水應急管理培訓課件
- 2024-2025學年陜西省西安市部分學校聯(lián)考高一上學期第四次階段性檢測歷史試題(解析版)
- 2024-2025學年山東省煙臺市高一下學期期中考試歷史試題(解析版)
- 2024-2025學年江蘇省連云港市贛榆區(qū)高一下學期期末考試歷史試題(解析版)
- 2026年生理學深度學習人體生理系統(tǒng)與功能全面試題庫
- 2026年市場營銷策略分析題庫與答案
- 2026年物流管理倉儲與配送優(yōu)化題集
- 2026年軟件開發(fā)崗面試題集專業(yè)技能與經(jīng)驗測試
- 2026年機械工程師設計原理與制造工藝題目集
- 2026年職場技能測試有效溝通與團隊合作策略
- 書店智慧空間建設方案
- 2026年中考英語復習專題課件:謂語動詞的時態(tài)和被動語態(tài)
- 糧食行業(yè)競爭對手分析報告
- 2025年危險品運輸企業(yè)重大事故隱患自查自糾清單表
- 2025至2030汽車傳感器清洗系統(tǒng)行業(yè)調(diào)研及市場前景預測評估報告
- 兒科MDT臨床技能情景模擬培訓體系
- 無菌技術及手衛(wèi)生
- GB/Z 104-2025金融服務中基于互聯(lián)網(wǎng)服務的應用程序編程接口技術規(guī)范
- (人教版)必修第一冊高一物理上學期期末復習訓練 專題02 連接體、傳送帶、板塊問題(原卷版)
- 門窗工程掛靠協(xié)議書
- 供應鏈韌性概念及其提升策略研究
評論
0/150
提交評論