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也是一种列表容 ...
随机推荐
- libuv 初窥--转
过年了,人都走光了,结果一个人活也干不了.所以我便想找点东西玩玩. 今天想试一下 libev 写点代码.原本在我那台 ubuntu 机器上一点问题都没有,可在 windows 机上用 mingw 编译 ...
- 简单概率dp(期望)-zoj-3640-Help Me Escape
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4808 题目大意: 有n条路,选每条路的概率相等,初始能力值为f,每 ...
- 关于sizeof的笔试面试题具体解释
原创Blog,转载请注明处处 http://blog.csdn.net/hello_hwc 注意:sizeof是编译期计算出结果的,这一点对后面的理解非常重要 一.关于结构体 先看下代码 #inclu ...
- java jquery 函数多參数传递
业务需求: 名次 伙伴 业绩 签单 面谈 每日目标 1 文彬 5100 6 10 查看目标 2 马红月 4550 4 6 查看目标 3 王刚 4100 3 9 查看目标 4 郭亚凯 3450 4 ...
- Swift - 操作表(UIActionSheel)的用法,也叫底部警告框
1,下面创建一个操作表(或叫底部警告框)并弹出显示 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 class ViewController: UIViewC ...
- google 搜索url详解
www.google.com [http://www.google.cn/search?q=112&hl=zh-CN&client=aff- 360daohang&hs=yhE ...
- 解决Eclipse中文乱码的方法
(1)设置Project的编码格式: 在 Workspace中新建的项目默认继承Workspace的编码设置.我们也能够单独更改某个项目的编码格式.右键点击project.选择 Properties, ...
- eclipse设置关联文件打开方式
window->preferences: General->Editors->File Associations
- ogre sample分析(一)
ogre自带了一些例子,逐个过一遍并自己动手做一些调整 1 Sample_BezierPatch:这个例子直接用数值来构造顶点缓存并创建entity,这种方法一般只能创建简单对象,本人以为复杂对象顶点 ...
- 跟我一起学extjs5(13--运行菜单命令在tabPanel中显示模块)
跟我一起学extjs5(13--运行菜单命令在tabPanel中显示模块) 上面设计好了一个模块的主界面,以下通过菜单命令的运行来把这个模块增加到主界面其中. 在MainModule. ...