Question
PLS FEEL THE ANSWERS according to the questions Q5) Add code to the function named worldClear, which takes a World as a parameter. It should
PLS FEEL THE ANSWERS according to the questions
Q5) Add code to the function named worldClear, which takes a World as a parameter. It should set every element of the array to INACCESSIBLE.
ANS:-
void worldClear(World world)
{
}
Q6) Add code to the function named worldDebugPrint that takes a World as a parameter. It should print out all the node values in the world in a grid and separated by tabs.
- Hint: Display the values in the array using two nested for-loops with cout statements inside. Print a newline (endl) after the last value in each line and a tab (\t') after each other value.
- Warning: You must match this format exactly, including using tabs (not spaces) to separate values on the same line. Otherwise, the test program will think the output is incorrect and dock you marks.
ANS:-
void worldDebugPrint(const World world)
{
}
Q7) Add code to the function named worldLoadNodes that takes a World and a string as parameters. The string represents the file name to load the nodes from. You should first open this data file for reading. Then load (i.e., read) the first ROW_COUNT * COLUMN_COUNT integers from the file into the World array. If the file cannot be opened, print an error message. Hereafter, you should always print an error message when a file cannot be opened.
- Hint: Read in the world nodes using formatted I/O (>> notation).
- Optional: Close the input file when you are done. If you do not, it will automatically be closed when the ifstream variable goes out of scope, which is normally at the end of the function.
ANS:-
void worldLoadNodes(World world, string filename)
{
}
Q8) Add code to the function named worldLoadAll that takes a World and a string as parameters. The string represents the world name. Use the world name parameter to calculate the names of the node data and text data files (e.g. "blizzard" becomes "blizzard_grid.txt" and "blizzard_text.txt"). Use these filenames to call the worldLoadNodes and worldLoadDescriptions functions.
- Hint: You can use + to add two strings, i.e., "Fred " + "Flintstone" gives "Fred Flintstone".
ANS:-
void worldLoadAll(World world, string game_name)
{
}
Extra part
world.h file
#pragma once
//#ifndef WORLD_H //#define WORLD_H
#include #include using namespace std;
//PART A const int ROW_COUNT = 6; const int COLUMN_COUNT = 9;
typedef unsigned int NodeValue;
const NodeValue INACCESSIBLE = 0; const NodeValue START_MESSAGE = 1; const NodeValue END_MESSAGE = 2; const NodeValue DEATH_NODE = 3; const NodeValue START_NODE = 4; const NodeValue VICTORY_NODE = 5;
typedef NodeValue World[ROW_COUNT][COLUMN_COUNT];
//PART B
void worldClear(World world);
void worldLoadAll(World world, string game_name);
void worldLoadNodes(World world, string filename);
void worldDebugPrint(const World world);
bool worldIsValid(const World world, int row, int column);
bool worldCanGoNorth(const World world, int row, int column);
bool worldCanGoSouth(const World world, int row, int column);
bool worldCanGoEast(const World world, int row, int column);
bool worldCanGoWest(const World world, int row, int column);
bool worldIsDeath(const World world, int row, int column);
bool worldIsVictory(const World world, int row, int column);
void worldFindValue(const World world, int& result_row, int& result_column, NodeValue value_to_find);
Full Code for the questions.
World.cpp file
#include
#include
#include
#include
void worldClear(World world)
{
}
void worldLoadAll(World world, string game_name)
{
}
void worldLoadNodes(World world, string filename)
{
}
void worldDebugPrint(const World world)
{
}
bool worldIsValid(const World world, int row, int column)
{
return false;
}
bool worldCanGoNorth(const World world, int row, int column)
{
return false;
}
bool worldCanGoSouth(const World world, int row, int column)
{
return false;
}
bool worldCanGoEast(const World world, int row, int column)
{
return false;
}
bool worldCanGoWest(const World world, int row, int column)
{
return false;
}
bool worldIsDeath(const World world, int row, int column)
{
return false;
}
bool worldIsVictory(const World world, int row, int column)
{
return false;
}
void worldFindValue(const World world, int& result_row, int& result_column, NodeValue value_to_find)
{
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started