|Feb 22, 2005, 08:48 PM||#1|
Can someone look over my C++ code please?
*sighs* I got a big problem, because the other students in my class acted up for the substitute while my teacher was gone, my teacher now has forbidden us to go into the computer lab until he thinks we're ready again, so now I have to pay for the other kid's actions because we still have to do programs, but now we just have paper and pencil to work with and I don't have any help from the computer. *sighs* So I don't know whether or not this code works or not, could someone look it over and tell me whether or not it looks okay?
The problem is we have to figure out the most undo buffers ever needed in a sequence of actions. C will stand for the user changing the data set, U will stand for the user undoing the most recent change, R will stand for the user redo an action(ie. cancelling the most recent Undo), and S will stand for the user saving the data set. I gave each letter a number value that'll make it easier, C equal 1, U will equal -1, R will equal 1, and S just resets the added up value to zero again. Some examples are:
CCCCCCCC -> this would require 8 buffers because the that's the most the data was changed another harder example is:
CCCCURUUCSCUCUS so using the values i set up, the first CCCC = 4, subrtract 1 for the U which leaves the current score at 3, add 1 for the R making the current score 4 again, minus 2 for the next two U's making the current = 2, add 1 for the C which makes current = 3, then S resets that to 0, and the next set of CUCU cancels each other out and the S at the end resets it to 0. so throughout that sequence, the highest number of times the data was changed was 4 times(right at the beggining) so the session requires 4 undo buffers because that was the most that was changed. hopefully you guys get what i'm saying ^^;
so here's what I have so far:
case 'C': current+=1;
case 'U': current-=1;
case 'R': current+=1;
cout<<"This session requires "current" undo buffers.";
I have no idea if this is right, but this is what I have so far. Also, I can't figure out how to set it up that max equals the highest number that was added up during the sequence of action and how to set it so the current is reset to 0 when S appears. Any and all help would be very greatly appreciated! Thanks!
|Feb 22, 2005, 09:13 PM||#2|
Well, you're sorta on the right track, but I see several errors.
First, are these letters input from the keyboard? I'm assuming so, it seems a little early for you to be doing file input.
OK, on to the errors. You need a loop. As is, your program will read one letter, determine what that letter is, add or subtract from current, and then print out either -1, 0, or 1.
Adding the reset is rather simple. Add a case to your switch for 'S'. In that case, you set current = 0.
Your if... else with the current and max is incorrect. I'll go ahead and tell you it would be this:
if(current > max) max = current;
Also, you need some input letter to indicate that the session is over and you can exit the loop.
Pseudocode for your program:
Declare and initialize variables.
Adjust current variable accordingly.
If current > max
Then max = current
End loop. Exit if 'end session' characer is input.
Hope this helps.
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|Library for simple Face and QR Code/Bar Code/Etc detection||DarthFoley||iPhone/iPad Programming||0||Jan 26, 2014 12:11 PM|
|Resolved: ML code for OSX server code||Processor||OS X 10.8 Mountain Lion||5||Jul 27, 2012 11:51 PM|
|AppStore:"The code you entered is not recognized as valid code" (or Already Redeemed)||sevimli||OS X 10.8 Mountain Lion||223||Jul 27, 2012 04:50 AM|
All times are GMT -5. The time now is 07:13 PM.