Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Dont advertise or spam! Only comment if you have full answer *******************

ID: 3542467 • Letter: D

Question

Dont advertise or spam! Only comment if you have full answer

*****************************************************************************************************************************************

******************************************************************************************************************************************


Write a program that reads and writes to a file one and two dimensional arrays that are dynamically allocated instead of statically declared. The bare bones and class definitions are already implemented in the directory, and what remains is for you to implement 4 functions of the DynamicReader. cpp file. The four functions are: read_lD_array (): read in the first number in the file that tells you how manyelements there are in the array. Suppose you put that information in a variable called doimedSize. (You can use whatever name you like of course) This function will create a single array with claimedSize elements and read the values from the file. Assuming nothing went wrong, it reads the numbers as expected and returns true. If the function finds that there are more numbers in the file than doimedSize, stop reading, output an error message stating that there are more, and return true. If there are not enough numbers in the file, output an error message, set readSize to the number actually read and return false. Of course, the variable readSize should reflect how many elements were actually read in after a successful execution of this function. read_2D_array (): read in the first two numbers in the file, which tells you how many rows and columns are in the array. Then create an appropriately sized array and read in the rest of the numbers. As in the previous function, the two error conditions also apply here. write_array (): depending on the value of dimensions, output the one or two dimensional array to the output file in the same format as in the input file. For example, if the input file looks like to the left, then the output file, to the right would also have the data with the same output: The overloaded

Explanation / Answer

#include "DynamicReader.h"

#include <iostream>

#include <cstdlib>

#include <STL>

using namespace std;

DynamicReader::DynamicReader() {


dimensions = 1;

oneDArray = NULL;

readSize = 0;


twoDArray = NULL;

nRows = 0;

nCols = 0;


readFileName = "";

writeFileName = "";


askedFileNames = false;

}


// REMEMBER TO CLEAN UP/DEALLOCATE THE ARRAYS!

DynamicReader::~DynamicReader() {

}


// THIS FUNCTION IS SOMETHING YOU HAVE IMPLEMENTED ALREADY

bool DynamicReader::open_IO(){

}


// THIS FUNCTION IS SOMETHING YOU HAVE IMPLEMENTED ALREADY

void DynamicReader::close_IO() {

}


/*--------------------------------------------------------------


This function asks the user for the filenames. This operation is

placed in a separate function because it is called multiple

times. Although it is awkward, ask the user for the dimensions of

the data structure in this function as well.


--------------------------------------------------------------*/

void DynamicReader::ask_filenames() {

cout << "Welcome. Please type in the name of the file to read the numbers. ";

cin >> readFileName;

cout << "Thank you. Please type in the name of the file to write the numbers. ";

cin >> writeFileName;

askedFileNames = true;


cout << "What are the dimensions of this data structure? ";

cin >> dimensions;

}


bool DynamicReader::read_1D_array(istream &in, string readFile) {

  

  

  

  

return true;

}


bool DynamicReader::read_2D_array(ostream &out, string writeFile) {

  

  

  

return true;

}


/*--------------------------------------------------------------

write_array() writes the array into the file with the name

writeFileName.

precondition: The output file is open, and nothing has been

written to the file before.


Remember that the output should have the same format as the

input.

--------------------------------------------------------------*/

// TAKE A LOOK AT THE read_array() FUNCTION IN THE HEADER FILE FOR HOW

// TO HANDLE THE DIFFERENCE BETWEEN 1D and 2D ARRAYS.

bool DynamicReader::write_array() {

}


ostream& operator << ( ostream& outs, DynamicReader& me ) {

return outs;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote