[SOLVED] CSE101 Assignment 3

35.00 $

Category: Tags: , ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon A3_2021507-wwmzws.zip (1294.4 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (2 votes)

Q1.

PROBLEMS

Remember the problem Transformations!! from Assignment 2, where we were performing transformations on an n-point 3D shape. This problem is an extension of that problem with certain modiications.

Firstly, if you didn’t create different functions for different transformations, you need to change your code so that there are at least these 3 functions –

  1. scale(x, y, z, sx, sy, sz) which returns scaled x’, y’ and z’ according to sx, sy and sz.
  2. translate(x, y, z, tx, ty, tz) which returns translated x’, y’ and z’ according to tx, ty and tz.
  3. rotate(x, y, z, axis, phi) which returns rotated x’, y’ and z’ according to axis and phi.

You also have to create a function matmul(A, B) which returns the matrix multiplication of matrices AandB.

After these modiications are done, your task is to create a A3_2021xxx_1_test.py which will test the correctness of the code. In Q1test.py there will be a total of 4 functions –

  1. test_matmul(A, B, true_C) which calculates the matrix multiplication of matrices A and B using the matmul(A, B) function and tests the returned matrix C with true_C. If they match, it returns True, and False otherwise.
  2. test_scale(x, y, z, sx, sy, sz, true_x, true_y, true_z) which scales x, y, z in accordance with sx, sy and sz using the scale(x, y, z, sx, sy, sz) function and tests the returned x’, y’, z’ with true_x, true_y, true_z respectively. If they match, it returns True, and False otherwise.
  3. test_translate(x, y, z, tx, ty, tz, true_x, true_y, true_z) which translates x, y, z in accordance with tx, ty and tz using the translate(x, y, z, tx, ty, tz) function and tests the returned x’, y’, z’ with true_x, true_y, true_z respectively. If they match, it returns True, and False otherwise.
  4. test_rotate(x, y, z, axis, phi, true_x, true_y, true_z) which rotates x, y, z in accordance with axis and phi using the rotate(x, y, z, axis, phi) function and tests the returned x’, y’, z’ with true_x, true_y, true_z respectively. If they match, it returns True, and False otherwise.

These matching are expected to be done only using assertions.

You will be making multiple test cases for all the functions and will test your code’s correctness. This problem will help you in understanding how a judge on a competitive programming website works.

Q2.
Cleaning services are crucial to our lifestyle, aesthetics and overall hygiene. Your task is to design a class for a cloth and apparel cleaning service. The class would be named, LaundryService. This class would be used to create Customer Speciic details, and would contain methods/functions for:

→ __init__(): The parameters passed to this function, during the object instantiation would be:

Parameter

Appropriate Type/ Values

Name of customer

String

Contact of customer

Numeric [integer]

Email

Alphanumeric [string]

Type of cloth

“Cotton”, “Silk”, “Woolen” or “Polyester”

Branded

A boolean

Season

“Summer” or “Winter” [string]

Inside __init__(), you will be assigning an id to a new customer. This id would be global variable and should be incremented automatically when a new customer is created, and the incremented value must be assigned as the id of the new customer.

→ customerDetails(): This will print out the details of a customer in the order:

  1. Their name
  2. Their contact no.
  3. Their email
  4. Type of cloth they deposited
  5. Whether the cloth is branded or not

##No need to print out the season

→ calculateCharge(): This will calculate the charge and return, based upon the following factors:

  1. Type of cloth: Cotton → 50 Rupees, Silk → 30 Rs., Woolen → 90 Rs., Polyester → 20 Rs.
  2. Branded: if True, 1.5 times the charge from step 1. Otherwise the charge is unchanged
  3. Season: if it is “Winter” charge is halved from step 2. Otherwise the charge is 2 times the

    charge from step 2.

→ inalDetails(): This function will call customerDetails() and calculateCharge() functions within itself. Furthermore, based upon the charge returned by the calculateCharge(), this function will further print the total charge and the expected day of return.

  1. If total charge is greater than 200, it will print out “To be returned in 4 days”
  2. Otherwise, it will print out “To be returned in 7 days”

After creation of the class, you need to able to create multiple objects of type LaundryService.
The parameters to be passed for the initialization would be taken from the user. Finally you will be calling indDetails() method from the object created.
Caveat: for the input for brand, you can take 0 or 1 from the user. It can be passed False or True, therewise during instantiation.

Another instantiation of a new object in the same running code (student are free to iterate for a given number of objects or they can restrict the number of objects for atleast 4) would give the result as:

The output can deviate in formatting and sequence of statements. This one is for reference only.

Q3.
Bank of IIIT-D is a newly opened bank that caters to the needs of the institute. The faculty, students and all the staffs can open a bank account under their name. The main purpose of this bank is to maintain some emergency funds for the user in case the need arises. There is no system to provide rate of interests to the users, for now.
A blueprint design/prototype has to be formulated for the bank. This task has come under the responsibility and accountability of Dr. Pankaj Jalote and Dr. Raghava Mutharaju. As banking services need to be robust and trustworthy, the professors need someone who could be relied upon, to build the prototype. Can they rely upon you?

Your task is to create a menu driven program. First of all, the code starts with some welcome message, and then asks the users to provide their username, password, and initial amount to be deposited into the bank. Then a menu driven approach has now to be utilized for these 4 tasks:

  1. Asking user to deposit a sum into their account
  2. Asking user to withdraw a sum from their account
  3. Asking the user if they want to see their bank statement, i.e, their past transaction history
  4. If the user still wish to continue.

Here comes the detailed implementation that should work behind the scenes to facilitate the previously mentioned tasks.

You need to create a class called BankAccount. The class BankAccount has 5 methods inside it. These are as follows:

● __init__()
● deposit()
● withdraw()
● authenticate()

● bankStatement()

1→ __init__():
This method, the usual constructor, accepts 4 parameters during object instantiation. These are the username, password, current balance. Remember, that the current balance, just after the instantiation, is the initial amount provided by the user in the menu driven code. It also creates a ile named ‘u.txt’, where u is the username itself. This ile contains the transaction history of a speciic user. This will be a unique ile created for every new user. You can assume that no two users have the same name.

2→ authenticate()
This method will ask the user to input “ provide their secret password”. It would return True or False depending upon whether the provided password matches with the password given, during the instantiation. This method is necessary as multiple authentications are required during a session. It would be called everytime a user wants to deposit, withdraw or view his bank statement.

3→ deposit()
This method will accept the amount to be deposited, as the parameter. It will be calling authenticate() to verify the user. You need to consider one caveat! There would be at most 2 wrong attempts while entering a password. You will be using assert, to ensure the number of attempts does not exceed 3. If it does, an AssertionError would be raised with the message “Too many wrong attempts!!”. This AssertionError must be handled using exception handling.
The current balance would be updated, by adding the amount to it.
The user speciic ile ‘u.txt’ would be again opened, and a text would be appended to the ile. The text would be of the form:
Timestamp The amount of Rupees 100.0 has been added Current balance → 600.0

For the timestamp you can use the datetime module directly, whose working is as follows:

Finally you will be closing the ile to ensure no error or glitch persists.

4 → withdraw()
This method will accept the amount to be withdrawn or debited, as the parameter. Again it will also be calling authenticate() to verify the user. Similar to deposit(), number of attempts allowed would be at most 3, and you would be using assertion to ensure the same.

The current balance would be updated, by subtracting the amount from it. Again a caveat!! You need to irst ensure that the amount to be withdrawn is less than the current balance, otherwise withdrawal would not be possible with a message “Low balance!! Cannot be debited at this time!” and then the function would simply return.

If the current balance is suficient, then user speciic ‘u.txt’ ile would be re-opened and a text would be appended to it, of the form:

Timestamp The amount of Rupees 100.0 has been debited Current balance → 600.0 Finally, the user speciic ile will be closed for the aforementioned rationale.

5 → bankStatement()
This method does not accept any parameter. It also calls authenticate() for veriication and assert to ensure the number of attempts to 3, similar to the steps followed in the previous two methods. Again the user speciic ile ‘u.txt’ will be opened in read mode. It will print out the transaction history line by line.

For this question, students’ can implement password validation and email address, as per their choice.

One sample run for the said implementation has been attached below:

Also the text ile has been generated :

With the content:

Q4.
Given a list of people objects, create a function sort_attribute() that sorts the list by an attribute name. The attribute to sort by will be given as a string, one among “firstname”, “lastname”, “age”.

You need to create a class called Person. The class Person has 2 methods inside it. These are as follows:

  • ●  __init__()
    This method, the usual constructor, accepts 3 parameters during object instantiation

    • ○  firstname (string)
    • ○  lastname (string)
    • ○  age (int)
  • ●  object_info()
    This method will print all 3 parameters of an instance of a class space separated, in the order irstname, lastname and age.

    For k queries that supply a string among “firstname”, “lastname” or “age”, sort the information for ‘n’ users for that particular attribute and return the person ids in ascending order for that sort of attribute. Print the menu as shown below in sample testcase and use that everytime

    Input format:
    The first line takes input ‘n’ for n information lines and ‘k’ for k queries
    Each of the ‘n’ lines takes 3 space separated inputs: Firstname, Lastname and Age (integer) Each of the next ‘k’ lines takes string inputs that could be “firstname”, “lastname” or “age”

    Output Format:

Each of the k lines consists of a line separated output of object_info() function of class Person. You can also implement __repr__() function in place of object_info().

Sample Menu (white), Input (italics) and Output (bold): Welcome to the Application!
Specify number of people to be enrolled: 3

Enter Firstname for Person 1: Michael Enter Lastname for Person 1: Smith Enter Age for Person 1: 40

Enter Firstname for Person 2: Alice Enter Lastname for Person 2: Waters Enter Age for Person 2: 21

Enter Firstname for Person 3: Zoey Enter Lastname for Person 3: Jones Enter Age for Person 3: 29

Specify number of Queries: 3 Query 1: firstname
Order:
Alice Waters 21

Michael Smith 40 Zoey Jones 29

Query 2: lastname Order:
Zoey Jones 29 Michael Smith 40 Alice Waters 21

Query 3: age Order:
Alice Waters 21 Zoey Jones 29 Michael Smith 40

Thanks for using the Application, if you wish to restart, press “Y” else press “N” to exit: N Exits!

Q5.

Placement Season is about to start at IIITD. You have to design an application to simplify the procedure. You have to make two classes – Student and Company.
Functions for the Student Class are described Below:

1. __init__ : This function takes 3 parameters: Name (String input), cgpa (Float input) and branch (String input) of the student. Possible branches include CSE, CSAM, ECE. You have to initialise another variable isPlaced to False.

2. isEligible : This function takes 1 parameter: Object of the Company. It checks if the student is eligible for the given company i.e.

– the student has cgpa >= the required cgpa for the Company, – the company is hiring from the student’s branch and
– the student is unplaced.

If the student is eligible for that company, then print “Student {name} is eligible for Company {name}”. If the student is not eligible, then print “Student {name} is not eligible for Company {name}”

3. apply : This function takes 1 parameter: Object of the company. It will add the student to the list of students who have applied for that particular Company.

4. getsPlaced : This will change the status of the student from unplaced to placed.

Functions for the Company Class are described Below:
1. __init__ : This function takes 4 parameters: Name (String input), requiredcgpa (float

input which is the least cgpa required to become eligible), branches (list of branches from which

the company will hire) and positionOpen (which is the maximum number of students that the company will hire). You also have to initialise another variable appliedStudents as an empty list and a variable applicationOpen to True.

2. hireStudents : This function does not take any parameters and will hire top k students from the list of appliedStudents based on their cgpa (k represents the number of positions open). When the company hires a particular student, you have to change the status of that student to placed. Now print the names of the students that the company has hired and the number of positions open for the company. This function in the end will call the function closeApplication.

3. closeApplication : This function also does not take any parameter and this will close the application of the Company and print the number of students that the company has hired.

After defining these classes, take inputs of atleast 5 students and 2 companies. Now you have to iterate on all the students and check if he or she is eligible for the company. If the student is eligible, then call the apply function for that student. After iteration on all the students, call the function hireStudents for company 1. Now again iterate on all the students and check if they are eligible and then call the function hireStudents for company 2.

NOTE: Remember while taking the input for the cgpa of the student, you need to use exception handling to ensure that the cgpa lies between 0 and 10. If the cgpa lies outside these bounds, throw exception using assertion statement of your choice (ex → “The cgpa is invalid”, or “Kindly provide correct and valid cgpa”, etc ).

Sample Run:

  • A3_2021507-wwmzws.zip