Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12365143
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类:

2013-01-04 17:11:56

一、案例需求:

使用面向对象方法设计一个商店收银系统。完成最基本的商品买卖收费统计问题。

 

1、最落后、原始写法


点击(此处)折叠或打开

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;

  9. namespace Sale
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public double total = 0;

  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }

  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.             double astract_total = Convert.ToDouble(textBox1.Text) * \
  21.    Convert.ToDouble(textBox2.Text);
  22.             listBox1.Items.Add(textBox3.Text + ": 单价 " + textBox1.Text \
  23. + ",数量 " + textBox2.Text);
  24.             total += count_1_actual_total(astract_total, \
  25.   Convert.ToDouble(textBox4.Text), \
  26.   Convert.ToDouble(textBox5.Text), \
  27.   Convert.ToDouble(textBox6.Text));

  28.             label4.Text = Convert.ToString(total) + "元";
  29.         }

  30.         private void button2_Click(object sender, EventArgs e)
  31.         {
  32.             textBox1.Text = "";
  33.             textBox2.Text = "";
  34.             textBox3.Text = "";
  35.         }

  36.         private double count_1_actual_total(double astract_total,\
  37.     double discount, \
  38.                                             double number_a, \
  39.       double number_b)
  40.         {
  41.             double actual_total = 0;
  42.             double tmp_total = astract_total * (discount / (double)10.0);

  43.             if (tmp_total >= number_a)
  44.             {
  45.                 actual_total = tmp_total - number_b;
  46.             }
  47.             else
  48.             {
  49.                 actual_total = tmp_total;
  50.             }

  51.             return actual_total;
  52.         }

  53.     }
  54. }


 2、运行效果

image


3、案例代码

 Sale.zip   


二、本实现方法存在问题分析


这种基本是最原始的面向过程式的写法,没有充分利用面向对象的强大功能。它存在几个弊端:这时基本没有面向对象的概念。其他问题保留,因为貌似也基本实现了需求。

阅读(1971) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~