• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
风的博客
o(∩_∩)o... 存在即合理
博客园    首页    新随笔    联系   管理    订阅  订阅
读书 大话设计模式 第二章 策略模式 C++实现 1-2小节 未完
呵呵,开始学习第二章了,由于要用到GUI,速度明显慢了不少了!o(∩_∩)o...
2.1商场收银软件
//图2-1


#define MAX 255
void CShopsumDlg::OnCompute() 
{
    UpdateData();
    
    m_totalPrices 
= m_num * m_price;

    
char str[MAX+1];
    sprintf (str, 
"单价:%8.2f 数量:%8d 合计:%10.2f", 
             m_price, m_num, m_totalPrices);
    m_recordList.AddString( str );
    UpdateData(FALSE);
}

2.2 增加打折

//图2-2

//添加了新的打折下拉列表,去掉sort属性
#define COUNT_TYPE_NUM 6
#define COUNT_TYPE_LENGTH 30

BOOL CShopsumDlg::OnInitDialog()
{
    …………
    
char  countType[COUNT_TYPE_NUM][COUNT_TYPE_LENGTH] = {"正常","打5折","打6折","打7折","打8折","打9折"};  
    
// TODO: Add extra initialization here
    for ( int i=0; i < COUNT_TYPE_NUM; i++ )
    {
        m_type.AddString(countType[i]);
    }
    
    m_type.SetCurSel(
0);
    
return TRUE;  // return TRUE  unless you set the focus to a control
}


//修改了结算中的代码
#define MAX 255
void CShopsumDlg::OnCompute() 
{
    
enum countpercent{
        COUNT100
=0,COUNT50,COUNT60,COUNT70,COUNT80,COUNT90
    };
    UpdateData();
    
double count = 1.0;
    
switch (m_type.GetCurSel())
    {
        
case COUNT100:
            count 
= 1.0;
            
break;

        
case COUNT50:
            count 
= 0.5;
            
break;

        
case COUNT60:
            count 
= 0.6;
            
break;

        
case COUNT70:
            count 
= 0.7;
            
break;

        
case COUNT80:
            count 
= 0.8;
            
break;

        
case COUNT90:
            count 
= 0.9;
            
break;

        
default:
            count 
= 1.0;
            
break;

    }
    m_totalPrices 
= m_num * m_price * count;

    
char str[MAX+1];
    sprintf (str, 
"单价:%5.2f  数量: %-5d  折扣:%.0f%% 合计:%5.2f", 
             m_price, m_num, count
*100, m_totalPrices);
    m_recordList.AddString( str );

    UpdateData(FALSE);
}
posted on 2008-09-24 20:30  Mr.Camus  阅读(687)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3