class PlasmaPistol{
private:
//properties
int theAmmo;
int theRateOfFire;
int theDestructivePower;
public:
//properties
bool safetyOn;
int maxAmmo;
//member function prototypes
void pressTrigger(void);
void load(int);
void setDestructivePower(int powerSetting);
int showDestructivePower(void);
void setRateOfFire (int boltsPerTriggerPress);
int showRateOfFire(void);
int ammoRemaining(void);
//constructors
PlasmaPistol(); //a default constructor that assigns default values to both
PlasmaPistol(int, int); //the private and public properties.
//An overload constructor that allows the destructive
//power and maxAmmo properties to be set when the object is instatiated
};
int main(void){
PlasmaPistol plasmaPistol1;//uses the default constructor
PlasmaPistol plasmaPistol2(7, 50);//uses the overloaded constructor
PlasmaPistol::PlasmaPistol(int powerSetting, int nmbrOfBolts){
theDestructivePower = powerSetting;
maxAmmo = nmbrOfBolts;
}
//these are the plasmaPistols methods
void PlasmaPistol:: pressTrigger(void){ //fires the plasma pistol and decreases the ammo count based
if (safetyOn != true){
if (theRateOfFire <= theAmmo){
cout << "Plasma Pistol Fired";
theAmmo -= theRateOfFire;
}
else{ //on the rateOfFire property. The pistol should not fire if //theSafetyOn property is true.
cout << "Plasma Pistol does not have enough ammo to fire or the plasma pistols safety is on"; // the safety is on
}
}
}
void PlasmaPistol::load(int nmbrOfBolts){
theAmmo = nmbrOfBolts;
theAmmo += 50;
if (theAmmo > maxAmmo)
theAmmo = maxAmmo;
} //adds ammo bolts to the plasma pistol. The amount of ammo bolts
//in the plasma pistol can not exceed theMaxAmmo property
void PlasmaPistol::setDestructivePower(int powerSetting){
theDestructivePower = powerSetting;
if (theDestructivePower < 1)
theDestructivePower = 1;
else if (theDestructivePower > 10)
theDestructivePower = 10;
} //changes the destructive power of the plasma pistol
int PlasmaPistol::showDestructivePower(void){
return theDestructivePower;
} //returns the value of theDestructivePower property
int PlasmaPistol::showRateOfFire(void){
return theRateOfFire;
} //returns the value of theRateOfFire property
int PlasmaPistol::ammoRemaining(void){
return theAmmo;
} //returns the amount of ammo remaining in the pistol
here is the output I'm getting:
Plasma Pistol 1's Destructive Power : 9
Plasma Pistol 1's Number of bolts left : 56
Plasma Pistol 1's Rate of fire : 5
Shooting 5bolts
Shooting 5bolts
Number of bolts left: 56
Plasma Pistol 2's Destructive Power : 7
Plasma Pistol 2's Number of bolts left : -858993460
Plasma Pistol 2's Rate of fire : -858993460
Shooting -858993460bolts
Shooting -858993460bolts
Number of bolts left: -858993460
Press any key to continue . . .
I need plasma pistol 2 to look like plasma pistol 1 and I'm stuck and so are my other friends any help is greatly appreciated;)
#include <iostream>
usingnamespace std;
class PlasmaPistol{
private:
//properties
int theAmmo;
int theRateOfFire;
int theDestructivePower;
public:
//properties
bool safetyOn;
int maxAmmo;
//member function prototypes
void pressTrigger(void);
void load(int);
void setDestructivePower(int powerSetting);
int showDestructivePower(void);
void setRateOfFire (int boltsPerTriggerPress);
int showRateOfFire(void);
int ammoRemaining(void);
//constructors
PlasmaPistol(); //a default constructor that assigns default values to both
PlasmaPistol(int, int); //the private and public properties.
//An overload constructor that allows the destructive
//power and maxAmmo properties to be set when the object is instatiated
};
int main(void){
PlasmaPistol plasmaPistol1;//uses the default constructor
PlasmaPistol plasmaPistol2(7, 50);//uses the overloaded constructor
cout << "Plasma Pistol 1's Destructive Power : " << plasmaPistol1.showDestructivePower() << endl;
cout << "Plasma Pistol 1's Number of bolts left : " << plasmaPistol1.ammoRemaining() << endl;
cout << "Plasma Pistol 1's Rate of fire : " << plasmaPistol1.showRateOfFire() << endl;
cout << "Shooting " << plasmaPistol1.showRateOfFire() << "bolts " << endl;
cout << "Shooting " << plasmaPistol1.showRateOfFire() << "bolts " << endl;
cout << endl;
cout << endl;
cout << "Number of bolts left: " << plasmaPistol1.ammoRemaining() << endl;
cout << endl;
cout << endl;
cout << "Plasma Pistol 2's Destructive Power : " << plasmaPistol2.showDestructivePower() << endl;
cout << "Plasma Pistol 2's Number of bolts left : " << plasmaPistol2.ammoRemaining() << endl;
cout << "Plasma Pistol 2's Rate of fire : " << plasmaPistol2.showRateOfFire() << endl;
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts " << endl;
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts " << endl;
cout << endl;
cout << endl;
cout << "Number of bolts left: " << plasmaPistol2.ammoRemaining() << endl;
return 0;
}
PlasmaPistol::PlasmaPistol(){
theAmmo = 56;
theRateOfFire = 5;
theDestructivePower = 9;
safetyOn = false;
maxAmmo = 100;
}
PlasmaPistol::PlasmaPistol(int powerSetting, int nmbrOfBolts){
theDestructivePower = powerSetting;
maxAmmo = nmbrOfBolts;
}
//these are the plasmaPistols methods
void PlasmaPistol:: pressTrigger(void){ //fires the plasma pistol and decreases the ammo count based
if (safetyOn != true){
if (theRateOfFire <= theAmmo){
cout << "Plasma Pistol Fired";
theAmmo -= theRateOfFire;
}
else{ //on the rateOfFire property. The pistol should not fire if //theSafetyOn property is true.
cout << "Plasma Pistol does not have enough ammo to fire or the plasma pistols safety is on"; // the safety is on
}
}
}
void PlasmaPistol::load(int nmbrOfBolts){
theAmmo = nmbrOfBolts;
theAmmo += 50;
if (theAmmo > maxAmmo)
theAmmo = maxAmmo;
} //adds ammo bolts to the plasma pistol. The amount of ammo bolts
//in the plasma pistol can not exceed theMaxAmmo property
void PlasmaPistol::setDestructivePower(int powerSetting){
theDestructivePower = powerSetting;
if (theDestructivePower < 1)
theDestructivePower = 1;
elseif (theDestructivePower > 10)
theDestructivePower = 10;
} //changes the destructive power of the plasma pistol
int PlasmaPistol::showDestructivePower(void){
return theDestructivePower;
} //returns the value of theDestructivePower property
void PlasmaPistol::setRateOfFire(int boltsPerTriggerPress){
theRateOfFire = boltsPerTriggerPress;
if (boltsPerTriggerPress < 1)
theRateOfFire = 1;
elseif
(boltsPerTriggerPress > 10)
theRateOfFire = 10;
}
int PlasmaPistol::showRateOfFire(void){
return theRateOfFire;
} //returns the value of theRateOfFire property
int PlasmaPistol::ammoRemaining(void){
return theAmmo;
} //returns the amount of ammo remaining in the pistol