Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//IN C++ PLEASE // lines.txt 0 a a b c 0 b d e f 1 c g h i 1 d j k l

//IN C++ PLEASE

// lines.txt

0 a a b c

0 b d e f

1 c g h i

1 d j k l

// Desired OUTPUT

Reading table from lines.txt ...

0| a b c | d e f | - - - | - - -

1| - - - | - - - | g h i | j k l

2| - - - | - - - | - - - | - - -

//

include

#include

#include

using namespace std;

// the following can be changed and the rest of the code should work

int const R = 3; // number of rows

int const C = 4; // number of columns

int const VM = 3; // table entry (vector) length

vector T[R][C]; // 3 rows and 4 columns table for now

// ------------------ Functions --------------------------------

int convert(char x)

{

** do a formula to convert a to 0, b to 1, c to 2 etc.

}

int readTable()

{ int row, col; // row and col numbers

char col_c; // column indicator

ifstream fin ("lines.txt", ios::in);

// Read in the file into T

while (fin >> row) // next line of file

{

fin >> col_c; col = convert(col_c); // convert to a slot number

vector v; // a vector to fill

char c; // one char from the file

// ** Fill v with chars from the file (there are VM chars)

// ** Put v in T[row][col]

}//end of while

}

// Displays a vector or "---" if the vector is empty

void showVector(vector v)

{ if (v.size() == 0) // empty entry

for (int i = 1; i <= VM; i++) cout << "- ";

else

// show the content of v separated by blanks (e.g. "a b c")

}

// Displays T as a table, separating entries with "|"

void displayTable()

{

// ** display T nicely labeled with row numbers (col numbers not needed)

// by calling showVector

}

// Driver

int main()

{

cout << "Reading table from lines.txt..." << endl;

readTable();

displayTable();

}//the end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions