Could someone please help me write this program using C++ please. The instructio
ID: 3751836 • Letter: C
Question
Could someone please help me write this program using C++ please. The instructions are in he pictures provided and the code in text below is the starting code:#include #include
void DisplayStats( int cab, int goat, int trav, int wolf ); void DisplayMenu(); void MoveObject( int& obj, int& trav ); bool CheckWin( int cab, int goat, int trav, int wolf ); bool CheckLose( int cab, int goat, int trav, int wolf );
int main() { int cabbage = 1, goat = 1, traveller = 1, wolf = 1; bool done = false; while ( !done ) { } } #include #include
void DisplayStats( int cab, int goat, int trav, int wolf ); void DisplayMenu(); void MoveObject( int& obj, int& trav ); bool CheckWin( int cab, int goat, int trav, int wolf ); bool CheckLose( int cab, int goat, int trav, int wolf );
int main() { int cabbage = 1, goat = 1, traveller = 1, wolf = 1; bool done = false; while ( !done ) { } }
About For this project, you will implement the Cabbage, Goat, Wolf game. You will need to implement: * Keeping track of which island each character is on (cabbage, goat, wolf, and traveller) Allow the traveller to move between islands, with or without another object Check for "lose state": Either cabbage and goat left alone, or goat and wolf left alone Check for "win state": All objects are on the 2nd island
Explanation / Answer
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
void DisplayStats( int cab, int goat, int trav, int wolf );
void DisplayMenu();
void MoveObject( int& obj, int& trav );
bool CheckWin( int cab, int goat, int trav, int wolf );
bool CheckLose( int cab, int goat, int trav, int wolf );
void DisplayStats( int cab, int goat, int trav, int wolf )
{
cout<<"ISLAND1"<<" ";
if(cab==1)
cout<<"Cabbage ";
if(goat==1)
cout<<"Goat ";
if(trav==1)
cout<<"Traveller ";
if(wolf==1)
cout<<"Wolf ";
cout<<" ";
cout<<"ISLAND2"<<" ";
if(cab==2)
cout<<"Cabbage ";
if(goat==2)
cout<<"Goat ";
if(trav==2)
cout<<"Traveller ";
if(wolf==2)
cout<<"Wolf ";
cout<<" ";
}
void DisplayMenu()
{
cout<<" ";
cout<<"1. move CABBAGE and TRAVELLER"<<" ";
cout<<"2. move GOAT and TRAVELLER"<<" ";
cout<<"3. move TRAVELLER ONLY"<<" ";
cout<<"4. move WOLF and TRAVELLER"<<" ";
}
void MoveObject( int& obj, int& trav)
{
//cout<<"Move Object"<<obj<<" "<<trav<<" ";
if(obj==1&&trav==1) //if both object and traveller are at Island 1
{
obj=2;
trav=2;
}
else if(obj==2&&trav==2) //if both object and traveller are at Island 2
{
obj=1;
trav=1;
}
else
{
cout<<"Can't move! Traveller must be on same island!"<<" ";
}
// cout<<"Moved Object"<<obj<<" "<<trav<<" ";
}
bool CheckWin( int cab, int goat, int trav, int wolf )
{
if(cab==2&&goat==2&&trav==2&&wolf==2)//If both are at Island 2 then win condition
{
return true;
}
else
{
return false;
}
}
bool CheckLose( int cab, int goat, int trav, int wolf )
{
if(cab==goat&&trav!=goat)//if cabbage and goat are present without traveller at same island , goat eats cabbage
return true;
else if(goat==wolf&&trav!=goat)//if wolf and goat are present only at same island without traveller, wolf eats goat
return true;
else
return false;
}
int main()
{
int cabbage = 1, goat = 1, traveller = 1, wolf = 1;
bool done = false;
while ( !done )
{
DisplayStats(cabbage,goat,traveller,wolf);
DisplayMenu();
int action;
cin>>action;
cout<<"Choosen action:"<<action<<" ";
if(action==1)
{
MoveObject(cabbage,traveller) ;//Move cabbage and traveller to different island
}
else if(action==2)
{
MoveObject(goat,traveller); //Move goat and traveller to different island
}
else if(action==3)
{
MoveObject(traveller,traveller); //Move traveller to different island
// traveller=3-traveller;
}
else if(action==4)
{
MoveObject(wolf,traveller);//Move wolf and traveller to different island
}
// DisplayStats(cabbage,goat,traveller,wolf);
if(CheckLose(cabbage,goat,traveller,wolf)==true)
{
cout<<"GAME OVER"<<" ";
done=true;
}
if(CheckWin(cabbage,goat,traveller,wolf)==true)
{
cout<<"YOU WIN!"<<" ";
done =true;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.