资源描述
Hebei Normal University of Science & Technology
专业:信息管理与信息系统13
学号: 0811130128
信息系统开发工具课程实习
2014-2015第1学期
题 目:课程实习
院(系、部):工商管理学院信息管理与信息系统
学 生 姓 名:支鹏宇
指 导 教 师:刘海滨
2015年12月25日
1 实习背景
C# 是微软对这一问题的解决方案。C#是一种最新的、面向对象的编程语言。它使得程序员可以快速地编写各种基于Microsoft .NET平台的应用程序,Microsoft .NET提供了一系列的工具和服务来最大程度地开发利用计算与通讯领域。
正是由于C#面向对象的卓越设计,使它成为构建各类组件的理想之选——无论是高级的商业对象还是系统级的应用程序。使用简单的C#语言结构,这些组件可以方便的转化为XML 网络服务,从而使它们可以由任何语言在任何操作系统上通过Internet进行调用。
最重要的是,C#使得C++程序员可以高效的开发程序,而绝不损失C/C++原有的强大的功能。因为这种继承关系,C#与C/C++具有极大的相似性,熟悉类似语言的开发者可以很快的转向C#。
其特点有:
· 语言简洁。
· 保留了C++的强大功能。
·快速应用开发功能。
· 语言的自由性。
· 强大的Web服务器控件。
· 支持跨平台。
· 与XML相融合。
C#几乎集中了所有关于软件开发和软件工程研究的最新成果:面向对象、类型安全、组件技术、自动内存管理、跨平台异常处理、版本控制、代码安全管理等。尽管像很多人注意到的一样,罗列上述特性时,总是让人想到JAVA,然而C#确实走得更远。但现实的情况是,非技术的因素往往更能决定一个产品的未来,尤其在计算机软件的历史上,技术卓越的产品,如OS/2、Mac OS、UNIX等,都败在了Windows漂亮的界面上。JAVA的用户主要是网络服务的开发者和嵌入式设备软件的开发者,嵌入式设备软件不是C# 的用武之地,而在网络服务方面,C# 的即时编译和本地代码Cache方案比JAVA虚拟机具有绝对的性能优势。何况C# 一旦成为一个像C++ 一样的公共的标准,软件开发商既可以省去JAVA的许可证费用,也不必担心成为微软的奴隶,那些反微软的人士和主张厂商独立的人士可能也不会有什么意见。这可能正是微软所期待的。
C# 将不可避免地崛起,在Windows平台上成为主角,而JAVA将在UNIX、Linux等平台上成为霸主,C++ 将继续在系统软件领域大展拳脚。
2 实习内容
2.1 Visual Studio 2010下的控制台程序
2.1.1实习目的和内容
实习目的:
1、了解所用的计算机系统的基本操作方法,学会独立使用该系统;
2、了解在该系统上如何编辑、编译、连接和运行一个C#程序;
3、通过运行简单的C#程序,初步了解C#程序的特点。
实习内容:
1、在visual studio 2010编辑环境下编辑范例中给出的程序、编译并运行。
2、设定如下题目要求学生独立完成:
(1)编写一个C#程序,输入a, b, c,d四个值,输出其中最小者。
根据上述题目要求编程并上机调试运行。
2.1.2代码和运行结果
1 输出最小值
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入第一个数");
double a = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("请输入第二个数");
double b = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("请输入第三个数");
double c = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入第四个数");
double d = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("最小的数");
Console.WriteLine(Min(a, b, c, d));
Console.ReadLine();
}
static double Min(double a, double b, double c, double d)
{
double Min1 = a < b ? a : b;
double Min2 = c < d ? c : d;
double Min = Min1 < Min2 ? Min1 : Min2;
return Min;
}
}
}
2.2 数组,结构和枚举实例
2.2.1实习目的和内容
实习目的:
1、掌握数组、结构和枚举类型的使用方法。
2、掌握各种类型数据的输入输出函数的应用方法。
3、掌握C#中数组、结构和枚举类型自带的一些方法。
实习内容:
1、在C#编辑环境下编辑范例中给出的程序、编译并运行。
2、本节实习题目:
自行编写应用程序,要求应用程序中涉及到数组、枚举或结构类型的使用,并能应用到C#自身提供的相关方法。上机运行程序并分析结果。
2.2.2代码和运行结果
1 数组实例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int[] myArray1 = new int[5] {11,22,33,44,55};
int[] myArray2 = new int[5];
for (int i = myArray1.Length - 1; i >= 0; i--)
{
myArray2[4 - i] = myArray1[i]; //一维数组逆序存放
}
Console.WriteLine("原数组为:");
foreach (int a in myArray1)
{
Console.WriteLine(a);
}
Console.WriteLine("逆序存放后的数组为:");
foreach (int b in myArray2)
{
Console.WriteLine(b);
}
Console.ReadLine();
} } }
2 枚举的使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
enum month { January, February, March, April, May, June, july, August, September, October, November, December };
static void Main(string[] args)
{
Console.WriteLine("请输入1-12的月份:");
int i = int.Parse(Console.ReadLine());
yuefen(i);
}
public static void yuefen(int i)
{
switch (i)
{
case 1: Console.WriteLine(month.January); break;
case 2: Console.WriteLine(month.February); break;
case 3: Console.WriteLine(month.March); break;
case 4: Console.WriteLine(month.April); break;
case 5: Console.WriteLine(month.May); break;
case 6: Console.WriteLine(month.June); break;
case 7: Console.WriteLine(month.july); break;
case 8: Console.WriteLine(month.August); break;
case 9: Console.WriteLine(month.September); break;
case 10: Console.WriteLine(month.October); break;
case 11: Console.WriteLine(month.November); break;
case 12: Console.WriteLine(month.December); break;
}
Console.ReadLine();
} } }
2.3 C#中的类型转换、字符处理
2.3.1实习目的和内容
实习目的:
1、掌握C#中的类型转换、字符处理;
2、掌握装箱和拆箱操作。
3、掌握C#中字符处理基本操作,如字符串的裁剪、替换和移除等。
实习内容:
在控制台下运行并调试装箱和拆箱操作、字符串的裁剪、替换和移除操作。
2.3.2代码和运行结果
1. 装箱、拆箱操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(String[] args)
{
//装箱
int val = 100;
object obj = val;
Console.WriteLine("对象的值为a{0}", obj);
//拆箱
int num = (int)obj;
Console.WriteLine("num: {0}", num);
Console.ReadLine();
}
}
}
2.字符串的裁剪、替换和删除
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
String s1 = "经得起寂寞,耐得住孤独,";
String s2 = "看得透风霜,才给得了你幸福。";
String s3 = "All Is Well!";
String newString = s1.Replace("得", " ");
String newString2 = s3.Substring(0, 4);
String newString1 = s3.Remove(0, 4);
String[] str = new String[3];
Console.WriteLine("从第三句截取的子串:{0}", newString2);
Console.WriteLine("第一句替换后的结果:{0}", newString);
Console.WriteLine("第一二句={0}{1}", s1, s2);
Console.WriteLine("第三句删除后的结果:{0}", newString1);
Console.ReadLine();
}
}
}
2.4 Winform编程中常用控件
2.4.1实习目的和内容
实习目的:
1、掌握Winform编程中常用控件的使用;
2、掌握Winform编程中基本控件的常用属性和事件。
实习内容:
利用.Net自带的常用控件,设计并实现一个简单的应用程序界面,要求用到button按钮、文本框、下拉列表框等基本控件以及基本的事件方法。
2.4.2代码和运行结果
1.兴趣统计
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)
{
//MessageBox.Show("你选择了?:\n"+z+x);
string z = "";
if (checkBox1.Checked == true)
{
z += "读书\n";
}
if (checkBox2.Checked == true)
{
z += "运动\n";
}
if (checkBox3.Checked == true)
{
z += "上网\n";
}
if (checkBox4.Checked == true)
{
z += "旅游\n";
}
if (checkBox5.Checked == true)
{
z += "男\n";
}
if (checkBox6.Checked == true)
{
z += "女\n";
}
MessageBox.Show("你选择了?:\n" + z);
} } }
2.5 Winform编程实例
2.5.1实习目的和内容
实习目的:
1、掌握Winform编程中常用控件的使用;
2、掌握Winform编程中模态对话框和非模态对话框的使用。
实习内容:
利用.Net自带的常用控件,设计并实现一个用户登录窗体,当用户登录成功,进入系统的主界面,主界面要求实现模态窗体风格。
2.5.2代码和运行结果
1. 用户登录系统
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String username = textBox1.Text;
String password = textBox2.Text;
if (username == "ZhiPengyu" && password == "1234567")
{
Successful s = new Successful();
s.Visible = true;
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
} } }
2.6 C#中类的定义和使用
2.6.1实习目的和内容
实习目的
1、掌握C#中类的定义和使用;
2、掌握类的继承、多态和封装特性。
实习内容
根据自己对面向对象程序设计思想的理解和对C#语法的掌握,自定义几个相关类,并实现类的继承、多态和封装特性。
2.6.2代码和运行结果
1. 类的多态
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace ConsoleApplication1
{
public class Person
{
private String name="张三";//类的数据成员声明
private int age=12;
protected virtual void Display()//类的虚方法
{
Console.WriteLine("姓名:{0},年龄:{1}",name,age);
}
public Person(string Name,int Age)//构造函数,函数名和类同名,无返回值
{
name=Name;
age=Age;
}
static public void DisplayData(Person aPerson)//静态方法
{
aPerson.Display();//不是静态方法调用实例方法,如写为Display()错误
}
}
public class Employee:Person//Person类是基类
{
private string department;
private decimal salary;
public Employee(string Name,int Age,string D,decimal S):base(Name,Age)
{
department=D;
salary=S;
}
protected override void Display()//重载虚方法,注意用override
{
base.Display();//访问基类同名方法
Console.WriteLine("部门:{0} 薪金:{1} ", department,salary);
}
}
class Class1
{ static void main(string[] args)
{ Person OnePerson=new Person("李四",30);
Person.DisplayData(OnePerson);//显示基类数据
Employee OneEmployee=new Employee("王五",40,"财务部",2000);
Person.DisplayData(OneEmployee); //显示派生类数据
}
}
}
2.类的继承
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace ConsoleApplication1
{
public class Person
{
protected string ssn = "111-222-333-444" ;
protected string name = "张三" ;
public virtual void GetInfo() {
Console.WriteLine("姓名: {0}", name) ;
Console.WriteLine("编号: {0}", ssn) ;
}
}
class Employee: Person
{
public string id = "ABC567EFG23267" ;
public override void GetInfo() {
// 调用基类的GetInfo方法:
base.GetInfo();
Console.WriteLine("成员ID: {0}", id) ;
}
}
class TestClass {
public static void Main() {
Employee E = new Employee() ;
E.GetInfo() ;
}
}
}
3.类的封装
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace ConsoleApplication3
{
public class User
{
private string m_name;
private string m_password;
private int m_tryCounter;
public string Name
{
get { return m_name; }
set { m_name = value; }
}
public string Password
{
get { return m_password; }
set { m_password = value; }
}
public void SignIn()
{
if (m_tryCounter < 3)
{
if (IsValid())
{
m_tryCounter = 0;
Console.WriteLine("User {0} was signed in.", m_name);
}
else
{
m_tryCounter++;
Console.WriteLine("User {0} is invalid. Can’¡¥t Sign in.", m_name);
}
}
else
{
Console.WriteLine("You try to sign in more than 3 times. You are be denied.");
}
}
public void SignOut()
{
m_tryCounter = 0;
Console.WriteLine("User {0} was signed out.", m_name);
}
private bool IsValid()
{
if (m_name.ToUpper() == "ADMIN" && m_password == "admin")
{
return true;
}
else
{
return false;
}
}
}
class Class1
{
static void Main(string[] args)
{
User user = new User();
user.Name = "Bruce";
user.Password = "test";
for (int i = 0; i <= 4; i++)
{
user.SignIn();
}
user.SignOut();
user.Name = "admin";
user.Password = "test";
for (int i = 0; i <= 4; i++)
{
user.SignIn();
}
user.SignOut();
user.Name = "admin";
user.Password="admin";
for(int i=0;i<=4;i++)
{
user.SignIn();
}
user.SignOut();
Console.ReadLine();
}
}
}
2.7 .Net数据库连接操作
2.7.1实习目的和内容
实习目的:
1、掌握.Net连接数据库的基本操作;
2、掌握Winform控件操作数据库的方法。
实习内容:
利用对数据库知识的掌握,自定义简单的数据库和相关表格,并能利用.Net中数据控件与数据库进行连接和相应操作,实现数据展示、数据的增删改查操作。
2.7.2代码和运行结果
1.数据库连接及学生信息的增删改查
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;
using System.Data.SqlClient;
namespace 学生绩点管理系统
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
展开阅读全文