Q1: Implement a class called Employee. a) A class named Employee b) Two private data members: name (string) and salary (int). c) Accessors and Mutators function for name, salary. d) implement a non-member function names output that will print all information of Employee object. Use following main() to test your class. int main(){ Employee a; a.setName("David"); a.setSalary(40000); cout<<"Name: "<<a.getName()<<endl; cout<<"Salary: "<<a.getSalary()<<endl; a.setName("Jack"); a.setSalary(50000); output(a); } Output from given main: (user input in bold font) Name: David Salary: 40000 Name: Jack Salary: 50000
Added by Daniela J.
Close
Step 1
We also need to create accessor and mutator functions for name and salary. Here's the implementation: ```cpp #include <iostream> #include <string> using namespace std; class Employee { private: string name; int salary; public: void setName(string Show more…
Show all steps
Your feedback will help us improve your experience
Rakesh Singhi and 99 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a program with an "Employee" class having two variables one for the named employee (String) and other for base salary (float). Create a function that calculates the total salary by adding 50% HRA to the salary and returns. Create an objectof this class in main function and set the name of the employee, call the salary function and print the calculated salary returned by the function with name of the employee.
Corbin T.
Create a class named 'Member' having the following members: Data members: 1 - Name 2 - Age 3 - Phone number 4 - Address 5 - Salary It also has a method named 'printSalary' which prints the salary of the members. Two classes 'Employee' and 'Manager' inherit the 'Member' class. The 'Employee' and 'Manager' classes have data members 'specialization' and 'department' respectively. Now, assign name, age, phone number, address, and salary to an employee and a manager by making an object of both of these classes and print the same.
Write the class definition for an Employee using the following UML: Employee -empName: String -empSurname: String -empNumber: String -empSalary: double +Employee() +Employee(n: String, sn: String, num: String) +setEmpName (nm: String): void +setEmpSurname (snm: String): void +setEmpNumber (num: String): void +setEmpSalary (sal: double): void +getEmpName(): String +getEmpSurname(): String +getEmpNumber(): String +getEmpSalary(): double +increaseSalary(amt: double): void +toString(): String The argument of the increaseSalary() method is a value representing the percentage increase required. Now write another class that contains a main method in which you use both constructors to construct 2 Employee objects. Use the Scanner class to enter values for all the instance variables. Now call the appropriate method/s to display the property values for each object. Increase the salary of each object by 10% and 15% respectively (use the Scanner class for input). Now display the property values for each object again.
Willis J.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD