Wednesday, January 22, 2014

An useful example of OOP.

    After the study of object oriented programming, I came up with a idea that I want to write a review program for myself to cope with those courses with a lot of definitions. In this case, I decided to write all the definitions in a text file: one definition per line, and each phrase would be separated from its definition by a "*". I used ADT to store my definitions. Basically, it is a dictionary, each key is a phrase, and the corresponding value is its definition. All of these are finished in initialization. After that, i add several method to this class. Firstly, there is a  pop method, it means when I got the right definition, I don't need to review this phrase anymore. Moreover, there is a method called "get_question", which is a getting a random number in range(2). If it is 0, then the phrase will show,  i need to give definition, and  compare with the formal one. if it is 1, there would be a multiple choice.  Whenever I get the right answer of one question, the corresponding key would be pop from the dictionary. Also, there is a method to check if the dictionary is empty, and whether I would like to restore the definitions and begin a new round. I import this class to my main function, use some while and if statements to make it a loop, I am pretty sure it would be helpful for remembering both the definitions and the OOP programming in csc148.

2 comments:

  1. TA: Talk more about the important concepts in the topic. Good work trying to implement your own ADT.

    ReplyDelete
  2. TA: Please use a SLOG with only English characters so others can easily find the button to post comments.

    ReplyDelete