当前位置:文档之家› 人民币大小写转换解析

人民币大小写转换解析

成绩评定表课程设计任务书一、实训题目和实训任务二、1. 实训题目人民币大小写转换2. 实训任务输入一个钱数,比如3456.45,显示其人民币大写:叁仟肆佰伍拾陆元肆角伍分。

用C#窗体程序实现,注意数字中带有零的情况,比如3009005.04。

多试一些,确保你的程序可用于银行储蓄系统。

3. 题目分析刚选这道题目的时候我认为这个应该是挺简单的一道题,运用数组定义单位和大写字符。

然后再通过循环来实现对数字的大写转换和单位的添加。

所以应该只有一个关键的转换代码。

可以让这个代码通过butto按钮实现转换。

之后对这个代码多次进行调试确保可以识别所有数字和单位然后重复这个关键代码就可以实现识别位数的增加达到规定要求。

然后在完成题目中其他要求比如对于零的处理,可以添加一个整形变量用来识别本位数是否为零,进而达到对零的识别。

完成课题中所有的要求。

其次添加一些别的简单的小功能比如类似计算器键盘的按钮的输入功能。

添加数字输入按钮、转换按钮、清空按钮等功能按钮。

这样可以使得程序更加丰满不会觉得太过于单调,使得界面更加丰满。

之后再添加各种图片用来装饰整个程序。

完成此程序。

4. 开发工具和环境开发工具:Visual Studio 2012环境:Windows 2000, XP, Vista等二、软件设计1. 关键技术分析①实现数值和单位赋值大代码//定义单位,大写,和用于判断的c,i,j,nstring[] a = { "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };string[] b = { "分", "角", "元", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千" };string c;int k = 0;int j;int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11;//输入数值i强制只能读到分位double i = double.Parse(textBox1.Text);int n = (int)(100 * i);//实现分位数的单位与数值转换a1 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; }}else { textBox2.Text = textBox2.Text; k++; }②实现对零的判断代码//个位数对于零的判断以及读法if (a3== 0){if (a2==0&&a3==0){ textBox2.Text = "元整" + textBox2.Text; }else textBox2.Text ="元零"+ textBox2.Text;}2. 软件模块设计总共14个button。

其中10个位输入数字键按钮,1个位小数点,1个实现退格按钮,1个实现文本全部清空按钮,1个实现人民币转换按钮总共两个label。

用来标识两个Textbox的功能总共2个Textbox,分别显示人民币金额和大写金额3. 软件界面设计三、软件测试及运行结果1.测试方案①输入人民币金额为:3009005.04程序运行结果应为:叁百万零万玖千零伍元肆分②输入:12345678.23程序运行结果应为:壹千贰百叁十肆万伍千陆百柒十捌元贰角叁分③输入:10000程序运行结果应为:壹万元整④输入12345678910程序运行结果应为:超出范围!2.测试结果①②③④四、收获和体会1.实习收获通过这次课程设计,让我更加深刻了解课本知识,和以往对知识的疏忽得以补充,在设计过程中遇到一些模糊的公式和专业用语,比如if,else的嵌套,窗体应用控件的构建和程序语句的编排,但是这些问题经过这次设计,都一一得以解决,我相信这本书中还有很多我为搞清楚的问题,但是这次的课程设计给我相当的基础知识,为我以后工作打下了严实的基础。

虽然这次课程是那么短暂的2周时间,我感觉到这些天我的所学胜过我这一学期所学,这次任务原则上是设计,其实就是一次大的作业,是让我对课本知识的巩固和对基本公式的熟悉和应用课程设计是培训学生运用本专业所学的理论知识和专业知识来分析解决实际问题的重要教学环节,是对本学期所学知识的复习和巩固。

同样,也促使了同学们的相互探讨,相互学习。

因此,我们必须认真、谨慎、踏实、一步一步的完成设计。

2. 实习体会通过此次课程设计,使我更加扎实的掌握了有关方面的知识,在设计过程中虽然遇到了一些问题,但经过一次又一次的思考,一遍又一遍的检查终于找出了原因所在,也暴露出了前期我在这方面的知识欠缺和经验不足。

实践出真知,通过亲自动手制作,使我们掌握的知识不再是纸上谈兵。

过而能改,善莫大焉。

在课程设计过程中,我们不断发现错误,不断改正,不断领悟,不断获取。

最终的检测调试环节,本身就是在践行“过而能改,善莫大焉”的知行观。

这次课程设计终于顺利完成了,在设计中遇到了很多问题,最后在老师的指导下,终于游逆而解。

在今后社会的发展和学习实践过程中,一定要不懈努力,不能遇到问题就想到要退缩,一定要不厌其烦的发现问题所在,然后一一进行解决,只有这样,才能成功的做成想做的事,才能在今后的道路上劈荆斩棘,而不是知难而退,那样永远不可能收获成功,收获喜悦,也永远不可能得到社会及他人对你的认可!五、源代码清单using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace 人民币大小写转换1403050216_{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){try{//定义单位,大写,和用于判断的c,i,j,nstring[] a = { "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };string[] b = { "分", "角", "元", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千" };string c;int k = 0;int j;int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11;//输入数值i强制只能读到分位double i = double.Parse(textBox1.Text);int n = (int)(100 * i);//实现分位数的单位与数值转换a1 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; } }else { textBox2.Text = textBox2.Text; k++; }//实现角位数的单位与数值转换n = n / 10;a2 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; } }else { textBox2.Text = textBox2.Text; k++; }//实现个位数的单位与数值转换n = n / 10;a3 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; } }else { textBox2.Text = textBox2.Text; k++; }//个位数对于零的判断以及读法if (a3== 0){if (a2==0&&a3==0){ textBox2.Text = "元整" + textBox2.Text; }else textBox2.Text ="元零"+ textBox2.Text;}//实现十元位数的单位与数值转换n = n / 10;a4 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; } }else { textBox2.Text = textBox2.Text; k++; }//十元位数对于零的判断以及读法if (a4 == 0){if (a3 != 0){ textBox2.Text = "零" + textBox2.Text; }else textBox2.Text = textBox2.Text;}//实现百位数的单位与数值转换n = n / 10;a5 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; } }else { textBox2.Text = textBox2.Text; k++; }//百位数对于零的判断以及读法if (a5 == 0){ textBox2.Text = "" + textBox2.Text; }//实现千位数的单位与数值转换n = n / 10;a6 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; }}else { textBox2.Text = textBox2.Text; k++; }//千位位数对于零的判断以及读法if (a6 == 0){ textBox2.Text = "" + textBox2.Text; }//实现万位数的单位与数值转换n = n / 10;a7 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = ("万" + textBox2.Text); k++; } }else { textBox2.Text = textBox2.Text; k++; }//万位数对于零的判断以及读法if (a7 == 0){ textBox2.Text = "零" + textBox2.Text; }//实现十万位数的单位与数值转换n = n / 10;a8 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; } }else { textBox2.Text = textBox2.Text; k++; }//十万数对于零的判断以及读法if (a8 == 0){if (a7 != 0){ textBox2.Text = "" + textBox2.Text; }else textBox2.Text = "万" + textBox2.Text;}//实现百万位数的单位与数值转换n = n / 10;a9 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; } }else { textBox2.Text = textBox2.Text; k++; }//实现千万位数的单位与数值转换n = n / 10;a10 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; }}else { textBox2.Text = textBox2.Text; k++; } //实现亿位数的单位与数值转换n = n / 10;a11 = j = n % 10;if (n != 0){if (j != 0){c = a[j - 1];textBox2.Text = (c + b[k] + textBox2.Text);k++;}else { textBox2.Text = (textBox2.Text); k++; } }else { textBox2.Text = textBox2.Text; k++; } }//错误提示超出数值范围catch(Exception){MessageBox.Show("超出范围!");}}//以上为人民币大小写转换核心程序//以下为按钮输入按钮键的代码//输入数值1private void button2_Click(object sender, EventArgs e){if (textBox1.Text == "0")textBox1.Text = "1";elsetextBox1.Text += "1";}//输入数值2private void button3_Click(object sender, EventArgs e){if (textBox1.Text == "0")textBox1.Text = "2";elsetextBox1.Text += "2";}//输入数值3private void button4_Click(object sender, EventArgs e){if (textBox1.Text == "0")textBox1.Text = "3";elsetextBox1.Text += "3";}//输入数值4private void button5_Click(object sender, EventArgs e) {if (textBox1.Text == "0")textBox1.Text = "4";elsetextBox1.Text += "4";}//输入数值5private void button6_Click(object sender, EventArgs e) {if (textBox1.Text == "0")textBox1.Text = "5";elsetextBox1.Text += "5";}//输入数值6private void button7_Click(object sender, EventArgs e) {if (textBox1.Text == "0")textBox1.Text = "6";elsetextBox1.Text += "6";}//输入数值7private void button8_Click(object sender, EventArgs e) {if (textBox1.Text == "0")textBox1.Text = "7";elsetextBox1.Text += "7";}//输入数值8private void button9_Click(object sender, EventArgs e) {if (textBox1.Text == "0")textBox1.Text = "8";elsetextBox1.Text += "8";}//输入数值9private void button10_Click(object sender, EventArgs e) {if (textBox1.Text == "0")textBox1.Text = "9";elsetextBox1.Text += "9";}//输入字符“.”private void button11_Click(object sender, EventArgs e) {string s = ""; bool c = false;for (int i = 0; i < textBox1.Text.ToString().Length; i++) {s = textBox1.Text.ToString().Substring(i, 1);if (s == ".")c = true;}if (!c)textBox1.Text += ".";elsetextBox1.Text += "";}//输入数值0private void button12_Click(object sender, EventArgs e) {if (textBox1.Text != "0"){ textBox1.Text += "0"; }}//实现退格功能private void button13_Click(object sender, EventArgs e) {string s = textBox1.Text.ToString();string s1 = s.Substring(0, s.Length - 1);if (s1.Length == 0)textBox1.Text = "0";elsetextBox1.Text = s1;}//实现复位功能private void button14_Click(object sender, EventArgs e){textBox1.Text = "0";textBox2.Text = "";}private void textBox1_TextChanged(object sender, EventArgs e){}private void label1_Click(object sender, EventArgs e){}private void label2_Click(object sender, EventArgs e){}private void Form1_Load(object sender, EventArgs e){}private void textBox2_TextChanged(object sender, EventArgs e){}}}(换页)参考文献[1] 轻松学c#,谷涛、扶晓、毕国锋遍著,电子工业出版社. 2013.6[。

相关主题