谁帮忙测试一下下面这段代码VS下能不能运行,谢谢
CReceipt.hclass 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();
};
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 << "备注: 人民币金额大写字体标准写法如下: 零, 壹, 贰, 叁, 肆, 伍, 陆, 柒, 捌, 玖";
}
#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;
}
#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下可以运行
如图所示