Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a program to satisfy the problem and make sure it compiles. You are provided with table.h and main-table.cpp. Create table.cpp. Here is the

Please write a program to satisfy the problem and make sure it compiles. You are provided with table.h and main-table.cpp. Create table.cpp.

image text in transcribedimage text in transcribedimage text in transcribed

Here is the header file:

#ifndef TABLE_CLASS #define TABLE_CLASS #include using std::vector; #include using std::cout; using std::endl; using std::ostream; class Table{ private: vector> table_; // 2D vector of long long width_; // how wide is t_ (how many columns) long height_; // how high is t_ (how many rows) long field_width_; // how wide each element is for printing public: // table will be width x height, default val is 0 Table(long width, long height, long field_w = 3, long val=0); // range from lo to hi, seed has default void fill_random(long lo, long hi, unsigned int seed=0); bool set_value(unsigned int row_num, unsigned int col_num, long val); long get_value (unsigned int row_num, unsigned int col_num) const; void print_table(ostream&); friend ostream& operator 

Here is the main.cpp file:

#include using std::cout; using std::endl; using std::boolalpha; #include using std::out_of_range; #include "table.h" int main (){ bool result_bool; long result_long; cout   The Problem We are going to work on making our own classes with private data members and accessors. We are going to build a Table class, a 2D vector class. Table class Way back in Week 7 we discussed the idea of a 2D vector (example 10.5). We want to see if we can incorporate those ideas in a Table class. The header for the Table class has the following private elements private 2D vector of long vector vector long>> table how wide is t how many columns) long width how high is t how many rows) long height width for setw for even columns long field width The methods are as follows Table (long width. long height long field w 3, ong val-0) constructor. Makes a Table that is square shaped, width by height. Each element is set to val, which defaults to 0. The field w is to set the width of field when printing each element (default 3). Remember that is a vector vector long and that what you can push back onto table table is a vector long> which constitutes a row of table void fill random (long lo, long hi, unsigned. int seed 0) method to set every t element to a random number of long between lo and hi inclusive. Seed sets the random number seed, defaults to 0 bool set value (unsigned int row num, unsigned. int col num, long val) a method to set a particular element, indicated by row num and co num, to the provided val o If row num and col num are indicies that exist in t sets that element to val and returns true o otherwise does not set the element and returns false long get value (unsigned int row num unsigned. int col num) const Method to provide the value at row num col num of t if those two indicies exist. o if the two indicies are valid, return the table element o if not, since we are practicing exceptions let's throw a doma in error ostream& operator

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

More Books

Students also viewed these Databases questions

Question

Describe the advantages of effective listening.

Answered: 1 week ago

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago

Question

5. Tell how job experiences can be used for skill development.

Answered: 1 week ago

Question

4. Explain the characteristics of successful mentoring programs.

Answered: 1 week ago