Question
In this project you will implement the DataFrame class along with the all the methods that are represented in the class definition. DataFrame is a
In this project you will implement the DataFrame class along with the all the methods that are represented in the class definition. DataFrame is a table with rows and columns columns and rows have names associated with them also. For this project we will assume that all the values that are stored in the columns and rows are integers. After you have tested your class, you have to execute the main program that is also given below. DataFrame Class: #include
using namespace std; class DataFrame {
protected:
int** table;
int noRows, noCols;
char** colNames;
char** rowNames;
public:
//Constructors
DataFrame ();
DataFrame (int rows, int cols);
//Output Method
void display();
//Setters
void setRowName(int row, char* name); void setColName(int col, char* name); int* operator[] (int i); //get row i;
//Getters
char** getRowNames();
char** getColNames();
int getNumberRows();
int getNumberCols();
DataFrame* getColumns(int* columns, int cLen);
DataFrame* getRows(int* rows, int rLen);
DataFrame* getRowsCols(int* rows, int rLen, int* cols, int cLen);
//Destructor
~DataFrame(); };
The main function: int main () { int c, r;
int selectC[3];
int selectR[10]; // Read the dataframe from input
// First line: two numbers seperated by space;
// first number is the number of rows (r) and
// second number is the number of columns (c) cin >> r >> c;
DataFrame* firstDF = new DataFrame(r,c);
// Second line: strings seperated by a comma (c of them); representing column names
// Third line: strings seperated by a comma (r of them); representing row names
// Fourth line and more: c number of integers in each of the r rows (seperated by)
// a space between integers in the same row.
// TODO: Student completes code for the above comment block
// using the display method, print (in the same format as the input):
// - the column names of the dataframe
// - the row names of the dataframe
// - the contents of the table in dataframe
// TODO: Student completes code for the above comment block // Execute the following code
// Read the column numbers that you want to extract
for (int i=0; i < 3; i++)
cin >> selectC[i];
DataFrame* tempColumns = (*firstDF).getColumns(selectC, 3);
(*tempColumns).display(); // Change the row names of select rows (*tempColumns).setRowName(2, "Jack");
(*tempColumns).setRowName(3, "Peter"); (*tempColumns).display(); // Read the row numbers that you want to extract for (int i=0; i < 10; i++)
cin >> selectR[i]; DataFrame* tempRows = (*firstDF).getRows(selectR, 10); (*tempRows).display();
// Change the column names of selected columns (*tempRows).setColName(2, "Scores");
(*tempRows).setColName(3, "Values");
(*tempRows).display();
// Extract the rows in SelectR and columns in SelectC DataFrame* tempColsRows = (*firstDF).getRowsCols(selectR, 10, selectC, 3); (*tempColsRows).display(); delete tempRows;
delete tempColumns;
delete tempColsRows;
// Sample Code for you and you must execute this DataFrame* myTable = new DataFrame(5,5); for (int i = 0; i < 5; i++) {
for (int j=0; j < 5; j++) {
(*myTable)[i][j] = i*j;
}
} (*myTable).display(); delete myTable;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started