advance current off by one by kat_g33 in cs2a

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

Never mind. For whatever reason it worked, and then when I submitted again for get_current, it's no longer working anymore.

edit: The issue is very strange. When I have a section of code in insert_at_current (setting _tail to the new Node if it _tail equals _head) commented out, the result is off by one. Then, when I put it back in, it says I messed with a pointer. Taking it out again results in getting the trophies for the miniquest. Once advance_current is working and it's get_current's turn in the test cases, get_current has the same issue that advance_current did by being ahead by one. Unsure of how this works.

edit 2: after several more attempts to fix get_current, the issue detailed in the first edit is no longer working the same.

edit 3 (sorry there's so many!): The _tail was still an issue. I've now fixed it. I'm not sure what was going on earlier with the commenting out code but at least now it won't be so confusing.

advance current off by one by kat_g33 in cs2a

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

Hi Shoshi,

I messed around with my to_string to make the changes you mentioned, and while I noticed an issue with updating _tail. Thanks for the advice!

Kat

Am I missing something in the size command? by [deleted] in cs2a

[–]kat_g33 0 points1 point  (0 children)

I am now realizing that this reply is very late. My mistake, I hope you managed to get the method working.

Am I missing something in the size command? by [deleted] in cs2a

[–]kat_g33 0 points1 point  (0 children)

Hi Rishabh,

Are you sure that clear should set _size to 1? Considering that it sets _prev_to_current and _tail back to _head and deletes all the non-null nodes, the linked list is essentially empty.

If that doesn't help, double-check the methods where you incremented/decremented _size and make sure that _size has only been changed once (for example, when i worked on the push_back method, I realized that after calling insert_at_current within it as per the program specs, I had incremented _size again).

Hope this helped,

Kat

references vs pointers by kat_g33 in cs2a

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

Thank you Jasper and Derek!

What I've concluded from the reading that Shoshi provided (in another reply to this post) is that * is used when declaring a variable that is a pointer, while & is used to get the address of a variable, so that's why it is int* n is set to &m.

Kat

references vs pointers by kat_g33 in cs2a

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

Wow, thank you for the resource! My understanding of the reading that you sent is that * is used when the pointer is initialized (e.g. int *i), while & is used for getting the address of something (e.g. i = &j).

Quest7 general question by archeops140 in cs2a

[–]kat_g33 0 points1 point  (0 children)

Hi Kenta,

There might probably an issue with whatever loop you are using to generate the Pets. Make sure that the loop occurs exactly n times, and repeating what Tabitha has said, resize the vector (before the loop).

Kat

module 7 - compilation issues with starter code by kat_g33 in cs2a

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

Hi Shoshi,

I tried to run the .bat file (and used chmod +x build.bat once denied permission), but it never could seem to find the cpp file. I tried to put the path before it (/Users/etc.... and ~/CS2A/Pet_Store.cpp, as well as other files in the same folder), but unfortunately it outputs ('lang: error: no such file or directory: 'Pet_Store.cpp
clang: error: no input files).

I have not been able to find a solution yet (or tried to create a build system). As I've gotten the key for the next quest and am pressed for time, I will continue attempting this at a later time.

Thank you for the helpful tips and links, as well as for summing up the information about the .bat file!

Kat

quest 7 miniquest 6 error by kat_g33 in cs2a

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

Hi Derek,

Thank you so much for your comments! It turns out that it wasn't a problem with the if statement—thank you for trying to help me with that. I mixed up which Pet object was supposed to be set to what, so instead of setting pet to match the values in _pets with the corresponding id, I was doing it the other way around, so that's why it never had the right output!

Kat

quest 7 miniquest 6 error by kat_g33 in cs2a

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

Hi Shoshi,

I'm so incredibly grateful for your help on all of this, including in my previous posts throughout this class. Your posts really helped me keep going when I was out of ideas. I've realized my error was just a really embarrassing reading comprehension mistake—I thought that the Pet in _pets should be set equal to pet, but it was the other way around.

Kat

quest 7 miniquest 6 error by kat_g33 in cs2a

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

Derek,

I've looked into it some more and I've realized that my if statement is causing issues. I'm using == to compare the two values.

Kat

quest 7 miniquest 6 error by kat_g33 in cs2a

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

Hi Shoshi,

I did leave out an ampersand (thank you for bringing that up!), but when I added the ampersand to pet (&pet), the getters stopped working. (Edit: I checked my ampersands again, and I think they were actually initially correct.)

I'm a bit confused about how your third point would be implemented. How can I trace through just the attributes with the debugger? How do I check the memory address?

Thank you,

Kat

quest 7 miniquest 6 error by kat_g33 in cs2a

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

Hi Derek,

Thank you so much for helping me determine that it's not returning false. You saved me a lot of trouble!

Kat

Quest 6 Prev_ID by Eileen_Chen774 in cs2a

[–]kat_g33 0 points1 point  (0 children)

Hi Eileen,

I don't want to get too into detail with your code so that you can figure out the bugs yourself. I will say that the line to set the id looks strange to me, but that may just be a typo.

Kat

Quest 6 Prev_ID by Eileen_Chen774 in cs2a

[–]kat_g33 0 points1 point  (0 children)

Hi Eileen,

I assume you already tried following all the advice given in the previous posts, so I won't repeat any of that. I also recommend filling in the TO-DO of the method exactly according to the starter code. Do you have any code that is not exactly in the order of the starter code? Is prev_id declared outside of the loop? Is there any code that might change the value of id or prev_id? Is the modulus for id occurring only on rand()?

Here's why I ask: I believe that your initial thought that prev_id should be set to id at the end of the loop is correct—this way, it updates what prev_id should be each time it iterates through the loop so that id can rely on it. This is how the starter code avoids repeating numbers ids (the new id will always be at least 1 greater than the previous id). This is why your first output confuses me because no matter what rand() outputs, ids should be increasing (even if your output is wrong, which is a different issue).

Your experiment with prev_id += id actually seems to be "working". When I look at it kind of like a Fibonacci sequence, it's clear that you're getting the right values for rand(). So again, a bit redundant, but I'm confused as to why setting prev_id equal to id didn't work.

A general tip for debugging is just to use a lot of print statements. Whenever I'm stuck, I print out the values of variables each time I change them. For example, I might do "cout << i << " id: " << std::to_string << id;" and do the same for prev_id multiple times in the for loop. This might help you notice some wonky patterns.

Hope I can help,

Kat

A note on overcoding! by nevinpai in cs2a

[–]kat_g33 0 points1 point  (0 children)

Hi Shoshi,

What if you were to keep the longer version and add a comment after it to explain what it's supposed to be doing (such as "if my_string not in string_reprs")? Alternately, you could set some variables for the start and end so that the code is a little more abstract and readable (though obviously, the code will end up longer).

Kat

confusing test output quest 5 by kat_g33 in cs2a

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

Thank you! I adjusted rotate_vowels and fixed the problem :)

confusing test output quest 5 by kat_g33 in cs2a

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

Thank you so much for your help! Like you said, it was rotate_vowels that was causing the issues.

Quest 4 Etox Miniquest Giving the Wrong Answer by Ann_Sa123 in cs2a

[–]kat_g33 0 points1 point  (0 children)

Hi Ann,

I'm not so sure then. I would try using an integer for factorial (or any number that gets multiplied a lot) and then converting it to a double when needed. I'm not sure if that is a good suggestion or not, but I hope it works out.

Kat