Starting from:

$30

CS115-Lab 8 Classes and Inheritance Solved

1.      Download the class Question​   (​ Question.py​          )​ that represents a typical Exam Question object. Review the details of this class.

a.      The class stores the following data attributes:

●  questionText

●  correctAnswer

●  score

●  studentAnswer

b.      The class defines the following methods:

●  an ​ __init__()​         ​ ​method​ ​that initializes the first 3 data members with values passed as parameters, initializes studentAnswer​          ​ to None.

●  Methods to return and update the values of all data attributes.

●  isCorrectAnswer()​: returns True if the correct answer matches the studentAnswer,  false if not.

●  answerQuestion()​: takes an answer as a parameter, and sets the studentAnswer​ with the value passed as a parameter.

●  scoreQuestion():​ if the studentAnswer​ is correct return the question score, otherwise return 0.

●  displayQuestion()​: prints the question text.

●  __repr__() returns the string representation of the Question​ object formatted as in the sample run.

 

                

 

c.      Write a class called  TrueFalseQuestion​        (​ TrueFalseQuestion.py​     )​ that represents subclass of a Question​               .​ 

                       a.    The class will store the additional data attribute:

●  incorrectPoints:​  the number of points to be deducted in case of a wrong answer.

 

d.      Your class should have an ​ __init__() ​          that:​      ● initializes the inherited data members to values passed as parameters, using the super class __init__() ​               method.​              

●  initializes the incorrectPoints​        to the final value passed as a parameter.​      

 

e.      You should override the following inherited methods:

●  scoreQuestion():​ if the studentAnswer​ is correct return the question score, otherwise return the negative incorrect points.​

●  displayQuestion(): prints the text: ‘True or False: ’ followed by the question text.

 

2.      Write an application, Exam.py,​           ​ that includes the following functionality:

a.      initializeQuestions():​ 

●  takes a fileName and an empty list as parameters. ● Using the data about Questions in the file, creates

Question/​ TrueFalseQuestion​   ​ objects and adds them to the list passed as parameter.

 

b.      gradeExam():​

●  Takes a list of Question ​         objects as a parameter.​ 

●  Displays a header *** Grading Exam ***,  see sample run for details.

●  Scores each question and returns the total points, and the sum of the correct answers for all questions. Correct answer score should be determined using the scoreQuestion() method for each question.​            

●  For each question answered incorrectly, displays the questions with the heading ‘Incorrect Answer’.  (see sample run)

●  Displays a footer *** End of Grading ***,  see sample run for details.

 

c.      The program should do the following:

●  Read the questions from the file using the function defined above.

●  For each question in the list, display the question and input the student’s (user’s) answer.

●  Store the student answer for each question.

●  Once the exam is finished, grade the exam using the function, and display the final score as shown in the sample run.

 

                

Sample File:

The file is a semi-colon delimited file, containing the following on each line: type of question (T for True False or R for regular), the question text, the correct answer, and the points. If the question is a true false question, it also contains points to deduct in case of an incorrect answer.



 

 

Sample Run:

True or False: 

Python is not a high level programming language?

 

Enter choice: True

Who invented Python?

 

Enter choice: I don't know

In what year was Google launched on the web?

 

Enter choice: 1998

In computing what is Ram short for?

 

Enter choice: Random Access Memory True or False: 

The # symbol can be places to the right of an executable statement ?

 

Enter choice: True True or False: 

Non-zero values map to False in Python?

 

Enter choice: False

 

 

*****************Grading Exam***************** Incorrect Answer!

Python is not a high level programming language?

Your Answer:True

Correct Answer:False 

 

Incorrect Answer!

Who invented Python?

Your Answer:I don't know

Correct Answer:Guido van Rossum 

More products