Вы находитесь на странице: 1из 6

Programming Hands-On

Duration: 180 minutes


Max Marks: 20

Instructions to candidates:

1. Read the problem statement, examples and other details carefully and implement the
solution
2. Code submitted with compilation errors may not get evaluated
3. DO NOT write code that result in infinite loops / infinite recursive calls

NOTE: NOT adhering to the above instructions may lead to reduction in score.

Question 1: Programming Fundamentals [5 Marks]

Problem Statement:
Write a Python program which takes a list of single digit integers as input parameter. List may
contain values ranging from 1 to 9. The function returns an integer as per logic below:
1. Using the individual elements of the list, find all the possible 3 digits number
combinations.
Note: For a single combination, element at same index position should not be considered
more than once
Example: Input list: [1, 2, 1]
Possible three digit combination: 121, 112, 211, 211, 112 and 121.
Note that 222, 122 and 221 are not considered because in these cases digit 2
occurring at index position 2 is appearing at least twice. In valid combinations
listed above, the digit 1 can repeat twice as in the original input list itself the
digit 1 is repeated twice. But 111 is not possible combination as 1 is not repeated
thrice in the list

2. From all the combinations obtained from step 1, consider only the unique combinations.
For the above example: Input list: [1, 2, 1]
Possible three digit unique combinations obtained from step 1:
121, 112 and 211.
Note: from the three digit number combinations listed above,
duplicates have been removed

3. Find the maximum number among the three digit combinations listed above. Append it
with the number of three digit combinations obtained in step 2.
For the above example: Input list: [1, 2, 1]
Possible unique three digit combination obtained from step 2: 121,
112 and 211.
The maximum number among the above is 211. Append it with the
number of three digit combinations. I.e. 3. If you append it to 211,
it will become 2113
4. Return the generated number in step 3
Example:
Input List: [1, 2, 1, 4]
Output: 42112
Possible unique three digit combinations: 121, 124, 112, 114, 142, 141, 211, 214, 241, 412, 411
and 421
Maximum Number among the combination: 421
Number of unique combinations: 12
Hence the output will be 42112.

Assumptions:
1. Input list would contain at least three elements and maximum of five elements.
2. Input list would not contain the digit 0 (zero)
Note: No need to validate the assumptions
Sample Input and Output:

Question 2: Object Oriented Programming [10 Marks]

Problem Statement: Ferrari rental services rent cars and want to automate the process of their
bill calculation. Write a Python program to implement the class diagrams given below.
Class Diagram:
Notes:
 Do not include any extra instance variables in the given classes
 Case sensitive comparison is required to be done wherever applicable and not
mentioned
 Value of no_of_kms member variable is assumed to be positive. It is not validated
 Read notes and examples for better understanding of the logic

Customer Class:

 This class has static dictionary named as member_cust_details which contains following
entries {'1001P':2050, '1051R':5345, '1072P':6896, '2019R':9100, '2913R':4500,
'2931P':3234}

Note: You need to initialize this dictionary.


calculate_discount(rental_amount):
 This method accepts a float rental_amount as an input parameter and calculates the
discount amount which is a float value on rental_amount
 It searches for the cust_id which is a string in the member_cust_details dictionary
 If cust_id is not found in the list, set discount amount to -1
 Otherwise, it upgrades the customer by invoking upgrade_customer() method and passing
rental_amount as input parameter
 It calculates the discount amount as below –
o Obtain the last character of the cust_id which represents customer_type
o Obtain the discount_percentage on rental_amount based on customer_type as per
table below –
o Using the discount_percentage calculate discount amount on rental_amount

Example 1: If the rental_amount is Rs. 20,000/- and the cust_id is ‘2019R’, the customer
gets upgraded and the discount amount given to him is Rs. 2000/-
Example 2: If the rental_amount is Rs. 15,000/- and the cust_id is ‘2119R’, the calculated
discount amount is -1

 It returns discount amount


CarDetails Class:

 This class has two static lists namely –


o car_types which is initialized to ["Hatch-back", "Sedan", "SUV"]
o per_day_rent which is initialized to [3500, 5000, 6000]
Note:

1. You need to initialize these lists.


2. car_types and per_day_rent lists have one to one correspondence. For example, per day
rent of car type “Sedan” is Rs. 5,000/-

identify_per_day_rent (car_type):
 This method accepts car_type which is a string as an input parameter and returns the
corresponding per_day_rent which is an integer value
 It searches for the car_type in car_types list
 If match not found, it initializes rent_per_day to -1
 Otherwise, it initializes per_day_rent to the corresponding value in per_day_rent list
 It returns rent_per_day

Note: Perform Case Insensitive comparison

For example, per_day_rent of car type “Sedan” is Rs. 5,000/- and per_day_rent of ‘XUV’ is -1

CarRental Class:

__init__(customer, no_of_kms, car_type):


 This method initializes customer and no_of_kms of VehicleRental class and initializes
car_type of this class

calculate_final_amount():
 This method calculates and returns final_amount
 It invokes identify_per_day_rent() method of CarDetails class to obtain per_day_rent
 It invokes identify_journey_days() method which sets journey_days and returns
excess_kms
 If per_day_rent is -1 or excess_kms is negative or journey_days is negative, set
final_amount to -1
 Otherwise, it calculates the final_amount as discussed below :-
o calculates rental amount for all the journey_days as product of the
journey_days and per_day_rent
o calculates excess_kms_amount using excess_kms as discussed below:-
 For every excess kilometer travelled, it charges Rs. 12/-
o calculates rental_amount as the sum of rental amount for all the journey_days
and excess_kms_amount
o It invokes calculate_discount() method by passing rental_amount as input
parameter and obtains discount amount
o If discount amount is -1, set final_amount to -1
o Otherwise,
 It calculates final_amount by subtracting discount amount from
rental_amount
 It updates member_cust_details of Customer class by adding
final_amount to the value of corresponding cust_id
 It returns final_amount

Question 3: Data Structures [5 Marks]


Problem Statement:
Consider an input queue containing characters as elements and an input stack containing integers
(integers can be either 1 or 2 only).

Example for input queue (front  rear): A, B, C


Example for input stack (top  bottom): 2, 1

Write a function which takes input queue and input stack as input parameters and returns an
output queue. The output queue contains same elements as that of input queue but in an order
which is determined by the elements of input stack.

For every element of the input stack, input queue is reordered based on the below rule-
 If the element in the stack is 1, then the first element in the queue (element at front) will
become last element (element at rear).
 If the element in the stack is 2, then the last element (element at rear) in the queue will
become the first element (element in front).
 After reordering the input queue based on the elements in the stack, if the reordered
queue and input queue are same, then based on the top element of the input stack
reordering has to be done once again.

Example:
Input_queue (frontrear): A, B, C
Input_stack (topbottom): 2, 1
Output_queue(frontrear): C, A, B

Step 1: For the first element in the input stack that is 2, the last element in the input queue that
is ‘C’ is moved to the front, so the input queue is now reordered as (front->rear) C, A, B.

Step 2: For the second element in the input stack that is 1, the first element in the reordered
input queue as per step 1 that is ‘C’ is moved to the rear of the queue, the input queue is now
reordered as (frontrear) A, B, C

Step 3: Now the reordered queue and the input queue are same and the top of the input stack is
2, the last element in the input queue that is “C” is moved to the front , so the input queue is
now reordered as (frontrear) C, A, B.

Step 4: Final elements in the output queue after step 3 are (frontrear) C, A, B

Note: For first element in input stack, original input queue is reordered first, then for each
element in input stack the previous reordered queue is referenced to reorder again

Assumption:

 Input queue and input stack will always contain at least one element each
 Input queue will always contain single character strings
 The elements in the input stack can be either 1 or 2
Note: No need to validate assumptions
Sample Input and Output:

Вам также может понравиться