Optimization is to add a sorting algorithm

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

You will continue to extend the program developed in Lab 6, by adding dynamically-allocated arrays, sorting, binary search, and multiple source files.
1. The first optimization is to change the static array of student records into a dynamically-allocated one. When the program starts, your program dynamically allocates an array of student records, and has a pointer (let's call it StudentRecords) point to it. The initial array size should be 40.
Finally, remember to release the dynamic array before terminating the program.
2. The second optimization is to add a sorting algorithm. Each time you add an item to the array (from disk or from keyboard), you call a function called SortMyArray(), which use the bubble sorting algorithm to sort the array in the ascending order, using student ID as the key. If done correctly, the array in the memory will always be sorted, even if the database is not sorted, or if you add new records from keyboard in random orders. Since the array is sorted, you can safely use binary search algorithms to search a record.
3. The 3rd optimization is to change the searc-by-ID function from linear search to binary search.
Bonus points (30%)
When you load entries from the database, or add new records from the keyboard, you will eventually run out of space in the dynamically allocated array. When this happen, you just do the following:

  •   Allocate another array which size is 10 records bigger the existing one
  •   Copy the contents of the old array to the new array
  •   Have the StudentRecords pointer points to the new array
  •   Delete the old array
  •   Hints: in addition to the StudentRecords pointer, you also need to maintain at least the following info: the maximum size of the current array, and the number of actual items stored in the current array.

Since you might need to expend the array when you are loading the database or adding records from the keyboard, you may want to put the above operations into a function. For
example, you can create a function called Add_a_record() that handle all of these steps. The Add_a_record() function is then called from the LoadDatabase() and Add_Record_from_Keyboard() function.
To test if your code works or not, change the initial array size to a very small number (say 5).

Reference no: EM13165807

Questions Cloud

From time to time words become obsolete : One more requirement, from time to time words become obsolete. When this happens, such word must be removed from the dictionary. Your program must account for this also.
Generate an array of 20 random integers from 0 to 9 : generate an array of 20 random integers from 0 to 9. Search for the first occurrence, if any, of the number 7, and report its position in the array.
Create 4 order class fields : Create 4 Order class fields: order number, customer name, quantity ordered, and total price. Create public accessors for each field except total price.
The recommended entry strategy into international markets : An expert system is used to determine whether the recommended entry strategy into international markets should be Investment (I), Contractual (C), or Export (E).
Optimization is to add a sorting algorithm : The second optimization is to add a sorting algorithm. Each time you add an item to the array (from disk or from keyboard), you call a function called SortMyArray(), which use the bubble sorting algorithm to sort the array in the ascending order, ..
The load master for a freighter : The load master for a freighter wants to determine the mix of cargo to be carried on the next trip. The ship's volume limit for cargo is 100,000 cubic meters, and it weight capacity is 2,310 tons.
Storage systems increasingly rely on the internet : Storage systems increasingly rely on the Internet infrastructure as a transport medium. What are the advantages of this approach? What problems are present in terms of security and reliability?
Slugworth candies : Slugworth Candies, LLC, is a candy maker company that employs 450 people. The company is composed of six departments: Executive Staff (20), Human Relations (6), Finance and Accounting (15), Marketing and Sales (15), Factory (150), and Research & D..
We would like to implement the lexical order : We would like to implement the lexical order for lists. For simplicity, we only consider lists of numbers, where , >= have their usual meaning.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program to accept a number representing

Write a program to accept a number representing how many first names the user willenter from the command line (5 names maximum), and the actual first names, fromthe command line. Create an array dynamically that has the same size as number ofnames.

  Write a program using for loops t

Write a program using for loops to produce the following output. Please read carefully the entire specification!

  Programmingto compute the volume of water in the cubic feet

Write down an algorithm (Programming in C) in order to compute the volume of water in the cubic feet, flowing through a pipe of diameter d in feet, having a velocity of v feet per second.

  Prepare a linux shell

Prepare a linux shell (in other words, write a C/C++ program) that will recursively prompt for input from the user. The shell should prompt as

  Write a c++ program that would take two 3x3 matrix

Write a C++ program that would take two 3x3 matrix and outputs the results of adding, subtracting and multiplying two matrices. Create at least three functions: one that performs addition,

  Write a c program which takes a string from command line

Write a c program which takes a string from command line with mainfunction has no parameter and convert the string in upperca

  Program to output value of tenth component of array

Write a C++ statements to perform the following: Set value of fourth component of array alpha to three times  value of eight component minus 57.

  Multidimensional arrays

multidimensional arrays to life, let's consider a specific example: How can you visualize a 4-dimensional array? How can you give meaning to each dimension this array has? What kind of application would such an array be useful for?

  Calculate that implements a simple arithmetic calculator

Write a  C program  calc.c that implements a simple arithmetic calculator. Input to the calculator consists of lines composed of integer constants separated by the five arithmetic operators used in C: +, -, *, /, and %. For each line of input,

  Make a class employee

Make a class EMPLOYEE with a name and salary. Make a class MANAGER inherit from EMPLOYEE. Add an instance field, named DEPARTMENT

  Write c++ program that reads in the average monthly rainfall

Write a C++ program that reads in the average monthly rainfall for a city for each month of the year and then reads in the actual monthly rainfall for each of the previous 12 months

  Ng stands for next guess

Where NG stands for next guess and LG stands for last guess. Write a function that calculates the square root of a number using this method. The initial guess will be the starting value of LG .

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