Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is my loadData function in my Scheduler class: void Scheduler::LoadData ( const std::string& filename ) { std::ifstream inputFile ( filename ) ; if (

Here is my loadData function in my Scheduler class: void Scheduler::LoadData(const std::string& filename){
std::ifstream inputFile(filename);
if (!inputFile.is_open()){
std::cerr << "Error opening file: "<< filename << std::endl;
return;
}
std::string line;
while (std::getline(inputFile, line)){
std::stringstream ss(line);
std::string type;
std::getline(ss, type, ',');
if (type =="G"|| type =="H"){
std::string groomerFirstName, groomerLastName, groomerPhone;
std::string ownerFirstName, ownerLastName, ownerPhone;
std::string petName, petType;
double groomingPrice, haircutPrice;
std::string date, time;
// Read strings with ',' delimiter
std::getline(ss, groomerFirstName, ',');
std::getline(ss, groomerLastName, ',');
std::getline(ss, groomerPhone, ',');
std::getline(ss, ownerFirstName, ',');
std::getline(ss, ownerLastName, ',');
std::getline(ss, ownerPhone, ',');
std::getline(ss, petName, ',');
std::getline(ss, petType, ',');
ss >> groomingPrice;
if (type =="H"){
ss.ignore(); // Ignore the comma
ss >> haircutPrice;
}
std::getline(ss, date, ',');
std::getline(ss, time, ',');
// Assuming DateTime has SetDate and SetTime functions
DateTime dateTime;
dateTime.SetDate(date); // Make sure SetDate handles the "dd/mm/yyyy" format
dateTime.SetTime(time); // Assuming SetTime handles the "hh:mm am/pm" format
if (type =="G"){
std::shared_ptr groomingAppointment = std::make_shared(
Person(groomerFirstName, groomerLastName, groomerPhone),
Pet(ownerFirstName, ownerLastName, ownerPhone, petName, petType),
dateTime.GetDate(),// Use the GetDate function to retrieve the formatted date
dateTime.GetTime(),// Use the GetTime function to retrieve the formatted time
groomingPrice);
appointments_.push_back(groomingAppointment);
} else if (type =="H"){
std::shared_ptr haircutAppointment = std::make_shared(
Person(groomerFirstName, groomerLastName, groomerPhone),
Pet(ownerFirstName, ownerLastName, ownerPhone, petName, petType),
dateTime.GetDate(),// Use the GetDate function to retrieve the formatted date
dateTime.GetTime(),// Use the GetTime function to retrieve the formatted time
groomingPrice,
haircutPrice);
appointments_.push_back(haircutAppointment);
}
}
}
inputFile.close(); Here is my SetDate function in the DateTime class: void DateTime::SetDate(const std::string& date){
std::istringstream dateStream(date);
char delimiter;
// Try parsing with '/' as delimiter
dateStream >> day_>> delimiter >> month_>> delimiter >> year_;
// If parsing fails, reset the stream position and try parsing with ',' as delimiter
if (dateStream.fail()){
dateStream.clear();
dateStream.seekg(0);
// Try parsing with ',' as delimiter
dateStream >> day_>> delimiter >> month_>> delimiter >> year_;
}
// If parsing still fails, reset the stream position and try parsing with '-' as delimiter
if (dateStream.fail()){
dateStream.clear();
dateStream.seekg(0);
// Try parsing with '-' as delimiter
dateStream >> day_>> delimiter >> month_>> delimiter >> year_;
}
std::cerr << "Parsed date: month="<< month_<<", day="<< day_<<", year="<< year_<< std::endl;
}. My issue is when I run the program the date gets printed as 00/00/0000 instead of the actual date. Can anyone see why? Is it a parsing issue? Thanks.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions