PSEUDOCODE PSEUDOCODE PSEUDOCODE The DriveRite Insurance Company provides automo
ID: 3855212 • Letter: P
Question
PSEUDOCODE PSEUDOCODE PSEUDOCODE
The DriveRite Insurance Company provides automobile insurance policies for drivers. Design a single class diagram showing the class, the application program, the relationship between the two, and multiplicity. Insert the completed class diagram into a Word document. Then write the pseudocode as described below. Be sure to follow the CSI 117 Style Criteria (Links to an external site.)Links to an external site. for naming conventions, class diagrams, pseudocode, keywords, and operators.
a. Create a PolicyHolder class that contains a policy number, customer age, and the number of accidents in which the driver has been involved in the last three years. Include the following:
i. A default constructor that initializes each attribute to some reasonable default value for a non-existent policy holder.
ii. Another constructor method that has a parameter for each data member, called the overloaded constructor. This constructor initializes each attribute to the value provided when an object of this type is instantiated. If the customer's age is not between 14 and 125 inclusive, then display an error message and set the age to 0.
iii. Accessor and mutator methods for each attribute. For the age mutator, if the customer's age is not between 14 and 125 inclusive, then set the age to 0, since this is obviously an error.
iv. A method that displays all the data about a policy holder.
b. An application program that contains two modules: the main() module and the checkAccident() module.
Include instructions in the main() module to do the following:
i. Create and initialize a PolicyHolder object using the default constructor, naming it newPolicyHolder. Call the appropriate methods to initialize all the data members for the newPolicyHolder object, choosing appropriate values.
ii. Create and initialize 2 different PolicyHolder objects using the overloaded constructor. Choose appropriate values for the attributes for each of the two PolicyHolder objects.
iii. Call the checkAccident() method for each PolicyHolder object, so there will be 3 calls to the checkAccident() method.
The checkAccident() module must do the following:
i. Accept a PolicyHolder argument (i.e., it has a parameter declared using PolicyHolder as the data type).
ii. Display all the data for any policy holder that is over 35 years old and has one accident or less.
Explanation / Answer
For policy holder class:
Create a class called policy holder(make sure it is public)
Define variables in it as follows:
1 int for policy number
1 int for age
1 int for number of accidents
Define a function with no return type and only the name policyholder. It doesnt have any parameters either.
Set policy number, age and accidents to 0
Define a function with no return type and only the name policy holder. It has three int parameters.
Set policy number to first parameter
Set age to second parameter
Check if age is less than 13 or greater than 126.
If yes, then print "error" and set age to 0
Set number of accidents to third parameter
Define a function setage with void return type and one int parameter
Set age to first parameter
Check if age is less than 13 or greater than 126.
If yes, then print "error" and set age to 0
Define a function setpolicynumber with void return type and one int parameter
Set policy number to first parameter
Define a function setnumaccidents with void return type and one int parameter
Set number of accidents to first parameter
Define a function getage with int return type and no parameters
Return age
Define a function getpolicynumber with int return type and no parameters
Return policynumber
Define a function getaccidents with int return type and no parameters
Return number of accidents
Define a function display with void return type and no parameters
Print policynumber age and number of accidents
For application program:
In main method:
Initialize policyholder named p1 with no arguments
Call setage function with 25 as argument
Call setpolicynumber function with 1234 as argument
Call setnumaccidents function with 2 as argument
Create new policyholder object named p2 with 36,2345,1 as argument
Create new policyholder object with named p3 45,2346,3 as argument
Call checkAccident method with p1 as argument
Call checkAccident method with p2 as argument
Call checkAccident method with p3 as argument
Define checkAccident method with no return type and PolicyHolder class named p as argument
Check if getage method of p returns a value greater than 35
If yes, Check if getaccidents method of p returns a value lesser than 2
If yes, call display method p
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.