Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Write 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 importantly, 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:

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 [Rail Rifle,Ion Cannon] means create a railRifle 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.

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 weapon. You will implement this exception in the weapon class as a struct with 3 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.4 Weapon Parent Class This is the parent class of ionCannon and railRifle.

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

2.2.5 ionCannon

The ionCannon is defined 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 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 railRifle

The railRifle is defined as follows:

railRifle

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

+railRifle()

+~railRifle()

+fire():string The class methods are as follows: railRifle: This is the constructor for the class. 5

railRifle: This is the destructor for the ion cannon. It prints out Rail Rifle Uninstalled! without the quotation marks and a new line at the end when the class is deallocated.

fire: If the rifle still has ammo, it must decrease the ammo by 1. It will return the following string: Rail Rifle fired!. Do not add quotation marks. If ammo is not available, instead throw the ammoOut exception.

Must contain weaponMount.h, weaponMount.cpp, ionCannon.h, ionCannon.cpp, railRifle.h, railRifle.cpp, weapon.h, weapon.cpp,main.cpp

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

Students also viewed these Databases questions

Question

Understand how to design effective service guarantees.

Answered: 1 week ago