Hey out there. Lerner had given me some great ideas for searching (scouring) a string. Only problem I'm having now is I can't get past the error for 'cannot convert const to a std' I also don't think I can use this function like I am within my prgm (at least the arguments are wrong)
Can someone help with this? This isDateValid() should work to verify my date structure. Due in the A.M. thanks!
Input validation can be a challenge, depending how nitpicky you want to be. Since your input format is so specific I'd suggest a grind it out char by char analysis. Maybe something along this lines:
(Toggle Plain Text)
bool isValidDate(stringType input)---->>>>>??????? (i'm just using a test file)
{
bool result = true;
//ensure each placeholder in input is a valid char
int numerals[8] = {0, 1, 3, 4, 6, 7, 8, 9)
if(input[2] != '/' || input[5] != '/')
result = false;
for(int i = 0; i < 7; ++i)
if(!isdigit(input[numerals[i]]))
result = false;
//parse input into 3 ints representing day, month, year
//now validate that day, month and year are valid integer values for using a calendar. For example
99/99/9999 would not be valid eventhough each char is valid.
return result;
}
#ifndef appt_h
#define appt_h
#include "ListA.h"
using namespace std; //PROJECT 1
class AppointmentBook
{
public:
AppointmentBook();
AppointmentBook::AppointmentBook(string the_date, string the_time, string the_purpose);
void cancelAppointment(string the_date, string the_time, bool &success);
void checkAppointment(string the_date, string the_time , string &the_purpose, bool &success);
void makeAppointment(string the_date, string the_time, string the_purpose, bool &success);
bool isAppointment(string the_date, string the_time);
bool isValidDate(string the_date);
//bool isValidTime(string the_time);
void display();
private:
List myAppList;
};
#endif
#include "appt.h"
#include <iostream>
using namespace std; //PROJECT 1
//Project 1
AppointmentBook::AppointmentBook()
{
}
AppointmentBook::AppointmentBook(string the_date, string the_time, string the_purpose)
{
bool success = false;
makeAppointment(the_date, the_time, the_purpose, success);
}
bool AppointmentBook::isValidDate(string the_date)
{
bool result = true;
int numerals[8] = {0,1,3,4,6,7,8};
{
if(the_date[2] == '/' || the_date[5] == '/')
{
result = true;
}
for(int i = 0; i < 7; i ++)
{
if(!isdigit(the_date[numerals[i]]))
{
result = false;
}
}
}
return 0;
}
void AppointmentBook::makeAppointment(string the_date, string the_time, string the_purpose, bool &success)
{
if(isAppointment(the_date, the_time))
{
success = false;
return;
}
ListItemType page;
page.date = the_date;
page.time = the_time;
page.purpose = the_purpose;
myAppList.insert(1, page, success);
}
bool AppointmentBook::isAppointment(string the_date, string the_time)
{
if(myAppList.getLength() == 0)
{
return false;
}
bool success = true;
ListItemType data;
for(int i = 1; i <= myAppList.getLength(); i ++)
{
myAppList.retrieve(i, data, success);
if(the_date == data.date && the_time == data.time)
{
return true;
}
}
}
void AppointmentBook::cancelAppointment(string the_date, string the_time, bool &success)
{
if(!isAppointment(the_date, the_time))
{
success = false;
}
else
{
ListItemType data;
for(int i = 1; i <= myAppList.getLength(); i ++)
{
myAppList.retrieve(i, data, success);
if(data.date == the_date && data.time == the_time)
{
myAppList.remove(i, success);
}
return;
}
}
}
void AppointmentBook::checkAppointment(string the_date, string the_time, string &the_purpose, bool &success)
{
ListItemType data;
if(!isAppointment(the_date, the_time))
{
success = false;
}
else
{
for(int i = 1; i <= myAppList.getLength(); i++)
{
myAppList.retrieve(i, data, success);
if(data.date == the_date && data.time == the_time)
{
the_purpose = data.purpose;
}
}
}
return;
}
void AppointmentBook::display()
{
bool success = true;
ListItemType data;
for(int i = 1; i <= myAppList.getLength(); i ++)
{
myAppList.retrieve(i, data, success);
cout << "Date: " << data.date <<" " << endl;
cout << "Time: " << data.time <<" " << endl;
cout << "Purpose: " << data.purpose << " " << endl;
}
}
#include <iostream>
#include "appt.h"
#include <string>
//using namespace std;
int main()
{
string the_purpose, the_date, the_time;
bool success;
cout << "Overloaded constructor taking values for arguments" << endl;
cout << endl;
AppointmentBook tester( "12/31/40", "11:00","do stufffff");
tester.display();
tester.isAppointment(the_date, the_time);
cout <<"'Make'checks to verify if there is an appointment, then will insert" << endl;
cout << "a new appointment"<< endl;
cout << endl;
tester.makeAppointment("11/29/44", "11:02", "do stuff", success);
tester.display();
cout << "Successfully inserted" << endl;
cout << endl;
tester.isValidDate("12/33/44");
cout << "'Cancel' checks to see if there is an appointment" << endl;
cout <<"that matches what it 'looks' for"<< endl;
cout << "and if 'found', removes it" << endl;
cout << endl;
tester.cancelAppointment("11/29/44", "11:02", success);
tester.display();
cout << "Found appointment 11/29 and successfully removed it" << endl;
cout << "Now making appointment again to demonstrate an unsuccessful removal" << endl;
cout << endl;
tester.makeAppointment("11/29/44", "11:02", "do stuff", success);
tester.cancelAppointment("11/28/44", "11:02", success);
tester.display();
cout <<"The following demonstrates same appointments still exist; therefore" << endl;
cout <<"no removal occured:" << endl;
cout << endl;
cout << "'Check' verifies if a 'same' appointment '12/31' exists," << endl;
cout << "then 'writes down' its corresponding purpose" << endl;
cout << endl;
tester.checkAppointment("12/31/40", "11:00", the_purpose, success);
cout << the_purpose << endl;
cout << "Found and successfully copied purpose 'do stuffff'" << endl;
system("pause");
return 0;
}