Main:This is my code for my main, employee.h, and node.h files. I'm trying to rewrite my main to use the node.h to were it is a singly linked list and am failing. Can someone show me how to actually obtain this?
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdlib>
#include <ctime>
#include "Employee.h"
#include "Node.h"
using namespace std;
void deleteList(Node** head_ref) {
Node* current = *head_ref;
Node* next;
while (current != NULL) {
next = current->next;
free(current);
current = next;
}
*head_ref = NULL;
}
int main(){
srand(time(NULL));
const int size=5;
string firstName[5]={"Kara","Barak","Bob","Whitni","Robin"};
string lastName[5]={"Ishihara","Bear","Stevens","Craig","Williams"};
string department[5]={"Sales","Social Network","Marketing","I.T.","Help Desk"};
Employee* p;
p=new Employee[5];
/*setSalary(p, size);
setRoles(p, size);
setSSN(p, size);
setfirst(p,size,firstName);
setlast(p,size,lastName);
setDepartment(p,size,department);
displayEmployee(p,size);*/
//attempt at linked list
Node* head=NULL;
Node* prev=NULL;
Employee e;
for(int i=0;i<10;i++){
Employee e;
Node* temp=new Node(e);
if(i==0){
head=temp;
prev=head;
}
else{
prev->next=temp;
prev=temp;
}
}
cout<<"========print employees in the list======"<<endl;
prev=head;
while(prev!=NULL){
cout<<(prev->e).first<<(prev->e).last<<(prev->e).SSN<<(prev->e).department<<(prev->e).salary<<(prev->e).role<<endl;
prev=prev->next;
}
deleteList(&head);
return 0;
}
Employee.h----
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;
enum Role {programmer, manager, director};
struct Employee {
string first;
string last;
int SSN;
string department;
double salary;
Role role;
};
void setSalary(Employee* e, int size){
for(int x=0;x<size;x++){
e[x].salary = 45000 + rand()% 20000;
}
}
void setRoles(Employee* e, int size){
for(int x=0; x<size;x++){
e[x].role = static_cast <Role> (rand()%3);
}
}
void setSSN(Employee* e,int size){
for(int x=0;x<size;x++){
int y=x;
e[x].SSN = rand()% 499999999 + 4000000000;
}
}
void setfirst(Employee* e, int size, string* name){
for(int x=0; x<size;x++){
int y = rand()%5;
e[x].first = name[y];
}
}
void setlast(Employee* e, int size, string* name){
for(int x=0;x<size;x++){
int y =rand()%5;
e[x].last =name[y];
}
}
void setDepartment(Employee* e,int size,string* d){
for(int x=0; x<size; x++){
int y= rand()%5;
e[x].department =d[y];
}
}
void displayEmployee(Employee* e, int size){
for(int x=0; x< size; x++){
string roles;
cout<<e[x].first<<" "<<e[x].last <<" "<<e[x].SSN <<" "<<e[x].department<<" "<<e[x].salary<<" ";
if(e[x].role==0){
cout<<"Programmer"<<endl;
}
else if(e[x].role==1){
cout<< "Manager"<<endl;
}
else if(e[x].role==2){
cout<<"Director"<<endl;
}
}
double average = (e[0].salary+e[1].salary+e[2].salary+e[3].salary+e[4].salary)/5;
cout<<"Average Salary: "<<average<<endl;
int numberOfProgrammers =0;
for(int x=0;x<size;x++){
if(e[x].role==0){
cout<<e[x].first<<" "<<e[x].last <<" "<<e[x].SSN <<" "<<e[x].department<<" "<<e[x].salary<<" Programmer"<<endl;
}
}
}
#endif
Node.h-----------
#ifndef NODE_H
#define NODE_H
#include "Employee.h"
typedef Employee EMP;
struct Node{
EMP e;
Node* next;
Node();
Node(EMP);
Node(EMP,Node* next);
};
Node::Node(){
next = NULL;
}
Node::Node(EMP e_param){
e=e_param;
}
Node::Node (EMP e_param,Node* next){
e=e_param;
this->next =next;
}
#endif
// Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std;
enum Role {programmer, manager, director};
struct Employee {
string first;
string last;
int SSN;
string department;
double salary;
Role role;
};
// set the salary of the employee
void setSalary(Employee &e){
//for(int x=0;x<size;x++){
e.salary = 45000 + rand()% 20000;
//}
}
// set the role of the employee
void setRoles(Employee &e){
//for(int x=0; x<size;x++){
e.role = static_cast <Role> (rand()%3);
//}
}
// set the ssn of the employee
void setSSN(Employee &e){
//for(int x=0;x<size;x++){
//int y=x;
e.SSN = rand()% 499999999 + 4000000000;
//}
}
// set the first name of the employee from the array of names
// param : Employee e
// size of the array name
// name array
void setfirst(Employee &e, int size, string* name){
//for(int x=0; x<size;x++){
int y = rand()%size;
e.first = name[y];
//}
}
// set the last name of the employee from the array of names
// param : Employee e
// size of the array name
// name array
void setlast(Employee &e, int size, string* name){
//for(int x=0;x<size;x++){
int y =rand()%size;
e.last =name[y];
//}
}
// set the department of the employee from the array of names
// param : Employee e
// size of the array d
// d array of departments
void setDepartment(Employee &e,int size,string* d){
// for(int x=0; x<size; x++){
int y= rand()%size;
e.department =d[y];
//}
}
void displayEmployee(Employee* e, int size){
for(int x=0; x< size; x++){
string roles;
cout<<e[x].first<<" "<<e[x].last <<" "<<e[x].SSN <<" "<<e[x].department<<" "<<e[x].salary<<" ";
if(e[x].role==0){
cout<<"Programmer"<<endl;
}
else if(e[x].role==1){
cout<< "Manager"<<endl;
}
else if(e[x].role==2){
cout<<"Director"<<endl;
}
}
double average = (e[0].salary+e[1].salary+e[2].salary+e[3].salary+e[4].salary)/5;
cout<<"Average Salary: "<<average<<endl;
int numberOfProgrammers =0;
for(int x=0;x<size;x++){
if(e[x].role==0){
cout<<e[x].first<<" "<<e[x].last <<" "<<e[x].SSN <<" "<<e[x].department<<" "<<e[x].salary<<" Programmer"<<endl;
}
}
}
// return the string value of the role
string getRole(Role role)
{
if(role==programmer){
return "Programmer";
}
else if(role==manager){
return "Manager";
}
else if(role==director){
return "Director";
}
return "";
}
#endif
//end of Employee.h
//Node.h
#ifndef NODE_H
#define NODE_H
#include "Employee.h"
typedef Employee EMP;
struct Node{
EMP e;
Node* next;
Node();
Node(EMP);
Node(EMP,Node* next);
};
Node::Node(){
next = NULL;
}
Node::Node(EMP e_param){
e=e_param;
next=NULL;
}
Node::Node (EMP e_param,Node* next){
e=e_param;
this->next =next;
}
#endif
//end of Node.h
// main.cpp : C++ program to implement Linked list of Employee objects
#include <iostream>
#include <ctime>
#include "Employee.h"
#include "Node.h"
using namespace std;
void deleteList(Node** head_ref) {
Node* current = *head_ref;
Node* next;
while (current != NULL) {
next = current->next;
delete current;
current = next;
}
*head_ref = NULL;
}
int main(){
srand(time(NULL));
const int size=5;
string firstName[5]={"Kara","Barak","Bob","Whitni","Robin"};
string lastName[5]={"Ishihara","Bear","Stevens","Craig","Williams"};
string department[5]={"Sales","Social Network","Marketing","I.T.","Help Desk"};
//attempt at linked list
Node* head=NULL;
Node* prev=NULL;
for(int i=0;i<10;i++){
// set the data for the employee
Employee e;
setSalary(e);
setRoles(e);
setSSN(e);
setfirst(e,size,firstName);
setlast(e,size,lastName);
setDepartment(e,size,department);
// create a new node
Node* temp=new Node(e);
// insert the node in the linked list
if(head==NULL){
head=temp;
prev=head;
}
else{
prev->next=temp;
prev=temp;
}
}
cout<<"========print employees in the list======"<<endl;
prev=head;
while(prev!=NULL){
cout<<(prev->e).first<<" "<<(prev->e).last<<" "<<(prev->e).SSN<<" "<<(prev->e).department<<" "<<(prev->e).salary<<" "<<getRole((prev->e).role)<<endl;
prev=prev->next;
}
deleteList(&head);
return 0;
}
//end of program
Output:

Main:This is my code for my main, employee.h, and node.h files. I'm trying to rewrite my...
Requirements: Finish all the functions which have been declared inside the hpp file. Details: string toString(void) const Return a visible list using '->' to show the linked relation which is a string like: 1->2->3->4->5->NULL void insert(int position, const int& data) Add an element at the given position: example0: 1->3->4->5->NULL instert(1, 2); 1->2->3->4->5->NULL example1: NULL insert(0, 1) 1->NULL void list::erase(int position) Erase the element at the given position 1->2->3->4->5->NULL erase(0) 2->3->4->5->NULL //main.cpp #include <iostream> #include <string> #include "SimpleList.hpp" using std::cin; using...
Hello, I have this code but its not running like it should:
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
class node
{
public:
typedef int data_t;
node *next;
data_t data;
node(data_t d) { next = NULL; data = d; }
};
class linked_list
{
private:
node *head;
public:
linked_list()
{
head = NULL;
}
int size()
{
node *tptr = head;
int c = 0;
while (tptr)
{
c++;
tptr = tptr->next;
}
return c;
}
void add(int...
redo program 1(what I have type on bottom to meet the following requirements) it must not interact with the user to receive inputs for efficiency in testing programs, while meeting the following requirements. in c++ Employee class Change the struct data type Employee to a class with all preexisting attributes(, or data members, or data fields) and an additional data member named count that keeps track of the number of Employee objects. Implement the interface that include the following functionalities...
This is just a partial C++ code. I am having a problem with the getline(cin, variable) statement of my code. Please run the code for yourself and see that it doesn't let you enter the full name. It skips the prompt to enter the name and goes straight to the next cout statement. I can't use cin alone because I need to capture and store both the first name followed by space followed by last name. I was trying to...
C++ comment code Comment the following code #include <iostream> using namespace std; class Node { public: Node(int val); int value; Node* next; }; Node::Node(int val){ value = val; } class List { public: List(); // Uncomment the line below once you're ready List(List &other); void push_front(int value); bool pop_front(int &value); void push_back(int value); bool pop_back(int &value); int at(int index); void insert_at(int index, int value); void remove_at(int index); int size(); private: // other members you may have used Node* head; Node*...
I'm having trouble getting this program to compile and run. It is in C++ Language and being run with CodeBlocks. Problem Statement: create and manage a linked list. Program will loop displaying a menu of user operations concerning the management of a linked list. Included will be: H create link at head R remove link at head T create link at tail K remove link at tail I remove link at ID S search...
I need help with understanding dummy nodes in doubly-linked lists. Here is the code that I have right now. ************city.h**************** #ifndef city_h #define city_h #include <string> using namespace std; class City{ public: City () { name = "N/A"; population = 0; } City (string nm, unsigned int pop){ name = nm; population = pop; } void setName (string name) { this -> name = name; } void setPopulation (unsigned int population){ this -> population = population; } string getName() const...
Hi I got error C2660 : 'valuein' : function does not take 2 parameters in visual studio 2013 this is my code so far #include <cstdlib> #include <list> #include <iostream> using namespace std; struct node { int data; node* next; }; void initialize(node*p); void insert(int data,int n); void remove(int b,int pos); bool empty(node*); void length(); bool valuein(int c); int reportvalue(int value); void ptintlist(); int menu(); int main() { struct node*head=NULL; char commands; int value; ...
Hello, can someone help me solve the remove function since when I try to remove it doesn't work, please and thank you. #include <iostream> #include <cstdlib> #include <string> using namespace std; class node { public: typedef int data_t; node *next; data_t data; node(data_t d) { next = NULL; data = d; } }; class linked_list { private: node *head; public: linked_list() { head = NULL; } // Get the...
Please rewrite this function using recursive function #include using namespace std; struct Node { char ch; Node* next; }; class LinkedList { Node* head; public: LinkedList(); ~LinkedList(); void add(char ch); bool find(char ch); bool del(char ch); friend std::ostream& operator<<(std::ostream& out, LinkedList& list); }; LinkedList::LinkedList() { head = NULL; } LinkedList::~LinkedList() { Node* cur = head, * tmp; while (cur != NULL) { tmp = cur->next; delete cur; cur = tmp; } } void LinkedList::add(char ch) { Node* cur = head,...