面向对象程序设计课程设计实验报告书.docx
- 文档编号:8002963
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:21
- 大小:1.52MB
面向对象程序设计课程设计实验报告书.docx
《面向对象程序设计课程设计实验报告书.docx》由会员分享,可在线阅读,更多相关《面向对象程序设计课程设计实验报告书.docx(21页珍藏版)》请在冰豆网上搜索。
面向对象程序设计课程设计实验报告书
《面向对象程序设计课程设计》
上机指导书
辽宁工程技术大学
理学院
目录
设计1:
设计一个对象类2
设计2:
设计一个简单的基于C/S结构的学生信息管理系统3
设计1:
设计一个对象类
设计目的:
1.领会面向对象程序设计的设计思想。
2.合理构建对象类的静态特征及对外的服务。
设计要求:
设计一个对象类,该类具有下列服务:
1.检测给定的字符串是否为数字
2.检测给定的字符串是否含有字母,数字和下划线
3.检测给定的字符串是否为有效的日期格式(日期格式:
2008-12-15)
4.检测给定的字符串是否为有效的身份证号码格式
5.返回一个随机的6位字符串(该字符串只含有数字和字母)
注意:
对象类方法的内部实现要使用高效的StringBuilder或StringBuffer实现,不要直接使用String对象进行操作。
考核形式
1.实验考勤20%:
2.上机操作能力及实验纪律占40%:
3.设计报告40%;
myString.cs
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 { charc=str.ElementAt(i); if((c>='a'&&c<='z')||(c>='A'&&c<='Z')) { character=true; } elseif((c>='0'&&c<='9')) { number=true; } elseif(c=='_') { underline=true; } } if(character||number||underline) { returntrue; } else { returnfalse; } } //判断是否为有效的日期格式 publicboolisValidDate() { stringpattern="\\d{4}-[0-1][0-9]-[0-3][0-9]"; returnRegex.IsMatch(this.str,pattern); } //判断是否为有效的身份证号 publicboolisValidID() { stringpattern="\\d{6}19\\d{2}[0,1][1-9][0-3][0-9]\\d{3}[0-9,x]"; returnRegex.IsMatch(this.str,pattern); } //产生随机六位字符串(包含数字或大小写字母) publicstaticStringrandomString() { StringBuildersb=newStringBuilder(); StringBuildersb1=newStringBuilder(); Randomr=newRandom(); for(inti=0;i<10;i++) { sb.Append(i); } for(inti=0;i<26;i++) { sb.Append((char)(i+'a')); sb.Append((char)(i+'A')); } for(inti=0;i<6;i++) { sb1.Append(sb.ToString().ElementAt((int)(r.NextDouble()*(sb.Length+1)))); } returnsb1.ToString(); } } } Program.cs usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Text.RegularExpressions; namespacemyString { 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+"是纯数字? \t"+m1.isNumber()); myStringm2=newmyString("我们_"); Console.WriteLine(m2.str+"包含字母数字下划线? \t"+m2.isContainIdentifier()); m2=newmyString("我们"); Console.WriteLine(m2.str+"包含字母数字下划线? \t"+m2.isContainIdentifier()); myStringm3=newmyString("2008-12-15"); Console.WriteLine(m3.str+"是有效日期? \t"+m3.isValidDate()); m3=newmyString("2008-12-45"); Console.WriteLine(m3.str+"是有效日期? \t"+m3.isValidDate()); myStringm4=newmyString("513030199409284315"); Console.WriteLine(m4.str+"是有效身份证号? "+m4.isValidID()); m4=newmyString("51303019940928431x"); Console.WriteLine(m4.str+"是有效身份证号? "+m4.isValidID()); m4=newmyString("51303019940928431a"); Console.WriteLine(m4.str+"是有效身份证号? "+m4.isValidID()); Console.WriteLine("随机六位字符串: "+myString.randomString()); } } } Result: 设计2: 设计一个简单的基于C/S结构的学生信息管理系统 实验目的: 1.领会面向对象程序设计的设计思想。 2.掌握设计对象类的数据成员及服务的方法。 3.学会运用面向对象程序设计的思想设计一个简单的信息系统。 实验要求: 设计一个简单的基于C/S结构的学生个人信息管理系统,该系统具有录入,查询,修改三项基本功能。 要求如下: 1.具有简单的录入,查询和修改的GUI 2.系统使用的GUI组件不得少于5种,越全面越好,但要合适(和谐界面) 3.存储数据的媒介可选择text文档或者数据库,推荐第一种 4.学生个人信息必须包括: 编号,姓名,性别,出生日期,是否已婚,身份证号,自我简介,其余可自行丰富。 5.具有对姓名,出生日期和身份证号进行简单效验的功能 6.学生编号随机产生 注意: 数据的存储媒介必须选择其中一种,也可以结合使用。 考核形式 1.实验考勤20%: 2.上机操作能力及实验纪律占40%: 3.实验报告40%; Program.cs usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Windows.Forms; namespacestudentSystem { staticclassProgram { /// ///应用程序的主入口点。 /// [STAThread] staticvoidMain() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); loginf1=newlogin(); DialogResultr=f1.ShowDialog(); if(r==DialogResult.OK){ Application.Run(newwelcome()); } } } } Login.cs usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Windows.Forms; namespacestudentSystem { publicpartialclasslogin: Form { publiclogin() { InitializeComponent(); } privatevoidbutton2_Click(objectsender,EventArgse) { if(textBox1.Text=="admin"&&textBox2.Text=="") { this.DialogResult=DialogResult.OK; } else { MessageBox.Show("用户名或密码不正确","错误提示"); } } privatevoidpictureBox1_Click(objectsender,EventArgse) {} privatevoidbutton3_Click(objectsender,EventArgse) { MessageBox.Show("此功能正在开发中......","温馨提醒",MessageBoxButtons.OK,MessageBoxIcon.Warning); } } } Welcome.cs usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Windows.Forms; namespacestudentSystem { publicpartialclasswelcome: Form { publicwelcome() { InitializeComponent(); } 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; usingSystem.IO; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Windows.Forms; usingSystem.Text.RegularExpressions; namespacestudentSystem { publicpartialclassForm1: Form { publicForm1() { InitializeComponent(); } privatevoidlabel1_Click(objectsender,EventArgse) {} privatevoidForm1_Load(objectsender,EventArgse) {} privatevoidpictureBox1_Click(objectsender,EventArgse) {} privatevoidpictureBox1_Click_1(objectsender,EventArgse) {} privatevoidlabel7_Click(objectsender,EventArgse) {} privatevoidtextBox4_TextChanged(objectsender,EventArgse) {} privatevoidtextBox5_TextChanged(objectsender,EventArgse) {} privatevoidbutton2_Click(objectsender,EventArgse) { if(! this.isValidID(textBox7.Text)) { MessageBox.Show("请输入正确的身份证号","提示",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); StringBuildersb=newStringBuilder(); sb.Append(textBox1.Text+""+textBox2.Text+""+textBox3.Text+""+textBox4.Text+""+textBox5.Text+""+textBox6.Text+""+textBox7.Text+""+textBox8.Text+""+textBox9.Text+dateTimePicker1.Text+""+richTextBox1.Text); for(inti=0;i { fs.WriteByte((byte)(sb.ToString())[i]); } fs.Close(); MessageBox.Show("保存成功,请查看文件D: /info.txt","提示"); } else { MessageBox.Show("请输入完整信息","提示",MessageBoxButtons.OK,MessageBoxIcon.Error); } } publicboolisNumber(stringstr) { try { int.Parse(str); } catch(Exception) { returnfalse; } returntrue; } publicboolisValidID(stringstr) { stringpattern="\\d{6}19\\d{2}[0,1][1-9][0-3][0-9]\\d{3}[0-9,x]"; returnRegex.IsMatch(str,pattern); } privatevoidbutton3_Click(objectsender,EventArgse) {} 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) {} privatevoidbutton4_Click(objectsender,EventArgse) {} privatevoidtextBox3_TextChanged(objectsender,EventArgse) {} privatevoidlabel4_Click(objectsender,EventArgse) {} privatevoidbutton5_Click(objectsender,EventArgse) {} privatevoidbutton6_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)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 面向 对象 程序设计 课程设计 实验 报告书
![提示](https://static.bdocx.com/images/bang_tan.gif)