GUI Programming in Visual C++?

This is a discussion on GUI Programming in Visual C++? within the C++ Programming forums, part of the General Programming Boards category; ...hi guys, for my A-Level computing coursework i need to design and implement a computerised system for a company or ...

  1. #1
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147

    GUI Programming in Visual C++?

    ...hi guys, for my A-Level computing coursework i need to design and implement a computerised system for a company or organisation. ive already choosen what im going to do, and what language im going to program it in. since i hate Microsoft Access.

    question is is, ive done previous programming in C++ using Dev-C++. however i could only use the console window. this time i would like to produce a more "rounded" system with a GUI. would i be able to transfer my knowledge to programming GUI's or do i need to learn some more before i attempt it? bearing in mind i need to have a completed system by February/March time.

    heres a copy of my previous years coursework, just to give you an idea of where im at in C++.

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <stdio.h>
    #include <fstream>
    using namespace std;
    
    //Declerations data stucure for bookers.
    struct booker
    {
         string name;
         string address;
         string addresstwo;
         string town;
         string county;
         string postcode;
         string tel_no;
         int fee_owed;
    };
    
    //Decleration of data structure for bookings.
    struct booking
    {
         int booker_id;
         int week, day, time;       
         string event_title;
         bool fee_paid;
    };      
    
    int main(int argc, char *argv[])
    {
    
    //Decleation of seperate, data structured arrays.
        booker bookers[50];
        booking bookings[50];
    
    //Decleration of misselanious variables.
      string event_title;
      int i, x, menu, submenu, ID, week, day, time, subanswer, money_total = 0;  
      int number_of_bookers = 1, number_of_bookings = 1, subanswertwo;
      string buffer;
      HANDLE hOut;
      COORD Position;
      hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    ofstream print; // stream variable declaration
    print.open("LPT1"); // open stream 
     
    int monp1 = 0, monp2 = 0, monp3 = 0, monp4 = 0;
    int tuep1 = 0, tuep2 = 0, tuep3 = 0, tuep4 = 0;
    int wedp1 = 0, wedp2 = 0, wedp3 = 0, wedp4 = 0;
    int thup1 = 0, thup2 = 0, thup3 = 0, thup4 = 0;
    int frip1 = 0, frip2 = 0, frip3 = 0, frip4 = 0;
    int satp1 = 0, satp2 = 0, satp3 = 0, satp4 = 0;
    
    //Function prototypes.
    int SaveBookersFile(booker*, int);
    int SaveBookers(booker*, int);
    int SaveBookingsFile(booking* , int);
    int UpdateMasterFile(int, int, int);
    
    //Small algorithm to pre-set selected variables to 0.
     for(i=1; i<50; i++){
              bookers[i].fee_owed = 0;
              bookings[i].booker_id = 0;
              };
    
    //Opening of masterfile for reading and storing in variables.
      ifstream master_file ("filesize.dat");
      master_file >> number_of_bookers;
      master_file >> number_of_bookings;
      master_file >> money_total;
      master_file.close();
    
    //Opening of bookers file for reading and feeding into bookers array.
      ifstream bookers_file ("bookers.dat");
      for(i=1; i<=number_of_bookers; i++)
      {
            bookers_file >> bookers[i].name;
            bookers_file >> bookers[i].address;
            bookers_file >> bookers[i].addresstwo;
            bookers_file >> bookers[i].town;
            bookers_file >> bookers[i].county;
            bookers_file >> bookers[i].postcode;
            bookers_file >> bookers[i].tel_no;
            bookers_file >> bookers[i].fee_owed;
      }   
            bookers_file.close();
    
    //Opening of bookings file for reading and feeding into bookings array.
     ifstream bookings_file ("bookings.dat"); 
     for(i=1; i<=number_of_bookings; i++)
      {
            bookings_file >> bookings[i].booker_id;
            bookings_file >> bookings[i].week;
            bookings_file >> bookings[i].day;
            bookings_file >> bookings[i].time;
            bookings_file >> bookings[i].event_title;
            bookings_file >> bookings[i].fee_paid;
      }   
            bookings_file.close();        
    
    //Beginning of program loop, firstly displaying menu options.
    while(menu != 8){
      system("color 1f");
      system("cls");
      cout << "Welcome To The Village Hall   " << endl;
      cout << endl;
      cout << "1) = Create Bookings          " << endl;
      cout << "2) = Edit/View Booker Details " << endl;
      cout << "3) = View Time Slots          " << endl;
      cout << "4) = Billings                 " << endl;
      cout << "5) = Usage Stats              " << endl;
      cout << "6) = Delete Bookers/Bookings  " << endl;
      cout << "7) = Regular Bookings         " << endl;
      cout << "8) = Quit Program             " << endl;
      cout << "                              : ";
      getline(cin,buffer,'\n'); 
      menu = atoi(buffer.c_str());
      system("cls");
    
    //Main switch statement for menu options.
      switch(menu){
    
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
      case 1:
           while(submenu != 3){
    
    //Creating a booking menu
           bookings:
           system("cls");
           cout << "Create a Booking..." << endl;
           cout << endl;
           cout << "1) = I Need To Create A New Booker" << endl;
           cout << "2) = Enter Booker ID" << endl;
           cout << "3) = Go Back To Menu" << endl;
           cout << "                          : ";
           getline(cin,buffer,'\n'); 
           submenu = atoi(buffer.c_str());
    
           if(submenu > 3 || submenu < 1){
           cout << "Sorry, invalid menu option !!!" << endl;
           Sleep(1500);
           break;
           }
           system("cls");
    
    //Switch statement for submenus of creating a booking.
         switch(submenu)
         {//Switch (Submenu)
    
    //Bookers variables are entered through keyboard.
         case 1:
              cout << "Please Enter The Following..." << endl;
              cout << endl;
              cout << "Name Of Individual Or Society : ";
              getline(cin,bookers[number_of_bookers].name,'\n');
              cout << "Address                       : ";
              getline(cin,bookers[number_of_bookers].address,'\n');
              cout << "Address Line Two              : ";
              getline(cin,bookers[number_of_bookers].addresstwo,'\n');
              cout << "Town                          : ";
              getline(cin,bookers[number_of_bookers].town,'\n');
              cout << "County                        : ";
              getline(cin,bookers[number_of_bookers].county,'\n');
              cout << "Postcode                      : ";
              getline(cin,bookers[number_of_bookers].postcode,'\n');
              cout << "Telephone Number              : ";
              getline(cin,bookers[number_of_bookers].tel_no,'\n');
              cout << endl;
              cout << "Your Booker ID Is            ** " << number_of_bookers << " **" << endl;
              cout << endl;
              system("PAUSE");
              SaveBookersFile(bookers, number_of_bookers);   //New booker is saved.
              number_of_bookers++;                          //Number of bookers is incremented by 1.
              UpdateMasterFile(number_of_bookers, number_of_bookings, money_total);
              break;              //Masterfile is updated of changes.
    
    //Secondary submenu for booking with ID number.
         case 2:
    
              //Bookers ID is entered.
              while(ID >= number_of_bookers){
              system("cls");
              cout << "Please Enter Booker ID     : ";
              getline(cin,buffer,'\n'); 
              ID = atoi(buffer.c_str());
              }    
    
              //Proposed booking slot week of month is entered.
              week = 0;
              while(week > 4 || week < 1){
              system("cls");
              cout << "1 = 1st Week, 2 = 2nd Week, 3 = 3rd Week, 4 = 4th Week" << endl;
              cout << "Week   (if applicable)        : ";
              getline(cin,buffer,'\n'); 
              week = atoi(buffer.c_str());
              }
              
              //Proposed booking slot day of week is entered.
              day = 0;
              while(day > 6 || day < 1){
              system("cls");
              cout << "1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat" << endl;
              cout << "Day                           : ";          
              getline(cin,buffer,'\n'); 
              day = atoi(buffer.c_str()); 
              }
              
              //Proposed booking slot time of day is entered.
              time = 0;
              while(time > 4 || time < 1){
              system("cls");
              cout << "(9am-12:30pm) (1:30-5pm)   (6pm-9:30pm)   (6pm-11.30pm)" << endl; 
              cout << "1 = Morning, 2 = Evening, 3 = Afternoon, 4 = + Extension" << endl;
              cout << "                                         (Fri + Sat Only)" << endl;
              cout << "Period                        : ";
              getline(cin,buffer,'\n'); 
              time = atoi(buffer.c_str());
              }
    
    //Statement to check and issue an error message if booking an invalid extension.
    if(day != 5 && day != 6 && time == 4){ 
              system("cls");
              cout << "Sorry, Extensions are Fri and Sat only!" << endl;
              system("PAUSE");
              break;}
    
    //Statement to check whether a discount is available.
    if(day == 5 && time == 4 || day == 6 && time == 4){
            cout << "Is This A Silver/Golden Wedding Or An 18th Birthday" << endl;
            cout << "1 = Yes, 2 = No" << endl;
            getline(cin,buffer,'\n'); 
            subanswer = atoi(buffer.c_str());
            };
    
    //Algorithm to check if proposed booking slot is free or not.
    for(i=1; i<=number_of_bookings; i++){
    if(bookings[i].week == week && bookings[i].day == day && bookings[i].time == time && bookings[i].booker_id >= 1){
    cout << "Sorry, " << bookers[bookings[i].booker_id].name << " has this time slot" << endl;
           system("PAUSE");
              goto bookings; } }
    
            //Title of event is entered.
            system("cls");
            cout << "Title Of The Event            : ";
            getline(cin,bookings[number_of_bookings].event_title,'\n');
            cout << endl;
    
            //Selection of if the fee has been paid or is to be billed.
            cout << "Fee Paid         = 1" << endl;
            cout << "Fee to be Billed = 0" << endl;
            cout << endl;
            getline(cin,buffer,'\n');
            bookings[number_of_bookings].fee_paid = atoi(buffer.c_str());
    
    //Algorithm to check if fee is not paid and to add appropriate amount to account.
            if(bookings[number_of_bookings].fee_paid == 0){
            switch(time){//switch
            case 1:
                 bookers[ID].fee_owed += 12;
                 money_total += 12;
                 break;
            case 2:
                 bookers[ID].fee_owed += 12;
                 money_total += 12;
                 break;
            case 3:
                 bookers[ID].fee_owed += 15;
                 money_total += 15;
                 break;
            case 4:
                 if(subanswer == 1){
                 bookers[ID].fee_owed += 10;
                 money_total += 10;
                 break;
                 };
                 if(subanswer == 2){
                 bookers[ID].fee_owed += 20;
                 money_total += 20;
                 break;
                 };}; };  
    
           //Bookings variables are entered into appropriate array slot.
           bookings[number_of_bookings].day = day;
           bookings[number_of_bookings].time = time;
           bookings[number_of_bookings].week = week;
           bookings[number_of_bookings].booker_id = ID;
    
           //Booking is saved.
           SaveBookersFile(bookers, number_of_bookers);
           SaveBookingsFile(bookings, number_of_bookings);
           number_of_bookings++;   
           UpdateMasterFile(number_of_bookers, number_of_bookings, money_total);   
    
              }//while(submenu != 3)   
         }//Switch (Submenu)
    
          //Submenu answer is set to zero to avoid selection errors.
          submenu = 0;
          break;
    
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        //Menu selection for edit/viewing bookers details.
        case 2:
           while(subanswer > 3 || subanswer < 1){
           cout << "Edit/View Booker Details" << endl;
           cout << endl;
           cout << "1 = View, 2 = Edit, 3 = Go To Menu" << endl;
           getline(cin,buffer,'\n'); 
           subanswer = atoi(buffer.c_str());
           system("cls");
           }
    
      //Switch statement for submenus of above.
      switch(subanswer){
    
    //Submenu for viewing bookers details.
         case 1:
    
            //Booker ID is entered.
            while(ID >= number_of_bookers){
            cout << "Please Enter Booker ID        : ";
            getline(cin,buffer,'\n'); 
            ID = atoi(buffer.c_str());
            }
    
            //Bookers details are displayed.
            cout << "Name Of Individual Or Society : ";
            cout << bookers[ID].name << endl;
            cout << "Address                       : ";
            cout << bookers[ID].address << endl;
            cout << "Address(2)                    : ";
            cout << bookers[ID].addresstwo << endl;
            cout << "Town                          : ";
            cout << bookers[ID].town << endl;
            cout << "County                        : ";
            cout << bookers[ID].county << endl;
            cout << "Postcode                      : ";
            cout << bookers[ID].postcode << endl;
            cout << "Telephone Number              : ";
            cout << bookers[ID].tel_no << endl;
            cout << "Fee Owed                      : ";
            cout << bookers[ID].fee_owed << endl;
            cout << endl;
            system("PAUSE");
            break;
    
    //Submenu for editing bookers details.
         case 2:
    
            //Bookers ID is entered.
            while(ID >= number_of_bookers || ID <= 0){
            cout << "Please Enter Booker ID        : ";
            getline(cin,buffer,'\n'); 
            ID = atoi(buffer.c_str());
            system("cls");
            }
    
            //Bookers ID is opened for editing.
            cout << "Name Of Individual Or Society : ";
            getline(cin,bookers[ID].name,'\n');
            cout << "Address                       : ";
            getline(cin,bookers[ID].address,'\n');
            cout << "Address Line Two              : ";
            getline(cin,bookers[ID].addresstwo,'\n');
            cout << "Town                          : ";
            getline(cin,bookers[ID].town,'\n');
            cout << "County                        : ";
            getline(cin,bookers[ID].county,'\n');
            cout << "Postcode                      : ";
            getline(cin,bookers[ID].postcode,'\n');
            cout << "Telephone Number              : ";
            getline(cin,bookers[ID].tel_no,'\n');
            SaveBookers(bookers, number_of_bookers);
            break;
    
    //Submenu option to return to main menu.
         case 3:
            break;
    
    }//switch (subanswer)
            break;
    
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    //Menu option to display time slots.
      case 3:
           print << "View Time Slots" << endl;
                  print << endl;
                  print << "!Every Slot FREE Unless Stated Otherwise!" << endl;
                  print << endl;
                  print << "Week Day  Time" << endl;
    
    //For loop + switch statment (algorithm) to search and display taken time slots.
                  for(i=1; i<=number_of_bookings; i++){
                           switch(bookings[i].week){
                           case 1: print << "1st  "; break;
                           case 2: print << "2nd  "; break;
                           case 3: print << "3rd  "; break;
                           case 4: print << "4th  "; break;
                           };
                           switch(bookings[i].day){
                           case 1: print << "Mon  "; break;
                           case 2: print << "Tue  "; break;
                           case 3: print << "Wed  "; break;
                           case 4: print << "Thu  "; break;
                           case 5: print << "Fri  "; break;
                           case 6: print << "Sat  "; break;
                           };
                           switch(bookings[i].time){
                           case 1: print << "Mor   : "; break;
                           case 2: print << "Aft   : "; break;
                           case 3: print << "Eve   : "; break;
                           case 4: print << "Ext   : "; break;
                           };
    
                          //Title of event is displayed besides time slot.
                          print << bookings[i].event_title << endl;
                           }
                           print << "\f" << endl;
                           system("PAUSE"); 
                           goto UsageStatsTwo;
    
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    //Menu option to create bills.
      case 4:
          print << "Billings" << endl;
          print << endl;
             
          //For loop displays all bookers bills serially.
          for(ID=1; ID<number_of_bookers; ID++){
    
          //Village halls address is displayed at side of bill.
          system("cls");
          Position.X = 35; Position.Y = 0;
          SetConsoleCursorPosition(hOut,Position);
          print << "                                Village Hall" << endl;
          Position.X = 35; Position.Y = 1;
          SetConsoleCursorPosition(hOut,Position);
          print << "                                Scorton" << endl;
          Position.X = 35; Position.Y = 2;
          SetConsoleCursorPosition(hOut,Position);
          print << "                                Richmond" << endl;
          Position.X = 35; Position.Y = 3;
          SetConsoleCursorPosition(hOut,Position);
          print << "                                North Yorkshire" << endl;
          Position.X = 35; Position.Y = 4;
          SetConsoleCursorPosition(hOut,Position);
          print << "                                DL10 6ET" << endl;
    
          //Bookers address is displayed at left-hand side of bill.
          Position.X = 0; Position.Y = 0;
          SetConsoleCursorPosition(hOut,Position);
          print << bookers[ID].address << endl;
          print << bookers[ID].addresstwo << endl;
          print << bookers[ID].town << endl;
          print << bookers[ID].county << endl;
          print << bookers[ID].postcode << endl;
          print << endl;
    
          //Bookers ID number is displayed next to bookers name.
          print << bookers[ID].name << " Ref : " << ID << endl;
          print << endl;
          print << "held the following event(s);" << endl;
          print << endl;
    
    //Group of different statements creating an algorithm to diaplay bookers events and payment status.
          for(x=1; x<=number_of_bookings; x++){
    
                if(ID == bookings[x].booker_id){
    
                    print << bookings[x].event_title;
    
                    switch(bookings[x].fee_paid){
               case 1: print << "          PAID " << endl;
                       break;
               case 0:
                          switch(bookings[x].time){
                     case 1: print << "       12 UNPAID" << endl;
                             break;
                     case 2: print << "       12 UNPAID" << endl;
                             break;
                     case 3: print << "       15 UNPAID" << endl;
                             break;
                     case 4: print << "       20 UNPAID" << endl;
                             break;
               }  break;
    }//switch case 
     }//if
      }//for loop(x)
    
          //Bookers total money owed is displayed.
          print << endl;
          print << "Total = " << bookers[ID].fee_owed << endl;     
          print << endl;
    
          //Footnote message is displayed at bottom of bill.
          print << "We very much hope we shall be given the opportunity" << endl;
          print << "of welcoming you back to the Village Hall. Please quote" << endl;
          print << "your Ref number when booking again\f" << endl;
          print << endl;
          system("PAUSE");
    }//for loop(id)
           
           break;
    
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    //Menu option for usage stats.
      case 5:
           UsageStatsTwo:
           print << endl;
           print << "***********************************************" << endl;
           print << endl;
           print << "Usage Stats" << endl;
    
           x = 0;
           for(i=1; i<=number_of_bookers; i++){
                    x += bookers[i].fee_owed;
                    }
          print << "Money Taken So Far         : " << x << endl;
                  
           for(i=0; i<number_of_bookings; i++){
                 
                      switch(bookings[i].day)
                      {
                      case 1:
                           switch(bookings[i].time)
                           {
                           case 1: monp1 += 1; break;
                           case 2: monp2 += 1; break;
                           case 3: monp3 += 1; break;
                           case 4: monp4 += 1; break;
                           }
                           break;
                      case 2:
                          switch(bookings[i].time)
                          {
                           case 1: tuep1 += 1; break;
                           case 2: tuep2 += 1; break;
                           case 3: tuep3 += 1; break;
                           case 4: tuep4 += 1; break;
                           }
                           break;
                      case 3:
                          switch(bookings[i].time)
                          {
                           case 1: wedp1 += 1; break;
                           case 2: wedp2 += 1; break;
                           case 3: wedp3 += 1; break;
                           case 4: wedp4 += 1; break;
                           }
                           break;
                      case 4:
                          switch(bookings[i].time)
                          {
                           case 1: thup1 += 1; break;
                           case 2: thup2 += 1; break;
                           case 3: thup3 += 1; break;
                           case 4: thup4 += 1; break;
                           }
                           break;
                      case 5:
                           switch(bookings[i].time)
                           {
                           case 1: frip1 += 1; break;
                           case 2: frip2 += 1; break;
                           case 3: frip3 += 1; break;
                           case 4: frip4 += 1; break;
                           }
                           break;
                      case 6:
                           switch(bookings[i].time)
                           {
                           case 1: satp1 += 1; break;
                           case 2: satp2 += 1; break;
                           case 3: satp3 += 1; break;
                           case 4: satp4 += 1; break;
                           }
                           break;
                            }
                             }
                           
           print << "Monday Period 1    : " << (100/9) * monp1 << " % " << endl;
           print << "Period 2           : " << (100/9) * monp2 << " % " << endl;
           print << "Period 3           : " << (100/9) * monp3 << " % " << endl;
           print << "Period 4           : " << (100/9) * monp4 << " % " << endl;
           print << "Tuesday Period 1   : " << (100/9) * tuep1 << " % " << endl;   
           print << "Period 2           : " << (100/9) * tuep2 << " % " << endl;
           print << "Period 3           : " << (100/9) * tuep3 << " % " << endl;
           print << "Period 4           : " << (100/9) * tuep4 << " % " << endl;
           print << "Wednesday Period 1 : " << (100/8) * wedp1 << " % " << endl;
           print << "Period 2           : " << (100/8) * wedp2 << " % " << endl; 
           print << "Period 3           : " << (100/8) * wedp3 << " % " << endl; 
           print << "Period 4           : " << (100/8) * wedp4 << " % " << endl; 
           print << "Thursday Period 1  : " << (100/8) * thup1 << " % " << endl;    
           print << "Period 2           : " << (100/8) * thup2 << " % " << endl;
           print << "Period 3           : " << (100/8) * thup3 << " % " << endl;
           print << "Period 4           : " << (100/8) * thup4 << " % " << endl;
           print << "Friday Period 1    : " << (100/8) * frip1 << " % " << endl;
           print << "Period 2           : " << (100/8) * frip2 << " % " << endl;         
           print << "Period 3           : " << (100/8) * frip3 << " % " << endl;
           print << "Period 4           : " << (100/8) * frip4 << " % " << endl;
           print << "Saturday Period 1  : " << (100/8) * satp1 << " % " << endl;
           print << "Period 2           : " << (100/8) * satp2 << " % " << endl;
           print << "Period 3           : " << (100/8) * satp3 << " % " << endl;
           print << "Period 4           : " << (100/8) * satp4 << " % " << endl;
           print << endl;
           system("PAUSE");
           break;
    
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    //Menu option for discarding booking/bookers details.
      case 6:
    
          //Submenu options are displayed.
          cout << "1 = Delete All Bookers, 2 = Delete All Bookings,  3 = Go To Menu" << endl;
          cout << endl;
          getline(cin,buffer,'\n');
          subanswer = atoi(buffer.c_str());
          if(subanswer == 3){break;}
    
    //Validation message for confirmation of deletion.
          if(subanswer != 3){
              cout << endl;
              while(subanswertwo > 2 || subanswer < 1){
              cout << "ARE YOU SURE YOU WANT TO PERMENENTLY DELETE BOOKERS/BOOKINGS" << endl;
              cout << "1 = Yes, 2 = NO" << endl;
              getline(cin,buffer,'\n'); 
              subanswertwo = atoi(buffer.c_str());
          }
           }
    
    //Selected bookers details are set to zero.
          switch(subanswer){
       case 1: if(subanswertwo == 2){break;};
    
        for(i=1; i<=number_of_bookers; i++){
             bookers[i].address = " ";
             bookers[i].addresstwo = " ";
             bookers[i].town = " ";
             bookers[i].county = " ";
             bookers[i].postcode = " ";
             bookers[i].tel_no = " ";
             bookers[i].fee_owed = 0;
         };
    
    //Selected bookings details are set to zero.
              case 2:
         for(i=1; i<=number_of_bookings; i++){
             bookings[i].booker_id;
             bookings[i].week = 0;
             bookings[i].day = 0;
             bookings[i].time = 0;
             bookings[i].event_title = " ";
             bookings[i].fee_paid = 0; 
         };
     };//switch(subanswer)
             break;              
    
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    //Menu option for creating a regular booking.
      case 7:
    
          //Menu question.
          cout << "Regular Bookings" << endl;
          cout << endl;
          cout << "When Would You Like Your Booking(s)" << endl;
          cout << endl;
    
          //Regular booking day of week is entered.
          day = 10;
          while(day > 6 || day < 1){
          cout << "1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat" << endl;
          cout << "Day                           : ";
          getline(cin,buffer,'\n'); 
          day = atoi(buffer.c_str());
          system("cls");
          }
    
          //Regular bookings time of day is entered.
          time = 10;
          while(time > 4 || time < 1){
          cout << "(9am-12:30pm) (1:30-5pm)   (6pm-9:30pm)   (6pm-11.30pm)" << endl; 
          cout << "1 = Morning, 2 = Evening, 3 = Afternoon, 4 = + Extension" << endl;
          cout << "                                         (Fri + Sat Only)" << endl;
          cout << "Period                        : ";
          getline(cin,buffer,'\n'); 
          time = atoi(buffer.c_str());
          system("cls");
          }
    
          //Regular event title is entered.
          cout << "Event Title                   : ";
          getline(cin,event_title,'\n');
          system("cls");
    
          //Regular event week selection menu.
          x = 10;
          while(x > 3 || x < 1){
          cout << "Which Week(s)?" << endl;
          cout << "1 = Every Week, 2 = Every Other Week, 3 = Specific Week Of Month" << endl;
          getline(cin,buffer,'\n'); 
          x = atoi(buffer.c_str());
          system("cls");
          }
    
          //Switch statement for week selection option selected.
          switch(x){
          case 1:
    
            //For loop for booking every week.
            for(i=1; i==4; i++){
              bookings[number_of_bookings].booker_id = 100;
              bookings[number_of_bookings].week = i;
              bookings[number_of_bookings].day = day;
              bookings[number_of_bookings].time = time;
              bookings[number_of_bookings].event_title = event_title;
              bookings[number_of_bookings].fee_paid = 1;
              number_of_bookings ++; 
             SaveBookingsFile(bookings, number_of_bookings);  //Booking is saved.
             UpdateMasterFile(number_of_bookers, number_of_bookings, money_total); //Master file is updated.
          }
          break;
    
          case 2:
    
            //For loop for booking every other week.
            for(i=1; i==4; i+2){
              bookings[number_of_bookings].booker_id = 100;
              bookings[number_of_bookings].week = i;
              bookings[number_of_bookings].day = day;
              bookings[number_of_bookings].time = time;
              bookings[number_of_bookings].event_title = event_title;
              bookings[number_of_bookings].fee_paid = 1;
              number_of_bookings ++;
              SaveBookingsFile(bookings, number_of_bookings);
              UpdateMasterFile(number_of_bookers, number_of_bookings, money_total);
            }
          break;
    
          case 3:
              cout << "Which Week in Particular   : ";
    
              //Desired week for regular booking is entered.
              week = 10;
              while(week > 4 || week < 1){
              getline(cin,buffer,'\n'); 
              week = atoi(buffer.c_str());
              }
    
              //Booking details are transfered into appropriate array.
              bookings[number_of_bookings].week = week;
              bookings[number_of_bookings].day = day;
              bookings[number_of_bookings].time = time;
              bookings[number_of_bookings].event_title = event_title;
              number_of_bookings++; //Bookings total is incremented by 1.
          break;
      };    
    
       SaveBookingsFile(bookings, number_of_bookings);  //Booking is saved.
       UpdateMasterFile(number_of_bookers, number_of_bookings, money_total); //Master file is updated.
       break;
    
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    //Menu option for quitting program.
      case 8:
           cout << "Terminating Program..." << endl;
           Sleep(1000);
           break;
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
    }//End of main option selection switch statement.
     }//End of program Loop.
                print.close(); // close stream 
        return EXIT_SUCCESS;
    }
    
    
    //Funtions for saving booker details.
    int SaveBookersFile(booker* bookers, int number_of_bookers)
    {
            //Opens bookers file for appending.
            ofstream bookers_file ("bookers.dat", ios::app);
            bookers_file << bookers[number_of_bookers].name << endl;
            bookers_file << bookers[number_of_bookers].address << endl;
            bookers_file << bookers[number_of_bookers].addresstwo << endl;
            bookers_file << bookers[number_of_bookers].town << endl;
            bookers_file << bookers[number_of_bookers].county << endl;
            bookers_file << bookers[number_of_bookers].postcode << endl;
            bookers_file << bookers[number_of_bookers].tel_no << endl;
            bookers_file << bookers[number_of_bookers].fee_owed << endl;
            bookers_file.close();
            return 0;
    }
    
    //Function for saving booking details.
    int SaveBookingsFile(booking* bookings, int number_of_bookings)
    {
            //Opens bookings file for appending.
            ofstream bookings_file ("bookings.dat", ios::app);
            bookings_file << bookings[number_of_bookings].booker_id << endl;
            bookings_file << bookings[number_of_bookings].week << endl;
            bookings_file << bookings[number_of_bookings].day << endl;
            bookings_file << bookings[number_of_bookings].time << endl;
            bookings_file << bookings[number_of_bookings].event_title << endl;
            bookings_file << bookings[number_of_bookings].fee_paid << endl;
            bookings_file.close();
            return 0;
    }
    
    //Function for updating master file.
    int UpdateMasterFile(int number_of_bookers, int number_of_bookings, int money_total)
    {
         //Opening of masterfile for updating.
         ofstream master_file ("filesize.dat");
         master_file << number_of_bookers << endl;
         master_file << number_of_bookings << endl;
         master_file << money_total << endl;
         master_file.close(); 
         return 0;
    }
    
    //Function for saving bookers details after a deletion.
    int SaveBookers(booker* bookers, int number_of_bookers)
    {
            //Opening of bookers file for re-filling.
            ofstream bookers_file ("bookers.dat");
            for(int i=1; i<=number_of_bookers; i++)
            {
            bookers_file << bookers[i].name << endl;
            bookers_file << bookers[i].address << endl;
            bookers_file << bookers[i].addresstwo << endl;
            bookers_file << bookers[i].town << endl;
            bookers_file << bookers[i].county << endl;
            bookers_file << bookers[i].postcode << endl;
            bookers_file << bookers[i].tel_no << endl;
            bookers_file << bookers[i].fee_owed << endl;
            }
            bookers_file.close();
            return 0;
    }
    thanks,

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,451
    Are you familiar with object oriented programming?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    Quote Originally Posted by laserlight
    Are you familiar with object oriented programming?
    i know roughly what it is, using classes etc a bit like the struct command but with more potential.

    i have 0 experience with it but if you feel it would be worth while im all ears. what do you have in mind?



    ps. you get more marks for your solution, not necesarily more techy but for appropriateness.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > heres a copy of my previous years coursework, just to give you an idea of where im at in C++.
    Who (or what) is teaching you C++?
    That should have earned you a failing grade.

    Your main() is 750 lines long, and contains goto statements. This is not a structured program.
    At the very least, each of the top-level menu options should be a separate function.

    There are many uses of system("some_cmd") to do various things.

    There isn't a single class in any of the code. It's not really a C++ program if you don't have classes.

    You could probably replace all the cin/cout stuff with printf/scanf from C and call it a C program.

    > int monp1 = 0, monp2 = 0, monp3 = 0, monp4 = 0;
    Ever consider
    int days[6][4]
    rather than having 24 separately named variables?

    Code:
                      switch(bookings[i].day)
                      {
                      case 1:
                           switch(bookings[i].time)
                           {
                           case 1: monp1 += 1; break;
    This huge double switch monster becomes
    days[ bookings[i].day ][ bookings[i].time ] ++;

    > int SaveBookersFile(booker*, int);
    > int SaveBookers(booker*, int);
    > int SaveBookingsFile(booking* , int);
    Had you used any classes, these would be member functions of that class.

    > for(i=1; i<=number_of_bookers; i++)
    Arrays start at 0, so on the off chance that you have 50 bookings, the last one goes off into unallocated memory.

    > day = atoi(buffer.c_str());
    Lookup string streams.

    > for(i=1; i==4; i++)
    Huh?
    This loop never runs, the test fails on the first pass.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    i know the program ist up to your kind of standards Salem, it was only AS level work and it earned me a mediumish B grade. considering that i was the ONLY person programming mine, everybody else was using Microsoft Access, i recieved no formal teaching on C++ at all. so i think i did fairly good considering.

  6. #6
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    so you guys think i should stick with console applications for my next project then?

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,451
    i know roughly what it is, using classes etc a bit like the struct command but with more potential.

    i have 0 experience with it but if you feel it would be worth while im all ears. what do you have in mind?
    I suggest that you work through the book Accelerated C++. After that, other books mentioned in the C++ Book Recommendations thread would be good for you to read, especially Effective C++ (by Scott Meyers). Only after you have a good foundation in C++ should you think about having a GUI-based C++ program.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    Quote Originally Posted by laserlight
    I suggest that you work through the book Accelerated C++. After that, other books mentioned in the C++ Book Recommendations thread would be good for you to read, especially Effective C++ (by Scott Meyers). Only after you have a good foundation in C++ should you think about having a GUI-based C++ program.
    at last thank you Laserlight. i shouldnt have got carried away with myself wanting to make a program with all the bells and whistles before i could successfully write a decent program lol.

    i guess ill just stick with the console window and brush up on my coding structure first,


    thanks for ya help guys and gals...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21