c++ Question 5 Finally, fill in the code for a play function that uses the battl
ID: 3731704 • Letter: C
Question
c++
Question 5 Finally, fill in the code for a play function that uses the battleShip class and runs a game of Battleship. Keep hitting all three ships until all three have been sunk and always hit them in the order Destroyer Carrier then Cruiser void play() I/TODO: Declare 3 instances/objects of the battleship class: Destroyer Carrier Cruiser I/TODe: Give the ships a size: Destroyer-3 Carrier-5 Cruiser-2 II you will need to call the appropriate methods // Once you have this running for one, expand this while loop to include the // other two instances. Have the while loop end when all three ships have been // sunk. Make your while condition while ship one is sunk OR ship two is sunk OR ship three is sunk.Explanation / Answer
void play(){
// declaring three object
battleShip Destroyer("Destroyer");
battleShip Carrier("Carrier");
battleShip Cruiser("Cruiser");
// set the ship size
Destroyer.setSize(3);
Carrier.setSize(5);
Cruiser.setSize(2);
while(Destroyer.isSunk() == false){
Destroyer.recordHit();
}
while(Carrier.isSunk() == false){
Carrier.recordHit();
}
while(Cruiser.isSunk() == false){
Cruiser.recordHit();
}
}
Thanks, let me know if there is any concern.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.