| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1169 人关注过本帖
标题:谁帮忙测试一下下面这段代码VS下能不能运行,谢谢
只看楼主 加入收藏
Jonny0201
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:52
帖 子:488
专家分:2603
注 册:2016-11-7
结帖率:100%
收藏
 问题点数:0 回复次数:1 
谁帮忙测试一下下面这段代码VS下能不能运行,谢谢
CReceipt.h
class CReceipt{
    private:
        std::string name;
        std::string item;
        double money;
        std::string money_CHN;
        int year;
        int mouth;
        int day;
        int moneyLenth;
    public:
        void setData(std::string n, std::string i, double m, int y, int mo, int d);
        void convert();
        void showReceipt();
};

CReceipt.cpp:
#include <iostream>
#include <string>
#include "CReceipt.h"
#include <iomanip>

using namespace std;
void CReceipt::setData(string n, string i, double m, int y, int mo, int d)
{
    name = n;
    item = i;
    money = (double)((int)(m * 100)) / 100;
    year = y;
    mouth = mo;
    day = d;
}
void CReceipt::convert()    //    To conver the number
{
    int m;
    m = (int)(money * 100);
    string str1[] = {"分","角","元","拾","佰","仟","万","拾"};
    string str2[] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
    int group[8];
    int i;
    for(i = 0; m > 0; i++)
    {
        group[i] = m % 10;
        m = m / 10;
    }
    moneyLenth = i + 1;
    for(int j = 7; j >= 0; j--)
    {
        money_CHN = money_CHN + (str2[group[j]] + str1[j]);
    }
}
void CReceipt::showReceipt()    //    To show the receipt
{
    cout << "\t\t\t\t" << "收款收据" <<endl;
    cout << "\t\t\t\t\t" << year << "年" << mouth << "月" << day << "日" << endl;
    cout << "———————————————————————————————————————————————————————————————————————————————————" << endl;
    cout << "|" << "交款单位(或交款人)" << "|";
    for(int i = 1; i <= (64 - name.size()) / 2; i++)
    {
        cout << " ";
    }
    cout << name;
    for(int i = 1; i <= (64 - name.size()) / 2; i++)
    {
            cout << " ";
    }
    cout << "|";
    cout << "———————————————————————————————————————————————————————————————————————————————————" << endl;
    cout << "|" << "          " << "|";
    for(int i = 1; i <= (64 - item.size()) / 2; i++)
    {
        cout << " ";
    }
    cout << item;
    for(int i = 1; i <= (64 - item.size()) / 2; i++)
    {
        cout << " ";
    }
    cout << "|";
    cout << "———————————————————————————————————————————————————————————————————————————————————" << endl;
    cout << "|" << " 金  额 (大 写)  ";
    for(int i = 1; i <= 24; i++)
    {
        cout << " ";
    }
    cout << money_CHN;
    for(int i = 1; i <= 13; i++)
    {
        cout << " ";
    }
    cout << "|" << endl;
    cout << "|";
    for(int i = 1; i <= 80 - moneyLenth; i++)
    {
        cout << " ";
    }
    cout << "¥" << fixed << setprecision(2) << money << "|" << endl;
    cout << "———————————————————————————————————————————————————————————————————————————————————" << endl;
    cout << "|" << "备注: ";
    for(int i = 1; i <= 75; i++)
    {
        cout << " ";
    }
    cout << "|" << endl;
    cout << "———————————————————————————————————————————————————————————————————————————————————" << endl;
    cout << "收款人公章" << "                         " << "交款人" << "                   " << "收款人" << "               " << endl;
    cout << "备注: 人民币金额大写字体标准写法如下: 零, 壹, 贰, 叁, 肆, 伍, 陆, 柒, 捌, 玖";
}

Receipt.cpp:
#include <iostream>
#include <string>
#include "CReceipt.h"
#include <cstdlib>

int getDays(int mouth, int year);
void display();
using namespace std;
int main(int argc, char *argv[]) {
    int userChoice;
    CReceipt R;
    display();
    cin >> userChoice;
    do{
        if(userChoice == 1) exit(0);
        system("cls");
        string n;
        string i;
        double m;
        int y;
        int mo;
        int d;
        cout << "Please enter the name : ";
        cin >> n;
        cout << "Please enter the item : ";
        cin >> i;
        moneyAgain : cout << "Please enter the money(If you enter 3.776792, the program will only save 3.77; And you cannot enter the number >= 1000000) : ";
        cin >> m;
        if(m >= 1000000){
            cout << "Program cannot support the money >= 1000000, please enter again!" << endl;
            goto moneyAgain;
        }
        cout << "Please enter the year : ";
        cin >> y;
        mouthAgain : cout << "Please enter the mouth : ";
        cin >> mo;
        if(mo <= 0 || mo > 12){
            cout << "Wrong mouth number!" << endl;
            goto mouthAgain;
        }
        dayAgain : cout << "Please enter the day : ";
        cin >> d;
        if(d <= 0 || d >= getDays(mo, y)){
            cout << "Wrong day number!" << endl;
            goto dayAgain;
        }
        R.setData(n, i, m, y, mo, d);
        R.convert();
        system("cls");
        R.showReceipt();
    }while(userChoice == 1);
}
int getDays(int mouth, int year)    //    To get the days of every mouth
{
    int day;
    switch (mouth){
        case 1:
            day = 31;
            break;
        case 2:
            if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) day = 29;
            else day = 28;
            break;
        case 3:
            day = 31;
            break;
        case 4:
            day = 30;
            break;
        case 5:
            day = 31;
            break;
        case 6:
            day = 30;
            break;
        case 7:
            day = 31;
            break;
        case 8:
            day = 31;
            break;
        case 9:
            day = 30;
            break;
        case 10:
            day = 31;
            break;
        case 11:
            day = 30;
            break;
        case 12:
            day = 31;
            break;
    }
    return day;
}
void display()    //    To display the menu
{
    cout << "1. Quit." << endl;
    cout << "2. Write a receipt." << endl;
}

上面这段代码在Linux下可以运行
如图所示
搜索更多相关主题的帖子: private convert public double money 
2017-03-28 21:13
Jonny0201
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:52
帖 子:488
专家分:2603
注 册:2016-11-7
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
2017-03-28 21:13
快速回复:谁帮忙测试一下下面这段代码VS下能不能运行,谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020837 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved