下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、判断是否是闰年课本 63用户输入整数反向显示课本 67或 68乘法表 课本 69判断从键盘输入大于3的整数是否为素数课本 70求输入所以数其中正数的和课本 70求1平方+2平方+n平方 小于等于1000的最大n 课本71或72读入一组数(以0结束) ,分别求奇数和偶数和static void Main( string args) int n,s1=0,s2=0; do n =int .Parse( Console.ReadLine();if (n%2=1)s1 += n;elses2 += n; while (n!=0);Console .WriteLine(" 奇数之和=0&quo
2、t; ,s1);Console .WriteLine(" 偶数之和=0" ,s2);输入正整数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 <= i; j+)s += j;Console .WriteLine( "s=0" , s);杨辉三角static void Main( string ar
3、gs) int i,j,c,n;Console .Write( "n:" );n= int .Parse( Console .ReadLine(); if (n>13)Console .WriteLine( " 输入的数值太大!" );else for (i=0;i<=n-1;i+)for (j=1;j<15-i;j+)Console .Write( " " );/ 每次循环显示2个空格c=1;Console .Write( "0 ",c);for (j=1;j<=i;j+) c=c*(i-
4、j+1)/j;if (c<100)if (c<10)Console .Write( "0 ",c);/ 显示3个空格else Console .Write( "0 ",c);/ 显示2个空格elseConsole .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);elsepi=pi-1.0/(2*i-1);pi=4*pi;Cons
5、ole .WriteLine("无=0” , pi);求水仙花数static void Main( string args) int i, n, a, b, c;for (i = 100; i <= 999; i+) n = i;c = n % 10; n = n / 10;b = n % 10; n = n / 10;a = n;if (a * a * a + b * b * b + c * c * c = i)Console .WriteLine( "0 1 2 = 3", a, b, c,a*a*a+b*b*b+c*c*c);/Console.Writ
6、e("0 ", i);Console .WriteLine();假设10个整数用一维数组存放,求最大值和次大值static void Main( string args) int a = new int 101,8,10,4,7,9,6,10,2,5;int n=10,max1,max2,i;max1=a0>a1?a0:a1;max2=a0>a1?a1:a0;for (i=2;i<n;i+)if (max1<ai)max2=max1;max1=ai;Console .WriteLine( "max1=0,max2=1" ,max1
7、,max2);用一个二维数组存放5个考生4门功课的考试成绩,求每位考生的平均成绩课本89页static void Main( string args) const int Max = 5;/ 考生数int Ave = new int Max;/ 定义一个一维数组存储考生的总成绩int , grade=88,75,62,84,96,85,75,92,/ 定义二维数组存储考生成绩68,63,72,78,95,89,76,98,76,65,72,63;for ( int i=0; i<Max; i+)for ( int j=0; j<4; j+) Avei += gradei,j;/ 累
8、加考生成绩for ( int k = 0; k < Max; k+)Console .WriteLine( "考生 0 平均成绩=1 " ,k+1, Avek/4.0);用俩个一维数组分别存放5个学生的学号和姓名,分别按学号和姓名排序课本 89页上级实验5class Program const int Max = 5;static void disp( int no, string name, string str) Console .WriteLine(str);Console .Write( " 学号 :t" );for ( int i = 0
9、; 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();static void Main( string args) int no = new int 2, 4, 5, 1, 3;string name = new str
10、ing "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
11、) Person p1 = new Person (2, 50);Animal a1 = new Animal ();p1.show();a1.show();public class Person/ 定义人类 public int legs;/ 腿的只数protected float weight; / 重量public Person()/ 默认构造函数 public Person( int legs1, float weight1) / 自定义方法F legs= legs1;weight = weight1;public void show() Console .WriteLine( &qu
12、ot; 某人有 0 只腿,重量为1kg" , legs, weight);class Animal/ 定义动物类 public int num;/ 腿的条数private float weight;public Animal() public Animal( int n, float num = n;weight = w;public void show()/ 重量/Animal 类的默认构造函数w) /Animal 类带2个参数的构造函数Console .WriteLine(" 某动物有0 只脚,重量为1kg" , num, weight);课本 124页 9/
13、 定义了一个委托,委托在传递方法时,方法必须带两个int 型的参数。public delegate int Call ( int num1, int num2);/ 在Delegates 类的内部定义 Mathl和 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( strin
14、g args) int result;Call objCall;/ 委托的对象Math objMath = new Math(); /Math 类的对象objCall =new Call (objMath.fun1);result = objCall(5, 3);/ 将委托实例化Console .WriteLine( " 结果为 0" , result);objCall =new Call (objMath.fun2);result = objCall(5, 3);/ 将委托实例化Console .WriteLine( " 结果为 0" , result
15、);课本 124页 10class List private int Max = 100;/ 存储最多元素private int num = 0;/ 存储的实际元素个数private object list; / 存储元素数组public List()/ 构造函数 list =new object Max;public void add( object obj) / 添加一个元素 listnum = obj;num+;public void delete( int pos) / 删除一个元素 for ( int i = pos + 1; i < num; i+)listi - 1 = l
16、isti;num-;public object get( int pos) / 获取指定位置的元素 if (pos < num)return listpos;elsereturn null ;public int getnum() / 获取实际元素个数 return num;public string disp() / 获取所有元素 string s = "" ;for ( int i = 0; i < num; i+)s += listi +" " ;return s;class Programstatic void Main( strin
17、g args)List list =new List ();list.add("abc" );list.add(1.23);list.add(2);'a' );list.add(Console .WriteLine(Console .WriteLine(Console .WriteLine(Console .WriteLine(" 元素序列:0" ,list.disp();" 元素个数:0" ,list.getnum();" 位置 1的元素 :0" ,list.get(1);" 删除位置2
18、的元素" );list.delete(2);Console .WriteLine(" 元素序列:0" , list.disp();课本124页 11publicclass Studentprivatestring name;privateint eng, math, sum;publicint psumgetreturn sum; publicvoid inscore()Console .Write( "姓名 :" );name =Console.ReadLine();Console .Write( " 英语 :" );en
19、g =int .Parse( Console .ReadLine();Console .Write( " 数学 :" );math =int .Parse(Console.ReadLine();sum = eng + math;public void display()Console .WriteLine("t0t1t2t3", name, eng, math, sum);class Programconst int Max = 100;static void sort( intn, params Student p)/ 采用冒泡排序法排序int i,
20、j;bool exchange;Student tmp;for (i = 0; i < n - 1; i+) exchange =false ;for (j = n - 2; j >= i; j-)if (pj + 1.psum > pj.psum) tmp = pj + 1;/pj+1<->pjpj + 1 = pj;pj = tmp;exchange =true ;if (exchange = false ) break ;static void Main( string args) int n, i;Student p = new Student Max;
21、/ 定义对象引用数组 Console .Write( "n:" );n =int .Parse( Console .ReadLine();for (i = 0; i < n; i+)/ 创建对象引用的实例pi =new Student ();for (i = 0; i < n; i+) Console .WriteLine( "输入第 0 个学生数据:" , i + 1);pi.inscore();Console .WriteLine( " 排序前 :" );Console .WriteLine( "t 姓名 t
22、 英语t 数学 t 总分 " );for (i = 0; i < n; i+)Console.Write( "序号 0:" , i + 1);pi.display();sort(n, p);/ 按总降序排序Console .WriteLine( " 排序后 :" );Console .WriteLine( "t 姓名 t 英语t 数学 t 总分 " );for (i = 0; i < n; i+) Console .Write( "第 0 名 :" , i + 1);pi.display();
23、课本124上机实验6/ 学生类/ 学号/ 姓名/Course 类对象数组/ 课程成绩数组class Student int sno;string sname;Course course;int score;double sgpa1;double sgpa2;/常见GPA: /标准GPA. /psno 属性可读可写public int psno get return sno; set sno =value ; public string psname/psname 属性可读可写 get return sname; set sname =value ; public void setcourse(
24、 params Course course1) / 设置课程 course =new Coursecourse1.Length;for ( int i = 0; i < course1.Length; i+) coursei = course1i; public void setscore( int score1) / 设置分数 score =new int score1.Length;for ( int i = 0; i < score1.Length; i+) scorei = score1i;public void computegpa() / 根据课程的学分以及学生成绩计算
25、GPA int i;double s, sumc = 0, sumgpa1 = 0, sumgpa2 = 0;for (i = 0; i < score.Length; i+)if (scorei >= 90)s = 4.0;/ 点数else if (scorei >= 80)s = 3.0;else if (scorei >= 70)s = 2.0;else if (scorei >= 60)s = 1.0; elses = 0.0;sumgpa1 += coursei.pcredits * s;sumgpa2 += coursei.pcredits * sco
26、rei;sumc += coursei.pcredits;sgpa1 = sumgpa1 / sumc;sgpa2 = sumgpa2 * 4 / sumc / 100;public void dispstud()/ 输出学生信息 Console .WriteLine("学号:0t 姓名 :1" , sno, sname);Console .WriteLine( " 课程名 t 学分 t 分数 " );for ( int i = 0; i < course.Length; i+)Console .WriteLine( " 0t1t2&qu
27、ot;, 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) cname = name;credits = xf;public string pcname get return cnam
28、e; set cname =value ; public int pcredits get return credits; set credits =valueclass Program static void Main( string Course course1 =/ 课程类/ 课程名/ 课程学分 args)new Course / 构造函数/pcname 属性,课程名可读可写/pcredits 属性,课程学分可读可写new Course ( " 课程1" ,4), new Course( "课程 2" ,3)new Course( " 课
29、程 3" ,2),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);putegpa();s1.dispstud();s1.dispgpa();课本157页 7using System;using
30、System.Collections.Generic;using System.Text;namespace Proj7_15 public class Employeeprivateprivatedouble bsalary= 1000;double psalary;privateint n;publicint pn get return n; set n = value ; public double compsalary() Console .Write( " 工作年数:" );pn =int .Parse( Console.ReadLine();psalary =
31、bsalary+30*pn;return psalary;public class UEmployee : Employee new public double compsalary() return 1.5 * psalary();class Program static void Main( string args) Employee emp1 = new Employee();psalary();, psalary();Console .WriteLine( " 该普通职工工资:0" ,UEmployee emp2 = new UEmployee();Console
32、.WriteLine( " 该本科生职工工资:0"课本157页 8public class Employee / 普通职工类privatedoublebsalary = 1000;/ 基本工资privatedoublepsalary;/ 实际工资privateint n;/ 工作年数public int pn get return n; set n = value ; public virtual double compsalary() / 计算普通员工工资 Console .Write( "工作年数:" );pn =int .Parse( Consol
33、e.ReadLine();psalary = bsalary + 30 * pn;return psalary;public class UEmployee : Employee / 本科生职工类 public override double compsalary() return 1.5 * psalary();public class GEmployee : Employee / 研究生职工类 public override double compsalary() return 2 * psalary();class Program static void Main( string arg
34、s) Employee emp1 = new Employee();Console .WriteLine( " 该普通职工工资:0" , psalary();UEmployee emp2 = new UEmployee();Console .WriteLine( " 该本科生职工工资:0" , psalary();GEmployee emp3 = new GEmployee();Console .WriteLine( " 该研究生职工工资:0" , psalary();课本 157页 9public class Person/ 人类
35、private int no;/ 编号private string name; / 姓名public void input() Console .Write( " 编号 :" );no =int .Parse( Console.ReadLine();Console .Write( " 姓名 :" );name = Console.ReadLine();public void disp() Console .WriteLine( " 编号 :0" ,no);Console .WriteLine( " 姓名 :0" ,
36、name);public class Student :Person/学生类 private string sclass;/ 班号private int degree;/成绩public void input() base.input();Console .Write( "班号:" );sclass =Console .ReadLine();Console .Write( "成绩:" );degree =int .Parse( Console.ReadLine();new public void disp() base.disp();Console .W
37、riteLine( "班号:0" ,sclass);Console .WriteLine( "成绩:0" ,degree);public class Teacher : Person / 教师类 private string prof;/ 职称private string depart;/ 部门public void input() base.input();Console .Write( " 职称 :" );prof =Console .ReadLine();Console .Write( " 部门 :" );
38、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 =Teacher t1 = newConsole .WriteLine(Console .WriteLine(Console .WriteLine(Console .WriteLi
39、ne(new Student ();Teacher ();" 输入一个学生数据:");s1.input()" 输入一个教师数据:");t1.input();" 显示一个学生数据:");s1.disp();" 显示一个教师数据:"); t1.disp();课本 157页 10publicclass Student : IComparableprivate string name;private int eng, math, sum;public int psum get return sum; public void
40、 inscore() Console .Write( "姓名 :" );name = Console.ReadLine();Console .Write( " 英语 :" );eng =int .Parse( Console .ReadLine();Console .Write( " 数学 :" );math =int .Parse( Console .ReadLine();sum = eng + math;public void display() Console .WriteLine( "t0t1t2t3",
41、name, eng, math, sum); public int CompareTo( object obj) / 实现接口方法 Student s = ( Student )obj;/ 转换为 Student 实例if (psum < s.psum) return 1;else if (psum = s.psum) return 0;else return -1;class Program static void Main( string args) int n, i;ArrayList myarr = new ArrayList ();Student p;/ 定义对象引用Conso
42、le .Write( "n:" );n =int .Parse( Console .ReadLine();for (i = 0; i < n; i+) Console .WriteLine( "输入第 0 个学生数据:" , i + 1);p =new Student ();/ 创建对象引用实例p.inscore();myarr.Add(p);Console .WriteLine( " 排序前 :" );Console .WriteLine( "t 姓名 t 英语t 数学 t 总分 " );i = 1;for
43、each ( Student s in myarr)Console .Write( "序号0:" , i+);/ 按总分降序排序s.display(); myarr.Sort();Console .WriteLine(" 排序后 :" );Console .WriteLine("t 姓名 t 英语t 数学 t 总分 " );i = 1;foreach ( Student s in myarr)Console .Write( "第 0 名 :" , i+);s.display(); 课本157页上机实验7public
44、 class BClass/ 基类 private string name; / 名称 private int no;/ 编号public BClass( string na, int n) / 构造函数 name = na; no = n;public void show() Console .Write( "0(1)", name, no);public class Book : BClass / 图书类 string author;/ 作者public Book( string na, int n, string auth):base(na, n) author =
45、auth;public void showBook() base.show();Console .Write( " 作者 :0" , author); public class Reader : BClass / 读者类 Book rent;/ 所借图书int top; public Reader( string na, int n):base(na, n) / 构造函数 rent =new Book5;top = 0; public void rentBook( ref Book b) renttop = b;top+; public void showReader()
46、Console .Write( " 读者 :" );base.show();Console .WriteLine( " 所借图书:" );for ( int i = 0; i < top; i+)/5 个空格Console .Write( "0:", i + 1);renti.show();Console .WriteLine(); class Program static void Main( string args) Book bl = new Book( "C语言", 100,"潭浩强&quo
47、t;);Book b2 = new Book( "数据结构" ,110, "严蔚敏"Book b3 = new Book( "软件工程" ,210,"陈华 ");Book b4 = new Book( "操作系统" ,208,"张明 ");Reader r1 = new Reader( " 王华 " ,1234);Reader r2 = new Reader( " 李兵 " ,2600);r1.rentBook(refb1);r1.re
48、ntBook(refb2);r1.rentBook(refb3);r2.rentBook(refb4);r1.showReader();r2.showReader();课本200页 3public partial class Form1 : Form int n = 0;/ 保存用户错误输入的次数public Form1() InitializeComponent();private void button1_Click( object sender, EventArgs e) if (textBox1.Text ="1234" && textBox2.Te
49、xt ="1234" ) MessageBox.Show( " 用户名 /口令正确");this .Close();/ 调用其他程序elseif (n<3)MessageBox.Show( " 用户名 /口令错误, 再次输入" );n+;elseMessageBox.Show( " 已经错误输入三次,退出");this .Close();课本200页 4public partial class Form2 : Form public Form2() InitializeComponent();private
50、void rbutton1_CheckedChanged( object sender, EventArgs e) Font f = new Font ( "宋体 " ,textBox1.Font.Size,textBox1.Font.Style); textBox1.Font = f;private void rbutton2_CheckedChanged( object sender, EventArgs e) Font f = new Font ( "楷体 _GB2312", textBox1.Font.Size, textBox1.Font.St
51、yle);textBox1.Font = f;/textBox1.Font.Name = " 楷体 _GB2312"private void rbutton3_CheckedChanged( object sender, EventArgs e) Font f = new Font (textBox1.Font.Name, 10, textBox1.Font.Style); textBox1.Font = f; private void rbutton4_CheckedChanged( object sender, EventArgs e) Font f = new Fon
52、t (textBox1.Font.Name, 16, textBox1.Font.Style); textBox1.Font = f;private void checkBox1_CheckedChanged( object sender, EventArgs e) if (checkBox1.Checked)Font f = new Font (textBox1.Font.Name, textBox1.Font.Size,FontStyle .Bold);textBox1.Font = f;elseFont f = new Font (textBox1.Font.Name, textBox1
53、.Font.Size,FontStyle .Regular);textBox1.Font = f; 课本200页5public partial class Form3 : Form int a=0, b=0;public Form3()InitializeComponent();private void Form3_Load( object sender, EventArgs e) listBox1.Items.Add("12" );listBox1.Items.Add("10" );listBox1.Items.Add("5" );
54、listBox1.Items.Add("8" );listBox1.Items.Add("22" );listBox1.Items.Add("25" );listBox1.Items.Add("9" );listBox2.Items.Add("9" );listBox2.Items.Add("15" );listBox2.Items.Add("20" );listBox2.Items.Add("32" );listBox2.Items.
55、Add("18" );listBox2.Items.Add("5" );listBox2.Items.Add("7" );listBox2.Items.Add("32" ); private void listBox1_SelectedIndexChanged( object sender, EventArgs e) a = int .Parse(listBox1.Text); private void listBox2_SelectedIndexChanged( object sender, EventArgs e) b = int .Parse(listBox2.Text);listBox3.Items.Add(string .Format( "0 x1=2" ,a,b,a*b); privatevoid listBox3_SelectedIndexChanged(object sender, EventArgs e) if (listBox3.SelectedIndex&g
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 幼儿园财务管理制度
- 幼儿园师德师风心得体会
- L-749329-Rac-L-754142-生命科学试剂-MCE
- 运动会加油稿简短7篇
- Isosorbide-Standard-生命科学试剂-MCE
- 落地式钢管脚手架搭拆工程施工设计方案
- 毕业季“勇敢之夜”活动方案
- 产业园区土地转让居间合同
- 住宅区石材搬运合同
- 农民工工资保障措施方案
- 广东省学校安全条例竞赛模拟题(第二套)附有答案
- 全草类中药的鉴定
- 水下混凝土工程施工安全要求
- 水利水电建筑工程专业人才培养指导方案
- 马鞍山祥恒包装有限公司2500MM瓦楞纸板生产线技改项目环境影响报告表
- 第八篇 动物实验技术
- 2023-2024学年吉林省长春市小学数学六年级上册期末高分通关测试题
- YC/T 336-2020烟叶收购站设计规范
- 公开课课件拿来主义
- 机加工企业风险告知牌通用
- 管理运筹学7运输问题课件
评论
0/150
提交评论