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;
}

Please indicate what line your compiler indicatecd the error was associated with. The actual error may not be on that line, but it's usually pretty close if it isn't.

Lerner. Thanks. lines 80.... .cpp and 240 where I test it. The way it is now. it compiles, but always returns false no matter how I set the dates. I just don't know how to figure the right parameters I think.

For the code I wrote, the input---12/33/44 would be invalid because it needs to be of the form 99/99/9999. So you could add additional logic to isValid to be sure the input string is 10 char long, not more and not less. That means 1/1/2200 would be wrong too, it should 01/01/2200 in order for the code I wrote to work. Even then, as I said before, the current version of this function won't invalidate this input--12/33/1944. Obviously December doesn't have 33 days in any year. That's where the additional logic I recommended comes in, if you want to include it.

Wow....OOOOPPS huge oversight on my part......I'm burned on this thing - Thnks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.