标题:一个简单的电费计算的程序,小生不才,望高手指教!
只看楼主
晴天一阵
Rank: 2
等 级:论坛游民
帖 子:40
专家分:24
注 册:2011-5-21
结帖率:91.67%
已结贴  问题点数:20 回复次数:5 
一个简单的电费计算的程序,小生不才,望高手指教!
#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();)出现问题,小生不才,困扰了几天。望高手赐教!
搜索更多相关主题的帖子: include person public charge 
2011-09-22 17:45
xg5699
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:140
专家分:522
注 册:2011-7-27
得分:20 
我用VS2005编译不止是第一个选项出错,全部都有问题
程序代码:
#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(){count=0;}//如不讲count初始化为0那么你猜猜count会是一个什么值?
    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]<<endl;
    }
    void main()
    {
        bool q=false;//判定条件退出
        person number;
        int n;
        int x=0,y=0;
        person();
       while(1)
       {
            cout<<"\n1.输入用户信息\n";
            cout<<"\n2.输出单个用户应缴费用\n";
            cout<<"\n3.打印列表\n";
            cout<<"\n4.退出!\n";
            cout<<"请输入你要进行操作的序号:";
            cin>>n;
           
            switch(n)
            {
            case 1:number.getperson();break;//break漏了
               
            case 2:number.charge();number.singleperson();break;
            case 3:number.charge();number.putperson();break;
            case 4:q=true;break;//选择了4q赋值为真
            default:cout<<"\n输入有误,请重新输入:\n";
            }
            if(q)//q为真退出while循环
                break;
          
       }
    }

这些错误全部是基础问题,这只是整个程序运行起来不出错误,但实际上你程序中数组的那些算法都是有问题的我就不仔细看了你自己找吧

[ 本帖最后由 xg5699 于 2011-9-22 18:26 编辑 ]

都不结贴我郁闷那!
2011-09-22 18:23
Toomj
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:257
专家分:1826
注 册:2011-5-17
得分:0 
以下是引用xg5699在2011-9-22 18:23:35的发言:
 
这些错误全部是基础问题,这只是整个程序运行起来不出错误,但实际上你程序中数组的那些算法都是有问题的我就不仔细看了你自己找吧
楼主加油哈
2011-09-23 10:03
晴天一阵
Rank: 2
等 级:论坛游民
帖 子:40
专家分:24
注 册:2011-5-21
得分:0 
回复 2楼 xg5699
谢谢指教....谢谢....
2011-09-23 13:28
晴天一阵
Rank: 2
等 级:论坛游民
帖 子:40
专家分:24
注 册:2011-5-21
得分:0 
回复 3楼 Toomj
嗯,谢谢...
2011-09-23 13:29
fz19910125
Rank: 2
来 自:上海
等 级:论坛游民
帖 子:52
专家分:11
注 册:2010-10-12
得分:0 
1>c:\documents and settings\administrator\桌面\150\xiaoyu\xiaoyu\xiaoyu.cpp(232) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\documents and settings\administrator\桌面\150\xiaoyu\xiaoyu\xiaoyu.cpp(235) : warning C4715: 'person::charge' : not all control paths return a value
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://c:\Documents and Settings\Administrator\桌面\150\xiaoyu\xiaoyu\Debug\BuildLog.htm"
1>xiaoyu - 0 error(s), 2 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
可以运行 但功能没完善
2011-09-23 16:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-350607-1-1.html




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

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