C++ Code I will Never write Again...

Thursday, 3 April 2008 08:04 by frimbob
   1: void Markets::RemoveItem(AUser au)
   2: {
   3:     char YN;
   4:     int key;
   5:  
   6:     try
   7:     {
   8:         //ask for an item
   9:         cout << "please select an item to delete" ;
  10:         cin >> key;
  11:  
  12:         //cast reference to item
  13:         item* ite =(item*)lst.at(key);
  14:         //cout << ite-> << endl; 
  15:         if(ite->MaxDiscount < 0){ throw 'a'; };//end if
  16:         cout << "delete this item " << ite->Name  <<"? (y/n): ";
  17:         //following was inspired by 
  18:         //http://www.augustcouncil.com/~tgibson/tutorial/iotips.html#problems
  19:         int bad_input;
  20:         do{
  21:             bad_input=0;
  22:             std::cin >> YN;
  23:             if(!std::cin)
  24:             {
  25:                 bad_input=1;
  26:                 std::cin.clear();
  27:                 std::cin.ignore();
  28:                 
  29:             }
  30:  
  31:         }while(bad_input);
  32:         //end if inspiration
  33:                         if(YN == 'y')
  34:         {
  35:             //remove the item
  36:             cat->removeproduct(ite);
  37:         };//end if
  38:  
  39:  
  40:     }
  41:     catch(...)
  42:     {
  43:         try
  44:         {
  45:             //cast reference to catagory
  46:             catagory* tcat = (catagory*)lst.at(key); 
  47:             if(tcat->subcatagories.size()) throw 'b';
  48:  
  49:             cout << " delete this catagory " << tcat->name <<"? (y/n) " << endl;
  50:             //following was inspired by 
  51:             //http://www.augustcouncil.com/~tgibson/tutorial/iotips.html#problems
  52:             int bad_input;
  53:             do{
  54:                 bad_input=0;
  55:                 std::cin >> YN;
  56:                 if(!std::cin)
  57:                 {
  58:                     bad_input=1;
  59:                     std::cin.clear();
  60:                     std::cin.ignore();
  61:                 }
  62:  
  63:             }while(bad_input);        
  64:             //end of inspiritation
  65:                                     if(YN == 'y')
  66:             {
  67:                 //the class value cat is the parent pass this object to delete
  68:                 cat->removecatagory(tcat);
  69:             };//endif
  70:  
  71:  
  72:         }
  73:         catch (...)
  74:         {
  75:             cout << "item could not be removed press u and  to continue:" << endl;
  76:             char temp;
  77:             cin >> temp;
  78:         };//end catch
  79:  
  80:     };//end catch
  81:  
  82: };//end of remove item
 

So why did I did I create this dam thing well, I was inspired by AJAX object creation if you believe that. Since there is no function that can return the correct browser type a try loop is used until the correct object name is reached

A similar problem, I had a vector of void* pointers that need to be cast into the correct type before they could be used,the vector contained 2 different types of pointers of the item* pointer and a category* pointer, obviously the typedef would not return a correct value for a void* pointer so I had to use this ugly piece to determine the type.

My advice about University projects don't start them days before there due especially when your tired and stressed and if you wish to create a list of mixed objects, don’t use a mixed list of pointers.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   Tech Tips
Actions:   E-mail | Permalink | Comments (250) | Comment RSSRSS comment feed

Preparation makes perfect

Wednesday, 20 February 2008 21:55 by frimbob

Well now that my next semester of university starts on the 25th of Feb, I find that I must spend time in preparation for my classes. Of main concern is the Object Oriented Programming (OOP) for short class.

I have in the past few months  spend time learning learn c#, For this class I need a working understanding of C++, While the syntax is similar and many of the methods are inherent in the .NET framework, study is still required.

In that endeavour I have purchased a book which I will be working from over the next few days:

[ Ivor Horton's Beginning Visual C++ 2005 ]

http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764571974.html

My Time Table

 timetable

I do get one day off a week to get work done, and only one early start, I have had worse timetables.  My only concern is Friday work stuff.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   Life and Stuff
Actions:   E-mail | Permalink | Comments (338) | Comment RSSRSS comment feed