Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 03-18-07   #1 (permalink)
WaterCooler
 
DanNEBTD's Avatar
 
amd nvidia

Join Date: Mar 2006
Location: Boca Raton, FL
Posts: 2,336

Rep: 120 DanNEBTD is acknowledged by manyDanNEBTD is acknowledged by many
Unique Rep: 103
Folding Team Rank: 348
Hardware Reviews: 8
Trader Rating: 8
Default C++ date help please

Part of my HW is to create a display of transactions with debits/credits/etc. I want them to be listed reverse chronologically but am having trouble getting the mind set on how to do this. The information is in an array of classes and the date is split into the day, month, and year as separate variables inside the class. I need to separate the customer's transactions via account number from the array then put those transactions in reverse chronological order.

Any help would be greatly appreciated . . . .it's been a long project and i think my brain is just fried.

>> oh i must also use an overloaded insertion operator to display those accounts. . .i can handle that (i think) but i didnt know if it would make a difference.
__________________
Quote:
Originally Posted by GuardianOdin View Post
Overkill doesn't exist on OCN. It's what we do.
XPS M1330: T7500, 4GB, 13.3" LED WXGA, 128 8400 GS, 120GB 5400RPM, 802.11 AGN, 9 cell, Fingerprint, Ultimate x64, 4 Year Accidental Damage/lojack/warranty.
__________________

System: The 1K CFM Machine
CPU
Opty 170 ccb1e 0609fpaw
Motherboard
A8N32-SLI
Memory
2 gigs Gskill PC4000
Graphics Card
EVGA 7950X2
Hard Drive
4x 36gig Raptors raid 0, 1x 200gig storage
Sound Card
XtremeMusic w/Z5500
Power Supply
PC&P Silencer 750 Quad
Case
Mozart Tx
CPU cooling
Stinger V6, quadrad
OS
Vista Home Premium x86
Monitor
32" Syntax Olevia
DanNEBTD is offline I fold for Overclock.net DanNEBTD's Gallery   Reply With Quote
Old 03-18-07   #2 (permalink)
4.0ghz
 
stargate125645's Avatar
 
intel nvidia

Join Date: Sep 2005
Location: Omaha, NE
Posts: 7,097

Rep: 338 stargate125645 is a proven memberstargate125645 is a proven memberstargate125645 is a proven memberstargate125645 is a proven member
Unique Rep: 219
FAQs Submitted: 1
Hardware Reviews: 9
Trader Rating: 21
Default

Use a for loop backwards. That is, start with the upper end of the array size and end at zero, with cntr-- as the operator (cntr is the counter).
__________________
System: BladeRunner
CPU
Core 2 Duo E6700 @ 3.714GHz
Motherboard
ASUS P5N32-E SLI
Memory
2 x 2GB G.Skill PKs DDR2 1066 @ 1066MHz 5-4-4-12
Graphics Card
XFX GeForce 8600GTS @ 750MHz/2137MHz
Hard Drive
4 x 36GB WD Raptors in RAID-0, 750GB WD AAKS
Sound Card
X-Fi XtremeGamer Fatal1ty Professional
Power Supply
Ultra X3 1000W
Case
Thermaltake Armor with A2400 (upgraded 25cm fan)
CPU cooling
Tuniq Tower 120 (lapped) with Silverstone FM121
GPU cooling
Stock
OS
Windows XP Professional 32-bit
Monitor
LG L203WTX 20.1" Widescreen (1680x1050)
stargate125645 is offline Overclocked Account stargate125645's Gallery   Reply With Quote
Old 03-18-07   #3 (permalink)
110100001101001111000
 
C-bro's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton, ON
Posts: 1,832

Rep: 283 C-bro is a proven memberC-bro is a proven memberC-bro is a proven member
Unique Rep: 215
FAQs Submitted: 6
Folding Team Rank: 237
Hardware Reviews: 9
Trader Rating: 1
Default

Quote:
Originally Posted by stargate125645 View Post
Use a for loop backwards. That is, start with the upper end of the array size and end at zero, with cntr-- as the operator (cntr is the counter).
I would also use that method, but throw in an 'if' statement as a filter by account number. Pseudocode wise:

FOR latest_transaction to first_transaction
IF transaction_acct_number == user_acct_number
PRINT current_transaction

That way you'll get the reverse chronological and it'll be filtered by acct. number. Not sure if that's what you need, but that's what I gathered.

EDIT: If you know how to use stacks, this will GREATLY simplify things. Create a stack called trans_history or something for each account number. After each transcation, check the account number and push the transaction onto that users stack. All you have to do for the transaction history is POP all the transactions from the user's trans_history and you're done. That's actually how I'd do this problem, now that I think of it. If you need help implementing a stack using normal arrays, feel free to ask.

System: RAID0R
CPU
Intel E2180 3.33GHz
Motherboard
Asus P5K-E/WIFI-AP vMod
Memory
2GB Kingmax DDR2-1066
Graphics Card
EVGA 8800GT
Hard Drive
2x250GB WD+500GB 7200.11
Sound Card
SB Audigy 2
Power Supply
Corsair CMPSU-550VX
CPU cooling
Arctic Cooling Freezer 7 Pro
GPU cooling
Zalman VF900-Cu
OS
Windows Vista Business 32-Bit
Monitor
HP F2105 21" & Samsung 712N

Last edited by C-bro : 03-18-07 at 01:40 PM.
C-bro is offline I fold for Overclock.net Overclocked Account C-bro's Gallery   Reply With Quote
Old 03-18-07   #4 (permalink)
WaterCooler
 
DanNEBTD's Avatar
 
amd nvidia

Join Date: Mar 2006
Location: Boca Raton, FL
Posts: 2,336

Rep: 120 DanNEBTD is acknowledged by manyDanNEBTD is acknowledged by many
Unique Rep: 103
Folding Team Rank: 348
Hardware Reviews: 8
Trader Rating: 8
Default

ok that clarifies some things. . . but how would i go about joining the three parts for the date? . . . I feel like im missing something very simple . . UGG . . . thanks for the help you two . . reps to both
__________________
Quote:
Originally Posted by GuardianOdin View Post
Overkill doesn't exist on OCN. It's what we do.
XPS M1330: T7500, 4GB, 13.3" LED WXGA, 128 8400 GS, 120GB 5400RPM, 802.11 AGN, 9 cell, Fingerprint, Ultimate x64, 4 Year Accidental Damage/lojack/warranty.
__________________

System: The 1K CFM Machine
CPU
Opty 170 ccb1e 0609fpaw
Motherboard
A8N32-SLI
Memory
2 gigs Gskill PC4000
Graphics Card
EVGA 7950X2
Hard Drive
4x 36gig Raptors raid 0, 1x 200gig storage
Sound Card
XtremeMusic w/Z5500
Power Supply
PC&P Silencer 750 Quad
Case
Mozart Tx
CPU cooling
Stinger V6, quadrad
OS
Vista Home Premium x86
Monitor
32" Syntax Olevia
DanNEBTD is offline I fold for Overclock.net DanNEBTD's Gallery   Reply With Quote
Old 03-18-07   #5 (permalink)
WaterCooler
 
DanNEBTD's Avatar
 
amd nvidia

Join Date: Mar 2006
Location: Boca Raton, FL
Posts: 2,336

Rep: 120 DanNEBTD is acknowledged by manyDanNEBTD is acknowledged by many
Unique Rep: 103
Folding Team Rank: 348
Hardware Reviews: 8
Trader Rating: 8
Default

oooh. . . so i should do this:
PHP Code:
For (countYear 2020accountYear >= 1990countYear--)
{
   For (
countMonth 12accountMonth >= 1countMonth--) 
   {
      For (
countDay 31accountDay >= 1countDay--)
      {
          If 
accountNumber CustNumber
          
{
               
cout << Transactions.data
          
}
      }
   }

Would that work? . . .
__________________
Quote:
Originally Posted by GuardianOdin View Post
Overkill doesn't exist on OCN. It's what we do.
XPS M1330: T7500, 4GB, 13.3" LED WXGA, 128 8400 GS, 120GB 5400RPM, 802.11 AGN, 9 cell, Fingerprint, Ultimate x64, 4 Year Accidental Damage/lojack/warranty.
__________________

System: The 1K CFM Machine
CPU
Opty 170 ccb1e 0609fpaw
Motherboard
A8N32-SLI
Memory
2 gigs Gskill PC4000
Graphics Card
EVGA 7950X2
Hard Drive
4x 36gig Raptors raid 0, 1x 200gig storage
Sound Card
XtremeMusic w/Z5500
Power Supply
PC&P Silencer 750 Quad
Case
Mozart Tx
CPU cooling
Stinger V6, quadrad
OS
Vista Home Premium x86
Monitor
32" Syntax Olevia
DanNEBTD is offline I fold for Overclock.net DanNEBTD's Gallery   Reply With Quote
Old 03-18-07   #6 (permalink)
4.0ghz
 
stargate125645's Avatar
 
intel nvidia

Join Date: Sep 2005
Location: Omaha, NE
Posts: 7,097

Rep: 338 stargate125645 is a proven memberstargate125645 is a proven memberstargate125645 is a proven memberstargate125645 is a proven member
Unique Rep: 219
FAQs Submitted: 1
Hardware Reviews: 9
Trader Rating: 21
Default

Assuming it is organized chronologically, that should work barring any minor syntax errors. I am not as sharp as I used to be with C++, so I can't guarantee anything. If you need to organize them by account number, then you will need some while loop to determine if it is an existing account or a new one and proceed from there as to how you will store the transaction information. The reverse for loop suggestion was me thinking you had everything listed in chronological order and you had to reverse it. You can also do two separate data sorts. That is, you can organize them by reverse chronological order and then a separate function can organize them by account number if it gets too confusing to do it in one step.
__________________
System: BladeRunner
CPU
Core 2 Duo E6700 @ 3.714GHz
Motherboard
ASUS P5N32-E SLI
Memory
2 x 2GB G.Skill PKs DDR2 1066 @ 1066MHz 5-4-4-12
Graphics Card
XFX GeForce 8600GTS @ 750MHz/2137MHz
Hard Drive
4 x 36GB WD Raptors in RAID-0, 750GB WD AAKS
Sound Card
X-Fi XtremeGamer Fatal1ty Professional
Power Supply
Ultra X3 1000W
Case
Thermaltake Armor with A2400 (upgraded 25cm fan)
CPU cooling
Tuniq Tower 120 (lapped) with Silverstone FM121
GPU cooling
Stock
OS
Windows XP Professional 32-bit
Monitor
LG L203WTX 20.1" Widescreen (1680x1050)
stargate125645 is offline Overclocked Account stargate125645's Gallery   Reply With Quote
Old 03-18-07   #7 (permalink)
110100001101001111000
 
C-bro's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton, ON
Posts: 1,832

Rep: 283 C-bro is a proven memberC-bro is a proven memberC-bro is a proven member
Unique Rep: 215
FAQs Submitted: 6
Folding Team Rank: 237
Hardware Reviews: 9
Trader Rating: 1
Default

That for-loop will most likely work, but I would really suggest implementing my earlier stack idea. I'll do a quick demo of how it would work with this list of transactions: Say we have acct numbers 01 and 02 and the following transactions:

date - account # - type - amt.

3/15/2007 - 02 - deposit - 2000
3/16/2007 - 01 - deposit - 5000
3/17/2007 - 02 - withdraw - 500
3/18/2007 - 01 - withdraw - 200

Those were the 4 transactions that happened. When they happen you'll put them onto a stack for each account. So every acct will have a stack of transactions. If you looks at this this independently, you'd see:

Account 01 stack:
3/18/2007 - 01 - withdraw - 200
3/16/2007 - 01 - deposit - 5000

Account 02 stack:
3/17/2007 - 02 - withdraw - 500
3/15/2007 - 02 - deposit - 2000

Since you push the items onto each respective stack as they happen, they're always sitting there in reverse chronological order. To view all the transactions for each customer you'd just go.

AccountXX.pop() and that would return the most recent transaction for the customer. That way you could specifiy only the 5 or 10 most recent transactions, or give the entire history of the client. In other words, if you were to pop off the entire account 01 stack, you'd see a list like this, since stacks always push and pop from the top of the list.

3/18/2007 - 01 - withdraw - 200
3/16/2007 - 01 - deposit - 5000


This gives as many transactions you want, for a given account number, and it does so in reverse chronological order.

System: RAID0R
CPU
Intel E2180 3.33GHz
Motherboard
Asus P5K-E/WIFI-AP vMod
Memory
2GB Kingmax DDR2-1066
Graphics Card
EVGA 8800GT
Hard Drive
2x250GB WD+500GB 7200.11
Sound Card
SB Audigy 2
Power Supply
Corsair CMPSU-550VX
CPU cooling
Arctic Cooling Freezer 7 Pro
GPU cooling
Zalman VF900-Cu
OS
Windows Vista Business 32-Bit
Monitor
HP F2105 21" & Samsung 712N
C-bro is offline I fold for Overclock.net Overclocked Account C-bro's Gallery   Reply With Quote
Old 03-18-07   #8 (permalink)
4.0ghz
 
stargate125645's Avatar
 
intel nvidia

Join Date: Sep 2005
Location: Omaha, NE
Posts: 7,097

Rep: 338 stargate125645 is a proven memberstargate125645 is a proven memberstargate125645 is a proven memberstargate125645 is a proven member
Unique Rep: 219
FAQs Submitted: 1
Hardware Reviews: 9
Trader Rating: 21
Default

I want account 01!
__________________
System: BladeRunner
CPU
Core 2 Duo E6700 @ 3.714GHz
Motherboard
ASUS P5N32-E SLI
Memory
2 x 2GB G.Skill PKs DDR2 1066 @ 1066MHz 5-4-4-12
Graphics Card
XFX GeForce 8600GTS @ 750MHz/2137MHz
Hard Drive
4 x 36GB WD Raptors in RAID-0, 750GB WD AAKS
Sound Card
X-Fi XtremeGamer Fatal1ty Professional
Power Supply
Ultra X3 1000W
Case
Thermaltake Armor with A2400 (upgraded 25cm fan)
CPU cooling
Tuniq Tower 120 (lapped) with Silverstone FM121
GPU cooling
Stock
OS
Windows XP Professional 32-bit
Monitor
LG L203WTX 20.1" Widescreen (1680x1050)
stargate125645 is offline Overclocked Account stargate125645's Gallery   Reply With Quote
Old 03-19-07   #9 (permalink)
WaterCooler
 
DanNEBTD's Avatar
 
amd nvidia

Join Date: Mar 2006
Location: Boca Raton, FL
Posts: 2,336

Rep: 120 DanNEBTD is acknowledged by manyDanNEBTD is acknowledged by many
Unique Rep: 103
Folding Team Rank: 348
Hardware Reviews: 8
Trader Rating: 8
Default

Thanks guys. . .

>> C-Bro I would do stack but a. I dont know how to and i would learn but b. my professor is one of those that would likely get mad at me applying things we havent learned in class yet

I ended up saying F' it and went oldest to newest using a complicated series of for loops. . . ill look into stacks for the future and inquire about them next class. I realized that part of the requirement was to calculate the balance at the time of display. . .which ment i had to use the beginning balance (which is often the earliest) first. . . . im sick of this class and am just taking the past of least resistance now

But thanks for all your help. . . its good to know i have a place where i can get help on the subject. there are only 4 people in my class and two are failing. . . and my instructor is an ass so he's little help.
__________________
Quote:
Originally Posted by GuardianOdin View Post
Overkill doesn't exist on OCN. It's what we do.
XPS M1330: T7500, 4GB, 13.3" LED WXGA, 128 8400 GS, 120GB 5400RPM, 802.11 AGN, 9 cell, Fingerprint, Ultimate x64, 4 Year Accidental Damage/lojack/warranty.
__________________

System: The 1K CFM Machine
CPU
Opty 170 ccb1e 0609fpaw
Motherboard
A8N32-SLI
Memory
2 gigs Gskill PC4000
Graphics Card
EVGA 7950X2
Hard Drive
4x 36gig Raptors raid 0, 1x 200gig storage
Sound Card
XtremeMusic w/Z5500
Power Supply
PC&P Silencer 750 Quad
Case
Mozart Tx
CPU cooling
Stinger V6, quadrad
OS
Vista Home Premium x86
Monitor
32" Syntax Olevia

Last edited by DanNEBTD : 03-19-07 at 12:17 AM.
DanNEBTD is offline I fold for Overclock.net DanNEBTD's Gallery   Reply With Quote
Old 03-19-07   #10 (permalink)
110100001101001111000
 
C-bro's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton, ON
Posts: 1,832

Rep: 283 C-bro is a proven memberC-bro is a proven memberC-bro is a proven member
Unique Rep: 215
FAQs Submitted: 6
Folding Team Rank: 237
Hardware Reviews: 9
Trader Rating: 1
Default

Quote:
Originally Posted by DanNEBTD View Post
Thanks guys. . .

>> C-Bro I would do stack but a. I dont know how to and i would learn but b. my professor is one of those that would likely get mad at me applying things we havent learned in class yet

I ended up saying F' it and went oldest to newest using a complicated series of for loops. . . ill look into stacks for the future and inquire about them next class. I realized that part of the requirement was to calculate the balance at the time of display. . .which ment i had to use the beginning balance (which is often the earliest) first. . . . im sick of this class and am just taking the past of least resistance now

But thanks for all your help. . . its good to know i have a place where i can get help on the subject. there are only 4 people in my class and two are failing. . . and my instructor is an ass so he's little help.

Good luck with it. Stacks would be the way to go, but like you said, if you haven't learned it yet, you most likely can't use it. Not sure if you can read this, but this was a very simple (and messy) implementation of a stack that I had to write. It's in Java but you should be able to see what they're all about. They're very handy.

Code:
public class MyStack <E>{
   protected int capacity; //Max number of elements
   protected E S[]; //Array of tyep E
   protected int top = -1; //Index of the top of the stack

   //Constructors
   public MyStack(){
       capacity = 1000;
       S =(E[]) new Object[capacity];
   }
   
   public MyStack (int i){
       capacity = i;
       S =(E[]) new Object[capacity];
   }
   //Returns size of Stack
   public int getSize(){
       return (top+1);
   }
   //Checks if Stack is empty
   public boolean isEmpty(){
       return (top<0);
   }
   //Pushes element onto stack
   public void push (E e){
       S[++top] = e;
   }
   //Pops element off stack
   public E pop() throws MyEmptyStackException{
       if (top < 0){
           throw new MyEmptyStackException ("Stack Is Empty!");
       }
       else{
           E e = S[top];
           S[top--] = null;
           return (e);
       }
   }
   //Returns the top element
   public E peek() throws MyEmptyStackException{
       if (top < 0){
           throw new MyEmptyStackException ("Stack Is Empty!");
       }
       else
           return (S[top]);
   }
}

System: RAID0R
CPU
Intel E2180 3.33GHz
Motherboard
Asus P5K-E/WIFI-AP vMod
Memory
2GB Kingmax DDR2-1066
Graphics Card
EVGA 8800GT
Hard Drive
2x250GB WD+500GB 7200.11
Sound Card
SB Audigy 2
Power Supply
Corsair CMPSU-550VX
CPU cooling
Arctic Cooling Freezer 7 Pro
GPU cooling
Zalman VF900-Cu
OS
Windows Vista Business 32-Bit
Monitor
HP F2105 21" & Samsung 712N
C-bro is offline I fold for Overclock.net Overclocked Account C-bro's Gallery   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 10:32 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.34063 seconds with 8 queries