|
||
Please check
this list semi-regularly. I may send you here if your question has
already been answered. Individual assignment questions will not show
up here, but rather on those assignment pages. The newest questions
will be placed on top.
(the newest questions are at the top) Project 6 Q&AWELL, I HATE TO SEE PEOPLE SO FRUSTRATED AND STRUGGLING, SO THE ANSWER BELOW SHOWS A LITTLE MORE THAN I EVER INTENDED ON GIVING YOU. PLEASE REALIZE THAT IF YOU HAVE DONE THINGS DIFFERENTLY, THIS DOESN'T MEAN YOU'RE WRONG! YOU HAD A LOT OF FREEDOM IN THIS ASSIGNMENT, SO DON'T THINK FOR A SECOND THAT THIS IS THE ONLY WAY TO GO ABOUT IT, OR THAT IF YOU DID IT DIFFERENTLY YOU ARE SOMEHOW WRONG. I JUST WANT YOU TO LEARN ABOUT CLASSES, AND WRESTLE WITH CREATING ONE YOURSELF.>Anyway, I am utterly
stuck on this project. I have gotten next to nothing finished because
I simply can’t organize the
Ok, it seems like classes are bugging you completely. Here's what to do to get somewhere. It's not the most elegant approach in the world, but just take the Date class and change it (use the monolithic file to start with, you can break it up later). Change the field names to the things you need to represent for a fighter (strength, punchPower, kickPower, and block). Then write yourself accessors for each of these, a read method, and a set method. These are all very short and just like the Date class, but they work on Fighters instead. Next, write a little block
of code that uses the methods you've done. I was hoping you guys
would come up with this kind of thing, so realize, this is only a SUGGESTION.
Here is a small segment that reads in fighter information, then has f1
try to punch f2.
Fighter f1, f2; f1.read();
cout << f2.getName() << " strength = " << f2.getStrength() << endl; // let f1 punch f2
// get the power of the punch
// tell f2 to take this damage
} cout << f2.getName() << " strength = " << f2.getStrength() << endl; cout << f2.getName() << " is ";
NOTE: You could replace the two lines in the else with this, if you wanted (this is equivalent): f2.takeDamage(f1.getPunchPower()); You are probably getting
caught up also on how strength, punch power, and blocking all work.
This is where you have to make something up and
>As I said, utterly lost
and again frustrated….. Perhaps it’s the fault of the text (hence,
your reference to another
I'm sorry it feels like that, trust me in that the frustration is from figuring out classes and not from this project. Most of the methods you will write are one liners, with a few perhaps 4 or 5 lines. The function that let's the two fighters go at it will be more lengthy, but still not that bad. Good luck, I hope this helps.
> If a player takes a hit, how do we know if the person > is taking a punch or a kick? Can you help me with the > expression, thanks. All that matters is that a player takes damage, it should not matter if it comes from a punch, kick, or an anvil falling from the sky. Just have a method that handles when damage is done. The paramter to this method would be the amount of damage done (which does depend on the other fighter, of course). Here's the idea: Fighter 1 does a kick
The details are up to you,
for example, fighter 1 could choose to punch instead, or fighter 2 could
choose to fight back instead of blocking, it's all up to you! Usind
random numbers to make these decisions is the best way to go, however,
since this is a simulation and not a game.
> Just need you to clarify something for me. Am I supposed to have the user > of the program press buttons to make the fighters punch, kick, block or are > we supposed to write a random function and let the user of the program sit > back and watch the fight on the screen? I suggest you just go with a simulation. While it would be cool to let two people decide on punches & kicks, we don't have the graphics and/or real time control to make this very realistic. So, use random numbers to control these decisions, when to punch, when to kick, when to block, etc. Just try to make it as realistic as possible within the framework we have set up. Comment a lot to explain your choices.
> can you give any hints for doing project 6? please! Try not to get overwhelmed, there really isn't anything horribly tricky about the assignment. You have to make some decisions, though, so just start simple and make sure you understand the date class inside and out. Start by writing your class header, write a few simple methods, then write a main() that uses the class. Once you get some simple things working, you can then add features one at a time. I can't really give more than that because then I'd be making the decisions I want you to make!
> I have a question about the testing file (stage 1) of > project 6. After throwing a punch, you want to perform > a kick and also print out the damage would be done to > the opponent. So what you want is the separate damage > from a punch and from a kick, or the total damage > after a punch and a kick? If you look at the project > page, in the stage 1, are number 3 and 4 related to > each other? Do you want to update the amount of damage > after performing a kick by adding the damage from a > punch? Or just print the damage of each case > separately? Please clarify, thanks. I think it is more realistic to keep punches and kicks separate. Your stage 1 is just there to test your methods and make sure your class works like you expect it to for the later stages, so do what you need to do to verify its correctness. I also don't think you should
complicate matters by letting a fighter do more than one move per round,
but if you want to, go for it.
Exam 2 Q&A
Well, you're not quite approaching it the right way. Think of it this way: Factorial is a problem. It's defined as follows: n! = n * (n-1)!
For example, 4! = 4 * 3!
Now, if you want to implement factorial in C++ you have to decide HOW TO DO IT. There are really only two ways to go about it: 1. use a loop
(iterative)
Thus, recursion is a WAY of solving a problem and factorial IS a problem. Nose around in the book, you'll find the iterative solution to factorial in there as well. The book didn't muddy up the waters, they had to pick some example to show how recursion worked! Now, the test problem is a different problem and much simpler than factorial. Here's how the CallMe example pans out: CallMe(8)
= 3 * CallMe(6)
CallMe(0) hits the base-case, which forces the recursion to stop. We can look at this and see 81. But, the computer has to "unwind" all the calls to CallMe(), so it is better to see it like this: = 3
* 3 * 3 * 3 * 1
Btw, you may want to review
lab 4, it introduced recursion and was pretty gentle, in my opinion.
Project 5 Q&A
Sure... you'll need another variable to hold that player's name. When you find a new leader in a category, update that variable at the same time. >
Good point, that was an oversight
by me. Let's use batting average. I'll update the example on
the web.
> I had a question about
the vars used in project 5...it would be much easier
Oh, I think the abbreviations
are sufficient. Be careful, though, some of them are not valid C++
identifiers. Minimal commenting would be good, yes, for each abbreviation.
I was working on project
5 and it's in the very beginning stages but i was
It just means that a players listed at-bats is not the true number of times that player has gone up the plate because walks and hbps are not included in that total. That way your batting average doesn't suffer when you get a walk (because it's a good thing). It was a clarification anyway, you can just use the formula exactly as it appears without understanding this. My suggestion for testing
is to use a very simple file (make one up and just put one line it, maybe
the Babe example?). It is always easiest to test on something small
early on.
>
It won't update the file, it will erase it and start a new one with the same name. In other words, it "overwrites" the existing file. This error message would pop up if you were on a computer system that did not allow you to create new files, or at least you were in an area where you don't have write access. >
Sure, write a small function
to try and open the file as an INPUT file, then if that fails, you know
the file doesn't exist. You don't have to do this in your program,
but it would be cool.
Comparing the sample output file and the sample screen display, I’m seeing there is a mismatch. Based on the result in the output file, the SLG team leader is supposed to be Drew (0.688). Yet the sample screen display you have on the project 5 webpage shows that Edmonds (0.539) is the SLG team leader. I was just wondering if your plan was to put the wrong result because it’s just a sample display or there is a reason for selecting Edmonds over Drew? Please clarify. No, it was a mistake.
I fixed the problem and the project page. Good job.
Another question is: when 2 people have the same record high (e.g Drew and Pujols have 21 home runs), who should be a leader? Just print either one as
the leader. In order to properly handle this (by printing all players
with 21 home runs), we would need arrays, which we haven't covered in class
yet.
> I was trying to open
the sample output file for
The computer you are on has
a file association for .dat files, it appears. You need to right
click on the file and do a "save link as" and specify a location.
From there you can open it up in notepad, or in a borland editor window,
or even word.
Project 4 Q&A(6/30)> I was wondering if there
is a command to clear the screen. I have
answering his own question... > I guess I should have
checked the help first. I found the command.
> 1. I can't find any reference in my notes or on the web for > "acceptableRange() function". Can you tell me where its at? Here you go. It was from 6/18. >
Nope! What you did is totally fine, you put your primary loop and switch a separate function. >
I'd suggest simplifying the condition on your loop. The general layout could be something like this: do
Thus, when the quit choice is seleted, the loop (and program) will end. >
I'll have to respectfully disagree. Intro to CS courses are like this all around the country, it's 4 credits and they were serious about the prior-programming background in the course description. Take a look at an assignment from a previous semester: It was the third assignment out of six, no less. Now, if this was CS7 (intro to Pascal), I'd totally agree with you. But this is an intro for CS majors with some programming experience.
> Based on the requirement for giving the user the option to reuse the > inputs and the previous calculated results, I found it extremely long > for the main function. Perhaps there is a better way to do it, I just > don't see it right now. > > To make sure that my program meets the requirement, I drew a general > structure for each case consider all the possible inputs and available > results that can be reused if the user wants. I attached here the > structure of Case 1 in main(). Please review it and let me know if I'm > heading the right direction. If this is the right structure, then in my > program, there are more than 3 pages of code just for Case 1. Does it > sound right? > 3 pages is definitely way too long for one case. I could possibly see all of main() taking close to 3 pages, but still that seems a bit much. Also, I want to make sure you know that this should be one of your very last modifications! It's tricky and you should definitely get a core program working that always asks for new input before you work on this part. I certainly don't want
people struggling this much, so I'm going to go ahead and suggest a
direct approach. Consider some function f with two inputs. Let's
deal with each argument individually. Pseudo-code to recycle previous input
would look something like this:
// obtain first input (x)Notice that the second if statement (for each) can be true if (1) the user requested a new value, or (2) the user has not entered a value for that variable yet. Thus, if the user does indeed want to give a new value for x, then somehow it needs to be "reset" so that the if statement immediately after it is true. To do this in C++, you may need to set up some other boolean variables to keep track of the status of your variables, or something. Also, I take back what I said about functions being used here. It looks like you could write a nice function with a reference parameter that reads in a variable if the user says s/he wants to enter a new one. This would clean up your cases dramatically.
> The wet bulb thing is screwing me up and so is the manipulators. what you > said in class isnt working -- about setiosflags and setprecision. are these > functions? or you just type them in or what?? I keep getting an error call > to non function so...!! also reusing the value already computed... thats > another tricky part! can you help at all?????? I can try. Let me say, though, that the frustration you are feeling is a part of programming. Sometimes things just don't work the way you want and you just have to keep fighting it. About this project... First, I strongly suggest not messing around with too much at once. For example, don't worry about the floating point output until you have some more basic things working, like the wet bulb function. Here are the rough steps you should take to convert the Wetbulb program into a function:
I urge you to copy and paste this into an empty Borland text-edit and run it. Play around with it and observe your changes, it's the best way to learn. Finally, about recycling the variables. Yes, it is tricky and something you should not attempt until you've got everything else working smoothly. If you don't get this ultimately to work, yes you'll lose points, but it is tons better than turning in a dog that attempts to do it, but screws up everything else. I suggest saving your program under different names at different stages too. As far as help goes on how to do it, I can't really tell you much... I want you to figure it out. Just ask yourself how you can detect if a value has been seen before at each time input is obtained. Do what you gotta to do detect this. Also, start small: get it to work for just one of the inputs, like RH. Then expand your solution to the other variables.
I am working on project 4 right now. So far so good, except the program seems long. Is it supposed to be this long? So far, what I have in my program are 6 functions (5 for calculation purpose and 1 for the menu), and one "long" main function. The main function wasn't that long until I added the option of reusing the temperature value. I don't know if there is a way to create another function for the reuse option. I'm still thinking about this. That's good. Of course,
there are lots of ways to write the program, but you should definitely
have 5 functions, one for each of the weather formulas, and another to
print the menu. All of these are called from main(), which can get
quite long given the amount of detail it has to handle. In this case,
it is totally fine for it to be long. I can't think of a clean way
to use functions to help you in the reuse of previous values.
One problem I ran into is: For the default case: if an invalid number is entered, then the error message appears. But along with it, the last result also appears before the menu. How do I fix this? Therefore, you don't want
to print for every menu choice, you only want to print for some of them.
Thus, you need to "protect" the print statement, much like you did with
printing in the hailstone program, with an appropriate if statement.
On the project page where you said "do not use any global variables for any reason", can you please explain this? Check out section 6.6 in
your book. In a nutshell, any variables you use in your program need
to be declared either inside of main(), or inside of one of your functions.
Global means it is accessible from everywhere. For example, your
prototypes are in a global location, they can be called from anywhere in
your whole program (main, functions, etc.). The problem with global
variables
(prototypes are not variables, of course) is that it makes programs very
difficult to follow (and modify, and debug, etc.), so we won't be using
them in our programs.
General Questions
Can you recommend any supplemental C++
books?
What labs can I use? Do I need
an account?
Can I use a different compiler?
Can I do the work at home?
Where can I get Borland C++ V5.02?
How do I turn in assignments?
Can I attend either lecture?
Can I attend any of the labs?
Can I safely skip the labs?
|
||
© 2000-2001 Jim Skrentny, University of Wisconsin |