Question: // In C++ please // Complete the Do's (bolded) #include using namespace std; void eat_white (istream & in) /* Pre: in is a valid input

// In C++ please

// Complete the Do's (bolded)

#include using namespace std; void eat_white (istream & in) /* Pre: "in" is a valid input file stream. Post: Any white space skipped over to EOF or the next non-white space character.*/ { while ((in.peek()!=EOF) && isspace(in.peek())) in.ignore(); }; int& element(int* twod, int dim2, int row, int col) /* DO 1 (start). Comment the entire block from here to "DO 1 (end)" below.*/ { int count = 0; for (int i = 0; i < row; i++) for (int j = 0; j < dim2; j++) count++; for (int j = 0; j < col; j++) count++; return twod[count]; }; /* DO 1 (end). Comment the entire block from "DO 1 (start)" above to here.*/ /*DO 2. Complete the following code by FILLING IN A SIMPLE FORMULA inside [...]: { return twod[...]; } and uncomment the block. */ void print2d (int * rect2d, int d1, int d2) { for (int i=0; i> d1; cout << endl << "Enter size of dimension #2: "; cin >> d2; rect2d = new int[d1*d2]; cout << endl << "Now enter " << d1 <<" rows, each with " << d2 << " values:" << endl; for (int i=0; i

for (int j=0; j> rect2d[d2*i+j]; char command; cout << endl << "If you want to get or set any particular element, input" << endl << "g (for get) or s (for set) followed by row and column" << endl << "(with zero-based indexing) and an integer value (for s)," << endl << "p to print the whole array, or d (for done) to end:" << endl; do { int i, j, val; eat_white(cin); cin >> command; if ((command == 's')||(command == 'S')) { cin >> i >> j >> val; element (rect2d, d2, i, j) = val; cout << endl << "Done setting the element at [" << i <<"," << j << "] to " << val << "." << endl << "Next command: "; } else if ((command == 'g') || (command == 'G')) { cin >> i >> j; cout << endl << "The element at [" << i <<"," << j << "] is "; cout << element (rect2d, d2, i, j) << "." << endl << "Next command: "; } else if ((command == 'p') || (command == 'P')) { cout<< endl << "Reporting values stored in the 2-d array, row by row:"<< endl; print2d (rect2d, d1, d2); cout << "Next command: "; } else if ((command != 'd') && (command != 'D')) cout << endl << "Please enter a valid command (s, S, g, G, d, or D): "; } while ((command != 'd') && (command != 'D')); return(0); };

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!