#include #include #include #include "CStr.hpp" #include "cmenu.hpp" #include "spitball.hpp" extern int num_commands; extern CMenu *commands[]; void Init_Commands(void) { commands[0] = new CMenuBell; strcpy(commands[0]->title, "Sound a bell.\n"); commands[1] = new CMenuSaying; strcpy(commands[1]->title, "Print a wise saying.\n"); commands[2] = new CMenuAdd; strcpy(commands[2]->title, "Add two numbers.\n"); num_commands = 3; } int main() { int i, sel; Init_Commands(); do { puts("\nMENU: \n"); for (i=0; ititle); printf("Enter a selection: "); scanf("%d", &sel); if (sel >= 0 && sel <= num_commands) commands[sel]->Do_Command(); }while (sel <= num_commands); try { // check for exceptions since constructors // can't return a value CStr string1, string2; string1.cpy("My name is "); string2.cpy("Burt."); string1.cat(string2.get()); printf("%s\n",string1.get()); CStr first("Burt"); //calls CStr::CStr(char *) CStr last = "Crockett"; //also calls CStr::CStr(char *) on var definition CStr name; name = first + " " + last; //calls operator= since not var definition CStr phrase = name + " was "; phrase += "here."; printf("%s\n",phrase.get()); printf("%s\n",name); // calls conversion function } catch (spitball gross) { printf("%s\n",gross); exit(-1); } return 0; }