I have been rushing trying to get this done by Monday 2am est. I'm trying to create a new project which consists of at least two classes: a base class and a derived class. The code of your project should include
* a composite object
* an example of inheritance
* at least one virtual and at least one pure virtual function
* at least one overloaded function
* at least one example of pointers
* at least one example of dynamic memory allocation
My code is garbled and incomplete, due to the fact I'm learning about pointers & dynamic memory allocation while putting this all together. It's definitely still a "work" in progress, and I'm moving everything around. I'm trying to determine how to represent the 'composition' portion of my code. Should I use ammo? Since the two derived classes have different amounts of it? Or Declare ammo as a virtual function since the sub-classes will represent different numbers - but both have ammo?
// Week6iLab_RyanRodgers.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
class Gun //abstract class
{
public:
Gun() { };
string name;
void shoot(int, double, int, int, int);
virtual void reload() = 0;
virtual void print() = 0; //pure virtual function
virtual void damage() = 0; //virtual function
virtual ~Gun(); //virtual destructor
static int ammo;
};
void shoot(int ammo, double hitPercent, int hit, int miss, int shotsFired)
{
ammo-- ;
shotsFired = hit + miss;
hitPercent = hit / shotsFired;
miss = shotsFired - hit;
void print();
cout << "Shots: " << shotsFired << endl;
cout << "Hit %: " << hitPercent << endl;
}
class MachineGun : public Gun //example of inheritance & derived class
{
public:
void setGunData(string name, void(*shoot)(void);
void shoot();
void print();
};
void
class Pistol : public Gun
{
public:
int ammo = 7;
};
int main()
{
Gun myGun;
myGun.shotsFired=shoot();
Gun *myGun();
myGun = new Gun();
myGun->ammo = hitPercent;
return 0;
}