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. Java线程并发中常见的锁--自旋锁 偏向锁

    随着互联网的蓬勃发展,越来越多的互联网企业面临着用户量膨胀而带来的并发安全问题.本文着重介绍了在java并发中常见的几种锁机制. 1.偏向锁 偏向锁是JDK1.6提出来的一种锁优化的机制.其核心的思想 ...

  2. NIO框架之MINA源码解析(转)

    http://blog.csdn.net/column/details/nio-mina-source.html http://blog.csdn.net/chaofanwei/article/det ...

  3. 【Demo 0001】Java基础-数据类型

    本章学习要点:       1.  了解Java 语言       2.  了解Java程序结构;        3.  了解Java中基本数据类型;       4.  掌握基本数据类型之间的运算 ...

  4. ruby语言仅仅是昙花一现

    Ruby语言本身存在非常久了,在国内一直没火过.非常多人仅仅是知道有这样的语言,会的人少之又少.不论什么一种语言坚持十来年的发展,变得越来越好,一定有它不平常的地方.不能任意的去比較语言本身的好与坏. ...

  5. java android面试题分析总结

    本文参考多处,一并感谢! http://www.blogjava.net/fanyingjie/archive/2007/06/27/126467.aspx http://baike.baidu.co ...

  6. mysql update 有无索引对比

    <pre name="code" class="html">mysql> desc ProductInfo; +--------------- ...

  7. linux log系统图

    log系统图 先贴图,怎么样,效果还不错吧,根据个人理解画的,如果不行将就用着吧.   解说 syslog是一种机制,在wiki中说这种机制可以使用udp,tcp,unix socket等把日志记录在 ...

  8. linux nc命令使用详解

    功能说明:功能强大的网络工具 语 法:nc [-hlnruz][-g<网关...>][-G<指向器数目>][-i<延迟秒数>][-o<输出文件>][-p ...

  9. 猎豹移动(金山网络)2015校园招聘(c++project师)

    1.已知类MyString的原型为: class MyString { public: MyString(const char *str=NULL);//普通构造函数 MyString(const M ...

  10. Cocos2d-x 3.1.1 lua-tests 开篇

    Cocos2d-x 3.1.1 lua-tests开篇   本篇博客打算从研究Cocos2d-x引擎提供的測试样例来写起,笔者针对Cocos2d-x 3.1.1这个版本号来介绍怎样来学习它给我们提供的 ...