Question

In: Computer Science

In C++ for netbeans. Use a 1 dimensional array object to create a 2 dimensional table...

In C++ for netbeans.

Use a 1 dimensional array object to create a 2 dimensional table object. Then modify to create a triangular table.

Objective -> create an array of dynamic objects of RowAray inside Table i.e. an Aggregate. See Specs RowAray.h, Table.h Then create a triangular table, i.e. Triangle.

Fill each cell with random 2 digit integers. The example Table has 8 columns of RowAray objects each filled with 6 rows of random 2 digit numbers.

Then create a triangular table using the concept of the original table.

Complete the class implementations RowAray.cpp, Table,cpp, and Triangle.cpp use the driver program, obtain similar results.

https://github.com/ml1150258/2019_Fall_CSC-CIS_17c/tree/master/Hmwk/Review1_CSC17c_Object_Array

When complete for #rows=#cols, then create a version 2 that does a random number of cols per row with sorted column size output like the first assignment for the Triangular Matrix.

We will augment this assignment later and progress to templates.

Solutions

Expert Solution

If you have any doubts, please give me comment...

RowAray.h

/*

* File:   RowAray.h

* Author: Dr. Mark E. Lehr

* Created on January 22nd, 2019, 8:36 PM

* Specification for the RowAray

*/

#ifndef ROWARAY_H

#define ROWARAY_H

#include <cstdlib>

class RowAray

{

private:

    int size;

    int *rowData;

public:

    RowAray(int size);

    ~RowAray();

    int getSize();

    int getData(int i);

};

#endif

RowAray.cpp

#include "RowAray.h"

RowAray::RowAray(int size)

{

    this->size = size;

    rowData = new int[size];

    for (int i = 0; i < size; i++)

    {

        rowData[i] = (rand() % 90) + 10;

    }

}

RowAray::~RowAray()

{

    delete rowData;

}

int RowAray::getSize()

{

    return size;

}

int RowAray::getData(int i)

{

    return rowData[i];

}

Table.h

/* 
 * File:   Table.h
 * Author: Dr. Mark E. Lehr
 * Created on January 22nd, 2019, 8:36 PM
 * Specification for the Table
 */

#ifndef TABLE_H

#define TABLE_H

#include "RowAray.h"

class Table

{

private:

    int szRow;

    int szCol;

    RowAray **records;

public:

    Table(int row, int col);

    ~Table();

    int getSzRow();

    int getSzCol();

    int getData(int r, int c);

};

#endif

Table.cpp

/* 
 * File:   Triangle.h
 * Author: Dr. Mark E. Lehr
 * Created on January 22nd, 2019, 8:36 PM
 * Purpose:  Specification of a Triangular array from a Row Array
 */

#include "Table.h"

Table::Table(int row, int col)

{

    this->szRow = row;

    this->szCol = col;

    records = new RowAray *[row];

    for (int i = 0; i < row; i++)

        records[i] = new RowAray(col);

}

Table::~Table()

{

    delete[] records;

}

int Table::getSzRow()

{

    return szRow;

}

int Table::getSzCol()

{

    return szCol;

}

int Table::getData(int r, int c)

{

    return records[r]->getData(c);

}

Triangle.h

#ifndef TRIANGLE_H

#define TRIANGLE_H

#include "RowAray.h"

class Triangle

{

private:

    int szRow;

    RowAray **records;

public:

    Triangle(int row);

    ~Triangle();

    int getSzRow();

    int getData(int r, int c);

};

#endif

Triangle.cpp

#include "Triangle.h"

Triangle::Triangle(int row)

{

    this->szRow = row;

    records = new RowAray *[row];

    for (int i = 0; i < row; i++)

        records[i] = new RowAray(row);

}

Triangle::~Triangle()

{

    delete[] records;

}

int Triangle::getSzRow()

{

    return szRow;

}

int Triangle::getData(int r, int c)

{

    return records[r]->getData(c);

}

main.cpp

/*

* File:   main.cpp

* Author: Dr. Mark E. Lehr

* Created on January 22nd, 2019, 8:36 PM

* Purpose:  Dynamic Object Arrays

*/

//User Libraries

#include <cstdlib>

#include <ctime>

#include <iostream>

using namespace std;

//User Libraries

#include "Table.h"

#include "Triangle.h"

//Global Constants

//Function Prototype

void prntRow(RowAray *, int);

void prntTab(Table *);

void prntTri(Triangle *);

//Execution Begins Here!

int main(int argc, char **argv)

{

    //Initialize the random seed

    srand(static_cast<unsigned int>(time(0)));

    //Declare Variables

    int rows = 6, cols = 8, perLine = cols / 2;

    //Test out the RowAray

    RowAray row(cols);

    //Print the RowAray

    cout << "The Row Array size = " << row.getSize()

         << " printed " << perLine << " per Line";

    prntRow(&row, perLine);

    //Test out the Table

    Table tab(rows, cols);

    //Print the Table

    cout << "The table size is [row,col] = [" << rows << "," << cols << "]";

    prntTab(&tab);

    //Test out the Triangular Table

    Triangle tri(rows);

    //Print the Triangular Table

    cout << "The triangular table size is [row,row] = [" << rows << "," << rows << "]";

    prntTri(&tri);

    //Exit Stage Right

    return 0;

}

void prntRow(RowAray *a, int perLine)

{

    cout << endl;

    for (int i = 0; i < a->getSize(); i++)

    {

        cout << a->getData(i) << " ";

        if (i % perLine == (perLine - 1))

            cout << endl;

    }

    cout << endl;

}

void prntTab(Table *a)

{

    cout << endl;

    for (int row = 0; row < a->getSzRow(); row++)

    {

        for (int col = 0; col < a->getSzCol(); col++)

        {

            cout << a->getData(row, col) << " ";

        }

        cout << endl;

    }

    cout << endl;

}

void prntTri(Triangle *a)

{

    cout << endl;

    for (int row = 0; row < a->getSzRow(); row++)

    {

        for (int col = 0; col <= row; col++)

        {

            cout << a->getData(row, col) << " ";

        }

        cout << endl;

    }

    cout << endl;

}


Related Solutions

Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4...
Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4 grocery stores. Each store has 3 departments where product presentation affects sales (produce, meat, frozen). Every so often a department in a store gets a bonus for doing a really good job. You need to create a program that keeps a table of bonuses in the system for departments. Create a program that has a two dimensional array for these bonuses. The stores can...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
Complete the "dumb" 8 queens program that Use the 1 dimensional array representation. C++ This is...
Complete the "dumb" 8 queens program that Use the 1 dimensional array representation. C++ This is the solution to the  question. i want this program to written in different WAY. nothing fancy. #include<cmath> #include<fstream> #include<iostream> using namespace std; bool ok(int b[][8]){ int rQueens=0, dQueens=0; for(int row=0; row<8; row++){ for(int column=0; column<8; column++){ //Rows test if(b[row][column]==1) rQueens++; if(rQueens>1) return false; //Diagonals test    for(int j=1; ((column-j)>=0)&&((row-j)>=0); j++){ if(b[row-j][column-j]==1&&b[row][column]==1) return false; } for(int k=1; ((column-k)>=0)&&((row+k)<8); k++){ if(b[row+k][column-k]==1&&b[row][column]==1) return false; } } rQueens=0; }...
In C Create a multi-dimensional array and print it out forwards, backwards and then transpose.
In C Create a multi-dimensional array and print it out forwards, backwards and then transpose.
Complete the 8 queens 1 dimensional array program with backtracking in c+++. (don't use go to...
Complete the 8 queens 1 dimensional array program with backtracking in c+++. (don't use go to statement ) and please describe all the code statement and show the code in complier and also which can be copied. thank you very much
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write Matrix Addition 2 D (dimensional) Array program in c++.
c++ (1) Create a class, named Board, containing at least one data member (two-dimensional array) to...
c++ (1) Create a class, named Board, containing at least one data member (two-dimensional array) to store game states and at least two member functions for adding players’ moves and printing the game board. Write a driver to test your class. (2). The data type of the two-dimensional array can be either int or char. As a passlevel program, the size of the board can be hardcoded to 10 or a constant with a pre-set value, anything between 4 and...
In C create an array of 4 integers. Assign a pointer to the array. Use the...
In C create an array of 4 integers. Assign a pointer to the array. Use the pointer to find the average value of the elements in the array and display the results on the screen.
create a C++ Program 1. Ask and get a course name 2. Create an array of...
create a C++ Program 1. Ask and get a course name 2. Create an array of students of size 10, 3. Initialize the elements of the students array of appropriate names and grades 4. Create an object of class GradeBook (provide the course name and the created student array, in 3 above, as arguments to the constructor call. The arguments are used to initialize the data members of the class GradeBook. Desired Output: ========================================================= Enter course name: Object Oriented Programming...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT