CS 115 – Introduction to Programming in Python Lab Guide 08 Solved

35.00 $

Category:

Description

5/5 - (1 vote)

Lab Objectives:  Classes and Inheritance​

Instructions:​ Upload your solutions as a single .zip file to the Lab08 assignment on Moodle before the end of your lab session. Use the following naming convention:

SS_Lab08_Surname_FirstName.zip where SS is the section number 01, 02, 03, etc.

 

  1. Download the class Question​ (​ py​          )​ that represents a typical Exam Question object. Review the details of this class.
    1. The class stores the following data attributes:
      • questionText
      • correctAnswer
      • score
      • studentAnswer
    2. 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.

 

 

 

  1. Write a class called TrueFalseQuestion​       (​ py​ )​ that represents subclass of a Question​              .​
  2. The class will store the additional data attribute:
    • incorrectPoints:​ the number of points to be deducted in case of a wrong answer.

 

  1. 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.​

 

  1. 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.

 

  1. Write an application,py,​ ​ that includes the following functionality:
    1. 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.

 

  1. 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.

 

  1. 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

 

*****************END OF GRADING*****************

Your score is:  17 / 27

 

  • Lab08-qc0wu0.zip