Question
After the portion of the code where you have removed the duplicates from the database file sort the data by the department field first and
After the portion of the code where you have removed the duplicates from the database file sort the data by the department field first and the item code field second in ascending order.
After writing your sorted data to the output file, output a tabular style report to standard output (do not output the report to a file).
Include in your report the appropriate headers for each column. You may assume that the report will print in portrait mode on a standard 8.5 x 11 sheet of paper. As an example:
Department Item Code Quantity Cost Total ________________________________________________________________ Outdoors 13107-070 257 2.71 696.47 Computers 66389-0001 948 94.43 89519.64 Movies 53808-0776 278 65.75 18278.50
Center the titles in each header. Left justify the data in each column with the exception of the floating point columns which are right justified. Floating point numbers should be displayed to two decimal places. The data should fit on in the portrait format. The total column is the result of the (quantity times the cost).
Do not design your program to the provided data file. Your submitted program will be run against other files of the same format.
data-base.csv
Some suggestions:
Read section B.5.4 of Programming Principles and Practice Using C++
Use the sort() function
If you created a class to hold a single data record then override the
PROGRAM BELOW
-----Record.h-------
#ifndef RECORD_H_ #define RECORD_H_ using namespace std; class Record { public: Record(std::string s); virtual ~Record(); friend bool operator ==(const Record &a, const Record &b); //friend bool operator
-------Record.cpp--------
#include
#include
#include "Record.h"
using namespace std;
#include
Record::Record(std::string s) {
// TODO Auto-generated constructor stub
//initializing private variables
int ind1=s.find(",");
int ind2=s.find(",",ind1+1);
department = s.substr(ind1+1,ind2-ind1);
ind1=ind2+1;
ind2=s.find(",", ind1+1);
item_code = s.substr(ind1, ind2-ind1);
ind1 = ind2+1;
ind2 = s.find(ind1,ind2-ind1);
quantity = atoi(s.substr(ind1, ind2-ind1).c_str()); //string to int
ind1=ind2+1;
cost = atof(s.substr(ind1).c_str()); //string to double
}
Record::~Record() {
// TODO Auto-generated destructor stub
}
// == operator overloading
bool operator ==(const Record &a, const Record &b) {
if (a.department == b.department && a.item_code == b.item_code
&& a.quantity == b.quantity && a.cost == b.cost)
return true;
else
return false;
}
//
std::ostream& operator
out
return out;
}
-------Main.cpp-------
#include
#include
#include
#include
#include
#include "Record.h"
using namespace std;
int main() {
vector records;
string filename;
cout
endl;
cin >> filename;
ifstream ifs(filename.c_str());
if(ifs){
cerr
return 1;
}
string line;
while(getline(ifs, line)){
records.push_back(Record(line));
}
ifs.close();
for (int i = 0; i
bool valid = false;
for (int j = 0; j
if(records[j] == records[i]){
valid = true;
break;
}
}
if(!valid)
i++;
else
records.erase(records.begin()+i); //delete if duplicate
}
//create output file
int index = filename.find_last_of("/");
string outfilename;
if(index == string::npos)
outfilename = "new_" + filename;
else
outfilename = filename.substr(0, index) + "ew_"
+filename.substr(index+1);
ofstream outfile(outfilename.c_str());
if(outfile.fail())
{
cout
return 1;
}
for(int i =0; i
{
outfile
}
outfile.close();
cout
return 0;
}
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