Question: Write a c++ program for the following UML introduction: You are working as a programmer designing a space ship weapon system for the newly forced

Write a c++ program for the following UML

introduction:

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 t a number

of dierent 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 dened as follows:

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 dened 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 ["Rail

Rie","Ion Cannon"] means create a railRie weapon at index 0 and so on. 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.

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 specically 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 specier error" and what clashes this might have with a compiler.

Remember that implementations of classes and structs must be done in .cpp files.

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 specically 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 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 specier error" and what clashes this might have with a compiler.

Remember that implementations of classes and structs must be done in .cpp files.

Weapon Parent Class

This is the parent class of ionCannon and railRifle. Both of these classes inherit

publicly from it. It is dened 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()

+re()=0:string

The class variables are as follows:

ammo: The amount of ammo stored in the weapon. As it is red, 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.

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

the outcome. It is virtual here.

ionCannon

The ionCannon is dened as follows:

ionCannon

-strength:int

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

+ionCannon(s:int)

+~ionCannon()

+setStrength(s:int):void

+getStrength():int

+fire():string

The class variables are as follows:

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

are red.

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 red at

strength: X" where X represents the strength before ring. 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

railRifle

The railRie is dened as follows:

railRifle

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

+railRifle()

+~railRifle()

+fire():string

The class methods are as follows:

railRie: This is the constructor for the class.

railRie: This is the destructor for the ion cannon. It prints out "Rail Ri

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

is deallocated.

re: If the rie still has ammo, it must decrease the ammo by 1. It will return the

following string: "Rail Rie red!". 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. Your submission must contain weaponMount.h, weaponMount.cpp, ionCannon.h, ionCannon.cpp, rail-

Rie.h, railRie.cpp, weapon.h, weapon.cpp,main.cpp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!