




已阅读5页,还剩49页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
学 生 实 验 报 告 册(理工类)课程名称: C#程序设计实验 专业班级:14计算机科学与技术(单)(1) 学生学号:学生姓名: 邵佳楠 所属院部: 计算机工程学院 指导教师: 马xx 2016 2017学年 第 1 学期 金陵科技学院教务处制金陵科技学院实验报告实验项目名称: C#基础编程 实验学时: 6 同组学生姓名: 无 实验地点: A104 实验日期: 实验成绩: 批改教师: 马青霞 批改时间: 实验1 C#基础编程一、实验目的1、熟悉Visual Studio .NET开发环境;2、掌握C#应用程序的基本操作过程;3、掌握C#的数据类型,运算符以及表达式的使用;4、掌握分支和循环语句的使用方法;5、掌握一维数组,二维数组及数组型数组的使用。二、实验要求1、编写程序要规范、正确,上机调试过程和结果要有记录;2、做完实验后给出本实验的实验报告。三、实验设备、环境安装有Visual Studio .NET2005以上版本软件。四、实验步骤1、 采用VS编写一个简单的控制台应用程序(1)打开VS开发工具。(2)在新建项目对话框中选择Visual C#,模板选择控制台应用程序,给项目命名为HelloConsole,然后点“浏览”按钮,选择项目的存储目录。(3)在Program.cs文件中,键入代码如下:using System;Namespace HelloConsole class Program static void Main(string args) String name; Console.Write(请输入姓名:); name = Console.ReadLine(); Console.WriteLine(欢迎0光临, name); Console.ReadLine(); (4)按F5或者点启动调试按钮运行程序,在控制台中输入“你的姓名”,回车。2、采用VS编写一个简单的windows窗体应用程序(1)打开开发工具。(2)在新建项目对话框中选择Visual C#,模板选择windows窗体应用程序,给项目命名为HelloForm,然后点“浏览”按钮,选择项目的存储目录。(3)在Form1窗体中拖放一个TextBox文本框、Label标签和Button按钮控件,修改Label的Text属性为”, 修改Button1的Text属性为”确定”。(4)双击Command1进入Form1.cs的代码界面,在button1_Click事件中键入代码如下:private void button1_Click(object sender, EventArgs e) label1.Text = 欢迎 + textBox1.Text + 光临; /或者 label1.Text = string.Format(欢迎0光临,textBox1.Text); (5)按F5或者点启动调试按钮运行程序,在文本框中输入“你的姓名”,单击“确定”按钮。运行结果(请截图):1、 采用VS编写一个简单的控制台应用程序2、采用VS编写一个简单的windows窗体应用程序五、实验内容1、编写一个控制台应用程序,输入自己的班级、学号、姓名并显示。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace student class Program static void Main(string args) String grade; String name; String number; Console.WriteLine(请输入班级:); grade = Console.ReadLine(); Console.WriteLine(请输入姓名:); name = Console.ReadLine(); Console.WriteLine(请输入学号:); number = Console.ReadLine(); Console .WriteLine (班级:0,姓名:1,学号:2,grade,name ,number ); Console .ReadLine (); 2、编写一个Windows窗体应用程序,输入自己的班级、学号、姓名并显示。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication2 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) MessageBox .Show (班级:+textBox1.Text+n姓名:+textBox2.Text +n学号:+textBox3 .Text ); 3、编写一个程序,用来判断输入的是大写字母,小写字母,数字还是其他的字符(if)。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication1 class Program static void Main(string args) Console.WriteLine(请输入一个字符:); char c = Convert.ToChar(Console.ReadLine(); if (c = a & c = A & c = Z) Console.WriteLine(该字母是大写字母); else if (char.IsDigit(c) Console.WriteLine(该字母是数字); else Console.WriteLine(其它字符); Console.ReadLine(); 4、编写一个程序,实现简单的加、减、乘、除的运算(switch)。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication3 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) int num1 = int.Parse(txtnum1.Text); int num2 = int.Parse(txtnum2.Text); switch (txtop.Text) case +: txtresult.Text = (num1 + num2) + ; break; case -: txtresult.Text = (num1 - num2) + ;break; case *: txtresult.Text = (num1 * num2) + ;break; case /: txtresult.Text = (num1 / num2) + ;break; default: txtresult.Text = error!;break; 5、定义一个一维数组,通过键盘输入10个两位整数,用foreach循环输出其中的内容。并求出其中的最大值和平均值,把结果显示出来。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication2 class Program static void Main(string args) int a = new int10; int i = 0; while (i = 10 & ai = 99) i+; Console.Write( 数组内容为:); foreach (int j in a) Console.Write(0 , j); Console.WriteLine(); Console.WriteLine(最大值: + a.Max(); Console.WriteLine(平均值: + a.Average(); Console.ReadLine(); 6、定义一个5行5列二维数组,用随机数给二维数组赋值,按照5行5列的格式显示出二维数组的内容,把最大值显示出来。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication2 class Program static void Main(string args) int, a = new int5, 5; int max; Random rnd = new Random(); Console.WriteLine(二维数组的内容为:); for (int i = 0; i 5; i+) for (int j = 0; j 5; j+) ai, j = rnd.Next(10, 99); Console.Write(0 , ai, j); Console.WriteLine(); max = a0, 0; for (int i = 0; i 5; i+) for (int j = 0; j max) max = ai, j; Console.WriteLine(最大值: + max); Console.ReadLine(); 实验项目名称: 面向对象编程 实验学时: 6 同组学生姓名: 无 实验地点: A104 实验日期: 实验成绩: 批改教师: 马青霞 批改时间: 实验2 面向对象编程一、实验目的、要求1、理解面向对象程序设计的思想和基本概念;2、掌握类的定义和使用;3、掌握类的数据成员,属性的定义和使用;4、掌握方法的定义,调用和重载以及方法参数的传递;5、掌握构造函数和析构函数的定义和使用。7、掌握虚方法的定义以及如何用虚方法实现多态;8、掌握抽象类的定义以及如何用用抽象方法实现多态;9、掌握集合的创建和操作方法;10、掌握接口的定义及使用方法。二、实验要求1、编写程序要规范、正确,上机调试过程和结果要有记录;2、做完实验后给出本实验的实验报告。三、实验设备、环境安装有VS.Net 2005以上版本软件。四、实验内容1、利用方法的重载两个整数和两个双精度类型数据求和。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _1 class Program static void Main(string args) Console.WriteLine(整型数据相加:); Add intadd = new Add(1, 2); intadd.Result(); Console.WriteLine(双精度数据相加:); Add doubleadd = new Add(1.1, 2.5); doubleadd.Result(); class Add public double add = 0; public Add(double x, double y) add = x + y; public Add(int x, int y) add = x + y; public void Result() Console.WriteLine(add); 2、定义一个Area类,用构造函数重载,实现矩形的面积,圆的面积,梯形的面积,定义一个ShowArea方法,显示结果。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication4 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) double len = double.Parse(txtlength.Text); double wid = double.Parse(txtwidth.Text); double r = double.Parse(txtr.Text); double sd = double.Parse(txtsd.Text); double xd = double.Parse(txtxd.Text); double hei = double.Parse(txtheight.Text); Area a1 = new Area(len,wid); Area a2 = new Area(r); Area a3 = new Area(sd, xd, hei); txtrec.Text = a1.ShowArea(len,wid); txtcir.Text = a2.ShowArea(r); txtech.Text = a3.ShowArea(sd, xd, hei); using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace WindowsFormsApplication4 class Area double len, wid, r, sd, xd, hei; public Area(double len, double wid) this.len = len; this.wid = wid; public Area(double r) this.r = r; public Area(double sd, double xd, double hei) this.sd = sd; this.xd = xd; this.hei = hei; public string ShowArea(double len,double wid) return (len * wid) + ; public string ShowArea(double r) return (3.14 * r * r) + ; public string ShowArea(double sd, double xd, double hei) return (sd + xd) * hei * 0.5) + ; 3、定义一个Students类,包括学号、姓名、性别、年龄4个属性,要求在性别属性中增加对性别的判断(只能输入男和女),在年龄属性中提供对不合法(年龄在10至50之间)输入的判断,并提供方法显示学生信息。构建该类,并测试。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _3 class Student int id, age; string name, sex; public int _id get return id; set id = value; public int _age get return age; set age = value; public string _name get return name; set name = value; public string _sex get return sex; set sex = value; class Program static void Main(string args) Student mz = new Student(); mz._id = 1413201011; mz._name = 周慧博; mz._sex = 男; mz._age = 20; Console.WriteLine(学号:0rn姓名:1rn性别:2rn年龄:3, mz._id, mz._name, mz._sex, mz._age); Console.ReadKey(); 4、设计一个Windows应用程序,在该程序中首先构造一个学生基本类,再分别构造小学生、中学生、大学生派生类,当输入相关数据,单击不用的按钮时,将分别创建不同的学生类对象,并输出当前学生的总人数,该学生的姓名,学生类型,平均成绩。程序要求:(1)每个学生都有的字段为姓名、年龄。(2)小学生的字段还有语文,数学,用来表示这两科的成绩。(3)中学生在此基础上增加英语成绩。(4)大学生分为必修课和选修课两项成绩。(5)学生类提供方法来统计自己的总成绩并输出。(6)通过静态成员自动记录学生总人数。(7)成员初始化通过构造函数完成。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication5 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) int age = Convert.ToInt32(txtAge.Text); double sub1 = Convert.ToDouble(txtSub1.Text); double sub2 = Convert.ToDouble(txtSub2.Text); Pupil p = new Pupil(txtName.Text, age, sub1, sub2); lblShow.Text += p.getInfo(); private void button2_Click(object sender, EventArgs e) int age = Convert.ToInt32(txtAge.Text); double sub1 = Convert.ToDouble(txtSub1.Text); double sub2 = Convert.ToDouble(txtSub2.Text); double sub3 = Convert.ToDouble(txtSub3.Text); Middle p = new Middle(txtName.Text, age, sub1, sub2, sub3); lblShow.Text += p.getInfo(); private void button3_Click(object sender, EventArgs e) int age = Convert.ToInt32(txtAge.Text); double sub1 = Convert.ToDouble(txtSub1.Text); double sub2 = Convert.ToDouble(txtSub2.Text); double sub3 = Convert.ToDouble(txtSub3.Text); College p = new College(txtName.Text, age, sub1, sub2, sub3); lblShow.Text += p.getInfo(); using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WindowsFormsApplication5 public abstract class Student protected string name; protected int age; public static int number; public Student(string name, int age) = name; this.age = age; number+; public string Name get return name; public virtual string type get return 学生; public abstract double total(); public string getInfo() string result = string.Format(总人数:0,姓名:1,2,3岁, number, Name, type, age); if (type = 小学生) result += string.Format(,平均成绩为0:N2:n, total() / 2); else if (type = 中学生) result += string.Format(,平均成绩为0:N2:n, total() / 3); else result += string.Format(,总学分为0:N2:n, total(); return result; using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WindowsFormsApplication5 public class Pupil : Student protected double chinese; protected double math; public Pupil(string name, int age, double chinese, double math) : base(name, age) this.chinese = chinese; this.math = math; public override string type get return 小学生; public override double total() return chinese + math; using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WindowsFormsApplication5 public class Middle : Student protected double chinese; protected double math; protected double english; public Middle(string name, int age, double chinese, double math, double english) : base(name, age) this.chinese = chinese; this.math = math; this.english = english; public override string type get return 中学生; public override double total() return chinese + math + english; using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WindowsFormsApplication5 public class College : Student protected double chinese; protected double math; protected double english; public College(string name, int age, double chinese, double math, double english) : base(name, age) this.chinese = chinese; this.math = math; this.english = english; public override string type get return 本科生; public override double total() return chinese + math + english; 5、设计一个Windows应用程序,在该程序中定义平面图形抽象类Figure和派生类圆(Circle)、矩形(Rectangle)和三角形(Triangle)。该程序实现的功能包括:输入相应图形的参数,如矩形的长和宽,单击相应的按钮,根据输入参数创建图形类并输出该对象的面积。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication7 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) double r = Convert.ToDouble(textBox1.Text); Circle c = new Circle(r); lblShow.Text += 圆面积为: + c.Area() + n; private void button2_Click(object sender, EventArgs e) double len = Convert.ToDouble(textBox1.Text); double wid = Convert.ToDouble(textBox2.Text); Rectangle r = new Rectangle(len, wid); lblShow.Text += 矩形面积为: + r.Area() + n; private void
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年食品药品监管考试模拟题发布
- 2025年建筑工程管理职业技能鉴定高级模拟题及答案
- 2025江苏省建筑安全员《A证》考试题库及答案
- 2025年环保工程师面试宝典环境治理技术与项目管理预测题
- 2025年软件架构设计师高级面试指南与模拟题集
- 2025年陪诊师考试题库及答案
- 2025年建筑设计师面试预测题库及实战模拟题集
- 2025年医院医疗技术人员招聘笔试全面解读及模拟题
- 桑德拉潜水艇销售课件
- 2025年陪诊师考试题目及答案
- 2025云南师范大学辅导员考试题库
- BEC商务英语(中级)阅读模拟试卷11(共405题)
- 语文课堂教学目标设计“四出发”
- 2025年度建筑劳务木工班组施工合作协议
- 矿业行业智能化矿山建设与运营方案
- 重大版英语六年级上册单词默写表
- 《画电气原理图接线》课件
- 停水停电停氧的应急预案
- 护理肝癌的疑难病例讨论
- 92枪械课件教学课件
- 2024年首届全国标准化知识竞赛真题题库导出版-中(多选题部分)
评论
0/150
提交评论