面向对象程序设计课程设计实验报告书文档格式.docx
《面向对象程序设计课程设计实验报告书文档格式.docx》由会员分享,可在线阅读,更多相关《面向对象程序设计课程设计实验报告书文档格式.docx(21页珍藏版)》请在冰豆网上搜索。
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Text.RegularExpressions;
namespacemyString
{
classmyString
{
publicStringstr;
publicintlength{get{returnstr.Length;
}}
publicmyString(Stringstr)
this.str=str;
}
//判断是否为数字
publicboolisNumber()
try
int.Parse(str);
catch(Exception)
returnfalse;
returntrue;
//判断是否含有字母、数字、下划线
publicboolisContainIdentifier()
boolcharacter=false,number=false,underline=false;
for(inti=0;
i<
this.length;
i++)
charc=str.ElementAt(i);
if((c>
='
a'
&
&
c<
z'
)||(c>
A'
Z'
))
character=true;
elseif((c>
0'
9'
number=true;
elseif(c=='
_'
)
underline=true;
if(character||number||underline)
else
//判断是否为有效的日期格式
publicboolisValidDate()
stringpattern="
\\d{4}-[0-1][0-9]-[0-3][0-9]"
;
returnRegex.IsMatch(this.str,pattern);
//判断是否为有效的身份证号
publicboolisValidID()
\\d{6}19\\d{2}[0,1][1-9][0-3][0-9]\\d{3}[0-9,x]"
//产生随机六位字符串(包含数字或大小写字母)
publicstaticStringrandomString()
StringBuildersb=newStringBuilder();
StringBuildersb1=newStringBuilder();
Randomr=newRandom();
10;
sb.Append(i);
26;
sb.Append((char)(i+'
));
6;
sb1.Append(sb.ToString().ElementAt((int)(r.NextDouble()*(sb.Length+1))));
returnsb1.ToString();
}
Program.cs
classProgram
staticvoidMain(string[]args)
/**/Console.ForegroundColor=ConsoleColor.Green;
Console.BackgroundColor=ConsoleColor.Red;
myStringm1=newmyString("
13266a4"
);
Console.WriteLine(m1.str+"
是纯数字?
\t"
+m1.isNumber());
m1=newmyString("
1326614"
Console.WriteLine(m1.str+"
+m1.isNumber());
myStringm2=newmyString("
我们_"
Console.WriteLine(m2.str+"
包含字母数字下划线?
+m2.isContainIdentifier());
m2=newmyString("
我们"
Console.WriteLine(m2.str+"
+m2.isContainIdentifier());
myStringm3=newmyString("
2008-12-15"
Console.WriteLine(m3.str+"
是有效日期?
+m3.isValidDate());
m3=newmyString("
2008-12-45"
Console.WriteLine(m3.str+"
+m3.isValidDate());
myStringm4=newmyString("
513030199409284315"
Console.WriteLine(m4.str+"
是有效身份证号?
"
+m4.isValidID());
m4=newmyString("
51303019940928431x"
Console.WriteLine(m4.str+"
+m4.isValidID());
51303019940928431a"
Console.WriteLine("
随机六位字符串:
+myString.randomString());
Result:
设计一个简单的基于C/S结构的学生信息管理系统
实验目的:
2.掌握设计对象类的数据成员及服务的方法。
3.学会运用面向对象程序设计的思想设计一个简单的信息系统。
实验要求:
设计一个简单的基于C/S结构的学生个人信息管理系统,该系统具有录入,查询,修改三项基本功能。
要求如下:
1.具有简单的录入,查询和修改的GUI
2.系统使用的GUI组件不得少于5种,越全面越好,但要合适(和谐界面)
3.存储数据的媒介可选择text文档或者数据库,推荐第一种
4.学生个人信息必须包括:
编号,姓名,性别,出生日期,是否已婚,身份证号,自我简介,其余可自行丰富。
5.具有对姓名,出生日期和身份证号进行简单效验的功能
6.学生编号随机产生
数据的存储媒介必须选择其中一种,也可以结合使用。
3.实验报告40%;
usingSystem.Windows.Forms;
namespacestudentSystem
staticclassProgram
///<
summary>
///应用程序的主入口点。
/summary>
[STAThread]
staticvoidMain()
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
loginf1=newlogin();
DialogResultr=f1.ShowDialog();
if(r==DialogResult.OK){
Application.Run(newwelcome());
Login.cs
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
publicpartialclasslogin:
Form
publiclogin()
InitializeComponent();
privatevoidbutton2_Click(objectsender,EventArgse)
if(textBox1.Text=="
admin"
textBox2.Text=="
"
this.DialogResult=DialogResult.OK;
MessageBox.Show("
用户名或密码不正确"
"
错误提示"
privatevoidpictureBox1_Click(objectsender,EventArgse)
{}
privatevoidbutton3_Click(objectsender,EventArgse)
此功能正在开发中......"
温馨提醒"
MessageBoxButtons.OK,MessageBoxIcon.Warning);
Welcome.cs
publicpartialclasswelcome:
publicwelcome()
privatevoidbutton3_click(objectsender,EventArgse)
Form1f1=newForm1();
f1.ShowDialog();
privatevoidbutton4_Click(objectsender,EventArgse)
Form2f2=newForm2();
f2.ShowDialog();
privatevoidbutton5_Click(objectsender,EventArgse)
Form3f3=newForm3();
f3.ShowDialog();
privatevoidbutton6_Click(objectsender,EventArgse)
if(MessageBox.Show("
你确定要退出吗?
确认"
MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
Application.Exit();
privatevoidwelcome_Load(objectsender,EventArgse)
Form1.cs
usingSystem.IO;
publicpartialclassForm1:
publicForm1()
privatevoidlabel1_Click(objectsender,EventArgse)
privatevoidForm1_Load(objectsender,EventArgse)
privatevoidpictureBox1_Click_1(objectsender,EventArgse)
privatevoidlabel7_Click(objectsender,EventArgse)
privatevoidtextBox4_TextChanged(objectsender,EventArgse)
privatevoidtextBox5_TextChanged(objectsender,EventArgse)
if(!
this.isValidID(textBox7.Text))
请输入正确的身份证号"
提示"
MessageBoxButtons.OK,MessageBoxIcon.Error);
elseif(this.isNumber(textBox1.Text)&
textBox2.Text!
="
textBox3.Text!
textBox4.Text!
textBox5.Text!
textBox6.Text!
textBox8.Text!
textBox9.Text!
FileStreamfs=File.Open("
d:
\\info.txt"
FileMode.OpenOrCreate);
sb.Append(textBox1.Text+"
+textBox2.Text+"
+textBox3.Text+"
+textBox4.Text+"
+textBox5.Text+"
+textBox6.Text+"
+textBox7.Text+"
+textBox8.Text+"
+textBox9.Text+dateTimePicker1.Text+"
+richTextBox1.Text);
sb.Length;
fs.WriteByte((byte)(sb.ToString())[i]);
fs.Close();
保存成功,请查看文件D:
/info.txt"
else
请输入完整信息"
MessageBoxButtons.OK,MessageBoxIcon.Error);
publicboolisNumber(stringstr)
try
catch(Exception)
publicboolisValidID(stringstr)
returnRegex.IsMatch(str,pattern);
privatevoidtextBox2_TextChanged(objectsender,EventArgse)
privatevoidlabel9_Click(objectsender,EventArgse)
privatevoidbutton1_Click(objectsender,EventArgse)
textBox1.Text="
textBox2.Text="
textBox3.Text="
textBox4.Text="
textBox5.Text="
textBox6.Text="
textBox7.Text="
textBox8.Text="
textBox9.Text="
richTextBox2.Text="
privatevoidtextBox9_TextChanged(objectsender,EventArgse)
privatevoidlabel2_Click(objectsender,EventArgse)
privatevoidtextBox8_TextChanged(objectsender,EventArgse)
privatevoidtextBox3_TextChanged(objectsender,EventArgse)
privatevoidlabel4_Click(objectsender,EventArgse)
privatevoidlabel3_Click(objectsender,EventArgse)
privatevoiddateTimePicker1_ValueChanged(objectsender,EventArgse)
privatevoidlabel6_Click(objectsender,EventArgse)
privatevoidrichTextBox1_TextChanged(objectsender,EventArgse)
privatevoidtextBox1_TextChanged(objectsender,EventArgse)
privatevoidlabel5_Click(objectsender,EventArgse)
privatevoidlabel11_Click(objectsender,EventArgse)
privatevoidlabel8_Click(objectsender,EventArgse)
privatevoidlabel10_Click(objectsender,EventArgse)
privatevoidtextBox7_TextChanged(objectsender,EventArgse)
privatevoidrichTextBox2_TextChanged(objectsender,EventArgse)