1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
#pragma warning(disable: 4996)
#include <cstdlib>
#include <iostream>
#include <string>
#include <cctype>
#include <stack>
#include <conio.h>
using namespace std;
// *** Class definitions ***
//base class
class Gun {
protected:
string g_manufacturer;
string g_caliber;
//string gunCabinet[2];
public:
Gun();
Gun(const string manufacturer, const string caliber) {
g_manufacturer = manufacturer;
g_caliber = caliber;
}
string getManufactuer() {
return g_manufacturer;
}
string getCaliber() {
return g_caliber;
}
void setManufactuer(string m);
void setCaliber(string c);
virtual void print();
};
class Handgun : public Gun {
protected:
string h_grips;
string h_sights;
bool h_laser;
public:
Handgun();
Handgun(const string manufacturer, const string caliber, const string grips, const string sights, const bool laser)
: Gun(manufacturer, caliber) {
h_grips = grips;
h_sights = sights;
h_laser = laser;
};
string getGrips() {
return h_grips;
}
string getSights() {
return h_sights;
}
bool getLaser() {
return h_laser;
}
void print();
void setGrips(string g);
void setSights(string s);
void setLaser(bool l);
};
class Revolver : public Handgun {
private:
bool r_singleAction;
int r_numberOfRounds;
/*Handgun(const string manufacturer, const string caliber, const string g, const string s, const bool l)
: Gun(manufacturer, caliber) {
grips = g;
sights = s;
laser = l;
};*/
public:
Revolver();
Revolver(const string manufacturer, const string caliber, const string grips, const string sights, const bool laser, bool singleAction, int numberOfRounds)
: Handgun(manufacturer, caliber, grips, sights, laser) {
r_singleAction = singleAction;
r_numberOfRounds = numberOfRounds;
}
string getSingleAction();
int getNumberOfRounds() {
return r_numberOfRounds;
}
void print();
void setSingleAction(bool singleAction);
void setNumberOfRounds(int numberOfRounds);
};
class Pistol : public Handgun {
private:
bool p_semiAuto;
public:
Pistol();
Pistol(const string manufacturer, const string caliber, const string grips, const string sights, const bool laser, bool semiAuto)
: Handgun(manufacturer, caliber, grips, sights, laser) {
p_semiAuto = semiAuto;
}
bool getSemiAuto() {
return p_semiAuto;
}
void print();
void setSemiAuto(bool semiAuto);
};
//main
int main()
{
Handgun myHandgun("Winchester", ".38","side","iron",true);
Revolver myRevolver("HK", ".45", "top", "iron", true, true, 500);
Pistol myPistol("Smith & Wesson", ".50", "top", "scope", true, true);
Gun *myGunCabinet[3];
myGunCabinet[0] = &myHandgun;
myGunCabinet[1] = &myRevolver;
myGunCabinet[2] = &myPistol;
for (int i = 0; i < 3; i++)
myGunCabinet[i] -> print();
//need this so the DOS window doesn't close
cout << "\n\n";
system("pause");
return 0;
}
//Class Implementations
void Gun::print() {
cout << "";
}
void Handgun::print() {
cout << "\nManufacturer: " << getManufactuer() << "\n";
cout << "Caliber: " << getCaliber() << "\n";
cout << "Grips: " << getGrips() << "\n";
cout << "Sigts: " << getSights() << "\n";
cout << "Laser: " << boolalpha << getLaser() << "\n";
}
void Revolver::print() {
cout << "Single Action: " << getSingleAction() << "\n";
cout << "Number of Rounds: " << getNumberOfRounds() << "\n";
}
void Pistol::print() {
cout << "Semi auto: " << boolalpha << getSemiAuto() << "\n";
}
string Revolver::getSingleAction() {
if (r_singleAction) {
return "Single Action";
}
else {
return "Not Single Action";
}
}
|