NEED C++ HELP. PLEASE FOLLOW DIRECTIONS CAREFULLY : Use a 1 dimensional array ob
ID: 3743918 • Letter: N
Question
NEED C++ HELP. PLEASE FOLLOW DIRECTIONS CAREFULLY:
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.
RowArray.h:
Table.h:
Triangle.h:
main.cpp:
}
Example Table:
8 #ifndef ROWARAYH #define ROWARAYH 10 11 class RowAray 12 13 14 15 16 17 18 19 20 21 22 #endif/* ROWARAYH private: int size; int *rowData; public: RowAray(int); RowAray) int getSize)freturn size;} int getData(int i){return rowData [i] ;Explanation / Answer
#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(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 Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.