CS 2413 Data Structures Programming Project 2 solved

$25.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (5 votes)

The goal of this project is to create extend the DataFrame class in C++ developed in Project 1 as
outlined in the project description. Document your project thoroughly as the examples in the
textbook (20 point penalty for poor documentation). This includes but not limited to brief header
comments for all classes/methods, explanatory comments for each section of code, meaningful
variable and method names, and consistent indentation.
Project Description
In this project you will create a new templated DataFrame class along with the all the methods
that are represented in the class definition. DataFrame is a table with rows and columns –
columns have names associated with them. Each row of the DataFrame is a single

(RowObject in this case), so the DataFrame maintains an array of pointers to RowObject. The
RowObject class is also defined below.
After you have tested your class, you have to execute the main program that is also given below.
RowObject Class
class RowObject { //Data from Leading Causes of Death in the USA
protected:
int ID;
int year;
char* causeName;
char* State;
int numberOfDeaths;
float averageAge;
public:
RowObject();
RowObject(int rid, int y, const char* cn, const char* s, int n, float age);
//write the ostream operator
//write the overloaded = operator for an extra 10 points
//write the destructor
};
DataFrame Class
template
class DataFrame {
protected:
DT** dataRows; // array of pointers to DT object
char** colNames;
int noRows, noCols;
public:
DataFrame ();
DataFrame(int numberOfRows, int numberOfColumns);
void display();
void display(int n); // display the first n records
void setColName(int col, const char* name);
DT& operator[] (int i); //get the ith row
char** getColNames();
int getNumberRows();
DataFrame* getRows(int* rows, int rLen);
void addRow(DT& newRow); // add a new row at the last row
void removeRow(int i); //remove the ith row
void insertRow(int position, DT& newRow);
void ~DataFrame();
//write the ostream operator
//write the = operator for an extra 10 points
};
The main function
// Write all the methods here and execute the following main program with some code that you
need to write.
int main () {
int noRows; //read the number of rows that needs to be read
DataFrame* DBT;
int selectR[10];
for (int i=0; i < 10; i++) { selectR[i] = i+2; } // Read the dataframe from input // First line: A single number indicating the number of rows to be read (not // including the header); In this case there are 5 columns (plus ID, see below) cin >> noRows;
DBT = new DataFrame(noRows, 5);
// Second line: strings separated by a comma (c of them); representing column names
// Third line and more: Each column values is separated by a COMMA and the
// last one by end of line
// Read the input; store the row number for each row read in ID
// ===== TODO =====
// Execute the following code
// Change the column names of selected columns
(*DBT).setColName(4, “Number Deaths”);
(*DBT).setColName(2, “Cause Name”);
cout << (*DBT);
// Extract the rows in SelectR
DataFrame* tempRows = (*DBT).getRows(selectR, 10);
(*tempRows).display();
// Code to test other methods
// Testing [] operator on DataFrame object and ostream on RowObject
cout << (*DBT)[4];
cout << (*DBT)[5];
cout << (*DBT)[10];
// Testing addRow, constructor for RowObject and getNumberRows method
RowObject* newRow;
newRow = new RowObject((*DBT).getNumberRows(),2018,”Cancer”,”Oklahoma”,200, 58.2);
(*DBT).addRow(*newRow);
// Testing destructor for RowObject
delete newRow;
newRow = new RowObject((*DBT).getNumberRows(),2018,”Opiod”,”Texas”,2000, 32.4);
(*DBT).addRow(*newRow);
delete newRow;
cout << (*DBT)[(*DBT).getNumberRows()-2];
cout << (*DBT)[(*DBT).getNumberRows()-1];
// Testing insertRow
newRow = new RowObject((*DBT).getNumberRows(),2016,”Cancer”,”Texas”,500, 72.1);
(*DBT).insertRow(1, *newRow);
delete newRow;
newRow = new RowObject((*DBT).getNumberRows(),2016,”Stroke”,”Oklahoma”,400, 68.1);
(*DBT).insertRow(4, *newRow);
delete newRow;
(*DBT).display(10);
// Testing removeRow
(*DBT).removeRow(1);
(*DBT).removeRow(3);
(*DBT).display(10);
// Extra Points 10 points for overloaded = operator for RowObject – uncomment to test
/* newRow = new RowObject((*DBT).getNumberRows(),2016,”Stroke”,”Arizona”,400, 68.1);
RowObject anotherOne;
anotherOne = newRow;
cout << anotherOne;
delete newRow; */
// Extra Points 10 points for overloaded = operator for DataFrame – uncomment to test
/* DataFrame newDF;
newDF = (*DBT);
newDF.display(10); */
delete DBT;
}
Constraints
1. In this project, the only header you will use is #include .
2. None of the projects is a group project. Consulting with other members of this class on
programming projects is strictly not allowed and plagiarism charges will be imposed on
students who do not follow this.