Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

// 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 #include #include #include

using namespace std;

//function declarations void readFile(); void quit(); void mainMenu();

//global variables

string GridXRange; string GridYRange; ifstream inData;

vector tokenStringVector;

//String tokenization function vector tokenizeString (string input, string delimiter) { size_t pos = 0; string token; vector result;

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 result;

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)

image text in transcribed

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

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

ISBN: 321321367, 978-0321321367

More Books

Students also viewed these Databases questions