Question #38480

Programming Data Structures
# 1
2. A student is a person, and so is an employee. Create a class person that has the data attribute common to both students and employees (name, social security number, age, gender, address, and telephone number) and appropriate method definitions. A student has a grade-point average (GPA), major, and year of graduation. An employee has a department, job title, and year of hire. In addition, employees (hourly rate, hours worked, and union dues) and salaried employees (annual salary). Define a class hierarchy and write and application class that you can use to first store the data for an array of people and then display that information in a meaningful way.

After testing, submit your solution


#2
Write code for a method
Public static Boolean sameElements (int [ ] a, int [ ] b)
That checks whether two arrays have the same elements in some order, with the same multiplicities. For example, two arrays
121 144 19 161 19 144 19 11
And
11 121 144 19 161 19 144 19
Would be considered

Expert's answer

Answer on Question#38480- Programming, C++

Programming Data Structures

1

2. A student is a person, and so is an employee. Create a class person that has the data attribute common to both students and employees (name, social security number, age, gender, address, and telephone number) and appropriate method definitions. A student has a grade-point average (GPA), major, and year of graduation. An employee has a department, job title, and year of hire. In addition, employees (hourly rate, hours worked, and union dues) and salaried employees (annual salary). Define a class hierarchy and write and application class that you can use to first store the data for an array of people and then display that information in a meaningful way.

After testing, submit your solution

2

Write code for a method

Public static Boolean sameElements (int [ ] a, int [ ] b)

That checks whether two arrays have the same elements in some order, with the same multiplicities. For example, two arrays

121 144

19 161

19 144

19 11

And

11 121

144 19

161 19

144 19

Would be considered

Solution #1:

#include <iostream>
#include <string>
using namespace std;
class Person
{
protected:
    string sName, sGender, sAddress, sTelephoneNum;
    int sSocSecurityNum, sAge;
public:
    virtual void Init() {}
    virtual void Display() {}
};
class Student : public Person
{
protected:
    double GPA, year;
    string major;
public:
    void Init() override
    {
        cout << endl << "Enter Name: "; cin >> sName;
        cout << endl << "Enter GPA: "; cin >> GPA;
        cout << endl << "Enter Major: "; cin >> major;
        cout << endl << "Enter Year: "; cin >> year;
        cout << endl << "Enter social security number: "; cin >> sSocSecurityNum;
        cout << endl << "Enter Age: "; cin >> sAge;
        cout << endl << "Enter Gender: "; cin >> sGender;
        cout << endl << "Enter Address: "; cin >> sAddress;
        cout << endl << "Enter Telephone Number: "; cin >> sTelephoneNum;
    }
    void Display() override
    {
        cout << endl << "Name: " << sName;
        cout << endl << "GPA: " << GPA;
        cout << endl << "Major: " << major;
        cout << endl << "Year: " << year;
        cout << endl << "Social Security Number: " << sSocSecurityNum;
        cout << endl << "Age: " << sAge;
        cout << endl << "Gender: " << sGender;
        cout << endl << "Address: " << sAddress;
        cout << endl << "Telephone Number: " << sTelephoneNum;
    }
};
class Employee : public Person
{
protected:
    string department, jobTitle, hourlyRate, hoursWorked, unionDues;
public:
    void Init() override
    {
        cout << endl << "Enter Name: "; cin >> sName;
        cout << endl << "Enter social security number: "; cin >> sSocSecurityNum;
        cout << endl << "Enter Age: "; cin >> sAge;
        cout << endl << "Enter Gender: "; cin >> sGender;
        cout << endl << "Enter Address: "; cin >> sAddress;
        cout << endl << "Enter Telephone Number: "; cin >> sTelephoneNum;
        cout << endl << "Enter department: "; cin >> department;
        cout << endl << "Enter job title: "; cin >> jobTitle;
        cout << endl << "Enter hourly rate: "; cin >> hourlyRate;
        cout << endl << "Enter union dues: "; cin >> unionDues;
    }
    void Display() override
    {
        cout << endl << "Name: " << sName;
        cout << endl << "Social Security Number: " << sSocSecurityNum;
        cout << endl << "Age: " << sAge;
        cout << endl << "Gender: " << sGender;
        cout << endl << "Address: " << sAddress;
        cout << endl << "Telephone Number: " << sTelephoneNum;
        cout << endl << "Department: " << department;
        cout << endl << "Job Title: " << jobTitle;
        cout << endl << "Hourly Rate: " << hourlyRate;
        cout << endl << "Union Dues: " << unionDues;
    }
};
int main()
{
    Person* virtual_stud = new Student();
    char chMenu = '0';
    while (chMenu != '3')
    {
        cout << endl << "1. Enter Data" << endl;
        cout << "2. Display Data" << endl;
        cout << "3. Exit" << endl;
        cout << "Enter your choice: ";
        cin >> chMenu;
        if (chMenu == '1')
        {
            virtual_stud->Init();
        }
        else if (chMenu == '2')
        {
            virtual_stud->Display();
        }
        else if (chMenu == '3')
        {
            break;
        }
    }
    delete virtual_stud;
    return 0;
}

Solution #2:

public static bool sameElements(int[] a, int[] b)
{
    if (a == null || b == null)
    {
        return false;
    }
    if (a.Length != b.Length)
    {
        return false;
    }
    int[] countA = new int[100];
    int[] countB = new int[100];
    for (int i = 0; i < a.Length; i++)
    {
        countA[a[i]]++;
        countB[b[i]]++;
    }
    for (int i = 0; i < 100; i++)
    {
        if (countA[i] != countB[i])
        {
            return false;
        }
    }
    return true;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS