打印收据,数组越界的问题
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
class Receipt
{
private:
string name;
string item;
double money;
string money_CHN;
int year;
int month;
int day;
public:
void setReceipt(string n,string i,double m,int y,int mt,int d);
void Convert();
void showReceipt();
void print();
void menu();
};
int main()
{
int num;
Receipt r;
do
{
r.menu();
cin>>num;
if(num==0) break;
else
{
r.print();
r.Convert();
r.showReceipt();
}
}while(num != 0);
}
void Receipt::setReceipt(string n,string i,double m,int y,int mt,int d)
{
name=n;
item=i;
money = (double)((int)(m * 100)) / 100;
year=y;
month=mt;
day=d;
}
void Receipt::Convert()
{
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 Receipt::print()
{
name = "jonny";
item = "jonny";
money = 123.123;
year = 2010;
month = 2;
day = 1;
setReceipt(name, item, money, year, month, day);
}
void Receipt::showReceipt()
{
//system("cls");
/*cout<<"’?‘/¥???£?《?…‘∫?"<<endl;*/
/*Sleep(1000);*/
/*system("cls");*/
//cout<<"\t\t"<<" ’?? ’ae〉"<<"\t\t"<<endl;
//cout<<year<<"??"<<month<<"‘?"<<day<<"》’"<<"\t\t\t\t"<<"No.00001"<<endl;
//cout<<"---------------------------------------------------"<<endl;
//cout<<"Ω???μ·OE???Ω???》??’√°£∫"<<name<<endl;
//cout<<"Ω???oe???£∫"<<item<<endl;
//cout<<"???" << money_CHN;
//cout<<endl;
//cout<<"\t\t\t"<<money<<"‘(TM)"<<endl;
//cout<<"---------------------------------------------------"<<endl;
cout << money_CHN;
}
void Receipt::menu()
{
//cout<<"---------------------------------"<<endl;
//cout<<" ≦?μ· "<<endl;
//cout<<"---------------------------------"<<endl;
//cout<<" 0.??≧^ "<<endl;
//cout<<" 1.?(TM) ’ae〉 "<<endl;
//cout<<"---------------------------------"<<endl;
}
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
class Receipt
{
private:
string name;
string item;
double money;
string money_CHN;
int year;
int month;
int day;
public:
void setReceipt(string n,string i,double m,int y,int mt,int d);
void Convert();
void showReceipt();
void print();
void menu();
};
int main()
{
int num;
Receipt r;
do
{
r.menu();
cin>>num;
if(num==0) break;
else
{
r.print();
r.Convert();
r.showReceipt();
}
}while(num != 0);
}
void Receipt::setReceipt(string n,string i,double m,int y,int mt,int d)
{
name=n;
item=i;
money = (double)((int)(m * 100)) / 100;
year=y;
month=mt;
day=d;
}
void Receipt::Convert()
{
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 Receipt::print()
{
name = "jonny";
item = "jonny";
money = 123.123;
year = 2010;
month = 2;
day = 1;
setReceipt(name, item, money, year, month, day);
}
void Receipt::showReceipt()
{
//system("cls");
/*cout<<"’?‘/¥???£?《?…‘∫?"<<endl;*/
/*Sleep(1000);*/
/*system("cls");*/
//cout<<"\t\t"<<" ’?? ’ae〉"<<"\t\t"<<endl;
//cout<<year<<"??"<<month<<"‘?"<<day<<"》’"<<"\t\t\t\t"<<"No.00001"<<endl;
//cout<<"---------------------------------------------------"<<endl;
//cout<<"Ω???μ·OE???Ω???》??’√°£∫"<<name<<endl;
//cout<<"Ω???oe???£∫"<<item<<endl;
//cout<<"???" << money_CHN;
//cout<<endl;
//cout<<"\t\t\t"<<money<<"‘(TM)"<<endl;
//cout<<"---------------------------------------------------"<<endl;
cout << money_CHN;
}
void Receipt::menu()
{
//cout<<"---------------------------------"<<endl;
//cout<<" ≦?μ· "<<endl;
//cout<<"---------------------------------"<<endl;
//cout<<" 0.??≧^ "<<endl;
//cout<<" 1.?(TM) ’ae〉 "<<endl;
//cout<<"---------------------------------"<<endl;
}
代码如上,很多已经注释掉了
但是运行的时候提示错误
调试的时候执行完for语句,就直接run stopped
提示:Terminated due to signal: SEGMENTATION FAULT (11)
实在是找不出问题在哪里, 有没有大神