| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1374 人关注过本帖
标题:为什么会出现这样的问题,怎么修改呀
只看楼主 加入收藏
陈静静
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2020-6-28
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
为什么会出现这样的问题,怎么修改呀

#include "Admin.h"
Admin::Admin()
{
     for(int i=0;i<COUNT;i++)
     {
     list[i]=NULL;//置空列表
     }
}
Admin::~Admin()   //清理工作
{
      for(int i=0;i<100;i++)
      {
           if(list[i]==NULL)
                break;
           else
                delete list[i];
      }
           cout<<"游戏结束!"<<endl;
}
void Admin::NewGame()
{
    cout<<"欢迎进入农场,请给您的农场起个响亮的名字吧:"<<endl;
    string n;
    cin>>n;
    name=n;
/****农场数据初始化****/
    money=100;
    eggs=0;
    golden_eggs=0;
    hair=0;
    caviar=0;
    for(int i=0;i<COUNT;i++)
    {
        list[i]=NULL;
    }
     cout<<"********恭喜您成功入驻"<<name<<"农场,祝您游戏愉快!********"<<endl;
}
void Admin::Start()//游戏开始
{
     cout<<"读档吗?y/n"<<endl;
     char input;
     cin>>input;
     if(input=='Y'||input=='y')
     {
       Load();
     }
     else
     {
         NewGame();
     }
     while(1)
     {
         Menu();
         cin>>input;
         switch(input)
         {
           case '1':
              Info();
                break;
           case '2':
              Enter();
                break;
           case '3':
              Buy();
                break;
           case '4':
              Sold();
                break;
           case '5':
              Save();
                break;
           case '6':
              Load();
                break;
           case '7':
                return;
            default:
                cout<<"输入选择有误,请重新输入。"<<endl;
        }
     }
}
void Admin::Menu()
{
    cout.setf(ios::left);
    cout<<setw(48)<<setfill('+')<<'+'<<endl;
    cout<<"请选择操作选项:"<<endl;
    cout<<setw(16)<<setfill(' ')<<"1.查看农场信息";
    cout<<setw(16)<<setfill(' ')<<"2.进入农场"<<endl;
    cout<<setw(16)<<setfill(' ')<<"3.购买动物";
    cout<<setw(16)<<setfill(' ')<<"4.出售物品"<<endl;
    cout<<setw(16)<<setfill(' ')<<"5.存档";
    cout<<setw(16)<<setfill(' ')<<"6.读档"<<endl;
    cout<<setw(16)<<setfill(' ')<<"7.退出程序"<<endl;
    cout<<setw(48)<<setfill('+')<<'+'<<endl;
}
void Admin::Info()
{
    cout<<setw(10)<<setfill('*')<<'*'<<"农场信息如下:"<<setw(10)<<setfill('*')<<'*'<<endl;
    cout<<"农场名称:"<<name<<endl;
    cout<<"拥有的总金币:"<<money<<endl;
    cout<<setfill(' ')<<setw(10)<<"动物种类 "<<setw(10)<<"动物个数 "<<setw(6)<<"产 品"
        <<setw(7)<<"产品数量"<<endl;
    cout<<setfill(' ')<<setw(10)<<"小鸡"<<setw(10)<<Chicken::Get_Count()<<setw(6)
        <<"鸡蛋"<<setw(7)<<eggs<<endl;
    cout<<setfill(' ')<<setw(10)<<" "<<setw(10)<<" "<<setw(6)<<"金 蛋"<<setw(7)
        <<golden_eggs<<endl;
    cout<<setfill(' ')<<setw(10)<<"兔兔"<<setw(10)<<Rabbit::Get_Count()<<setw(6)
        <<"兔毛"<<setw(7)<<hair<<endl;
    cout<<setfill(' ')<<setw(10)<<"小鱼"<<setw(10)<<Fish::Get_Count()<<setw(6)
        <<"鱼子酱"<<setw(7)<<caviar<<endl;
    cout<<setfill(' ')<<setw(10)<<" "<<setw(10)<<" "<<setw(6)<<" "<<setw(7)<<endl;
}
void Admin::Buy()
{
    int chicken_price=8;
    int rabbit_price=15;
    int fish_price=20;
    char buy, confirm;
    Animal *p;//指向基类的指针
    int pay;//应付款
    while(1)
    {
       cout.setf(ios::left);
       cout<<setw(5)<<setfill('*')<<'*'<<" 请 选 择 你 要 购 买 的 动 物 ! (1. 鸡 2.兔兔 3.鱼 4. 返 回)"<<setw(5)<<setfill('*')<<'*'<<endl;
       cin>>buy;
       switch(buy)
       {
         case '1':
            pay=chicken_price;
            cout<<"买小鸡需要花费"<<pay<<"金币,确定吗?y/n"<<endl;
            cin>>confirm;
            if(confirm!='Y'&&confirm!='y')
            {
                return;
            }
        if(money<pay)
        {
            cout<<"金币不够了!去卖点产品吧!"<<endl;
            return;
        }
        money-=pay;
        p=new Chicken;
        cout<<"购买到一只小鸡,请给它起个名字吧:"<<endl;
        break;
        return;
    case '2':
        pay=rabbit_price;
        cout<<"买兔兔需要花费"<<pay<<"金币,确定吗?y/n"<<endl;
        cin>>confirm;
        if(confirm!='Y'&&confirm!='y')
        {
            return;
        }
        if(money<pay)
        {
            cout<<"金币不够了!去卖点产品吧!"<<endl;
            return;
        }
        money-=pay;
        p=new Rabbit;
        cout<<"购买到一只兔兔,请给它起个名字吧:"<<endl;
        break;
    case '3':
        pay=fish_price;
        cout<<"买鱼需要花费"<<pay<<"金币,确定吗?y/n"<<endl;
        cin>>confirm;
        if(confirm!='Y'&&confirm!='y')
        {
            return;
        }
        if(money<pay)
        {
            cout<<"金币不够了!去卖点产品吧!"<<endl;
            return;
        }
        money-=pay;
        p=new Fish;
        cout<<"购买到一只鱼,请给它起个名字吧:"<<endl;
        break;
    case '4':
        return;
    default:
        cout<<"输入选择有误"<<endl;
        return;
       }
    bool flag=true;
    string name;
    while(flag)//判断是否重名
    {
        cin>>name;
        for(int i=0;i<COUNT;i++)//不管是否同类,都不能同名(整个农场中)
        {
            if(list[i]!=NULL && list[i]->Get_name()==name)
            {
                cout<<"已经有这个名字了!再想一个吧!"<<endl;
                break;
            }
        }
        if(i==100)
        flag=false;
    }
        p->Set_name(name);
        cout<<"谢谢惠顾,购买完成!"<<endl;
        for(int i=0;i<100;i++)
        {
            if(list[i]==NULL)
            {
                list[i]=p;//指针指向的内容赋给list
                break;
            }
        }
    }
}
void Admin::Enter()
{
    char Site;
    while(1)
    {
        cout<<setw(5)<<setfill('*')<<'*'<<" 请 选 择 你 要 进 入 的 场 地 ! (1. 鸡 场 2.兔窝 3. 鱼池 4. 返 回)"<<setw(5)<<setfill('*')<<'*'<<endl;
        cin>>Site;
        switch(Site)
        {
        case '1':
            cout<<setw(10)<<setfill('*')<<'*'<<"欢迎来到鸡场!(经过照顾小鸡可以得到鸡蛋!)"<<setw(10)<<setfill('*')<<'*'<<endl;
            TakeCare(0);
            break;
        case '2':
            cout<<setw(10)<<setfill('*')<<'*'<<"欢迎来到兔窝!(经过照顾兔兔可以得到兔毛!)"<<setw(10)<<setfill('*')<<'*'<<endl;
            TakeCare(0);
            break;
        case '3':
            cout<<setw(10)<<setfill('*')<<'*'<<"欢迎来到鱼池!(经过照顾鱼可以得到鱼子酱!)"<<setw(10)<<setfill('*')<<'*'<<endl;
            TakeCare(0);
            break;
        case '4':
            return;
        default:
            cout<<"输入选择有误,请重新输入。"<<endl;
        }
    }
}

void Admin::TakeCare(int type)
{
    string name;
    int i;
    for(i=0;i<COUNT;i++)
    {
        if(list[i]!=NULL && list[i]->Get_type()==type)
        {
            list[i]->Show();
        }
    }
        cout<<"你要照顾哪只小动物?按键 0 退出"<<endl;
        while(1)
        {
            cin>>name;
            if(name=="0")
            return;
            for(i=0;i<COUNT;i++)
            {
                if(list[i]!=NULL && list[i]->Get_type()==type &&list[i]->Get_name()==name)
                {
                    break;
                }
            }
            if(i==COUNT)
            {
                cout<<"没有这个名字。请重新输入:"<<endl;
            }
            else
            {
                break;
            }
            int res = list[i]->TakeCare();
            switch(res)
            {
            case 1:
                eggs++;
                break;
            case 2:
                golden_eggs++;
                break;
            case 3:
                hair++;
                break;
            case 4:
                caviar++;
                break;

            }
            TakeCare(type);
}
void Admin::Load()//读档
{
    ifstream infile("Ranch.txt",ios::in);
    if(!infile)
    {
        cerr<<"无法打开文件,读档失败!"<<endl;
        return;
    }
    bool statu[4];
    int type,i,j;
    string na;
    infile>>name>>money>>eggs>>golden_eggs>>hair>>caviar;
    while(1)
    {
        infile>>type>>na;
        for(j=0;j<4;j++)
        {
            infile>>statu[j];
        }
        if (infile.eof())
            break;//寻找插入位置
        for(i=0;i<COUNT;i++)
        {
            if(list[i]==NULL)            
                break;
        }
        switch(type)
        {
        case 0:
            list[i]=new Chicken(na,statu);
            break;
        case 2:
            list[i]=new Rabbit(na,statu);
            break;
        case 3:
            list[i]=new Fish(na,statu);
            break;
        default:
            {
                cout<<"读档有误。"<<endl;
                return;
            }
        }
    }
        cout<<"读档成功!"<<endl;
        cout<<endl;
}

void Admin::Save()
{
    ofstream outfile("Ranch.txt",ios::out);
    if(!outfile)
    {
        cerr<<"无法打开文件,存档失败!"<<endl;
        return;
    }
    outfile<<name<<" "<<money<<" "<<eggs<<" "<<golden_eggs<<" "
        <<hair<<" "<<caviar<<" "<<endl;
    for(int i=0;i<COUNT;i++)
    {
        if(list[i]!=NULL)
        {
            list[i]->Save(outfile);
        }
    }
    outfile.close();
    cout<<"存档成功!"<<endl;
}

void Admin::Sold()
{
    int egg_price=3,golden_price=6,hair_price=10,caviar_price=30,gain;
    cout<<setw(10)<<setfill('*')<<'*'<<"欢迎来到商店!(你可以出售你拥有的产品!)"<<setw(10)<<setfill('*')<<'*'<<endl;
    cout<<setw(10)<<setfill(' ')<<"产品名称"<<setw(10)<<"个数"<<setw(10)<<"售价"<<endl;
    cout<<setw(10)<<setfill(' ')<<"1. 鸡蛋 "<<setw(10)<<eggs<<setw(8)<<egg_price<<endl;
    cout<<setw(10)<<setfill(' ')<<"2. 金蛋 "<<setw(10)<<golden_eggs<<setw(8)<<golden_price<<endl;
    cout<<setw(10)<<setfill(' ')<<"3. 兔毛 "<<setw(10)<<hair<<setw(10)<<hair_price<<endl;
    cout<<setw(10)<<setfill(' ')<<"4. 鱼子酱 "<<setw(10)<<caviar<<setw(10)<<caviar_price<<endl;
    cout<<setw(10)<<setfill(' ')<<"5. 小鸡 "<<setw(10)<<Chicken::Get_Count()<<setw(10)<<10<<"(一只)"<<endl;
    cout<<setw(10)<<setfill(' ')<<"6. 兔兔 "<<setw(10)<<Rabbit::Get_Count()<<setw(10)<<20<<"(一只)"<<endl;
    char a;
    while(1)
    {
        cout<<setw(10)<<setfill('*')<<'*'<<" 请选择你要出售的商品编号,0 键返回. "<<setw(10)<<setfill('*')<<'*'<<endl;
        cin>>a;
        switch(a)
        {
        case '1':
            if(eggs==0)
            {
                cout<<"没有鸡蛋了!赶快去鸡场照顾小鸡吧!"<<endl;
            }
            else
            {
                gain=eggs*egg_price;
                cout<<"出售成功! 金币+"<<gain<<endl;
                money+=gain;
                eggs=0;
            }
            break;
        case '2':
            if(golden_eggs==0)
            {
                cout<<"没有金蛋了!赶快去鸡场照顾小鸡吧!"<<endl;
            }
            else
            {
                gain=golden_price*golden_eggs;
                cout<<"出售成功! 金币+"<<gain<<endl;
                money+=gain;
                golden_eggs=0;
            }
            break;
        case '3':
            if(hair==0)   
            {
                cout<<"没有兔毛了!赶快去兔窝照顾兔兔吧!"<<endl;
            }
            else
            {
                gain=hair*hair_price;
                cout<<"出售成功!金币+"<<gain<<endl;
                money+=gain;
                hair=0;
            }
            break;
        case '4':
            if(caviar==0)   
            {
                cout<<"没有鱼子酱了!赶快去鱼池照顾小鱼吧!"<<endl;
            }
            else
            {
                gain=caviar*caviar_price;
                cout<<"出售成功!金币+"<<gain<<endl;
                money+=gain;
                caviar=0;
            }
            break;
        case '5':
            {
                string name;
                cout<<"输入小鸡的名字:";
                cin>>name;
                int i;
                for(i=0;i<100;i++)
                {
                    if(list[i]==NULL)
                        break;
                    if(list[i]->Get_name()==name)
                        break;
                }
                delete list[i];
                for(int j=i+1;j<100;j++)
                {
                    list[j-1]=list[j];
                    if(list[j]==NULL)
                        break;
                }
                money=money+10;
                cout<<"出售小鸡,成功金币+10"<<endl;
                break;
            }
        case '6':
         {
          string name;
          cout<<"请输入兔兔的名字:"<<endl;
          cin>>name;
          int i;
          for(i=0;i<100;i++)
          {
           if(list[i]==NULL)
               break;
           if(list[i]->Get_name()==name)
               break;
          }
          delete list[i];
          for(int j=i+1;j<100;j++)
          {
              list[j-1]=list[j];
              if(list[j]==NULL)
               break;
          }
          money+=20;
          cout<<"出售兔兔成功,金币+20"<<endl;//添加小鸡的价钱函数
          break;
         }
        case '0':
            return;
            default:
                cout<<"输入选择有误,请重新输入。"<<endl;
        }
    }
}



Admin.cpp
D:\Microsoft Visual Studio\MyProjects\模拟农场\Admin.cpp(298) : error C2601: 'Load' : local function definitions are illegal
D:\Microsoft Visual Studio\MyProjects\模拟农场\Admin.cpp(346) : error C2601: 'Save' : local function definitions are illegal
D:\Microsoft Visual Studio\MyProjects\模拟农场\Admin.cpp(367) : error C2601: 'Sold' : local function definitions are illegal
D:\Microsoft Visual Studio\MyProjects\模拟农场\Admin.cpp(491) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
搜索更多相关主题的帖子: cout case break list Admin 
2020-06-28 10:25
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9031
专家分:54061
注 册:2011-1-18
收藏
得分:10 
error C2601: 'Load' : local function definitions are illegal

好好的函数,怎么变成了“local function”呢?很显然是花括号不匹配。
这就简单了,正常人的代码都是要排版的,那你就排版一下你的代码呗,看看哪个大括号少了。
2020-06-28 11:04
八画小子
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:37
帖 子:709
专家分:2063
注 册:2010-11-11
收藏
得分:10 
来错地方了,你是在C语言论坛问C++的问题。
2020-07-01 12:55
快速回复:为什么会出现这样的问题,怎么修改呀
数据加载中...
 
   



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

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