Author Topic: Bow before me, for I am a l33t coding God!  (Read 6771 times)

Rob

  • New improved. Now with added something...
  • Jackass In Charge
  • Posts: 5959
  • Karma: +86/-149
  • Approaching 60 from the wrong damn direction...
Bow before me, for I am a l33t coding God!
« on: May 19, 2006, 11:08:08 AM »
Code: [Select]
#pragma package(smart_init)

void WarehouseType::Init(void)
{
int R;
int S;
int InCode;
int InQuantity;
ifstream DataFile;
   for (R=0; R<=MaxR; R=R+1)
      for (S=0; S<=MaxS; S=S+1)
   {
      Bins[R][S].Code = 0;
      Bins[R][S].Quantity = 0;
   }
   DataFile.open("WHData.dat");
   if(DataFile)
   {
      while(!(DataFile.eof()))
      {
         DataFile >> R >> S >> InCode >> InQuantity >> ws;
         Bins[R][S].Code = InCode;
         Bins[R][S].Quantity = InQuantity;
      }
    }
}

AnsiString WarehouseType::Store(int InCode, int InQuantity)
{

int R;
bool Found;
int S;
AnsiString Message;
R = 0;

while(!Found && (R<=MaxR))
{
   S=0;
   while(!Found && (S<=MaxS))
   {
      if(Bins[R][S].Quantity == 0)
         Found = true;
      else
         S = S+1;
   }
   if(!Found)
      R = R+1;
}

if(Found)
{
   Bins[R][S].Code = InCode;
   Bins[R][S].Quantity = InQuantity;
   Message = "Store in row " + AnsiString(R + 1) + " slot " + AnsiString(S + 1);
   return Message;
}
else
{
   Message = "Warehouse is full.";
   return Message;
}
}

AnsiString WarehouseType::Supply(int OutCode, int OutQuantity)
{
int R;
int S;
int AmountNeeded;
AnsiString Message;

R=0;
AmountNeeded = OutQuantity;
Message = "";

while ((AmountNeeded > 0) && (R <= MaxR))
{
   S=0;
   while ((AmountNeeded > 0) && (S <= MaxS))
   {
      if(Bins[R][S].Code == OutCode)
      {
         if(AmountNeeded >= Bins[R][S].Quantity)
         {
            AmountNeeded = AmountNeeded - Bins[R][S].Quantity;
            Message = Message + "Take " + AnsiString(Bins[R][S].Quantity)
                              + " from row "
                              + AnsiString(R + 1)
                              + ", slot"
                              + AnsiString(S+1) + "\n";
            Bins[R][S].Quantity = 0;
            Bins[R][S].Code = 0; //Nothing in there now//
         }
         else
         {
            Bins[R][S].Quantity = Bins[R][S].Quantity - AmountNeeded;
            Message = Message + "Take " + AnsiString(AmountNeeded)
                              + " from row "
                              + AnsiString(R + 1)
                              + ", slot"
                              + AnsiString(S+1) +"\n";
            AmountNeeded = 0;
         }
      }
      S = S + 1;
   }
   R = R + 1;
}
if(AmountNeeded>0)
   Message = Message + "Shortfall of " + AnsiString(AmountNeeded);
return Message;

}

void WarehouseType::Final(void)
{
int R;
int S;
ofstream DataFile;
   DataFile.open("WHData.dat");
   if(DataFile)
   {
      for (R = 0; R <= MaxR; R = R + 1)
         for (S = 0; S <= MaxS; S = S + 1)
            if(Bins[R][S].Quantity != 0)
            {
               DataFile << R << "\n";
               DataFile << S << "\n";
               DataFile << Bins[R][S].Code << "\n";
               DataFile << Bins[R][S].Quantity  << "\n";
            }
    DataFile.close();
   }
}

 :thumbsup: :D

Ken Fitlike

  • Jackass V
  • Posts: 1568
  • Karma: +25/-22
  • Ebeneezer McScrooge
Re: Bow before me, for I am a l33t coding God!
« Reply #1 on: May 19, 2006, 11:31:23 AM »
Quote from: gcc 3.4.5(mingw special)
main.cpp:13: warning: ignoring #pragma package
main.cpp:15: error: `WarehouseType' has not been declared
main.cpp: In function `void Init()':
main.cpp:21: error: `ifstream' was not declared in this scope
main.cpp:21: error: expected `;' before "DataFile"
main.cpp:22: error: `MaxR' was not declared in this scope
main.cpp:23: error: `MaxS' was not declared in this scope
main.cpp:25: error: `Bins' was not declared in this scope
main.cpp:23: warning: unused variable 'MaxS'
main.cpp:22: warning: unused variable 'MaxR'
main.cpp:28: error: `DataFile' was not declared in this scope
main.cpp:33: error: `ws' was not declared in this scope
main.cpp:34: error: `Bins' was not declared in this scope
main.cpp:33: warning: unused variable 'ws'
main.cpp:21: warning: unused variable 'ifstream'
main.cpp: At global scope:
main.cpp:40: error: `AnsiString' does not name a type
main.cpp:77: error: `AnsiString' does not name a type
main.cpp:127: error: `WarehouseType' has not been declared
main.cpp: In function `void Final()':
main.cpp:131: error: `ofstream' was not declared in this scope
main.cpp:131: error: expected `;' before "DataFile"
main.cpp:132: error: `DataFile' was not declared in this scope
main.cpp:135: error: `MaxR' was not declared in this scope
main.cpp:136: error: `MaxS' was not declared in this scope
main.cpp:137: error: `Bins' was not declared in this scope
main.cpp:136: warning: unused variable 'MaxS'
main.cpp:135: warning: unused variable 'MaxR'
main.cpp:131: warning: unused variable 'ofstream'

 18 error(s), 8 warning(s)

:p

I've been meaning to ask you how that OU computing (C++ course was it?) was going, though so - how's that OU computing course going? Is it this one?
And what rough beast, its hour come round at last,
Slouches towards Bethlehem to be born?.

Rob

  • New improved. Now with added something...
  • Jackass In Charge
  • Posts: 5959
  • Karma: +86/-149
  • Approaching 60 from the wrong damn direction...
Re: Bow before me, for I am a l33t coding God!
« Reply #2 on: May 19, 2006, 12:12:10 PM »
Yup, that's the kiddy.

By the way, it's designed to be compiled in a real compiler...


:D

Ken Fitlike

  • Jackass V
  • Posts: 1568
  • Karma: +25/-22
  • Ebeneezer McScrooge
Re: Bow before me, for I am a l33t coding God!
« Reply #3 on: May 19, 2006, 12:17:08 PM »
So, how is/was it for you? Easy/hard? Boring/interesting? Presumably they furnish you with some sort of course specific compiler, too, so that those #pragmas and ansistrings have some sort of contextual meaning?
And what rough beast, its hour come round at last,
Slouches towards Bethlehem to be born?.

Rob

  • New improved. Now with added something...
  • Jackass In Charge
  • Posts: 5959
  • Karma: +86/-149
  • Approaching 60 from the wrong damn direction...
Re: Bow before me, for I am a l33t coding God!
« Reply #4 on: May 19, 2006, 12:30:50 PM »
Well, it's not too bad. Problem is, having done a bit of C++ before, some of the coursework can be boring, but I have to do it in case I miss something important. Also the OU has particular ways it wants things done (i+1 instead of i++ for example).

The compiler is good ole Borland C++ Builder 5. AnsiString and other things like WriteIntPr, ReadStringPr (write an integer with a prompt, read a string with a prompt) are included in a course-specific header.

The code above is just a snippet, hence most of your errors. The function prototypes etc are in a seperate header file.

I'm about half way through, and yes, I'm quite enjoying it. TMA due next week :eek:

Rob

  • New improved. Now with added something...
  • Jackass In Charge
  • Posts: 5959
  • Karma: +86/-149
  • Approaching 60 from the wrong damn direction...
Re: Bow before me, for I am a l33t coding God!
« Reply #5 on: May 19, 2006, 12:34:23 PM »
Oh, and to be precise it's not really a C++ course, it's a programming course that happens to use C++. We do a lot of pseudocode design stuff like

Code: [Select]
1 open DataFile for writing
2 loop for R <-- 0 to MaxR
2.1    loop for S<-- 0 to MaxS
2.2       if Bins[R][S].code ≠ 0
2.3          write R to DataFile
2.4          write S to DataFile
2.5          write  Bins[R][S].Code to DataFile
2.6          write Bins[R][S].Quantity to DataFile
2.7    loopend
2.8 loopend
3.1 close DataFile

which I detest :)

Ken Fitlike

  • Jackass V
  • Posts: 1568
  • Karma: +25/-22
  • Ebeneezer McScrooge
Re: Bow before me, for I am a l33t coding God!
« Reply #6 on: May 19, 2006, 12:40:48 PM »
>>Borland C++ Builder 5<<

I wondered about that.

>>pseudocode<<

Oh. :( The advantage of fiddling with code as a hobby is being able to ignore stuff that doesn't interest you, whether or not it may be useful.

Good luck with the rest of your studies, though! :)
And what rough beast, its hour come round at last,
Slouches towards Bethlehem to be born?.

Rob

  • New improved. Now with added something...
  • Jackass In Charge
  • Posts: 5959
  • Karma: +86/-149
  • Approaching 60 from the wrong damn direction...
Re: Bow before me, for I am a l33t coding God!
« Reply #7 on: May 19, 2006, 01:11:26 PM »
Cheers Ken.

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Bow before me, for I am a l33t coding God!
« Reply #8 on: May 19, 2006, 05:03:49 PM »
edit: nvm

keep it up!

incognito

  • In the Abis
  • Jackass IV
  • Posts: 544
  • Karma: +15/-20
Re: Bow before me, for I am a l33t coding God!
« Reply #9 on: June 02, 2006, 06:41:16 AM »
Quick question, what's this pragma stuff used for?

Rob

  • New improved. Now with added something...
  • Jackass In Charge
  • Posts: 5959
  • Karma: +86/-149
  • Approaching 60 from the wrong damn direction...
Re: Bow before me, for I am a l33t coding God!
« Reply #10 on: June 02, 2006, 03:36:23 PM »
It's an implementation-defined directive. Please don't ask me to explain that...

:)

incognito

  • In the Abis
  • Jackass IV
  • Posts: 544
  • Karma: +15/-20
Re: Bow before me, for I am a l33t coding God!
« Reply #11 on: June 03, 2006, 07:54:27 PM »
Could you please explain that? :)

Rob

  • New improved. Now with added something...
  • Jackass In Charge
  • Posts: 5959
  • Karma: +86/-149
  • Approaching 60 from the wrong damn direction...
Re: Bow before me, for I am a l33t coding God!
« Reply #12 on: June 04, 2006, 08:33:54 AM »
*pokes i_c with a stick*