本质上,我现在要做的是构建一个程序,允许您在选择类时从 3 个不同的类(坦克、近战、远程)中进行选择,然后将其命名为 20 个或更少字符的名称。在选择了 5 个职业并为每个英雄命名后,它会打印出你选择的每个职业的名称和生命值。代码是这样的:
#include "Driver.h"
#include <stdio.h>
#include "Mele.h"
#include "Ranged.h"
#include "Tank.h"
int main(void)
{
Champion *champ[5];
int i, choice;
printf("Enter the number for which class you would like to add to your team\n");
for(i = 0; i <= 4; i++)
{
char name[20];
//printf("Enter the number for which class you would like to add to your team");
printf("1 = Tank\n");
printf("2 = Ranged\n");
printf("3 = Mele\n");
scanf_s("%d", &choice);
if(choice == 1)
{
printf("Give him a name!\n");
scanf("%s", name);
champ[i] = new Tank(name);
}
else if(choice == 2){
printf("Give him a name!\n");
scanf("%s", name);
champ[i] = new Ranged(name);
}
else if(choice == 3){
printf("Give him a name!\n");
scanf("%s", name);
champ[i] = new Mele(name);
}
else
{
printf("You did not enter a number between 1 and 3 please try again!\n");
i = i - 1;
}
}
for(i = 0; i <= 4; i++)
{
printf("%s has %f health", champ[i]->getName(), champ[i]->getHealth());
}
return 0;
}
这是主要功能
冠军班长这样:
Champion::Champion(void)
{
}
Champion::Champion(char name1[])
{
name = name1;
}
char* Champion::getName(void)
{
return name;
}
double Champion::getHealth(void)
{
return health;
}
int Champion::getFluid(void)
{
return fluid;
}
double Champion::getArmor(void)
{
return armor;
}
double Champion::getSpecialA(void)
{
return specialA;
}
double Champion::getDamage(void)
{
return physDamage;
}
void Champion::setHealth(double health1)
{
health = health1;
}
void Champion::setFluid(int fluid1)
{
fluid = fluid1;
}
void Champion::setArmor(double armor1)
{
armor = armor1;
}
void Champion::getSpecialA(double specialA1)
{
specialA = specialA1;
}
void Champion::setDamage(double physDamage1)
{
physDamage = physDamage1;
}
然后我还有另外 4 个职业,分别是坦克、远程和近战;所有这些都继承自 Champion 并具有与 Champion 相同的设置。当我运行程序时,我得到了这个:
'dragons_rage.exe': Loaded 'C:\Users\Tom\Documents\Visual Studio 2010\Projects\dragons_rage\Debug\dragons_rage.exe', Symbols loaded.
'dragons_rage.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'dragons_rage.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'dragons_rage.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'dragons_rage.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
First-chance exception at 0x5dfc14cf (msvcr100d.dll) in dragons_rage.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.
Unhandled exception at 0x5dfc14cf (msvcr100d.dll) in dragons_rage.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.
The program '[516] dragons_rage.exe: Native' has exited with code -1073741819 (0xc0000005).
我不确定这些错误是什么以及它们意味着什么,如果我能得到一些帮助,那将是惊人的谢谢!!!!