C++
It is common for an organization to have different categories of employees, such that one Employee class can not easily describe all types of Employees.In this project, you will code a basic Employee class, and then a number of classes which derive from the Employee class (inherit), adding Employee specifics. An application program which stores info for one company will have use objects of different types to model the all employees.
Part I: The Employee Class
First create the Employee class described below. This class will serve as a base class. All specific employee typed will be derived from this class. :
Employee |
-lastName:string -firstName:string -idNum:int |
+Employee() //default values assigned to all variables +Employee(int idNum, string lname, string fname) +void setLName(string) +void setFName(string) +void setIDNum(int) +string getLName() +sgtringgetFName() +intgetIDNum() +void displayName() +void display() |
Stick with the access specifiers on the diagram. Items denoted as + are public, - are private.
NOTE: There are NO protected member variables in this class
The constructors both initialize all member variables. Sets functions set the indicated member variable of the object, and get functions return the value of the indicated member variable of the object.
The displayName() function prints out the last name and ID only, and the display()function outputs the all employee information that is stored.
PART II: The Derived Classes
Salaried |
Hourly |
Commission |
||
-weeklySal:double |
-payperhr:double -hrsworked:double |
-basesalary:double -comAmount:double |
||
+Salaried(string lname, string fname) +Salaried(string lname, string fname, double sal) +void setSal(double nsal) +double getSal() +void displaySal() +void display() |
+Hourly(string lname, string fname) +Hourly(string lname, string fname, double newpay) +void setPay(double) +void setHrs(double nhr) +double getPay() +double getHrs() +void displayHrly(): +void display() |
+Commission(string lname, string fname) +Commission(string lname, string fname, double bsal) +void setBase(double npay) +void setCom(double nhr) +double getBase() +double getCom() +void displayBase() +void displayEmp() |
As you can see, Employee is a base class, which is extended by the Hourly, Salaried and Commissioned classes. The derived classes describe 3 ‘types’ of employee.
Each of the derived classes provides instance data necessary for determining an employee’s weekly earnings, and both set (mutator) and get(accessor) methods for these additional variables. A salaried employee just gets a prearranged salary per week. An hourly employee’s weekly salary is based on the hourly rate and number of hours worked that week. A commissioned employee gets a base pay per week, plus the amount of commission earned that week. Each of these classes provides two display functions, one that outputs info specific for that class, one that overrides the base class function display(), to output all info on the object (both base and derived class data).
The displaySal() function outputs the employee name, id and weekly salary.
The displayHrly() function outputs the employee name, id and hourly rate.
The displayBase() function outputs the employee name, id and base pay.
Once these classes are working and tested you are ready to begin part III.
Part III The Application
You are to write an application which will allow the user to enter all his/her employees and their data. This application will allow the user to print out information on employees.
(This project will be updated in a future project assignment, so be sure to stick to the specifications. This will make the update happen more smoothly)
This application is to store each of the three types of objects in it’s own vector. That is, you will have a vector<Salaried>, a vector<Hourly> and a vector<Commission>.
Your program is to provide the following options for the user:
* add a new salaried employee
* add a new hourly employee
* add a new commissioned employee
* list all employees with a particular last name
* output all information for all employees stored
* search for an employee with a particular id number
* output the name and salaries ONLY of all salaried employees
* output the name and hourly rate ONLY of all salaried employees
* output the name, id and base salary of all commissioned employees
You are to submit 9 files, Employee.h, Employee.cpp, Salaried.h, Salaried.cpp, Hourly.h, Hourly.cpp, Commission.h, Commission.cpp, and your main program file.
In: Computer Science
Using Java:
Create a class called MyNumber with an integer private attribute.
Create a constructor that defines an integer parameter to set the private integer attribute.
Create a setter that validates the attribute does not accept a value lower than 2 or the method will throw a IllegalArgumetException.
Create a getter to return the private integer attribute value.
Define a public method that is called isPrime() that returns a boolean and implements the Sieve of Eratosthenes method.
Define a public method that is called numberOfPrimes() that returns the number of prime numbers between 2 and the private attribute value.
Demonstrate this object in a main method that allows the user to interact with all the public methods of your class.
In: Computer Science
In your app.cpp file, create a demo illustrating a scenario where storing numbers in a linked list is more efficient than an array. Your demo should generate a sufficiently large number of random integers and insert them into both the list, and the array. Your demo should also provide the time it took to complete the operations in the array, and in the linked list. It should show that the linked list was faster.
app.cpp
#include <iostream>
#include <Array.h>
#include <LinkedList.h>
using namespace std;
int main(){
// Your code here...
return 0;
}
Support code-
Array.h
#ifndef Array_h
#define Array_h
#include <iostream>
#include <ostream>
struct ResizableArray {
// This is the poiner to the start of our array
long* data;
// Keep track of how much memory we have allocated
long size;
// Keep track of how much memory we have used
long counter;
// A default constructor
ResizableArray(){
// Start off by allocating memory for 1 int
data = new long[1];
// This means we have allocated for 1
size = 1;
// And we are currently using 0
counter = 0;
}
// This is a copy constructor. It specifies what happens when
// the array needs to be copied. In this case it performs
// a deep copy, which is what we need
ResizableArray(const ResizableArray& other){
size = other.size;
counter = other.counter;
data = new long[other.size];
for (long i = 0; i < other.size; i++){
data[i] = other.data[i];
}
}
// Overloading the == operator. Now we can compare
// two ResizableArrays with the == operator
bool operator==(const ResizableArray rhs) const {
// If the sizes or counters are different, it's not a match
if (size != rhs.size){
return false;
}
if (counter != rhs.counter){
return false;
}
// Assume the arrays match
bool same = true;
// And try to find a contradiction
for (long i = 0; i < counter; i++){
if (data[i] != rhs.data[i]){
return false;
}
}
// Colud not get a contradiction
return true;
}
// Print the contents we have
void print(){
for (long i = 0; i < counter; i++){
std::cout << data[i] << std::endl;
}
}
// Get the value at a specified position
int get(long index){
return data[index];
}
// Set the value at a specified position with a given integer
void set(long index, long value){
data[index] = value;
}
void insert(long index, long value){
if (index < size){
for(long i = counter; i > index; i--){
data[i] = data[i-1];
}
data[index] = value;
counter++;
if (counter == size){
long oldSize = size;
size = size * 2;
long* newArr = new long[size];
for (long i = 0; i < oldSize; i++) {
newArr[i] = data[i];
}
delete[] data;
data = newArr;
}
}
else{
int oldSize = size;
while (index+1 >= size){
size *=2;
}
if (size > oldSize){
long* newArr = new long[size];
for (long i = 0; i < oldSize; i++) {
newArr[i] = data[i];
}
delete[] data;
data = newArr;
}
for (long i = counter; i < index; i++){
data[i] = 0;
}
data[index] = value;
counter = index + 1;
}
}
// Store a new value in the array
void append(long value){
// The very first time this is called
// we know we have enough storage allocated
// because we allocated space for 1 int
// so we store it
data[counter] = value;
// and increase the counter
counter++;
// If we are out of space, i.e. we have
// stored as much as we have allocated
// then we need to increase our storage space
if (counter == size){
// Just for convenience, store the old size
long oldSize = size;
// Let's double the amount of storage we have
size = size * 2;
// Allocate another chunk of memory
// twice as big as the first
long* newArr = new long[size];
// Copy all elements from the old location
// to the new location
for (long i = 0; i < oldSize; i++) {
newArr[i] = data[i];
}
// Release the old location
delete[] data;
// Make our data pointer point to the new location
data = newArr;
}
}
// This is called a destructor. It simply releases the
// memory we have been using.
~ResizableArray(){
delete[] data;
}
};
// This is an overload of the << operator, which allows us
// to print out the ResizableArray with cout <<
std::ostream& operator<<(std::ostream& os, const ResizableArray& arr) {
for (long i = 0; i < arr.counter; i++){
os << arr.data[i] << " ";
}
return os;
}
#endif
LinkedList.h
#ifndef LinkedList_h
#define LinkedList_h
#include <iostream>
#include <ostream>
struct Node{
long data;
Node* next;
Node (){
data = 0;
next = NULL;
}
Node (long n){
data = n;
next = NULL;
}
};
struct LinkedList{
Node* head;
Node* last;
LinkedList(){
head = NULL;
last = NULL;
}
LinkedList(const LinkedList& other){
head = NULL;
if (other.head != NULL){
Node* temp = other.head;
while (temp != NULL){
append(temp->data);
temp = temp->next;
}
}
last = other.last;
}
void append (long n){
if (head == NULL){
head = new Node(n);
last = head;
}
else{
Node* theNode = new Node(n);
last->next = theNode;
last = last->next;
}
}
void prepend(long n){
Node* temp = new Node(n);
temp->next = head;
head = temp;
}
bool operator==(const LinkedList& other) const {
Node* ours = head;
Node* theirs = other.head;
while (ours != NULL){
if (theirs == NULL){
return false;
}
if (ours->data != theirs->data){
return false;
}
else{
ours = ours->next;
theirs = theirs->next;
}
}
return theirs == NULL;
}
~LinkedList(){
Node* temp = head;
while (temp != NULL){
head = head->next;
delete temp;
temp = head;
}
}
};
std::ostream& operator<< (std::ostream& os, const LinkedList& theList){
Node* temp = theList.head;
while (temp != NULL){
os << temp->data << " ";
temp = temp->next;
}
return os;
}
#endif
TimeSupport.h
//
// A small library for timing our programs
//
#ifndef TimeSupport_h
#define TimeSupport_h
#include <chrono>
typedef enum {
sec,
mill
} Unit;
typedef std::chrono::time_point<std::chrono::high_resolution_clock> timestamp;
long time_diff(timestamp start, timestamp end, Unit u = mill){
if (u == mill){
auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
return (long) diff;
}
else{
auto diff = std::chrono::duration_cast<std::chrono::seconds>(end-start).count();
return (long) diff;
}
}
timestamp current_time(){
return std::chrono::high_resolution_clock::now();
}
#endif
RandomSupport.h
//
// A small library for sampling random numbers from a uniform distribution
//
#ifndef RandomSupport_h
#define RandomSupport_h
#include <random>
int call_counter = 0;
typedef std::uniform_int_distribution<long> uniform_distribution;
typedef std::mt19937 randomizer;
randomizer new_randomizer(){
randomizer rng;
rng.seed(std::random_device()());
return rng;
}
uniform_distribution new_distribution(long start, long end){
uniform_distribution dist(start, end);
return dist;
}
long sample(uniform_distribution& dist, randomizer& r){
call_counter++;
return dist(r);
}
#endif
In: Computer Science
1 Lab: Sorting
This lab will introduce you to some basic sorting algorithms. There
will be three algorithms included in the
lab Quicksort, Mergesort, and Heapsort. Quicksort will already be
completed for you, it is there for you to
refernce. Merge and Heap will need to be completed.
2 Lab: Assignment
Complete the functions heapify and mergesort. DO NOT change main or
the function declarations. Start
with a MAXSIZE to be set to 100 (defined up top) to ensure you are
sorting correctly, you can uncomment
the print statements in main. Make sure your re-comment out the
print statements after you ensure you are
sorting correctly. Once you are sorting correctly increase MAXSIZE
up to 100,000 and run it again.
• Mergesort is missing the RECURSIVE calls
• Mergesort also needs to put the recursive calls together
• heapify also needs RECURSIVE calls
Lab 6.cpp:
//Written by Danny Radosevich
//Code for UWYO COSC 2030
//Lab6
#include <random>
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <chrono>
using namespace std;
#define MAXSIZE 100000
//sorting
//function declarations
int partition(int arr[], int low, int high);
void quickSort(int quick[],int low, int high);
void merge(int arr[], int left, int mid, int right, int
size);
void mergeSort(int merge[], int left, int right, int size);
void heapSort(int heap[], int size);
void heapify(int arr[],int size, int index);
int main()
{
//for loop to get an illsorted array
int heap[MAXSIZE];
int merge[MAXSIZE];
int quick[MAXSIZE];
srand(unsigned(time(NULL)));
for(int i = 0; i<MAXSIZE;i++)
{
//set all three arrays to the same thing
int temp = rand()%(10*MAXSIZE);
heap[i] = temp;
merge[i] = temp;
quick[i] = temp;
}
//make sure the arrays are the same, so we can best test which is
most efficient
/*
for(int i = 0; i<MAXSIZE;i++)
{
cout<<heap[i]<<"\t"<<merge[i]<<"\t"<<quick[i]<<endl;
}*/
//time heap sort
std::chrono::high_resolution_clock::time_point t1 =
std::chrono::high_resolution_clock::now();
heapSort(heap,MAXSIZE);
std::chrono::high_resolution_clock::time_point t2 =
std::chrono::high_resolution_clock::now();
std::chrono::duration<double> time_span =
std::chrono::duration_cast<std::chrono::duration<double>
>(t2 - t1);
cout << "heapSort took " << time_span.count() <<
" seconds."<<endl;
//time merge sort
t1 = std::chrono::high_resolution_clock::now();
mergeSort(merge,0, MAXSIZE -1, MAXSIZE);
t2 = std::chrono::high_resolution_clock::now();
time_span =
std::chrono::duration_cast<std::chrono::duration<double>
>(t2 - t1);
cout << "mergeSort took " << time_span.count() <<
" seconds."<<endl;
//time quick sorting
t1 = std::chrono::high_resolution_clock::now();
quickSort(quick, 0, MAXSIZE -1);
t2 = std::chrono::high_resolution_clock::now();
time_span =
std::chrono::duration_cast<std::chrono::duration<double>
>(t2 - t1);
cout << "quickSort took " << time_span.count() <<
" seconds."<<endl;
//print the new arrrays
/*
for(int i = 0; i<MAXSIZE;i++)
{
cout<<heap[i]<<"\t"<<merge[i]<<"\t"<<quick[i]<<endl;
}*/
return 0;
}
int partition(int arr[], int low, int high)
{
int pivot = arr[high];
int lowIndex = (low-1);
for(int i = low; i< high; i++)
{
if(arr[i]<=pivot)
{
lowIndex++;
swap(arr[lowIndex], arr[i]);
}
}
swap(arr[lowIndex+1],arr[high]);
return (lowIndex+1);
}
void quickSort(int quick[],int low, int high)
{
if(low<high)
{
int partIndex = partition(quick,low,high);
//sort elements based on the partition
quickSort(quick,low, partIndex-1);
quickSort(quick,partIndex+1, high);
}
}
void merge(int arr[], int left, int mid, int right, int
size)
{
int i, j, k = 0; //control variables for later
int sizeOne = mid -left +1; //size of left arrays
int sizeTwo = right - mid;//size of right array
//arrays for each size
//int *a = new int[variable_int];
int *leftArray = new int[sizeOne];
int *rightArray = new int[sizeTwo];
//copy the data into the arrays
for(i = 0; i<sizeOne; i++ )
{
leftArray[i] = arr[i+left];
}
for(j = 0; j<sizeTwo; j++)
{
rightArray[j] = arr[mid+1+j];
}
i = 0;
j = 0;
k = left;
while(i<sizeOne && j<sizeTwo &&
k<size)
{
if(leftArray[i]<=rightArray[j])
{
arr[k] = leftArray[i];
i++; //only increment when we use an element
}
else
{
arr[k] = rightArray[j];
j++;//same as above
}
k++;
}
//now we need to clear the remainder in the arrays
while(i<sizeOne && k <size)
{
arr[k] = leftArray[i];
i++;
k++;
}
while(j<sizeTwo && k <size)
{
arr[k] = rightArray[j];
j++;
k++;
}
delete[] leftArray;
delete[] rightArray;
}
void mergeSort(int toMerge[], int left,int right, int size)
{
if(left<right)
{
//find the mid point
int mid = left+(right-left)/2;
//recursivley call mergeSort
//YOUR CODE GOES HERE
//YOUR CODE GOES HERE
//but the whole thing together
//YOUR CODE GOES HERE
}
}
//Heap sort functions
void heapify(int arr[], int size, int index)
{
int largestPos = index; //set the largest as the root
int leftChildPos = 2*index+1; //get the left child with
offset
int rightChildPos = 2*index+2; //get right child by offset
//check if left child in bounds and larger than root
if(leftChildPos<size &&
arr[leftChildPos]>arr[largestPos])
{
largestPos = leftChildPos; //we found a new largest
}
if(rightChildPos<size &&
arr[rightChildPos]>arr[largestPos])
{
largestPos = rightChildPos; //we found a new largest
}
//check if the largest is no longer root (we switched)
if(largestPos != index)
{
//SWAP two elements in the array
//YOUR CODE GOES HERE
// Recursively heapify the affected sub-tree
//YOUR CODE GOES HERE
}
}
void heapSort(int heap[], int size)
{
//the rearranges the array
for(int i = size/2 - 1; i>=0; i--)
{
//call heapify
heapify(heap,size,i);
}
for(int i = size-1; i>=0; i--)
{
// Move current root to end
swap(heap[0], heap[i]);
// call max heapify on the reduced heap
heapify(heap, i, 0);
}
}
In: Computer Science
Part II: gdb (Debugging under Unix)
/*reverse.c */
#include <stdio.h>
void reverse(char *before, char *after);
main()
{
char str[100]; /*Buffer to hold reversed string */
reverse("cat", str); /*Reverse the string "cat" */
printf("reverse(\"cat\")=%s\n", str); /*Display result */
reverse("noon", str); /*Reverse the string "noon" */
printf("reverse(\"noon\")=%s\n", str); /*Display result */
}
void reverse(char *before, char *after)
{
int i;
int j;
int len;
len=strlen(before);
for(j=len, i=0; j>=0; j--, i++)
after[i]=before[j];
after[len]=NULL;
}
In: Computer Science
What is the cloud computing delivery model for Amazon S3. Justify your answer.
In: Computer Science
In Python, I have a turtle that is already coded to move in correlation with the keys I set (I can control the turtle). I need to put a second turtle in that moves WHILE the first turtle is moving and being controlled. The second turtle needs to do the following while the first turtle is still listening and being controlled:
-It needs to begin facing a random direction
-It needs to move at a speed of .5 the entire time
-It needs to move completely randomly for 40 moves, and every 40 completely random moves it does, it needs to turn in a random direction and continue moving in that direction.
-If the turtle reaches more than 250 units from the middle of the screen, the turtle needs to teleport back to the center of the screen and it needs to continue moving randomly and repeat this if it reaches 250 again.
-The turtle cannot have a line behind it, i.e. the turtle should not leave a line drawn/trace
So the turtle needs to appear with the first turtle and must appear in a random direction, move randomly 40 times, then move in a random direction until it reaches 250 units from the middle of the screen (if it reached the middle of the screen during it's 40 moves, it should reset the same) and once it reaches 250, or if at any point it does, it should teleport back to the middle of the screen and go back to moving randomly. At the same time all of this is happening, the first turtle is still doing it's thing and listening to my keyboard commands.
Please provide a code for the second turtle to be doing the above directions. If I need to alter the first turtle's code to have both of them moving at the same time, please detail how and if possible provide code. Thank you
In: Computer Science
Explain both TCP/IP and ISO/OSI communication protocol stacks, identifying each of the protocol layers. How does encapsulation work in this layered design? In terms of ratio header/payload, estimate the optimistic accumulate overhead these protocols incur for each application “packet” that is transmitted over the Internet.
In: Computer Science
javascript BlackJack
i made a blackjack game, the code is below
//this method will return a shuffled deck
function shuffleDeck() {
//this will store array fo 52 objects
const decks = []
const suits = ['Hearts', 'Clubs', 'Diamonds', 'Spades']
const values = ['Ace', 'King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'One']
//run a loop till 52 times
for (let i = 0; i < 52; i++) {
//push a random item
decks.push({ suit: suits[Math.floor(Math.random() * suits.length)], value: values[Math.floor(Math.random() * values.length)] })
}
return decks
}
//function that will draw four cards form the deck
function draw(decks) {
return {
player: [decks[0], decks[1]],
computer: [decks[2], decks[3]]
}
}
//first shuffle the deck
const shuffled = shuffleDeck()
console.log((shuffled))
//now draw the card
const drawn = draw(shuffled)
console.log("\n\nDrawn Cards :" ,(drawn))
i want to make a node application that will listen for user input. this is what i have so far for it.
function startGame () {
let input;
input = prompt("Welcome to Blackjack. Do you want to play? (Y)es or
(N)o").toUpperCase();
if (input == 'Y') {}
}
i am stuck on how to finish the startGame Function.
In: Computer Science
Critically analyse how managers can exploit the value generated by the information infrasturcture. Justify your answer providing examples of managerial actions that are useful to exploit the value generated by the information infrasturcture.
In: Computer Science
This is to check to ensure you are current in your work.
Please create a simple calculator with only +, - and divide. It has to be able to enter any numbers (including decimals) and be able to do the following functions:
+, -, divide and multiply.
Please have the answers, always rounded to two decimal figures. The calculator will also have to be able to take up to 5 values.
In: Computer Science
need a visual studio solution for the following: 1. Radio buttons that limit the us er to only one choice (nested selection structure) 2. A group box for your radio buttons 3. Controls to prevent unwanted characters in text boxes 4. At least one message box 5. At least one select case statement
In: Computer Science
a)Explain the relationship between the cost performance index and schedule performance index.
b)What is the purpose of the work package? Who will create it?
In: Computer Science
Revise the MeanMedian class so that the user can enter any number of values up to 20. If the list has an even number of values, the median is the numeric average of the values in the two middle positions. Allow the user to enter 9999 to quit entering numbers.
In: Computer Science
If no WHERE clause is used along with a __?__ join, it produces a result set containing the number of rows in a first table multiplied by the number of rows in the second table (also known as the Cartesian product). ?
LEFT,
RIGHT,
INNER,
OUTER,
CROSS,
PARALLEL)
In: Computer Science