Array of Objects

Source: Internet
Author: User

 

You shoshould be comfortable with the content in the modules up to and including the module "arrays" for this project.

Create a class called consultco that holds a private class calledEmployeeThat contains the name, pay rate and Social Security Number of an employee of a consulting firm called consultco. the consultco class shoshould also have an array that holds all of the objects of all of the employees in the array. this will be an array of employee objects.

Here is a logical divisor of this array of objects:

 

 

You will also need functions to satisfy the following requirements:

Minimum requirements:

  • An add function to hire a new employee. this function shoshould create a new object with the employee information (name, payrate and Social Security number) and then it shoshould add that new object to the array. you areNotRequired to update an employee's data if the employee exists. (5 points)
  • A report function that will display the name, pay rate and Social Security Number of all employees. (5 points ).
  • A raise function that will give all employees a 10% raise. (5 points ).
  • You will also need a main function that creates callthe function (s) You created to meet the requirements of this project (5 points ).

Notes:

The module lab activity "lookup! "Can beExtremelyHelpful for this project. Just by following the lab activity (and the video demos if needed), you can make significant progress toward completing this assignment.

 

 

Answer

 

# Include "class. H"


Int main ()
{

Bool running = true;
Companyco database;

Int choice = 0;

While (running = true)
{
STD: cout <"\ N1. Addan employee" <STD: Endl;
STD: cout <"\ N2. checkdatabase" <STD: Endl;
STD: cout <"\ N3. Thisis a good day... increase all salaries by 10%! "<STD: Endl;
STD: cout <"\ n4.exit \ n" <STD: Endl;
STD: CIN> choice;

If (choice = 1)
{
STD: cout <"add anemployee" <STD: Endl;
Database. addemployee ();
}

Else if (choice = 2)
{
STD: cout <"checkdatabase" <STD: Endl;
Database. displaydata ();
}

Else if (choice = 3)
{
Database. increasesalary ();
}

Else
{
STD: cout <"exit" <STD: Endl;
Running = false;
}
}

Return 0;
}

 


# Include "class. H"

Companyco: companyco ()
{
// To keep the size of the array smallenough for testing purposes...
Size = 7;
Populated = 0;
}

Companyco: Employee: employee ()
{
// Default value for all theunpopulated areas within the Array
Name = "Not applicable ";
Payrate = 0.0;
SSN = 000;
}


Void companyco: addemployee ()
{
Employee record;

STD: string name;
Float payrate;
Int SSN;

STD: cout <"Please enter the name:" <STD: Endl;
STD: CIN> name;
STD: cout <"Please enterthe payrate:" <STD: Endl;
STD: CIN> payrate;
STD: cout <"Please enterthe SSN:" <STD: Endl;
STD: CIN> SSN;

Record. Name = Name;
Record. payrate = payrate;
Record. SSN = SSN;
STD: cout <"recordadded \ n" <STD: Endl;

// Update table
Entries [populated] = record;
Populated ++;
}


Void companyco: displaydata ()
{
Int limit; // user can specify how muchto output

STD: cout <"Enter the number of eployees you want to see:" <STD: Endl;
STD: CIN> limit;

For (INT I = 0; I <limit; I ++)
{
STD: cout <entries [I]. Name <STD: Endl;
STD: cout <entries [I]. payrate <STD: Endl;
STD: cout <entries [I]. SSN <STD: Endl;
STD: cout <STD: Endl;
}
}


Void companyco: increasesalary () // increases salary by 10% however, all newmembers of the array will have no benefit from this...
{
For (INT I = 0; I <size; I ++)
{
Entries [I]. payrate = entries [I]. payrate * 1.1;
}

STD: cout <"\ nsalary increased. \ n" <STD: Endl;

 

Muqi Studio

# Include <iostream>
# Include <sstream>


Class companyco
{
PRIVATE:
Class employee
{
Public:
STD: string name;
Float payrate;
Int SSN;
Employee ();
};
Int size;
Int populated;
Employee entries [7]; // 7 .. is a magicnumber

Public:
Companyco ();
Void addemployee ();
Void displaydata ();
Void increasesalary ();
};

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.