一个简单的电费计算的程序,小生不才,望高手指教!
#include<iostream>#include<stdlib.h>
#include<math.h>
using namespace std;
const int M=100;
class person
{
char name[M][M];
float elect[M];
float sum[M];
int count;
public:
person(){ };
person(int count)
{
count=0;
}
float charge(void);
void getperson(void);
void putperson(void);
void singleperson(void);
};
void person::getperson(void)
{
cout<<"输入用户名";
cin>>name[count];
cout<<"输入用电量";
cin>>elect[count];
count++;
}
void person::putperson(void)
{
cout<<"用户名"<<" "<<"用电单位"<<" ";
cout<<"应缴费用"<<"\n";
for(int i=0;i<count;i++)
{
cout<<name[i]<<" "<<elect[i]<<" ";
cout<<sum[i]<<"\n";
}
}
float person::charge(void)
{
for(int i=0;i<count;i++)
{ if(elect[i]<83.3)
sum[i]=50;
else if (elect[i]>=83.3&&elect[i]<=100)
sum[i]=60*elect[i];
else if(elect[i]>100&&elect[i]<=300)
sum[i]=6000+80*(elect[i]-100);
else if(elect[i]>300)
sum[i]=2200+90*(elect[i]-300)+(elect[i]-300)*0.15;
return sum[i];
}
}
void person::singleperson()
{
cout<<sum[count-1];
}
void main()
{
person number;
int n;
int x=0,y=0;
person();
do
{
cout<<"\n1.输入用户信息\n";
cout<<"\n2.输出单个用户应缴费用\n";
cout<<"\n3.打印列表\n";
cout<<"\n4.退出!\n";
cout<<"请输入你要进行操作的序号:";
cin>>n;
switch(n)
{
case 1:number.getperson();
case 2:number.charge();number.singleperson();break;
case 3:number.charge();number.putperson();break;
case 4:break;
default:cout<<"\n输入有误,请重新输入:\n";
}
cout<<"请按任意键继续";
cin>>y;
system("cls");
}while(n!=4);
}
VS2010生成解决方案没问题,输入用户信息时(case 1:number.getperson();)出现问题,小生不才,困扰了几天。望高手赐教!