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. 自适应滤波器(Adaptive Filter)

    ======= Wikipedia的解释 ======= 自适应滤波器是能够根据输入信号自动调整性能进行数字信号处理的数字滤波器.作为对比,非自适应滤波器有静态的滤波器系数,这些静态系数一起组成传递函 ...

  2. HOW TO: How to import UUID function into Postgre 9.3

    1. Open a command console and go to the directory where you installed Postgre server. e.g. D:\Progra ...

  3. Tokyo Tyrant(TTServer)系列(四)-tcrmgr远程管理与调试

    Tokyo Tyrant(TTServer)系列-tcrmgr(远程管理与调试) tcrmgr是TokyoTyrant的管理工具,对ttserver进行管理与执行命令: 通过输入tcrmgr回车,能够 ...

  4. 一个跨平台的 C++ 内存泄漏检测器

    2004 年 3 月 01 日 内存泄漏对于C/C++程序员来说也可以算作是个永恒的话题了吧.在Windows下,MFC的一个很有用的功能就是能在程序运行结束时报告是否发生了内存泄漏.在Linux下, ...

  5. 显示形状回归算法(ESR)代码介绍

    源地址:http://www.thinkface.cn/thread-3704-1-6.html 人脸对齐包括两个部分,分别为训练部分和测试部分.所有的代码基于opencv2.0.(一)训练阶段Ste ...

  6. ROOT android 原则。 基于(zergRush)

    从: http://bbs.gfan.com/android-2996211-1-1.html 须要ROOT的同学请去上面的地址下载. a.控制手机创建个暂时目录,然后把zergRush脚本写入此目录 ...

  7. codeforces 659B Qualifying Contest

    题目链接:http://codeforces.com/problemset/problem/659/B 题意: n个人,m个区.给出n个人的姓名(保证不相同),属于的区域,所得分数.从每个区域中选出成 ...

  8. NetBeans工具学习之道:NetBeans的(默认)快捷键

    没什么好介绍的,是netbeans的快捷键,比較全面.看到好多坛子里还在问eclipse下的这个快捷键怎么netbeans下没有呢.曾经收集的,如今列在以下: 事实上,在当前安装的netbeans的 ...

  9. 自己动手写处理器之第一阶段(2)——MIPS指令集架构的演变

    将陆续上传本人写的新书<自己动手写处理器>(尚未出版),今天是第三篇.我尽量每周四篇 MIPS指令集架构自上世纪80年代出现后.一直在进行着更新换代,从最初的MIPS I到MIPS V,发 ...

  10. 【机器学习】SVM核函数

    知识预备 1. 回顾:logistic回归出发,引出了SVM,即支持向量机[续]. 2.  Mercer定理:如果函数K是上的映射(也就是从两个n维向量映射到实数域).那么如果K是一个有效核函数(也称 ...