Question

project-8c Write a class named Employee that has data members for an employee's name, ID_number, salary,...

project-8c

Write a class named Employee that has data members for an employee's name, ID_number, salary, and email_address (you must use those names - don't make them private). Write a function named make_employee_dict that takes as parameters a list of names, a list of ID numbers, a list of salaries and a list of email addresses (which are all the same length). The function should take the first value of each list and use them to create an Employee object. It should do the same with the second value of each list, etc. to the end of the lists. As it creates these objects, it should add them to a dictionary, where the key is the ID number and the value for that key is the whole Employee object. The function should return the resulting dictionary.

Remember in your testing that printing an object of a user-defined class will just print out the object's type and address in memory. You must specifically access its data members if you want to print their values.

The file must be named: make_employee_dict.py

the programming language is a python, python 2.7(venv) ~pycharmprojects/greeting/venv/bin/python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here is the code in Python.

Let me know for any help with any other questions.

I wrote a main function to test the functionality,

=====================================================================

class Employee():

    def __init__(self,name,id,salary,email):
        self.name=name
        self.ID_number = id
        self.salary= salary
        self.email_address=email
    def __str__(self):
        return 'Name: {}, ID: {}, Salary: ${}, Email: {}'.format(self.name,self.ID_number,self.salary,self.email_address)

def make_employee_dict(names,ids,salaries,emails):
    emp_dict={}
    for i in range(len(names)):
        emp_dict[ids[i]] = Employee(names[i],ids[i],salaries[i],emails[i])
    return emp_dict

def main():

    names=['John','Alan','Peter','James']
    ids=[123,345,567,789]
    salaries=[45000,55000,65000,34000]
    emails=['john.a@email.com','alan.b@email.com','peter.c@email.com','james.d@email.com']

    emp_dict = make_employee_dict(names,ids,salaries,emails)

    for id,emp in emp_dict.items():
        print(id,emp)


main()

=====================================================================

Code screenshot

Add a comment
Know the answer?
Add Answer to:
project-8c Write a class named Employee that has data members for an employee's name, ID_number, salary,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to add class objects to a dictionary? *PYTHON ONLY* NO IMPORT RANDOM Write a class...

    How to add class objects to a dictionary? *PYTHON ONLY* NO IMPORT RANDOM Write a class named Employee that has data members for an employee's name, ID_number, salary, and email_address (you must use those names - don't make them private). Write a function named make_employee_dict (outside of the Employee class) that takes as parameters a list of names, a list of ID numbers, a list of salaries and a list of email addresses. The function should take the first value...

  • 1. Write a class named Employee that holds the following data about an employee in attributes:...

    1. Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. (employee.py) 2. Create a UML diagram for Employee class. (word file) 3. Create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. (employee_App.py) The program should present a menu that lets the user perform the following actions: ✓ Look up an employee in the dictionary ✔ Add a new...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

  • Write a class named Employee that holds the following data about an employee in attributes: name,...

    Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. Don't include a constructor or any other methods. Written in Python and formatted like it says below!!!!! Once you have written the class, write a program that creates three Employee objects to hold the following data: Name ID Number Department Job Title Susan Meyers 47899 Accounting Vice President Mark Jones 39119 IT Programmer Joy Rogers 81774 Manufacturing Engineering...

  • Using C++, Write a class named Employee that has the following member variables: name. A string...

    Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...

  • Write a C++ program that has one base class named EMPLOYEE   that has private members NAME,...

    Write a C++ program that has one base class named EMPLOYEE   that has private members NAME, SALARY, YEAR_HIRED   and one derived class named MANAGER that inherits from EMPLOYEE. MANAGER also has private member  STAFF   which is an array of strings.   In the body of program, declare an object of each and enter data.

  • Part 1 (employee.py): Write a class name Employee that holds the following data about an employee...

    Part 1 (employee.py): Write a class name Employee that holds the following data about an employee in attributes:name, ID number, department and job title. Once you have written the class, write a program that creates three Employee objects to hold the following data: The program should store this data in the three objects, then display the data for each employee on the screen as a table like this (Use fstring or "format" function to format the output as a table,...

  • Python: Design a Ship class that has the following members: A member variable for the name...

    Python: Design a Ship class that has the following members: A member variable for the name of the ship. A member variable for the year that the ship was built. An init method and appropriate accessors and mutators. A print function that displays the ship’s name and the year it was built. Design a CruiseShip class that is derived from the Ship class. The CruiseShip class should have the following members: A member variable for the maximum number of passengers....

  • Write a class named Taxicab that has three private data members: one that holds the current...

    Write a class named Taxicab that has three private data members: one that holds the current x-coordinate, one that holds the current y-coordinate, and one that holds the odometer reading (the actual odometer distance driven by the Taxicab, not the Euclidean distance from its starting point). The class should have an init method that takes two parameters and uses them to initialize the coordinates, and also initializes the odometer to zero. The class should have get members for each data...

  • Java using data structures The objective is to create your own Hash Table class to hold...

    Java using data structures The objective is to create your own Hash Table class to hold a list of employees and their ID numbers. I've provided the TableEntry class which will be each data object in the hash table. The list of employees will be provided as a .txt file and must be read with the code. please create a .txt file called Employees.txt with the info provided so that the java code can read it in. Employees.txt: (No WhiteSpace...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT