lundi 27 juin 2022

Trying to make my program more efficient in terms of vectors, but I'm not sure how to go about it? [closed]

Here is my github link for the code to look at: https://gist.github.com/rarelambo21/e385c6dd228d7dc949fe689999d203b1

To give some context, I am working on some side projects in taking some of my old lab classes and trying to program them in other languages. Originally this program was for C# but I decided to code it in C++ and use vectors.

How the program works, is that it ask the user to some questions. The user can enter questions, answers and difficulty into the quiz, remove them, modify them and take the quiz as well. Option 6 is a debug feature I added to make sure everything is being added into the vector right. In the original lab, it used array list or list in C#, which is why I chose vectors.

My question is mainly for the function "removeQuestion()." That was my first time using vectors to thing length, and I wasn't sure if this was the most optimal way to remove vectors from the stack. I did it in this way because I wanted to remove a specific vector from the stack and out of all the options this was the way that made sense to me. If there is a better way I would like someone to point me in the right direction.

Also, I wanted to know why this line of code didn't work for the vector: question.erase(question[rIndex])

But why does this line work for vectors: question[rIndex] = inputQ

Also if there are other pointers that you can point out in my program that can make me a better programmer please feel free to inform me. This is my first time trying things out on my own so, I'm sure I made some mistakes or could have done things better in some way form or fashion.

PS, I added a lot of comments especially in the beginning of certain functions because someone told me that it is a good practice to comments things like that for the purposes of yourself and other going back and viewing your code. Are the comments a it too much, or it is a good mix?

Thank you.

Aucun commentaire:

Enregistrer un commentaire