Help me finish this please
I have to Create a new project that consists of at least two classes: a base class and a derived class. It should also contain at least one more class that will be used to instantiate the composite member of either the base or the derived class.
I have most of it but I think I need to have an overload somewhere and maybe a class with people but not sure what or how to implement it. Someone please help me.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
class Gun
{
protected:
int shotsFired;
int hit;
int miss;
double hitPercent;
string name;
int ammo;
public:
Gun();
Gun(int);
virtual ~Gun();
void shoot(int, double, int, int, int);
void reload();
virtual void print() = 0;
virtual void damage();
};
Gun::Gun()
{
shotsFired = 0;
hit = 0;
miss = 0;
hitPercent = 0.0;
name = "Generic Gun";
ammo = 0;
}
Gun::Gun(int rounds)
{
if (rounds >= 0)
{
ammo = rounds;
}
}
void Gun::shoot(int ammo, double hitPercent, int hit, int miss, int shotsFired)
{
ammo--;
shotsFired = hit + miss;
hitPercent = hit / shotsFired;
miss = shotsFired - hit;
cout << "Shots: " << shotsFired << endl;
cout << "Hit %: " << hitPercent << endl;
}
void Gun::damage()
{
}
Gun::~Gun()
{
}
class MachineGun : public Gun
{
public:
MachineGun();
void print();
};
MachineGun::MachineGun() :Gun(30)
{
name = "Machine Gun";
}
void MachineGun::print()
{
cout << "Your machine gun has " << ammo << " shots left." << endl;
}
class Pistol : public Gun
{
public:
Pistol();
void print();
};
Pistol::Pistol()
{
name = "Pistol";
}
void Pistol::print()
{
cout << "Your pistol has " << ammo << " shots left." << endl;
}
int main()
{
MachineGun *mGun = new MachineGun();
mGun->print();
Pistol *mPistol = new Pistol();
mPistol->print();
delete(mGun);
delete(mPistol);
cin.get();
return 0;
}