Thursday, December 24, 2009

Intro to Programming and Algorithm Design Help?

I need help with the following problem. I am having trouble on how I need to have the computer read the current record and compare it to the previous record. I know there is way, and I also know there has to be a loop in this problem. And does anyone have an idea on how the transaction would be negative? So any help with this would greatly be appreciated. Please explain how you got your answer just don't give me an answer. I really want to figure this out, I'm just having some trouble.





Create the flowchart for a program that validates the contents of a file. The file you are validating contains daily sales data from a pet store. Each record in the file contains credit card transaction information, consisting of an approval number and the amount of the charge. Your program should output the information from records whose approval number is lower than the previous record or if the amount of the transaction is negative.Intro to Programming and Algorithm Design Help?
OK, since this is a homework assignment I'm not going to give you the answer, just a rough sketch (it HAS to be rough because you're making a flowchart, which is a sketch in itself).





What you do is, you read the very first record, let's call it PrevRec for Previous Record. You can't compare a single record, you need a second one to compare it with. But you don't just want to read two records right away because if you did that, the logic to determine which data you should keep for future use would be overly complicated. It's actually very educational to try it anyway.





Instead, you should start a loop that first checks if the end of file has been reached. Inside that loop you read another record, let's call it CurrRec for Current Record. Compare CurrRec with PrevRec, and if the approval number of CurrRec is lower than that of PrevRec (or if the amount is negative), print the required data.


Next, copy CurrRec to PrevRec, effectively throwing away the (now obsolete) data from PrevRec, and turning the CurrRec into the PrevRec. In the final step of your algorithm you perform the next cycle of your loop.





In this cycle, CurrRec is overwritten with the data of the next record on the disk. Its data is then used to compare it with PrevRec, etc., etc...





I hope that helps.








####


[A poster who deleted his/her message], above, is producing a lot of crapola. First, for a flow chart you don't need to know where the data resides NOR what the implementation language is. That's totally irrelevant in the software development phase where flow charts are created.





Second: if you wrote code that first reads records into an array, based on the specs given in your question, you'd get fired by any knowledgeable superior (OR when your program starts to crumble). RAM storage (where such an array would reside) is typically a LOT smaller than disk storage (where the data would be stored), and you should always assume in your development efforts that -where possible- your RAM will get flooded by disk data. In my arrangement, over flooding your RAM is extremely unlikely, since there are at any time only two records in memory.





I guess things aren't as 'obvious' as [a poster who deleted his/her message] suggests in the first line of his/her answer.





Oh, and don't let the people who click the thumbs-down button below confuse you. My answer is flawless, just not very thoughtfully phrased toward [a poster who deleted his/her message]. :-)


#####

No comments:

Post a Comment