




已阅读5页,还剩21页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
判断是否是闰年 课本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 else s2 n while n 0 Console WriteLine 奇数之和 0 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 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 j 1 j if c 100 if c 10 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 求水仙花数 static void Main string args int i n a b c for i 100 i a 1 a 0 a 1 max2 a 0 a 1 a 1 a 0 for i 2 i n i if max1 a i max2 max1 max1 a i Console WriteLine max1 0 max2 1 max1 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 Ave i grade i j 累加考生成绩 for int k 0 k Max k Console WriteLine 考生 0 平均成绩 1 k 1 Ave k 4 0 用俩个一维数组分别存放5个学生的学号和姓名 分别按学号和姓名排序 课本89页上级实验5 class 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 0 t no i Console WriteLine Console Write 姓名 t for int i 0 i name Length i Console Write 0 t name i Console WriteLine 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页8 class Program static void Main string args 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 某人有 0 只腿 重量为 1 kg legs weight class Animal 定义动物类 public int num 腿的条数 private float weight 重量 public Animal Animal类的默认构造函数 public Animal int n float w Animal类带2个参数的构造函数 num n weight w public void show Console WriteLine 某动物有 0 只脚 重量为 1 kg num weight 课本124页9 定义了一个委托 委托在传递方法时 方法必须带两个int型的参数 public delegate int Call int num1 int num2 在Delegates类的内部定义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 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 课本124页10 class List private int Max 100 存储最多元素 private int num 0 存储的实际元素个数 private object list 存储元素数组 public List 构造函数 list new object Max public void add object obj 添加一个元素 list num obj num public void delete int pos 删除一个元素 for int i pos 1 i num i list i 1 list i num public object get int pos 获取指定位置的元素 if pos num return list pos else return null public int getnum 获取实际元素个数 return num public string disp 获取所有元素 string s for int i 0 i num i s list i 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 Console WriteLine 元素个数 0 list getnum Console WriteLine 位置1的元素 0 list get 1 Console WriteLine 删除位置2的元素 list delete 2 Console WriteLine 元素序列 0 list disp 课本124页11 public class Student private string name private int eng math sum public int psum get return sum public void 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 t 0 t 1 t 2 t 3 name eng math sum class Program const int Max 100 static void sort int n params Student p 采用冒泡排序法排序 int i j bool exchange Student tmp for i 0 i i j if p j 1 psum p j psum tmp p j 1 p j 1 p j p j 1 p j p j tmp exchange true if exchange false break static void Main string args int n i Student p new Student Max 定义对象引用数组 Console Write n n int Parse Console ReadLine for i 0 i n i 创建对象引用的实例 p i new Student for i 0 i n i Console WriteLine 输入第 0 个学生数据 i 1 p i inscore Console WriteLine 排序前 Console WriteLine t姓名 t英语 t数学 t总分 for i 0 i n i Console Write 序号 0 i 1 p i display sort n p 按总降序排序 Console WriteLine 排序后 Console WriteLine t姓名 t英语 t数学 t总分 for i 0 i n i Console Write 第 0 名 i 1 p i display 课本124上机实验6 class Student 学生类 int sno 学号 string sname 姓名 Course course Course类对象数组 int score 课程成绩数组 double sgpa1 常见GPA值 double sgpa2 标准GPA值 public int psno 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 Course course1 Length for int i 0 i course1 Length i course i course1 i public void setscore int score1 设置分数 score new int score1 Length for int i 0 i score1 Length i score i score1 i public void computegpa 根据课程的学分以及学生成绩计算GPA int i double s sumc 0 sumgpa1 0 sumgpa2 0 for i 0 i 90 s 4 0 点数 else if score i 80 s 3 0 else if score i 70 s 2 0 else if score i 60 s 1 0 else s 0 0 sumgpa1 course i pcredits s sumgpa2 course i pcredits score i sumc course i pcredits sgpa1 sumgpa1 sumc sgpa2 sumgpa2 4 sumc 100 public void dispstud 输出学生信息 Console WriteLine 学号 0 t姓名 1 sno sname Console WriteLine 课程名 t学分 t分数 for int i 0 i course Length i Console WriteLine 0 t 1 t 2 course i pcname course i pcredits score i 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 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 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页7 using System using System Collections Generic using System Text namespace 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 工作年数 pn int Parse Console ReadLine psalary 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 Console WriteLine 该普通职工工资 0 psalary UEmployee emp2 new UEmployee Console WriteLine 该本科生职工工资 0 psalary 课本157页8 public class Employee 普通职工类 private double bsalary 1000 基本工资 private double psalary 实际工资 private int n 工作年数 public int pn get return n set n value public virtual double compsalary 计算普通员工工资 Console Write 工作年数 pn int Parse Console 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 args 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页9 public class Person 人类 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 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 WriteLine 班号 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 部门 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 输入一个学生数据 s1 input Console WriteLine 输入一个教师数据 t1 input Console WriteLine 显示一个学生数据 s1 disp Console WriteLine 显示一个教师数据 t1 disp 课本157页10 public class Student IComparable private string name private int eng math sum public int psum get return sum public void 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 t 0 t 1 t 2 t 3 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 定义对象引用 Console 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 foreach 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页上机实验7 public 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 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 Book 5 top 0 public void rentBook ref Book b rent top b top public void showReader Console Write 读者 base show Console WriteLine 所借图书 for int i 0 i top i Console Write 0 i 1 5个空格 rent i show Console WriteLine class Program static void Main string args Book b1 new Book C语言 100 潭浩强 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 ref b1 r1 rentBook ref b2 r1 rentBook ref b3 r2 rentBook ref b4 r1 showReader r2 showReader 课本200页3 public partial class Form1 Form int n 0 保存用户错误输入的次数 public Form1 InitializeComponent private void button1 Click object sender EventArgs e if textBox1 Text 1234 this Close 调用其他程序 else if n 0 listBox3 Items RemoveAt listBox3 SelectedIndex 课本200页6 public partial class Form4 Form public Form4 InitializeComponent private void Form4 Load object sender EventArgs e comboBox1 Items Add 北京 comboBox1 Items Add 上海 comboBox1 Items Add 天津 comboBox1 Items Add 广州 comboBox1 Items Add 武汉 comboBox1 Items Add 沈阳 comboBox1 Items Add 合肥 comboBox1 Items Add 长沙 comboBox1 Items Add 重庆 private void comboBox1 KeyPress object sender KeyPressEventArgs e MessageBox Show e KeyChar ToString if e KeyChar 13 按Enter键后判断 if comboBox1 Items Contains comboBox1 Text label2 Text 你的输入已在组合框 else comboBox1 Items Add comboBox1 Text label2 Text 你的输入新项已添加到组合框中 private void comboBox1 SelectedIndexChanged object sender EventArgs e MessageBox Show string Format 你选择了 0 项 comboBox1 Text 课本200页上机实验8 public partial class Form5 Form struct StudType public int no public string name public string sex public string sclass public DateTime rq StudType stud new StudType 10 定义一个结构类型的数组 public Form5 InitializeComponent private void Form5 Load object sender EventArgs e 给定义的数组赋初值 stud 0 no 1 stud 0 name 王华 stud 0 sex 男 stud 0 rq new DateTime 1980 2 10 stud 0 sclass 99091 stud 1 no 2 stud 1 name 李强 stud 1 sex 男 stud 1 rq new DateTime 1981 10 4 stud 1 sclass 99101 stud 2 no 3 stud 2 name 张丽 stud 2 sex 女 stud 2 rq new DateTime 1980 3 2 stud 2 sclass 99091 stud 3 no 4 stud 3 name 汪洋 stud 3 sex 男 stud 3 rq new DateTime 1980 1 5 stud 3 sclass 99101 stud 4 no 5 stud 4 name 江华 stud 4 sex 男 stud 4 rq new DateTime 1980 3 10 stud 4 sclass 99091 stud 5 no 6 stud 5 name 李英 stud 5 sex 女 stud 5 rq new DateTime 1980 6 2 stud 5 sclass 99101 stud 6 no 7 stud 6 name 胡军 stud 6 sex 男 stud 6 rq new DateTime 1981 10 9 stud 6 sclass 99091 stud 7 no 8 stud 7 name 刘驰 stud 7 sex 女 stud 7 rq new DateTime 1982 5 2 stud 7 sclass 99101 stud 8 no 9 stud 8 name 宋仁 stud 8 sex 男 stud 8 rq new DateTime 1980 8 3 stud 8 sclass 99101 stud 9 no 10 stud 9 name 许兵 stud 9 sex 男 stud 9 rq new DateTime 1980 11 8 stud 9 sclass 99091 将学号都添加到组合框中 for int i 0 i 10 MessageBox Show 没有该学号的记录 else textBox1 Text stud i no ToString 显示找到的学生记录 textBox2 Text stud i name textBox3 Text stud i sex textBox4 Text stud i sclass textBox5 Text stud i rq ToString 课本236页2 public partial class Form1 Form public Form1 InitializeComponent private void menu11 Click object sender EventArgs e Font f new Font 宋体 label1 Font Size label1 Font Style label1 Font f private void menu12 Click object sender EventArgs e Font f new Font 仿宋 GB2312 label1 Font Size label1 Font Style label1 Font f private void menu13 Click object sender EventArgs e Font f new Font 黑体 label1 Font Size label1 Font Style label1 Font f private void menu14 Click object sender EventArgs e Font f new Font 幼圆 label1 Font Size label1 Font Style label1 Font f private void menu15 Click object sender EventArgs e Font f new Font 楷体 GB2312 label1 Font Size label1 Font Style label1 Font f private void menu21 Click object sender EventArgs e Font f new Font label1 Font Name 28 label1 Font Style label1 Font f private void menu22 Click object sender EventArgs e Font f new Font label1 Font Name 20 label1 Font Style label1 Font f private void menu23 Click object sender EventArgs e Font f new Font label1 Font Name 16 label1 Font Style label1 Font f private void menu24 Click object sender EventArgs e Font f new Font label1 Font Name 12 label1 Font Style label1 Font f private void menu25 Click object sender EventArgs e Font f new Font label1 Font Name 8 label1 Font Style label1 Font f 课本237页上机实验9 public partial class Form2 Form public Form2 InitializeComponent private void Form2 Load object sender EventArgs e treeView1 Indent 20 treeView1 Nodes Add 哺乳动物 treeView1 Nodes 0 Nodes Add 豹子 treeView1 Nodes 0 Nodes Add 老虎 treeView1 Nodes 0 Nodes Add 北极熊 treeView1 Nodes 0 Nodes Add 狼 treeView1 Nodes 0 Nodes Add 大象 treeView1 Nodes 0 Nodes Add 犀牛 treeView1 Nodes Add 鱼类 treeView1 Nodes 1 Nodes Add 鲨鱼 treeView1 Nodes 1 Nodes Add 热带鱼 treeView1 Nodes 1 Nodes Add 金鱼 treeView1 Nodes Add 鸟类 treeView1 Nodes 2 Nodes Add 天鹅 treeView1 Nodes 2 Nodes Add 猫头鹰 treeView1 Nodes 2 Nodes Add 翠鸟 private void treeView1 AfterSelect object sender TreeViewEventArgs e string s s e Node Text listView1 Items Clear listView1 LargeImageList imageList1 listView1 SmallImageList imageList2 switch s case 哺乳动物 listView1 Items Add 豹子 0 listView1 Items Add 老虎 0 listView1 Items Add 北极熊 0 listView1 Items Add 狼 0 listView1 Items Add 大象 0 listView1 Items Add 犀牛 0 break case 鱼类 listView1 Items Add 鲨鱼 0 listView1 Items Add 热带鱼 0 listView1 Items Add 金鱼 0 break case 鸟类 listView1 Items Add 天鹅 0 listView1 Items Add 猫头鹰 0 listView1 Items Add 翠鸟 0 break private void menu1 Click object sender EventArgs e listView1 View View LargeIcon private void menu2 Click object sender EventArgs e listView1 View View SmallIcon private void menu3 Click object sender EventArgs e listView1 View View List private void menu4 Click object sender EventArgs e listView1 View View Tile 课本254页3 public partial class Form1 Form public Form1 InitializeComponent private void Form1 Paint object sender PaintEventArgs e Graphics gobj this CreateGraphics Pen bluePen new Pen Color Blue 5 Pen redPen new Pen Color Red 5 Rectangle myRectangle new Rectangle 50 50 100 80 gobj DrawRectangle bluePen 30 20 100 80 gobj DrawRectangle redPen myRectangle 课本254页4 public partial class Form2 Form public Form2 InitializeComponent private void Form2 Paint object sender PaintEventArgs e Graphics gobj this CreateGraphics double PI 3 14159 gobj FillPie Brushes Blue 30 30 130 80 0 300 gobj FillPie Brushes Red 30 30 130 80 0 60 private void Form2 Load object sender EventArgs e 课本254页5 public partial class Form3 Form public Form3 InitializeComponent private void Form3 Paint object sender PaintEventArgs e Graphics gobj this CreateGraphics HatchBrush myBrush new HatchBrush HatchStyle BackwardDiagonal Color Blue Color Green Pen myPen new Pen Color Red 8 gobj DrawEllipse myPen 20 20 150 100 gobj FillEllipse myBrush 20 20 150 100 课本254页6 public partial class Form4 Form public Form4 InitializeComponent private void Form4 Paint object sender PaintEventArgs e int i StringFormat strFormat Font strFont SolidBrush strBrush Graphics gobj this CreateGraphics for i 10 i 24 i 6 strFormat new StringFormat strFont new System Drawing Font 隶书 i strBrush new SolidBrush Color Red gobj DrawString 中华人民共和国 strFont strBrush 2 i 3 i strFormat 课本254上机实验10 public partial class Form5 Form public Form5 InitializeComponent private void button1 Click object sender EventArgs e Pen myPen new Pen System Drawing Color Blue Graphics gobj this CreateGraphics gobj DrawLine myPen 30 30 120 120 private void button2 Click object sender EventArgs e Pen myPen new Pen System Drawing Color Blue Graphics gobj this CreateGraphics gobj DrawEllipse myPen new Rectangle 30 30 100 100 private void button3 Click object sender EventArgs e Graphics gobj this CreateGraphics string drawString 使用DrawString方法 Font myFont new Font 黑体 16 Brush b new SolidBrush System Drawing Color Blue float x 30 0F float y 30 0F StringFormat myFormat new StringFormat gobj DrawString drawString myFont b x y myFormat 课本274页3 public partial class Form1 Form public
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年中国普法试题库及答案
- 2025年维修电工中级plc试题及答案
- 2025年建二级考试题及答案
- 材料认购协议书
- 村民砂场协议书
- 村里重建协议书
- 果树代管协议书
- 枣庄离婚协议书
- 染厂计件协议书
- 2025年中医考试方剂试题及答案
- 第一章可靠性概论教材
- 标志logo设计报告
- 殡葬寿衣店行业分析
- 新人教版七年级下册数学(全册)同步练习随堂练习一课一练
- 标识牌安装工艺
- 血液净化专科进修汇报
- 回弹法检测泵送混凝土抗压强度技术规程DB64-T697-2011
- EHS法律法规清单与合规性评价结果记录表
- 2024年陕西榆林能源集团有限公司招聘笔试参考题库附带答案详解
- IQC来料检验作业指导书
- 团员组织关系转接介绍信(样表)
评论
0/150
提交评论