Question
I need your help with my C++ program to implement the dynamic array allocation (involving pointers, new and delete operators) when reading in and storing
I need your help with my C++ program to implement the dynamic array allocation(involving pointers, new and delete operators) when reading in and storing the content from the readFile.txt file. No hard coding allowed.
Below are the txt file and my codes.
// The range of 'horizontal' indices, inclusive // E.g. if the range is 0-4, then the indices are 0, 1, 2, 3, 4 GridX_IdxRange=0-8
// The range of 'vertical' indices, inclusive // E.g. if the range is 0-3, then the indices are 0, 1, 2, 3 GridY_IdxRange=0-8
--------------------------------------------------------------------------------------------------------------------------
Codes:
#include
using namespace std;
//function declarations void readFile(); void quit(); void mainMenu();
//global variables
string GridXRange; string GridYRange; ifstream inData;
vector
//String tokenization function vector
while((pos = input.find(delimiter)) != string::npos) { token = input.substr(0, pos); result.push_back (token); input.erase(0, pos + delimiter.length()); } result.push_back (input); return (result); }
//main int main() { mainMenu(); return 0; }
//read in a file void readFile() { string readFile;
cout>readFile; cout
//open input file inData.open(readFile);
while (!inData) //while filename does not exist { cout > readFile; inData.open(readFile); }
string line; vector
while (getline(inData, line)) { if(line[0] == '/' && line[1] == '/') continue; //Ignore comment lines if(line.size()
//implement the dynamic array here and display the content
}
void quit() { cout
void mainMenu() { int num_choice; cout>num_choice; cout
switch(num_choice) { case 1: readFile(); break;
case 2: quit(); break;
default: cout
------------------------------------------------------------------------------------------------
Desired output: (when user enter choice 1 and types in readFile.txt)
readFile - Notepad File Edit Format View Help // The range of 'horizontal' indices, inclusive // E.g. if the range is 0-4, then the indices are 0, 1, 2, 3, GridX_IdxRange=0-8 4 // The range of 'vertical' indices, inclusive // E.g. if the range is 0-3, then the indices are 0, 1, 2, 3 GridY_IdxRange=0-8 Reading in GridX_IdxRange: 0-8...done! Reading in GridY_IdxRange: 0-8... done
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