Array of Objects
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的更多相关文章
- 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 ...
- How to use Jackson to deserialise an array of objects
first create a mapper : import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper mapper = ne ...
- 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 ...
- 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 ...
- [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 ...
- iOS 判断数组array中是否包含元素a,取出a在array中的下标+数组方法详解
目前找到来4个解决办法,第三个尤为简单方便 NSArray * arr = @["]; //是否包含 "]) { NSInteger index = [arr indexOfObj ...
- 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($ ...
- [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 ...
- Cocos2d-x之Array
| 版权声明:本文为博主原创文章,未经博主允许不得转载. Array是一个列表类容器,是一种线性序列结构:列表容器中的元素是有序的,可以通过下标来访问,就和数组一样.其中Vector也是一种列表容 ...
随机推荐
- HDU--杭电--4502--吉哥系列故事——临时工计划--背包--01背包
吉哥系列故事——临时工计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) To ...
- Codeforces Round #257 (Div. 2) B Jzzhu and Sequences
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
- How to get the source code of the chromium of the specified revision
I'd like to get the source code of the chromium 34.0.1847.9. gclient config http://src.chromium.org/ ...
- Pyhon安装media模块
都是教科书惹的祸,它没有说清楚.media看着很标准,其实不是python自带的库.需要安装第三方软件后才能用. 在这里http://pythonhosted.org/PyGraphics/insta ...
- Lambda高手之路第二部分
转http://www.cnblogs.com/lazycoding/archive/2013/01/06/2847579.html 闭包的影响 为了展示闭包的影响,我们看下面这个例子. var bu ...
- 18.如何自我Struts2它Struts2标签和综合汇总文章有点早
18.如何自我Struts2它Struts2标签和综合汇总文章有点早[视频] 之前写了一篇"打算做一个视频教程探讨怎样自学计算机相关的技术",优酷上传不了.仅仅好传到百度云上: h ...
- adnroid仿miui的dialog
先来看下效果图: 当中show和dismiss的时候有动画效果. 原先试过使用PopupWindow来做,可是使用的时候不是那么舒服,毕竟不是dialog嘛. 所以这次尝试还是使用dialog来做 , ...
- iOS安全攻击和防御(24):敏感的保护方案逻辑(1)
iOS安全攻击和防御(24):敏感的保护方案逻辑(1) Objective-C代码easy被hook.暴露信息太赤裸裸,为了安全,改用C来写吧! 当然不是所有代码都要C来写,我指的是敏感业务逻辑代码. ...
- poj3694(tarjan缩点+lca)
传送门:Network 题意:给你一个连通图,然后再给你n个询问,每个询问给一个点u,v表示加上u,v之后又多少个桥. 分析:方法(1219ms):用并查集缩点,把不是桥的点缩成一个点,然后全图都是桥 ...
- TBDR缺点
TBDR全称Tile-based Deferred Rendering.它是Power VR独特的TBR技术的一种延伸实现手段.TBR/TBDR通过将每一帧画面划分成多个矩形区域,并对区域内的全部像素 ...