Question

C++

Program 2 Consider a class Employee with data members: age (an integer), id (an integer) and salary (a float), and their corr

} int Employee::getId() { }

float Employee::getSalary() { } Write a main routine in which you create an 2-D array of Employee x[2][3]. Set the values for

Turn-Ins: 1) UML class diagram for the class. Algorithm and test plan for THE CLASS 2) Implement the class and driver functio

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

Short Summary:

  • Implmented Employee class and main method as desribed.

Source Code:

#include <iostream>
using namespace std;

class Employee
{
private:
int age;
int id;
float salary;
public:
Employee(){
age = 0;
id = 0;
salary = 0;
}
  
void setAge(int x){
age = x;
}
  
void setId(int x){
id = x;
}
  
void setSalary(float x){
salary = x;
}
  
int getAge();
int getId();
float getSalary();
};

// outside of class - member function definition
int Employee::getAge(){
return age;
}

int Employee::getId(){
return id;
}

float Employee::getSalary(){
return salary;
}

void PrintEmployee(Employee x[2][3], int length1, int length2);
int main()
{
// Create an array if Employee with two elements
Employee x[2][3];
  
// set the values for all the elementsof te array by using public member functions
x[0][0].setAge(30);
x[0][0].setId(111);
x[0][0].setSalary(30000);
  
x[0][1].setAge(31);
x[0][1].setId(112);
x[0][1].setSalary(31000);
  
x[0][2].setAge(32);
x[0][2].setId(113);
x[0][2].setSalary(32000);
  
x[1][0].setAge(33);
x[1][0].setId(114);
x[1][0].setSalary(33000);
  
x[1][1].setAge(34);
x[1][1].setId(115);
x[1][1].setSalary(34000);
  
x[1][2].setAge(35);
x[1][2].setId(116);
x[1][2].setSalary(35000);
  
// call PrintEmployee() with a proper parameter list
PrintEmployee(x, 2, 3);
  
return 0;
}

// Print Employees
void PrintEmployee(Employee x[2][3], int length1, int length2){
int totalAge = 0;
float totalSalary = 0;
// iterate through the length1 and length2
for(int row = 0; row < length1; row++){
for(int column = 0; column < length2; column++){
// use public methods to print the results
cout << "Age: " << x[row][column].getAge()
<< " ID: " << x[row][column].getId()
<< " Salary: $" << x[row][column].getSalary() << endl;
// add age and Salary to running totals
totalAge += x[row][column].getAge();
totalSalary += x[row][column].getSalary();
}
}
int totalEmployees = length1 * length2;
// Print Average age and Salary
cout << endl << endl << "Average Age: " << totalAge / totalEmployees << endl;
cout << "Average Salary: $" << totalSalary / totalEmployees << endl;
}

Sample Run:

Age: 30 ID: 111 Salary: $30000 Age: 31 ID: 112 Salary: $31000 Age: 32 ID: 113 Salary: $32000 Age: 33 ID: 114 Salary: $33000 A

**************************************************************************************

Feel free to rate the answer and comment your questions, if you have any.

Please upvote the answer and appreciate our time.

Happy Studying!!!

**************************************************************************************

Add a comment
Know the answer?
Add Answer to:
C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer)...
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
  • c++ please need help with this question Consider a class Employee with data members: age(an integer),...

    c++ please need help with this question Consider a class Employee with data members: age(an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee {        private:             int age;             int id;             float salary;        public:             Employee( ); // default constructor: age=0, id=0, and salary=0             Employee(Employee &x);   // copy constructor           Employee& operator = (Employee &x); // equal sign operator             void setAge(int x);    // let age = x...

  • c++ only Design a class representing an Employee. The employee would have at least these private...

    c++ only Design a class representing an Employee. The employee would have at least these private fields (Variables): name: string (char array) ID: string (char array) salary: float Type: string (char array) All the variables except for the salary should have their respective setters and getters, and the class should have two constructors, one is the default constructor and the other constructor initializes the name,ID and type of employee with valid user input. The class should have the following additional...

  • Code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; ...

    code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; Specification: In this lab, five functions need to be implemented using the given ADT. 1. Employee* readRecord(FILE*) This function receives a FILE pointer created before. It reads a line from the provided csv file, and creates an Employee struct pointer with the information from that line then returns the pointer back to the calling function. Each line in the provided csv file contains the id, salary,...

  • In Java: Executable Class create an array of Employee objects. You can copy the array you...

    In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...

  • Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person...

    Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person objects to a random access file. --------------------- Person.cpp--------------------------------- // Class Person stores customer's credit information. #include <string> #include "Person.h" using namespace std; // default Person constructor Person::Person( int idValue, string lastNameValue, string firstNameValue, int AgeValue ) { setID( idValue ); setLastName( lastNameValue ); setFirstName( firstNameValue ); setAge( AgeValue ); } // end Person constructor // get id value int Person::getID() const { return id;...

  • 2. In the following program an employee of a company is represented by an object of...

    2. In the following program an employee of a company is represented by an object of type employee consisting of a name, employee id, employee salary and the workday starting time. The starting time is a class time 24 object. Implement the class employee. Declaration of Employee and Time Classes /* File : employeetime.h Hlustrates composition of classes */ #ifndef EMPLOYEETIME.H #define EMPLOYEETIME.H #include <iostream> #include <string> using namespace std; class time 24 { private : int hour; int minute...

  • I have most of the code for this assignment but need some help getting the rest....

    I have most of the code for this assignment but need some help getting the rest. Go to bottom to see what I have. Please help me figure out the foreach loops and the put() statement. In this assignment, you will be using a new data structure, HashMaps, to repeat Assignment 8.3. Main Method (5 points) Declare and initialize an HashMap with values of type of type Employee, and keys of type integer. In a while loop, keep initializing objects...

  • In this exercise, we will be refactoring a working program. Code refactoring is a process to...

    In this exercise, we will be refactoring a working program. Code refactoring is a process to improve an existing code in term of its internal structure without changing its external behavior. In this particular example, we have three classes Course, Student, Instructor in addition to Main. All classes are well documented. Read through them to understand their structure. In brief, Course models a course that has a title, max capacity an instructor and students. Instructor models a course instructor who...

  • You only need to use Junit to test 3 methods of the Nurse class. public Nurse(int...

    You only need to use Junit to test 3 methods of the Nurse class. public Nurse(int a, float s) { ... } public boolean isBusy() {...} public void retire() {....} code: public class Nurse { private int numOfPatients; private float salary; // Helping function // private void trace(char* s) { cout << s << endl; } // Implementor function public Nurse(int a, float s) { numOfPatients =a; salary=s; } // Access function public int getNumOfPatients() { return numOfPatients; } public...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

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