Question
C++ program involving file IO. I have a database file with comma separated values. The values are in the format (index, department, item code, quantity,
C++ program involving file IO. I have a database file with comma separated values. The values are in the format (index, department, item code, quantity, cost). There are duplicates in this database file. Read in the database, remove the duplicates, and write a new comma separated database file without the duplicates. The index field in the new file must be sequential and start at one. Do not design the program to the provided data file. The submitted program will be run against other files of the same format.
Program tasks:
Prompt the user for the database file name. This file name is the path and the file name. For example "/home/folder/database.csv". Do not assume the file is in a particular directory. Use a single prompt. Open the database Read in the records using a custom class to hold a record Remove the duplicates. Note: A duplicate is identified by all four fields being the same Write the scrubbed database as a new CSV file starting with 'new_' and the input database file name. Write the new file to the same directory that the database file was read from. For example "/home/folder/new_database.csv" The index field in the new file must be sequential and start at one.
Some suggestions:
Create a class to hold a single data record.
Override the == operator to ease comparison and override the << operator to output the comma separated values. Use the class constructor to receive a line from the database then parse the values or override the >> input operator. Modify the string stream getline() delimiter to a comma.
Use a vector to contain the data records. While the provided database file contains valid data be aware of potential errors from bad data records. Do not write the program just for the attached data file.
Here is the database file:
1,Outdoors,13107-070,257,2.71 2,Computers,66389-0001,948,94.43 3,Movies,53808-0776,278,65.75 4,Baby,41250-416,310,99.52 5,Toys,64058-413,783,45.65 6,Electronics,56062-422,219,20.95 7,Games,37808-453,478,41.23 8,Books,0268-1154,976,65.17 9,Toys,17089-075,484,67.69 10,Automotive,68788-9852,501,71.57 11,Electronics,37000-265,189,27.97 12,Jewelry,0527-1414,68,32.81 13,Toys,64092-113,450,55.23 14,Clothing,14783-015,975,97.03 15,Baby,68084-045,809,55.3 16,Music,42507-158,362,56.92 17,Games,36987-1476,203,36.95 18,Kids,50844-428,606,20.93 19,Baby,0781-5234,430,16.24 20,Automotive,0378-1049,82,81.32 21,Music,64679-701,487,28.77 22,Outdoors,63739-141,195,83.23 23,Books,0268-1154,976,65.17 24,Baby,76519-1003,430,16.24 25,Games,65342-1393,496,69.07 26,Electronics,0409-9630,797,92.55 27,Jewelery,33261-028,500,66.3 28,Computers,66336-058,375,84.16 29,Outdoors,51672-1330,128,68.85 30,Movies,53808-0776,278,65.75 31,Beauty,48951-8130,725,83.42 32,Baby,59779-224,848,82 33,Industrial,55711-070,753,46.48 34,Industrial,76446-002,272,89.03 35,Sports,68151-2870,185,2.86 36,Toys,0245-0709,783,45.65 37,Games,49999-963,523,93.65 38,Beauty,52125-508,500,2.38 39,Toys,54092-381,783,45.65 40,Beauty,55154-6649,666,79.52 41,Jewelry,57664-327,46,10.28 42,Grocery,49738-453,317,29 43,Grocery,68382-792,266,48.63 44,Outdoors,0268-6731,335,70.04 45,Beauty,68788-9494,12,16.81 46,Beauty,52125-508,500,2.38 47,Outdoors,33261-144,809,2.95 48,Computers,0641-6040,104,88.13 49,Automotive,0781-3059,577,95.24 50,Kids,60429-038,459,29.68 51,Sports,10578-024,185,2.86 52,Toys,64092-113,450,55.23 53,Jewelry,55111-586,297,53.61 54,Automotive,30142-289,282,33
Here is the program so far:
main.cpp:
#include
Record.h:
#ifndef RECORD_H_ #define RECORD_H_ //record class class Record{ public: //Constructor Record(std::string s); //De-constructor virtual ~Record(); //Overloaded == and < operators friend bool operator ==(const Record &a, const Record &b); friend bool operator <(const Record &a, const Record &b); //Overload << operator friend std::ostream& operator <<(std::ostream&, const Record&); private: std::string department; std::string item_code; int quantity; double cost; }; #endif
Record.cpp:
#include
using namespace std;
Record:Record(string s){
}
Record::~Record*(){
}
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