急急急,c++有关类创建问题

wiflly 2015-06-07 12:31:39
最近在写一些代码,找网上的题目练手,现在有一题,是“魔兽世界之一:备战”,题目链接在这儿:
http://cshwmooc.openjudge.cn/homework/3w1/
现在卡住了
//
// war.cpp
// war
//
// Created by vi on 15/5/23.
// Copyright (c) 2015年 vi. All rights reserved.
//

#include <iostream>
#include <string>
const int WARRIOR_num=5;

using namespace std;


class warrior{
friend class Headquarter;
private:
int no; //编号
int kindno; //武士的种类编号 0 dragon 1 ninja 2 iceman 3 lion 4 wolf
int eachlife=life[kindno];
public:
static string names[WARRIOR_num]; //名字的集合,按照编号排
static int life[WARRIOR_num]; //dragon 、ninja、iceman、lion、wolf
string get_name(); //获得武士的名字
// int get_life(); //获得武士的生命值
warrior(){};
};

//int warrior::get_life(){
// return life[kindno];
//}
string warrior::get_name(){
return names[kindno];
}



class Headquarter{
friend class warrior;
private:
int totalStrength=0; //总的生命值
bool stop; //是否停止制造
warrior *knight[10000]; //假设有10000武士
string color; //总部的颜色
int totalWarrior[WARRIOR_num]={0,0,0,0,0}; //各种武士的数量,武士的种类编号 0 dragon 1 ninja 2 iceman 3 lion 4 wolf
int allWarrior=0; //总共制造了多少武士
int making_ord[2][WARRIOR_num]; //各司令部制造武士的顺序
public:
Headquarter(){};
Headquarter(string color,int strength):color(color),totalStrength(strength){}; //初始化总部的生命值和颜色
void make_war(); //制造武士,把相应的数据保留
// void set_color(string a);
void print_case(int); //根据制造后保留的数据把相应的数据打印出来
int get_allWarr(); //获得一共制造了多少武士
void set_making(int *a); //初始化制造的顺序
};

void Headquarter::set_making(int *a){
int *b=a;
for(int i=0;i<2;i++)
{
b=a;
for(int j=0;j<5;j++){
making_ord[i][j]=*b;
b++;
}
}
}

int Headquarter::get_allWarr(){
return allWarrior;
}
void Headquarter::make_war(){

int start_index=0;
for(int time=0;totalStrength>0;time++){
knight[time]=new warrior();

for(int i=0;i<2;i++){
for(int j=start_index;j<WARRIOR_num;j++){
if(i==1&&j==5){
stop=true;
break;
}
else if(totalStrength-knight[time]->life[making_ord[i][j]]>=0){ //making_ord[i][j]得到的就是此刻制造的武士,名字的序号
knight[time]->no=time;
knight[time]->kindno=making_ord[i][j];
totalWarrior[making_ord[i][j]]++;
i=2;
start_index=j;
allWarrior++;
start_index++;
break;
}
else
continue;
}
}

if(stop){

delete knight[time];
break;
}

}
}

//void Headquarter::set_color(string a){
// color=a;
//}

void Headquarter::print_case(int time){
cout << "hello" << endl;
if(allWarrior>time)
printf("%03d %s headquarter stops making warriors",time,color.c_str());
else
printf("%03d %s %s %d bron with strength %d,%d %s in %s headquarter/n",time,color.c_str(),knight[time]->get_name().c_str(),
knight[time]->no,knight[time]->eachlife,totalWarrior[knight[time]->kindno],knight[time]->get_name().c_str(),color.c_str());

}

string warrior::names[WARRIOR_num] = { "dragon","ninja","iceman","lion","wolf" };
//int Headquarter::making_ord[2][WARRIOR_num] = { { 2,3,4,1,0 },{3,0,1,2,4} }; //两个司令部武士的制作顺序序列



#include <string>
#include <iostream>
#include <stdio.h>

int main(){
int all_life;
cin >> all_life;
scanf("%d %d %d %d %d",&warrior::life[0],&warrior::life[1],&warrior::life[2],&warrior::life[3],&warrior::life[4]);
Headquarter red("red",all_life),blue("blue",all_life);
int red_ord[WARRIOR_num]={2,3,4,1,0},
blue_ord[WARRIOR_num]={3,0,1,2,4};
red.set_making(red_ord);
blue.set_making(blue_ord);

red.make_war();
blue.make_war();
//red.set_making(red_ord);
//blue.set_making(blue_ord);
for(int time=0;red.get_allWarr()>time&&blue.get_allWarr()>time;time++){
red.print_case(time);
blue.print_case(time);
}

}


麻烦帮我看看哪里出问题了。刚学这些还是蛮多不懂的,谢谢了
...全文
444 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-06-08
  • 打赏
  • 举报
回复
偶 遇到编译错误 都是用 “每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。” 的方法解决的。 遇到链接错误 将错误信息中出现的标识符放在百度里面搜一下,看其在哪个.lib中,然后在本地硬盘上搜索该.lib,如果没有,在网上搜索相关库或模块下载安装,然后将其所在目录填写到“附加依赖库所在目录”中,将其名字添加到“附加依赖库”中,重新连接。 VC6: 工程、设置、Link、分类:Input、附加库路径:填写附加依赖库所在目录 分号间隔多项 工程、设置、Link、分类:Input、对象/库模块:填写附加依赖库的名字.lib 空格间隔多项 VS20xx: 项目、属性、链接器、常规、附加库目录:填写附加依赖库所在目录 分号间隔多项 项目、属性、链接器、输入、附加依赖项:填写附加依赖库的名字.lib 空格或分号间隔多项 遇到运行错误 参考下面: 代码功能归根结底不是别人帮自己看或讲解或注释出来的;而是被自己静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。 提醒:再牛×的老师也无法代替学生自己领悟和上厕所! 单步调试和设断点调试(VS IDE中编译连接通过以后,按F10或F11键单步执行,按Shift+F11退出当前函数;在某行按F9设断点后按F5执行停在该断点处。)是程序员必须掌握的技能之一。
fly_dragon_fly 2015-06-08
  • 打赏
  • 举报
回复
什么问题要自己说一下
jiqiang01234 2015-06-07
  • 打赏
  • 举报
回复
单步调试,自然知道问题
wiflly 2015-06-07
  • 打赏
  • 举报
回复
怎么没人帮忙看看啊。在线等啊

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧