已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
.NET技术实验报告书实验一 基础C#程序设计实验学时:4学时一、实验目的 1、掌握.Net Framework的安装及配置方法;2、熟悉C#程序的基本结构和基本语句;3、并掌握其编辑、编译、运行方法。4、理解C#语言是如何体现面向对象编程基本思想;5、掌握类对象的定义;6、掌握虚拟方法和重载方法的使用。7、掌握抽象类和抽象方法的使用。二、实验内容 1.从键盘输入两个数进行比较,并定义一个字符串变量,当数1小于数2时,字符串变量为“less than”,当当数1等小于数2时字符串变量为“equal to”,当数1大于数2时字符串变量为“greater than”。2、编一个猜数程序,程序设定一个1位十进制数,允许用户猜3次,错了告诉比设定数大还是小。3、定义日期类型Date。要求有以下面成员:年、月、日变量,重载的构造方法,一个实现年、月、日单独的输入,一个实现从系统时间里读出年月日,并实现打印方法成员,该方法要按照“XXXX年XX月XX日”格式输出日期。4、编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班级和成绩,教师数据有编号、姓名、职称和部门。要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师类数据操作类teacher的基类。三、实验要求1、 实验前根据实验内容复习相关章节,设计出程序框架。2、 编写相应的程序,写出完整的程序代码,包括注释,注意书写的层次结构。3、 调试程序,完成程序。4、 整理实验步骤,总结经验和体会。5、 上交实验报告和源程序。实验1.1代码using System;namespace BaiduAnswer class Guess public static int GuessMethod() Random seed = new Random(); return seed.Next(0, 10); static void Main() int result = GuessMethod(); for (int i = 1; i 9) Console.WriteLine(你所输入的数字非法,数字只能位!); else if (t result) Console.WriteLine(很抱歉,你所猜的数比随机数值大!); else if (t = result) Console.WriteLine(恭喜您,猜对了!); Console.WriteLine(现在公布答案,这次你所猜的数为:0, result);Console.ReadLine(); 实验1.1截图实验1.2代码using System;using System.Collections.Generic;using System.Text;namespace IF class IF static void Main(string args) string comparison; Console.WriteLine(请输入一个数:); double var1 = Convert.ToDouble(Console.ReadLine(); Console.WriteLine(请输入另一个数:); double var2 = Convert.ToDouble(Console.ReadLine(); if (var1 var2) comparison = less than; else if (var1 = var2) comparison = equal to; else comparison = greater than; Console.WriteLine(第一个数0第二个数., comparison); Console.ReadLine(); 实验1.2截图实验1.3代码using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication3 class Date int dYear; int dMonth; int dDaytime; String dTime; public Date() public Date(int dyear, int dmonth, int ddaytime) dYear = dyear; dMonth = dmonth; dDaytime = ddaytime; public void getTime() dTime = DateTime.Now.ToString(yyyy年MM月dd日); Console.WriteLine(当前时间:0, dTime); public void show() Console.WriteLine(0年1月2日, dYear, dMonth, dDaytime); class Program static void Main(string args) Date time1= new Date(); time1.show(); time1.getTime(); Console.ReadLine(); 实验1.3截图实验1.4代码using System;namespace ConsoleApplication4 class Person /定义person类 string name; string number; public void Input() Console.Write(请输入姓名:); name = Console.ReadLine(); Console.Write(请输入编号:); number = Console.ReadLine(); public void PersonDisplay() Console.WriteLine(); Console.WriteLine(相关信息:); Console.WriteLine(姓名: + name); Console.WriteLine(编号: + number); class Student : Person /Student类继承Person类 string studentClass; double score; public void StudentIput() Console.Write(请输入班级:); studentClass = Console.ReadLine(); Console.Write(请输入成绩:); score = Convert.ToDouble(Console.ReadLine(); public void StudentDisplay() Console.WriteLine(班级: + studentClass); Console.WriteLine(成绩: + score); Console.WriteLine(-); class Teacher : Person /Teacher类继承Person类 string title; string department; public void TeacherIput() Console.Write(请输入职称:); title = Console.ReadLine(); Console.Write(请输入部门:); department = Console.ReadLine(); public void TeacherDisplay() Console.WriteLine(职称: + title); Console.WriteLine(部门: + department); Console.WriteLine(-); class Program static void Main(string args) START: Console.Write(是否添加信息?请输入“Y/y”或“N/n”选择添加或退出:); string choose = Console.ReadLine(); if (choose = Y | choose = y) SELECT: Console.Write(输入“S/s”添加学生信息,输入“T/t”添加教师信息:); string select = Console.ReadLine(); if (select = S | select = s) /添加学生信息 Student stu = new Student(); stu.Input(); stu.StudentIput(); stu.PersonDisplay(); stu.StudentDisplay(); goto START; else if (select = T | select = t) /添加教师信息 Teacher tea = new Teacher(); tea.Input(); tea.TeacherIput(); tea.PersonDisplay(); tea.TeacherDisplay(); goto S
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论