i have this c program but i need help with a few functions C

i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship.

Thanks you

#include <iostream>
#include <string>
using namespace std;

enum Alignment { us, them, chaotic };

class Ship
{
private:
string name;
Alignment align;
int xLoc;
int yLoc;
int range;
int currHealth;
int attackPower;
int maxHealth;
virtual string getType() { return \"Ship\"; }

public:
Ship(string name, int x, int y, Alignment align, int maxHeal, int rng, int attackPwr);
virtual void attack(Ship* target) {}
int getX();
int getY();
Alignment getAlign();
string status();
int getHealth();
virtual void move() {}
void changeAlign(Alignment align);
void accessDamage(int amt);

};
class Battle : public Ship
{
private:
int torpedoes;
string getType();

public:
Battle(string name, int x, int y, Alignment align);
void move();
void attack(Ship* target);
string status();
};
Ship::Ship(string name, int x, int y, Alignment align, int maxHeal, int rng, int attackPwr)
{
Ship::name = name;
xLoc = x;
yLoc = y;
Ship::align = align;
maxHealth = maxHeal;
range = rng;
attackPower = attackPwr;
currHealth = maxHealth;
}

int Ship::getX()
{
return xLoc;
}

int Ship::getY()
{
return yLoc;
}

Alignment Ship::getAlign()
{
return align;
}

string Ship::status()
{
string strStatus = \"\";
strStatus += \"Name: \" + name + \"\ \";
strStatus += \"Type: \" + getType() + \"\ \";
strStatus += \"Health: \" + to_string(currHealth) + \"\ \";
strStatus += \"Location: (\" + to_string(xLoc) + \", \" + to_string(yLoc) + \")\ \";
return strStatus;
}

int Ship::getHealth()
{
return currHealth;
}

void Ship::changeAlign(Alignment newAlign)
{
align = newAlign;
}

void Ship::accessDamage(int amt)
{
int newAmt = currHealth - amt;
if (newAmt >= 0 && newAmt <= maxHealth)
  currHealth = newAmt;
}
class Corvette : public Ship
{
private:
string getType();

public:
Corvette(string name, int x, int y, Alignment align);
void move();
void attack(Ship* target);
};
void Corvette::attack(Ship* target)
{

}
class Cruiser :public Ship
{
private:
string getType();

public:
Cruiser(string name, int x, int y, Alignment align);
void move();
void attack(Ship* target);
};

class Repair :public Cruiser
{
public:
Repair(string name, int x, int y, Alignment align);
void attack(Ship* target);
};


int main()
{
Ship **fleet;
int numShip;

// cout << \"How many ships do you want ? \";
// cin >> numShip;

numShip = 6;
fleet = new Ship *[numShip];
fleet[0] = new Battle(\"Constitution\", 0, 0, us);
fleet[1] = new Cruiser(\"Enterprize\", 20, 20, chaotic);
fleet[2] = new Corvette(\"1000Falcon\", 0, 5, us);
fleet[3] = new Repair(\"DocMcStuffings\", 2, 2, them);
fleet[4] = new Battle(\"BoatyMcBoatFace\", 10, 10, chaotic);
fleet[5] = new Cruiser(\"Titanic\", 15, 15, us);

for (int i = 0; i < numShip; i++) cout << fleet[i]->status();
for (int i = 0; i < numShip; i++) fleet[i]->move();
for (int i = 0; i < numShip; i++) cout << fleet[i]->status();
for (int i = 0; i < numShip; i++)
  for (int j = 0; j < numShip; j++)
   if (i != j && fleet[i]->getHealth()>0) // cannot attack self, and dead do not attack.
    fleet[i]->attack(fleet[j]);

for (int i = 0; i < numShip; i++) cout << fleet[i]->status();

enum Alignment us, them, chaotic) Ship (the base class) attributes name string align Alignment Loc integer Loc integer range int curr Health integer attack Power: integer max Health. integer methods public Ship Cname string, x integer y integer align Alignment maxHeal integer rng integer attackPwr integer curr Health is set to maximum public virtual attack (target Ship) void private virtual getType() string// Battleship Cruiser Corvette \'\'Repairship\" public getX ():i returns the x coordinate nt public getYO:int returns the y coordinate public getAlign C) Alignment returns the alignment public status string see format below getHealth() integer public virtual move G) void changes position by the amount of that type of ship increases health by 1 (until max reached) public change Align C) :void changes the alignment public accessDamage (amt int) void changes the health by amt, (keeping it within bounds to,maxHealth]

Solution

Answer:

#include <iostream.h>
#include <string.h>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>   
void displaygamerwindow();
void shiplocation();
void systemlocation();
void systemoption(int capacity1, int leftsidedirection, int upwards, int word_taken);
void systemwindow();
void locationselect(int capacity, int left, int up, int word_input);
char shiplabel[10], systemlabel[10];
int x,locatevertical, locatehorizontal,locateupwards,locateleftwards,computevertical, computehorizontal,computeupwards,computeleftwards;
char gamerboard [10][10]=
{
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
};
char hiddensystem [10][10]=
{
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
};
char displayedsystem [10][10]=
{
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00},
};

main()
{
HANDLE result;
result = GetStdHandle(STD_OUTPUT_HANDLE);
cout<<\"Loading Please Wait : \"<<endl;
Sleep(1000);
system(\"CLS\");
cout<<\"Loading Please Wait :\"<<endl;
Sleep(1000);
system(\"CLS\");
cout<<\"Loading Please Wait :\"<<endl;
Sleep(1000);
system(\"CLS\");
cout<<\"Loading Please Wait :\"<<endl;
Sleep(1000);
system(\"CLS\");
  
SetConsoleTextAttribute(result, FOREGROUND_BLUE|BACKGROUND_CYAN);
cout<<\"Lets Play BattleShip Game :\"<<endl;
SetConsoleTextAttribute(result, FOREGROUND_CYAN|FOREGROUND_GREEN|FOREGROUND_BLUE);

systemlocation();
systemwindow();
return 0;
}

void systemwindow()
{

computehorizontal=0;
computevertical=0;
cout << \"\" << endl;
cout << \" System Board \" << endl;
cout << \".........................................................\" << endl;
cout << \" |0|1|2|3|4|5|6|7|8|9|\" ;
cout<<\'\ \';
cout << computehorizontal << \"|\";
do
{
if(computehorizontal == 9 && computevertical == 10)
{break;}
if(computevertical > 9 && computehorizontal < 9)
{
cout << \"|\"<< endl;
computehorizontal = computehorizontal + 1;
cout << (computehorizontal) << \"|\";
computevertical = 0;
}
if(computehorizontal < 10)
{
if(computevertical < 9)
{
cout << hiddensystem[computehorizontal] [computevertical] << \" \";
}
if(computevertical > 8)
{
cout << hiddensystem[computehorizontal] [computevertical];
}
}
computevertical = computevertical + 1;
}
while(computehorizontal < 10);
computehorizontal = 0;
computevertical = 0;
cout << \"|\" << endl;
cout << \"................................................................\" << endl;
cout << \"\" << endl;
}

void systemlocation()
{
srand(time(NULL));
for (x=5;x>=2;x--)
{
switch(x)
{
case 5:
strcpy(systemlabel,\"Carrier\");
break;
case 4:
strcpy(systemlabel,\"Battleship\");
break;
case 3:
strcpy(systemlabel,\"Kruiser\");
break;
case 2:
strcpy(systemlabel,\"Destroyer\");
break;
}
do
{
computeleftwards=rand()%(10);
computeupwards=rand()%(10);
}
while((hiddensystem[computeleftwards][computeupwards]!=00));
hiddensystem[computeleftwards][computeupwards]=int(systemlabel[0]);
systemoption(x,computeleftwards,computeupwards, (int(systemlabel[0])));
}
do
{
computeleftwards=rand()%(10);
computeupwards=rand()%(10);
}
while((hiddensystem[computeleftwards][computeupwards]!=00));
hiddensystem[computeleftwards][computeupwards]=00;
systemoption(3,computeleftwards,computeupwards, 00);
}

void systemoption(int capacity1, int leftsidedirection, int upwards, int word_taken)
{
srand(time(NULL));
int select,circle;
select=1+rand()%(4);
switch (select)
{
case 1:
for(circle=1;circle<capacity1;circle++)
{
if(hiddensystem[leftsidedirection-circle][upwards]!=00 || int(leftsidedirection-(capacity1-1))<(0))
{
hiddensystem[leftsidedirection][upwards]=00;
x=x+1;
break;
}
if(int(leftsidedirection-(capacity1-1)) >= (0) && x==capacity1)
{
for(circle=1;circle<capacity1;circle++)
{hiddensystem[leftsidedirection-circle][upwards]=word_taken;}
systemwindow();
}
}
break;
case 2:
for(circle=1;circle<capacity1;circle++)
{
if(hiddensystem[leftsidedirection+circle][upwards]!=00 || int(leftsidedirection-(capacity1-1))>(9))
{
hiddensystem[leftsidedirection][upwards]=00;
x=x+1;
break;
}
if(int(leftsidedirection-(capacity1-1)) <= (9) && x==capacity1)
{
for(circle=1;circle<capacity1;circle++)
{hiddensystem[leftsidedirection+circle][upwards]=word_taken;}
systemwindow();
}
}
break;
case 3:
for(circle=1;circle<capacity1;circle++)
{
if(hiddensystem[leftsidedirection-circle][upwards]!=00 || int(leftsidedirection-(capacity1-1))>(9))
{
hiddensystem[leftsidedirection][upwards]=00;
x=x+1;
break;
}
if(int(upwards+(capacity1-1)) <= (9) && x==capacity1)
{
for(circle=1;circle<capacity1;circle++)
{hiddensystem[leftsidedirection][upwards+ circle]=word_taken;}
systemwindow();
}
}
break;
case 4:
for(circle=1;circle<capacity1;circle++)
{
if(hiddensystem[leftsidedirection-circle][upwards]!=00 || int(upwards-(capacity1-1))<(0))
{
hiddensystem[leftsidedirection][upwards]=00;
x=x+1;
break;
}
if(int(upwards-(capacity1-1)) >= (0) && x==capacity1)
{
for(circle=1;circle<capacity1;circle++)
{hiddensystem[leftsidedirection][upwards-circle]=word_taken;}
systemwindow();
}
}
break;
}
}

void displaygamerwindow()
{
locatehorizontal=0;
locatevertical=0;
cout << \"\" << endl;
cout << \" Gamer \'s Board\" << endl;
cout << \".................................................................\" << endl;
cout << \" |0|1|2|3|4|5|6|7|8|9|\" ;
cout<<\'\ \';
cout << locatehorizontal << \"|\";
do
{
if(locatehorizontal == 9 && locatevertical == 10)
{break;}
if(locatevertical > 9 && locatehorizontal < 9)
{
cout << \"|\"<< endl;
locatehorizontal = locatehorizontal + 1;
cout << (locatehorizontal) << \"|\";
locatevertical = 0;
}
if(locatehorizontal < 10)
{
if(locatevertical < 9)
{
cout << gamerboard[locatehorizontal] [locatevertical] << \" \";
}
if(locatevertical > 8)
{
cout << gamerboard[locatehorizontal] [locatevertical]<<flush;
}
}
locatevertical = locatevertical + 1;
}
while(locatehorizontal < 10);
locatehorizontal = 0;
locatevertical = 0;
cout << \"|\" << endl;
cout << \"................................................................................\" << endl;
cout << \"\" << endl;
}

void locationselect(int capacity,int left,int up,int word_input)
{
int select,circle;
cout<<\"Do you need any ship to face: \"<< \'\ \' << \"1. UP 2.DOWN 3.RIGHT 4.LEFT\"<<\'\ \';
cin>>select;
switch (select)
{
case 1:
for(circle=1;circle<capacity;circle++)
{
if(gamerboard[left-circle][up]!=00 || int(left-(capacity-1))<(0))
{
gamerboard[left][up]=00;
cout<<\"Don\'t place ships illegally...\"<<endl;
x=x+1;
break;
}
if(int(left-(capacity-1)) >= (0) && x==capacity)
{
for(circle=1;circle<capacity;circle++)
{gamerboard[left-circle][up]=word_input;}
displaygamerwindow();
}
}
break;
case 2:
for(circle=1;circle<capacity;circle++)
{
if(gamerboard[left+circle][up]!=00 || int(left-(capacity-1))>(9))
{
gamerboard[left][up]=00;
cout<<\"Please check ships place correctly.\"<<endl;
x=x+1;
break;
}
if(int(left-(capacity-1)) <= (9) && x==capacity)
{
for(circle=1;circle<capacity;circle++)
{gamerboard[left+circle][up]=word_input;}
displaygamerwindow();
}
}
break;
case 3:
for(circle=1;circle<capacity;circle++)
{
if(gamerboard[left-circle][up]!=00 || int(left-(capacity-1))>(9))
{
gamerboard[left][up]=00;
cout<<\"Please check ships place correctly\"<<endl;
x=x+1;
break;
}
if(int(up+(capacity-1)) <= (9) && x==capacity)
{
for(circle=1;circle<capacity;circle++)
{gamerboard[left][up+ circle]=word_input;}
displaygamerwindow();
}
}
break;
case 4:
for(circle=1;circle<capacity;circle++)
{
if(gamerboard[left-circle][up]!=00 || int(up-(capacity-1))<(0))
{
gamerboard[left][up]=00;
cout<<\"Please check ships place correctly\"<<endl;
x=x+1;
break;
}
if(int(up-(capacity-1)) >= (0) && x==capacity)
{
for(circle=1;circle<capacity;circle++)
{gamerboard[left][up-circle]=word_input;}
displaygamerwindow();
}
}
break;
}
}

void shiplocation()
{
for (x=5;x>=2;x--)
{
switch(x)
{
case 5:
strcpy(shiplabel,\"Carrier\");
break;
case 4:
strcpy(shiplabel,\"Battleship\");
break;
case 3:
strcpy(shiplabel,\"Kruiser\");
break;
case 2:
strcpy(shiplabel,\"Destroyer\");
break;
}
do
{
cout<<\"Locating one end of the \"<<shiplabel<<\".\"<<\'\ \';
cout<<\"Place left side coordinate followed by top :\"<< \'\ \';
cin>>locateleftwards;
cin>>locateupwards;
}
while(locateleftwards<0||locateleftwards>9||locateupwards<0||locateupwards>9||(gamerboard[locateleftwards][locateupwards]!=00));
gamerboard[locateleftwards][locateupwards]=int(shiplabel[0]);
displaygamerwindow();
locationselect(x,locateleftwards,locateupwards, (int(shiplabel[0])));
}
do
{
cout<<\"Locate one end of the Submarine.\"<<\'\ \';
cout<<\"Place left side coordinate followed by top \"<< \'\ \';
cin>>locateleftwards;
cin>>locateupwards;
}
while(locateleftwards<0||locateleftwards>9||locateupwards<0||locateupwards>9||(gamerboard[locateleftwards][locateupwards]!=00));
gamerboard[locateleftwards][locateupwards]=00;
displaygamerwindow();
locationselect(3,locateleftwards,locateupwards, 00);
}

i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship. Thanks you #include <iostream&
i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship. Thanks you #include <iostream&
i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship. Thanks you #include <iostream&
i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship. Thanks you #include <iostream&
i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship. Thanks you #include <iostream&
i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship. Thanks you #include <iostream&
i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship. Thanks you #include <iostream&
i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship. Thanks you #include <iostream&
i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship. Thanks you #include <iostream&
i have this c++ program but i need help with a few functions. Can someone fill in the move and attack functions for each ship. Thanks you #include <iostream&

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site