You should 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 called employee that contains the name, pay rate and social security number of an employee of a consulting firm called consultCo. The consultCo class should 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 diagram 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 should create a new object with the employee information (name, payrate and social security number) and then it should add that new object to the array.  You are not required 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 calls the function(s) you created to meet the requirements of this project (5 points).

Notes:

The Module Lab Activity "Lookup!" can be extremely helpful 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. Add
an employee" << std::endl;
      std::cout << "\n2. Check
database" << std::endl;
      std::cout << "\n3. This
is 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 an
employee" << std::endl;
         database.addEmployee();
      }

else if (choice == 2)
      {
         std::cout << "Check
database" << 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 small
enough for testing purposes...
   size = 7;
   populated = 0;
}

companyCo::employee::employee()
{
   //Default value for all the
unpopulated 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 enter
the Payrate: " << std::endl;
   std::cin >> payRate;
   std::cout << "Please enter
the SSN: " << std::endl;
   std::cin >> ssN;

record.name = name;
   record.payRate = payRate;
   record.ssN = ssN;
   std::cout << "Record
added\n\n\n" << std::endl;

//update table
   entries[populated] = record;
   populated++;
}

void companyCo::displayData()
{
   int limit; //user can specify how much
to 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 new
members 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;

木其工作室

#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 magic
number

public:
   companyCo();
   void addEmployee();
   void displayData();
   void increaseSalary();
};

Array of Objects的更多相关文章

  1. The method below converts an array of objects to a DataTable object in C#.

    http://www.c-sharpcorner.com/blogs/dynamic-objects-conveting-into-data-table-in-c-sharp1 public stat ...

  2. How to use Jackson to deserialise an array of objects

    first create a mapper : import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper mapper = ne ...

  3. Why does typeof array with objects return “Object” and not “Array”?

    https://stackoverflow.com/questions/4775722/check-if-object-is-an-array One of the weird behaviour a ...

  4. Co-variant array conversion from x to y may cause run-time exception

    http://stackoverflow.com/questions/8704332/co-variant-array-conversion-from-x-to-y-may-cause-run-tim ...

  5. [JavaScript] Array.prototype.reduce in JavaScript by example

    Let's take a closer look at using Javascript's built in Array reduce function. Reduce is deceptively ...

  6. iOS 判断数组array中是否包含元素a,取出a在array中的下标+数组方法详解

    目前找到来4个解决办法,第三个尤为简单方便 NSArray * arr = @["]; //是否包含 "]) { NSInteger index = [arr indexOfObj ...

  7. PHP 根据对象属性进行对象数组的排序(usort($your_data, "cmp");)(inside the class: usort($your_data, array($this, "cmp")))

    PHP 根据对象属性进行对象数组的排序(usort($your_data, "cmp");)(inside the class: usort($your_data, array($ ...

  8. [Ramda] R.project -- Select a Subset of Properties from a Collection of Objects in Ramda

    In this lesson we'll take an array of objects and map it to a new array where each object is a subse ...

  9. Cocos2d-x之Array

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. Array是一个列表类容器,是一种线性序列结构:列表容器中的元素是有序的,可以通过下标来访问,就和数组一样.其中Vector也是一种列表容 ...

随机推荐

  1. xcode6 cocos2dx开玩笑git和github学习记录

    1. git Xcode4开始,它一直Git作为一个内置的源代码控制(Source Control)工具,所以对于新项目的用途git要管理非常方便.在新建项目向导.可以直接选择Git作为源控制工具.项 ...

  2. HDU 1240——Asteroids!(三维BFS)POJ 2225——Asteroids

    普通的三维广搜,须要注意的是输入:列,行,层 #include<iostream> #include<cstdio> #include<cstring> #incl ...

  3. Android中网络流量控制(防火墙)——Iptables

    Iptables简单介绍 iptables是与最新的 2.6.x 版本号 Linux 内核集成的 IP 信息包过滤系统. 假设 Linux 系统连接到因特网或 LAN.server或连接 LAN 和因 ...

  4. MingW环境下的windows编程

    一般在进行windows编程时都使用vc++精简版,其插入菜单,图片等资源等更简单,且vc中对中文有更好的支持,win7下安装的Mingw中文并不能很好地显示,有光标显示的位置和光标实际位置不符的问题 ...

  5. [Cacti] memcache安装执行、cacti监控memcache实战

    简单介绍 Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的.眼下全世界不少人使用这个缓存项目来构建自己大负载的站点,来分担数据库的压力. Memcache官方站 ...

  6. Ubuntu下实现双屏独立切换

    在编码时,总觉得屏幕大小不够,要是能多个屏多好,可以这样 把你的显示器连接到你的电脑,然后开启一个终端 输入:xrandr 显示如下: LVDS1 connected 1366x768+1024+0 ...

  7. GNU C的使用

    基本语法 gcc [options] [filenames]  说明:  在gcc后面可以有多个编译选项,同时进行多个编译操作.很多 的gcc选项包括一个以上的字符.因此你必须为每个选项指定各 自 ...

  8. FZU2179(数位dp)

    传送门:Chriswho 题意:求区间[1,n]内能整除自己本身各位数字的数的个数. 分析:这题跟CF 55D Beautiful numbers一样的,一个数能被它的所有非零数位整除,则能被它们的最 ...

  9. Android开发之使用URL訪问网络资源

    Android开发之使用URL訪问网络资源 URL (UniformResource Locator)对象代表统一资源定位器,它是指向互联网"资源"的指针. 资源能够是简单的文件或 ...

  10. I2C分析三

    1 引言 IIC (Inter-Integrated Circuit1总线是一种由Philips公司开发的2线式串行总线,用于连接微控制器及其外围设备.它是同步通信的一种特殊形式,具有接口线少.控制方 ...