What are the advantages of using an ordered array

Assignment Help C/C++ Programming
Reference no: EM13936645

Part 1- Use pseudo code to describe your add, remove, find, and display options.

Part 2- Answer the following questions

1. What are the inefficiencies associated with using an unordered array if duplicates are not allowed?

2. What are the advantages of using an ordered array?

3. When would using an unordered array be preferred over using an ordered array?

4. Define Big-Oh notation. Explain how z and c in the definition relate to the evaluation of algorithm efficiency.

5. Why does computer science often describe algorithms in terms of lg instead of ln?

6. How do you convert ln(x) to lg(x)?

7. Give an example of algorithm with Big-Oh values of: N2, N lg N, 1, and N.

8. Why is Big-Oh 2N represent an algorithm called intractable?

9. How much slower would a linear search be on 1024 items than 16 items?

10. How much slower would a binary search be on 1024 items than on 16 items?

Part 3- Implement the program.

Instructions

1. For all our labs, use the Eclipse IDE. On your own computer, you will need to install MinGW. You will also need to download and install the C development toolkit (CDT). There are many tutorials on the Web to step you through this process. Eclipse is a popular IDE for C development; it includes a good interactive debugger and project control

2. Write a C program that will maintain a list of employees using either ordered or unordered arrays. Each employee in the list should store an identifier number (integer), a name (String - char array), and a salary (Double). Allow operations to add, remove, display single, display list, reset the list, create a initial list with randomly populated items, help, and exit.

3. You can choose either an unordered list or an ordered list for your implementation. If you choose an unordered list, sort it before display. For an ordered list, use a binary search instead of a linear search.

4. You don't need to implement a GUI for this project. Just create a menu of selections as listed below:

Employee Maintenance

1) Add Employee
2) Remove Employee
3) Display Employee
4) Display Employee List
5) Reset List
6) Create Initial List
7) Sort
8) Help
9) Quit
Please Select:

Note: The sort option is unnecessary if you implement an ordered list.

5. To add an employee, randomly pick an integer employee number that must be unique. The C function rand() can be used. A list of available employee numbers must also be maintained. Initially, this list can be filled with a sequential list of integers. To add a new employee, randomly pick one of these integers and replace its entry in the list with the final entry. Ask the user for an Employee name and salary. Keep track of the number of item numbers that are available using an integer counter.

6. When you remove an employee, the employee number should be returned to the free list.

7. Make sure to validate that the salary is within a reasonable range. You can use the C scanf function. Recall that scanf("%s*") is needed to clear the input buffer after an error. Always output appropriate error messages when the user types in something illegal. Robust programs should never crash.

8. My implementation contained three files; one for the main program (lab1.c), one for the list of employees (EmployeeList.c), and one for maintaining each employee (Employee.c). I also created a header file (empstructs.h), which contained a structure for the employee items and various symbolic constants (see below).

#ifndef EMPSTRUCTS_H_

#define EMPSTRUCTS_H_

#include <string.h>

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#define MAX_EMPLOYEES 100

#define EMP_SIZE 30

#define LINE 80

#define OPTIONS 9

#ifndef NULL

#define NULL ((void *) 0)

#endif

#define FALSE 0;

#define TRUE 1;

typedef struct

{

int id;

char name[EMP_SIZE];

double salary;

} EMPLOYEE;

typedef struct

{

int freeCount;

int employeeIndex;

int numEntries;

int freeList[MAX_EMPLOYEES];

EMPLOYEE *employees[MAX_EMPLOYEES];

} EMPLOYEE_LIST;

/* Declared in Employee.c */

void destroyEmployee(EMPLOYEE**);

EMPLOYEE* createEmployee(char*, double, int);

char* employeeToString(EMPLOYEE*, char*);

/* Declared in EmployeeList.c */

void initializeEmployeeList(EMPLOYEE_LIST*);

EMPLOYEE* insert(EMPLOYEE_LIST*, char*, double);

void sort(EMPLOYEE_LIST*);

int delete(EMPLOYEE_LIST*, int);

void deleteAll(EMPLOYEE_LIST*);

EMPLOYEE* find(EMPLOYEE_LIST*, int);

int traverse(EMPLOYEE_LIST*, void (*)(EMPLOYEE*, char*));

#endif /* EMPSTRUCTS_H_ */

9. When you create a new employee, use the malloc command to allocate the appropriate amount of memory. sizeof(EMPLOYEE), assuming your employee structure is called EMPLOYEE, returns the number of bytes needed for the malloc command. When you remove an employee, or if you are resetting the employee list, make sure to call C's freefunction when getting rid of employees. C does not include garbage collection, so failing to do this leads to memory leaks.

10. The Create option will use a 'for' loop to automatically add items to the employee list. Random non-duplicate item number values are required (as we described above). Use any algorithm that you choose to generate different values for the names and salaries; duplicate field values are ok. A simple way to choose employee names is to declare an array of possible names. The following statement can then be used to randomly choose a description:

name = names[(int)(Math.Rand()%namesSize)];

For the salary field, (int)(Math.Rand()%RANGE) + MINSALARY can be used to guarantee that a valid dollar and cents value is used.

11. The help command redisplays the menu. Otherwise, it should only display once when the program starts.

Reference no: EM13936645

Questions Cloud

Set of experience knowledge structure : Set of Experience Knowledge Structure (SOEKS) is knowledge representation in an artificial system that would support discovering, adding, storing and sharing knowledge through experience in a similar way that humans DNA do. SOEKS is then later car..
Write a program to do calculations with a 2-d array : You are to development the following functions to support this effort. Write a function for each of the following actions.
Analyse and evaluate intellectual property requirements : Analyse and evaluate intellectual property requirements associated with commercial innovation
Relationship between deforestation and wildlife extinction : In the deforestation segment, show estimations of the current and potential impact of deforestation on world cultures. Finally, take the visitors from land to the aquatic life zones. Describe methods that could be (or already are being) implemente..
What are the advantages of using an ordered array : What are the inefficiencies associated with using an unordered array if duplicates are not allowed? What are the advantages of using an ordered array? When would using an unordered array be preferred over using an ordered array
Essential you develop factual and logical arguments : The purpose of this assignment is to conduct a feasibility study and report whether it would be wiser to implement ERP systems in SMEs. You need to think about what are the critical success factors, has any one conducted feasibility studies for a..
What are the three trophic levels in an ecosystem : What are the three trophic levels in an ecosystem, What are the three trophic levels and give an example of each.2. What trophic level do you think is the most important in the ecosystem and why?
Would that help bring back some of the lost biodiversity : What could be the pros and cons of populating the area with animals such as lions, cheetahs, hyenas, elephants, camels, etc.? Would that help bring back some of the lost biodiversity?
How much new employer valued teamwork : Ben was perplexed. He had been looking forward to the first team project in his new job. He had heard how much his new employer valued teamwork. At his previous job he hadn't encountered teams....What is the situation Ben faces? What are the core ..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Lab9 c lab 9 c i request this twice but no answer on this

lab 9 c ltbrgti request this twice but no answer on this please could you check this for

  Syntax for structures in c

How is the syntax for a class in C++ similar to the syntax for structures in C? Use this syntax to create your own programmer-defined class

  Potential classes to be implemented in the future

Discuss any potential classes to be implemented in the future

  Program that generates a new list

Given a list listA of numbers, write a program that generates a new list listB with the same number of elements as listA, such that each element in the new list is the average of its neighbors and itself in the original list. For example, if listA..

  Prepare the weighted scoring model for three exams

Prepare the weighted scoring model. Final grades are based on three exams worth 15%, 20%, and 25%, respectively; homework is worth 20%.

  Create class that allows you to generate number of plants

In your driver, you should create at least 2 different plants, after you instantiate a plant, you should print out the information about the plant, then water the plant at least three times and then print out the plant again.

  Program to count the number of heart beat

If a human heart beats on the average of once a second, how many times does the heart beat in a lifetime of n years? (Use 365.25 for days in a year). Write a program to count the number of heart beat.

  Write the output of the program

Design a C++ program that will interactively prompt for and read the name of the input file interactively prompt for and read the name of a file to write the output of the program to write the following to the specified output file your name, sect..

  Write appropriate mutator functions that store values

A default constructor that assigns empty strings ("") to the name, department, and position member variables, and 0 to the idNumber member variable.

  Display the array, the average and the number of days above

Write a program that stores the daily temperatures for the month of April in an array name dailytemp. Calculate the average temperature for the month and the count the number of days that the daily temperature was above the average.

  Program that will read in such an array

Write a program that will read in such an array, and repeatedly prints it so the user can select the direction in which to move next. The user's requested move can prompt a number of responses

  The rpn calculator program

The RPN calculator program should read the RPN expression as an entire line from stdin.Input will consist of a single line. After completing the evaluation of the expression, the program should print the contents of the entire stack, starting with th..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd