Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- //#include <fstream.h>
- #include <string.h>
- #include<cstdlib.h>
- using namespace std;
- void displayMenu ()
- {
- cout << "What would you like to do?" << endl;
- cout << "New -Creates a new data file" << endl;
- cout << "Open -Opens a data file" << endl;
- cout << "Report -Read a data file" << endl;
- cout << "Quit -Exits the program" << endl;
- }//end menu
- void trimTrailingSpace (char cmd1[])
- {
- int n;
- bool foundNonSpace;
- n = strlen(cmd1)-1;
- foundNonSpace = false;
- while (!foundNonSpace && n >= 0)
- {
- if (cmd1[n] != ' ')
- foundNonSpace=true;
- else
- n = n --;
- }//end while
- cmd1[n + 1] = '\0';
- }//end trailing
- void trimLeadingSpace (char cmd1[], char cmd2[])
- {
- int i= 0;
- int b=0;
- while (cmd1[i]==' ')
- {
- //cout<<"error";
- i++;//Eat leading white space
- }//end while
- while (cmd1[i] != '\0')
- {
- cmd2[b] = cmd1[i]; //Copy character over
- b++;
- i++;
- }//end while
- //cout<<"errorspace3";
- }//end leading
- void doNew ()
- {
- int a;
- int b;
- cout << "Enter Integer." << endl;
- cin >> a;
- for (b = 1; b <= a; b++)
- {
- cout << b << endl;
- }//end for
- }//end new
- void doOpen ()
- {
- cout << "You have selected Open." << endl;
- }//end open
- void doReport ()
- {
- cout << "You have selected Report." << endl;
- }//end report
- void doQuit ()
- {
- cout << "You have closed the program." << endl;
- }//end quit
- //--------------------------------------------------------
- int main ()
- {
- char cmd1[65];
- char cmd2[65];
- char newCommand[] = "new";
- char openCommand[] = "open";
- char reportCommand[] = "report";
- char quitCommand[] = "quit";
- displayMenu ();
- //cout<<"error1";
- cin.getline (cmd1, 65);
- //cout<<"error2";
- trimLeadingSpace (cmd1, cmd2);
- trimTrailingSpace (cmd2);
- //cout<<"error3";
- //trimLeadingSpace (cmd1, cmd2);
- while (stricmp(cmd2, quitCommand)!=0)
- {
- //cout << "Error While!" << endl; //error check
- if (stricmp(strstr(newCommand, cmd2), newCommand) == 0)
- {
- doNew ();
- //return 1;
- }
- else if (stricmp(strstr(openCommand, cmd2), openCommand) == 0)
- {
- cout << "Error: Open" << endl;
- doOpen ();
- //return 1;
- }
- else if (stricmp(strstr(reportCommand, cmd2), reportCommand) == 0)
- {
- doReport ();
- //return 1;
- }
- else
- {
- cout << "You have entered an invalid choice. " << endl;
- }
- strcpy(cmd1, "");
- displayMenu ();
- cin.getline (cmd1, 65);
- trimLeadingSpace (cmd1, cmd2);
- trimTrailingSpace (cmd2);
- }//end while
- while (stricmp(strstr(quitCommand, cmd2), quitCommand) == 0)
- {
- doQuit();
- return 0;
- }//end while
- }//end main
- //--------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment