int ValidMoney(char *Mon, Screen *scr){ int ok = 1; double val; char junk; int ret; ret = sscanf(Mon, "%lf%c", &val, &junk); if(ret != 1){ ok = 0; strcpy((char *)scr->getField(1)->data(), "Ivalid Number, please enter digits only"); } else{ if(val<1000 || val > 30000){ ok = 0; strcpy((char *)scr->getField(1)->data(), "Valid values are between and including 1000 and 30000"); } } if(ok){ strcpy((char *)scr->getField(1)->data(), ""); } scr->getField(1)->display(); return ok; } int ValidPhone(char *PhNo, Screen *scr){ int ok = *PhNo++ == '('; int i; for(i=0;ok && i<3;i++){ ok = ok && isdigit(*PhNo++); } ok = ok && *PhNo++ == ')'; ok = ok && *PhNo++ == ' '; for(i=0;ok && i<3;i++){ ok = ok && isdigit(*PhNo++); } ok = ok && *PhNo++ == '-'; for(i=0;ok && i<4;i++){ ok = ok && isdigit(*PhNo++); } ok = ok && *PhNo == 0; if(!ok){ strcpy((char *)scr->getField(1)->data(), "Ivnvalid Phone No. Enter Only as: (999) 999-9999"); } else{ strcpy((char *)scr->getField(1)->data(), ""); } scr->getField(1)->display(); return ok; } struct Resort{ double weeklyPrice; char name[41], location[31], country[29], agentPhone[15]; }; class ResortBrowser{ Screen ResScr, welcome, message, HelpScr; Resort cur; Resort R[100]; int rnum, RSFnum, insert, ResNum, pageno, nameno, locno, ctryno, phonno, priceno; void MakeHelpScr(){ HelpScr.add(Label(1,1,50," ")); HelpScr.add(Label(2,1,50," Help Screen--- ")); HelpScr.add(Label(3,1,50," ")); HelpScr.add(Label(4,1,50," F1: Help Screen ")); HelpScr.add(Label(5,1,50," F2: Apply changes to current resort ")); HelpScr.add(Label(6,1,50," F3: Add new resort to the end of list (AS5) ")); HelpScr.add(Label(7,1,50," ")); HelpScr.add(Label(8,1,50," F5: Delete currect resort (AS5) ")); HelpScr.add(Label(9,1,50," ")); HelpScr.add(Label(10,1,50," F9: Save all to file (BY YOU FOR AS5) ")); HelpScr.add(Label(11,1,50," F10: Load all from file (BY YOU FOR AS5) ")); HelpScr.add(Label(12,1,50," F12: Exit the program ")); HelpScr.add(Label(13,1,50," ")); } void MakeResScr(){ ResScr.add(Label(17, 2, 52)); // 1 error ResScr.add(Label(18, 2, 52)); // 2 message (never used) ResScr.add(Label(0,1,dtioColumns(),"F1:Help PG_DN:Next PG_UP:Previous ESC_KEY:Undo Changes")); ResScr.add(Label(2,18,40, "Resort Browser Rec No:")); pageno = ResScr.add(Label(2,58,5)) - 1; ResScr.add(Label( 4, 3, 13, "Resort Name:")); nameno = ResScr.add(Field(4, 16,40)) - 1; ResScr.add(Label(6, 3, 10,"Location:")); locno = ResScr.add(Field(6, 13, 31)) - 1; ResScr.add(Label( 8, 3, 10, "Country:")); ctryno = ResScr.add(Field( 8, 12, 28)) - 1; ResScr.add(Label( 10, 3, 16, "Agent Phone No:")); phonno = ResScr.add(VField(10, 19, 14,"",ValidPhone)) - 1; ResScr.add(Label(12, 3, 15, "Weekly Price: ")); priceno = ResScr.add(VField(12, 19, 15, "", ValidMoney)) - 1; } void SetResort(Resort &R){ char price[15]; sprintf(price,"%.02lf",R.weeklyPrice); strcpy((char *)ResScr.getField(nameno)->data(),R.name); strcpy((char *)ResScr.getField(locno)->data(),R.location); strcpy((char *)ResScr.getField(ctryno)->data(),R.country); strcpy((char *)ResScr.getField(phonno)->data(),R.agentPhone); strcpy((char *)ResScr.getField(priceno)->data(),price); } void SetPageNo(int p){ char pn[10]; sprintf(pn,"%03d", p); strcpy((char *)ResScr.getField(pageno)->data(), pn); } void GetResort(Resort &R){ strcpy(R.name,(char *)ResScr.getField(nameno)->data()); strcpy(R.location,(char *)ResScr.getField(locno)->data()); strcpy(R.country,(char *)ResScr.getField(ctryno)->data()); strcpy(R.agentPhone,(char *)ResScr.getField(phonno)->data()); sscanf((char *)ResScr.getField(priceno)->data(),"%lf",&R.weeklyPrice); } void MakeWelcomeScreen(){ welcome.add(Label(5, dtioColumns()/2-16, dtioColumns(),"Assignment4 main")); welcome.add(Label(10, 10,dtioColumns(),"Please use this program to test your screen.cpp and screen.h")); welcome.add(Label(12, 10,dtioColumns(),"Press F1 to see the help window at anytime (except now!)")); welcome.add(Label(20, 10,dtioColumns(),"Press any key to conitue...")); welcome.display(); } void MakeMessage(){ message.add(Label(1,1,dtioColumns()-1)); message.add(Label(2, 1, dtioColumns()-1)); message.add(Label(3,1,dtioColumns()-1)); message.add(Label(4, 1, dtioColumns()-1)); } int MsgBox(const char *mes,const char *lead=" Press any key"){ strcpy((char *)message.getField(1)->data(),mes); strcpy((char *)message.getField(3)->data(),lead); message.edit(true); return dtioGetchar(); } void ShowWelcome(){ welcome.edit(true); dtioGetchar(); } void ShowHelp(){ HelpScr.edit(true); dtioGetchar(); } public: ResortBrowser(Resort *res, int ResSize) { RSFnum = 1; ResNum = ResSize; insert = 1; for(int i=0;i0) curfld--; SetResort(R[curfld]); break; case F(1): ShowHelp(); break; case F(2): ans = MsgBox(" Apply changes?", " (Y)es or (N)o"); if(ans == 'y' || ans == 'Y'){ GetResort(R[curfld]); MsgBox(" Data Saved"); } break; case F(3): MsgBox(" Add a blank new record to the end of list.", " This is to be done for assignment 5 by you"); break; case F(5): MsgBox(" Delete the currect record.", " This is to be done for assignment 5 by you"); break; case F(9): MsgBox(" Save all the resorts in the binary file", " This is to be done for assignment 5 by you"); break; case F(10): MsgBox(" Load all the saved resrots into the program", " This is to be done for assignment 5 by you"); break; case ESCAPE: SetResort(R[curfld]); break; case F(12): ans = MsgBox(" Exit Program?", " (Y)es or (N)o"); done = (ans == 'y' || ans == 'Y'); break; } } } }; int main(void){ Resort R[100] = { {1267.45, "Barcelo Marina Palace", "Varadero", "Cuba", "(416) 234-2345"}, {2159.99, "Iberostar", "Varadero", "Cuba", "(416) 234-2346"}, {2400.26, "Golden Crown Paradise Spa", "Cancun", "Mexico", "(416) 234-2444"}, {2899.54, "Secrets Excellence All Suites Resort", "Punta Cana", "Domincan Republic", "(416) 234-2347"}, {1849.64, "Melia Cayo Coco", "Cayo Coco", "Cuba", "(416) 234-2347"}, {1889.84, "ventura Spa Palace", "Mayan Riviera", "Mexico", "(416) 254-5547"}, {3849.04, "El Dorado Seaside Suites", "Mayan Riviera", "Mexico", "(416) 254-2527"} }; dtioStart(); ResortBrowser rb(R, 7); rb.run(); dtioStop(); };