Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A C++ program: You are working as a programmer designing a space ship weapon system for the newly forced Space Force . The weapon system

A C++ program:

You are working as a programmer designing a space ship weapon system for the newly

forced

Space Force

. The weapon system is a generic weapon housing that can fit a number

of different weapons that are all controlled by a ship pilot in the same way. Most im-

portantly, is the emphasis on safety. During combat, the weapon systems cannot become

unreliable or fail lest the pilots be put in unnecessary danger. Therefore you will need to

provide mechanisms to combat this.

2.2.1 weaponMount

This is the mounting system for the weapons. It can store a number of weapons and

control them as well as handle problems. It is defined as follows:

2

weaponMount

-weapons:weapon **

-numWeapons: int

---------------------------

+weaponMount(numWeapons:int, weaponList: string *)

+~weaponMount()

+accessWeapon(i:int):weapon *

The class variables are as follows:

weapons: A 1D array of weapon pointers. It must be able to accept any type of

weapon defined in the hierarchy.

numWeapons: The number of weapons that are mounted into the system.

The class methods are as follows:

weaponMount: This is the constructor. It will receive a list of weapons as a string

array plus the number of weapons. It must allocate memory for the weapons variable

and create a weapon based on the information provided by the string array. Create

one weapon of the type indicated at each index of the array. For example [Laser

Cannon Q,Ion Cannon] means create a laserCannon weapon at index 0 in quad

fire mode and so on. Laser Cannon S would imply to create a laserCannon weapon

with the single firing mode. The default strength for an ion cannon is 5.

weaponMount: The class destructor. It must deallocate all of the memory assigned

to the class.

accessWeapon: This receives an int which provides an index in the weapons list. It

will return the weapon that is stored at that position. If no such weapon is found

there, then throw a weaponFailure exception.

2.2.2 weaponFailure

This is a custom exception class used in the context of this system. It will inherit publicly

from the exception class. You will need to override specifically the

what

method to return

the statement Weapon System Failure! without the quotation marks. The name of this

class is

weaponFailure

. This exception will be used to indicate a failure of the weapon

system. You will implement this exception in the

weaponMount

class as a struct with

public access. You will need to research how to specify exceptions due to the potential

for a loose throw specifier error and what clashes this might have with a compiler.

Remember that

implementations

of classes and structs must be done in .cpp files.

2.2.3 ammoOut

This is a custom exception class used in the context of this system. It will inherit publicly

from the exception class. You will need to override specifically the

what

method to return

the statement Ammo Depleted! without the quotation marks. The name of this class

is

ammoOut

. This exception will be used to indicate a depletion of ammunition for a

3

weapon. You will implement this exception in the

weapon

class as a struct with public

access. You will need to research how to specify exceptions due to the potential for a loose

throw specifier error and what clashes this might have with a compiler. Remember that

implementations

of classes and structs must be done in their corresponding .cpp files.

2.2.4 Weapon Parent Class

This is the parent class of

ionCannon

and

laserCannon

. Both of these classes inherit

publicly from it. It is defined according to the following UML diagram:

weapon

-ammo:int

-type:string

-------------------

+weapon()

+weapon(a:int, t:string)

+getAmmo():int

+getType():string

+setAmmo(s:int):void

+setType(s:string):void

+

weapon()

+fire()=0:string

The class variables are as follows:

ammo: The amount of ammo stored in the weapon. As it is fired, this will deplete.

type: The type of the weapon as a string. Examples include: Rail Rifle,Laser

Cannon,Doom Cannon, Missile Launcher and Ion Cannon.

The class methods are as follows:

weapon: The default class constructor.

weapon(a:int, t:string): The constructor. It will take two arguments and instantiate

the class variables accordingly.

getAmmo,setAmmo: The getter and setter for the ammo.

getType,setType: The getter and setter for the ammo.

weapon: The destructor for the class. It is virtual.

fire: This is the method that will fire each of the weapons and produce a string of

the outcome. It is virtual here.

4

2.2.5 ionCannon

The ionCannon is defined as follows:

ionCannon

-strength:int

------------------------------

+ionCannon(s:int)

+~ionCannon()

+setStrength(s:int):void

+getStrength() const:int

+fire():string

The class variables are as follows:

strength: The strength of the ion cannon. Ion cannons get stronger the longer they

are fired.

The class methods are as follows:

ionCannon: The class constructor. This receives an initial strength for the ion

cannon.

ionCannon: This is the destructor for the ion cannon. It prints out Ion Cannon

Uninstalled! without the quotation marks and a new line at the end when the class

is deallocated.

fire: If the cannon still has ammo, it must decrease the ammo by 1. It will also

increase the strength by 1. It will return the following string: Ion Cannon fired at

strength: X where X represents the strength before firing. Do not add quotation

marks. If ammo is not available, instead throw the

ammoOut

exception.

getStrength/setStrength: The getter and setter for the strength variable.

2.2.6 laserCannon

The laserCannon is defined as follows:

laserCannon

-firingMode:char

------------------------------

+laserCannon(f:char)

+~laserCannon()

+fire():string

+getMode():char

+setMode(s:char):void

The class methods are as follows:

5

laserCannon: This is the constructor for the class. It receives a firing mode as a

char. The mode can be: Q or S for quad, single or burst fire respectively.

laserCannon: This is the destructor for the laser cannon. It prints out Laser

Cannon Uninstalled! without the quotation marks and a new line at the end when

the class is deallocated.

getMode/setMode: The getter and setter for the mode variable.

fire: If the cannon still has ammo, it must decrease the ammo by the amount

determined by the firing mode. You cannot fire if you do not have all the ammo

available for the mode. A single laser cannon uses 1 ammo. A quad laser cannon

uses 4 ammo. If fired as a single, it will return the following string: Laser Cannon

fired!. If fired as a quad, it will return the following string: Laser Cannon Quad

Burst fired!. Do not add quotation marks. If ammo is not available, instead throw

the

ammoOut

exception.

You will be allowed to use the following libraries:

sstream,exception, cstring,string,

iostream

. You will have a maximum of 10 uploads for this task. Your submission must

contain

weaponMount.h, weaponMount.cpp, ionCannon.h, ionCannon.cpp, laser-

Cannon.h, laserCannon.cpp, weapon.h, weapon.cpp, main.cpp

and a makefile.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions