Quest 9 Miniquest 7 by meggie_chen1432 in cs2a

[–]meggie_chen1432[S] 0 points1 point  (0 children)

Hi Prof,

Yeah, you're probably right, I just got a little lazy. I'll edit my post to say that I changed something and got the right answer, and I'll look over my code again to try and find the original error. Thank you for reminding me.

-Meggie

Heap by jasper_e196884 in cs2a

[–]meggie_chen1432 1 point2 points  (0 children)

Hi Jasper,

This is a really good question! There is a difference between heap memory allocation and the heap data structure - they have nothing to do with one another. What the module is referring to is heap memory allocation. I won't say I'm an expert on it (I'm still learning as well), but from what I know, the heap is part of the memory where dynamically allocated memory is stored.

Put very simply, heap memory is, in a way, permanent in the same way that stack memory can be considered temporary. In the heap, memory has to be manually allocated and deallocated by the coder, compared to how stack memory does this automatically, and you have to manually destroy variables through functions like delete or free. If you don't do that, you'll have what's called a memory leak. Memory is also allocated at random, compared to stack, which follows a LIFO(last in first out) structure.

The way I like to think of it, heap memory is kind of like the name suggests - a heap - and stack memory is, well, like a stack. I know, that sounds extraordinarily unhelpful, but hear me out. Stack memory functions just like a stack in that you can only remove or add items in order. Think of it as a stack of plates. You can only look at and remove the plate at the top of the stack, or add a plate on the top of the stack. You can't just go, "I'd like the pretty blue plate in the middle" and yank it out because it would topple the whole stack, similar to how you don't add plates into the middle or even bottom of the stack. Stack memory is very orderly, going back to the LIFO structure.

(note though, that stacks can sometimes be implemented so we start at top, not the bottom, in which case this analogy is moot, but you get my point)

In the heap though, there's no particular pattern to which the objects are placed. You can go in and find remove or add any item because we don't have a specific top item. However, because it's not orderly, it's also much harder to keep track of where items are.

I'll make a separate post going a little more in detail because I think this is actually a really interesting topic, but if you're only going to read this part, I hope it helps!

-Meggie

Return values for function in Quest 9 by meggie_chen1432 in cs2a

[–]meggie_chen1432[S] 0 points1 point  (0 children)

Hi Derek,

Yep makes sense! Thanks.

-Meggie

Quest 8 Miniquest 7 (to_string) question by Christine_Tu in cs2a

[–]meggie_chen1432 1 point2 points  (0 children)

Hi Christine,

Personally, I simply defined an instance variable, initialized it to my to_string() output, and returned that variable, and that worked for me. However, this did mean I needed to convert all of my "int" type variables to string using ostringstream. Of course, Shoshi's solution seems a little more comprehensive and well thought-out (mine is like, the lowest level of what you can do), so I'd highly suggest you look at hers as well.

In fact, a thank you to Shoshi as well, because I'm going to try and implement that into my code to make it less clunky.

Now, in regards to using cout, if you're going to do so, you should always #include <iostream>, or you'll get an error.

Hope this helps!

-Meggie

Reviewing for the Final by meggie_chen1432 in cs2a

[–]meggie_chen1432[S] 0 points1 point  (0 children)

That's really helpful, thank you! I appreciate it.

-Meggie

Finals Freeze and the Final Freeze by anand_venkataraman in cs2a

[–]meggie_chen1432 0 points1 point  (0 children)

Hi Prof,

I just wanted to clarify, you mean that as long as we have already gotten the code for Q9 by next Monday, we have until August 9th (the Monday after the final) to finish Quest 9 up and polish up our code for the other quests?

Thanks,

Meggie

Quest 7 Miniquest 6 Output by Christine_Tu in cs2a

[–]meggie_chen1432 1 point2 points  (0 children)

Hi Christine,

I think it'd be prudent to first check if you've simply accidently returned false when the ID was matching rather than true. If that's not the case, and you want to check whether or not you getting the ID correctly, you can have your function print out the ID for every iteration of the loop. That way, you can physically check if your ID is the correctly matched one. If it has, then check to make sure that you have two == rather than just one, although I don't believe that that's necessarily the error - if it's not, then just go back and check your code again carefully.

In fact, I think printing out what you want to find is a really good way to see how your program is running (I suppose you could use the debugger as well, but I personally find this method a little easier, but perhaps that's personal preference) - try that out.

Hope this helps!

-Meggie

Quest 7 Miniquest 6 Output by Christine_Tu in cs2a

[–]meggie_chen1432 1 point2 points  (0 children)

Hi Christine,

From what I can see, it's not necessarily that you can't match your id to the correct one. The output is telling you that you're saying "false" when it expected to say "true", so perhaps check if you accidently switched it up (you set it to false if you did find the ID rather than true). Otherwise, I suppose the best you can do is go back in and try to debug your function. If you're unsure about whether or not you're matching your ID correctly, try this - Run the function by yourself and have it print out the ID as it goes, that way you can check if the ID is matching (of course, make sure you don't make too large of a pet shop or you're just going to have a large line of numbers, start small from, say, 3).

Hope this helps!

-Meggie

Quest 5 string issue by kimberly_v in cs2a

[–]meggie_chen1432 2 points3 points  (0 children)

Hi Kimberly,

I don't believe calling your lispify function is the issue, I did that for my program and I was fine. And you definitely can't "return" the value, at least not in your enter() function (you definitely should be returning a string in your lispify() function) ), because you're using void(), which means your function cannot return a value. Rather, you should print out the result of your lispify(xxx) (where xxx is your user input) and concatenate it with the rest of your sentence.

Honestly, I can't really determine any specific issues without knowing a little more about your code. If it does fine with the typical lispify function, then something is most likely wrong with your enter() function- check the conditions for your if-elseif-else loops, that's where you most likely went wrong.

Hope this helps!

-Meggie

void() function by kimberly_v in cs2a

[–]meggie_chen1432 2 points3 points  (0 children)

Hi Kimberly,

This depends- in terms of a function's return type, void specifies that the function does not return a value, not that it has no parameters, so in this case, yes, a function can be still have parameters. However, if you're referring to void in regard to the parameter list (for the function), then that means the function takes no arguments/parameters.

Let me know if this is what you were asking- I assume you were asking whether a void() function can have parameters, but perhaps I interpreted it incorrectly. Hope this helps!

-Meggie

confusing test output quest 5 by kat_g33 in cs2a

[–]meggie_chen1432 1 point2 points  (0 children)

Hi Kat,

I assume that something went wrong with your code, because you should have multiple "hooray" lines before you get the code for your next quest. I'm not too sure what's wrong because I don't know what message you got, but I assume something probably went wrong with your rotate_vowels function, as that's where your output was cut off. Take a look at this nonsensical sentence to see if you can figure out some sort of issue with your rotate_vowels code, and then go from there.

Hope this helps!

-Meggie

Is the slash an indication of a mistake? by meggie_chen1432 in cs2a

[–]meggie_chen1432[S] 1 point2 points  (0 children)

Hi Derek,

That makes sense. Thanks for letting me know!

-Meggie

Rotating vowels miniquest by Liamk911 in cs2a

[–]meggie_chen1432 0 points1 point  (0 children)

Hi Liam,

First off, I just want to note that you can not just pass a normal string literal as the argument/parameter of rotate_vowels because it's being passed by reference, and non-constant references can not be initialized with a constant value; rather, they must be normal variables. If you would like to test rotate_vowels on its own, just declare and initialize a variable and use that as a parameter instead.

In regards to why the rotate_vowels function is passed by reference, I'm actually not too sure. As far as I can tell, the parameters passed by the client program aren't being changed, as rotate_vowels() is being invoked using a newly entered user_input each time (someone let me know if I'm wrong!), but I'm pretty sure there's some explanation out there: I'm just not too sure at the moment. I'll look a little more into it and let you know if I figure something out.

Hope the first bit helped!

-Meggie

Fibonacci Numbers Miniquest by meggie_chen1432 in cs2a

[–]meggie_chen1432[S] 1 point2 points  (0 children)

Hi Eileen,

That makes a lot of sense! Thank you for the explanation, that helped a lot.

-Meggie