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 count occurrences() function that accepts a string

Write a CountOccurrences() function that accepts a string to be searched and a sub-string to be found. The function should return the # of times the sub-string is found. Write a tester file that declares a secret sentence as a constant.

  Create program to input miles driven and gallons used

Create a program in C++ which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and display the miles per gallon

  The funtion should take as parameters

Write a function in c ++ that multiplies two functions. the funtion should take as parameters two fraction structures. Then, the function should multiply the two fractions and return the solution as a fraction structure.

  Write a program to find that number for nguyen.

In some Asian countries, 8 and 6 are considered lucky digits. Any number containing only 8s and 6s is considered lucky number, e.g. 6, 8, 66, 668, 88, 886 .... Nguyen is a student who likes mathematics very much. Nguyen likes lucky numbers but only o..

  Define a structure to store marks of a student

Define a structure to store roll no, name and marks of a student - using the structure of Q2. a), above write a 'C' program to create a file "student.dat". There must be one record for every student in the file.

  Write a program that will input letters grade(a,b,c,d,f)

Write a program that will input letters grade(A,B,C,D,F), the number of which is input by the user (a maximum of 50 grades). The grades will be read into array. A function will be called five times(once for each letter grade) and will return the tota..

  Least number of comparisons needed

What is the least number of comparisons needed to sort an array of 6 numbers, in the worst case, using any sorting algorithm that sorts with binary comparisons? Explain

  A perfect solution is impossible or too expensive

Optimization is often encountered in engineering problems. More often than not, a perfect solution is impossible or too expensive to find and implement. Therefore, we resort to sub-optimal, yet useful, solutions. This assignment tackles a classical p..

  Using an abstract class with only pure virtual functions

Using an abstract class with only pure virtual functions, create three small classes unrelated by inheritance---clases Building, Car and Bicycle. Give each class some uique appropriate attributes and behaviors that it does not have in common with oth..

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Whitewater high school has contracted

Whitewater High School has contracted you to write a program that will read a file of student names and test scores in the formation FIRST NAME LAST NAME: SCORE1 SCORE2 SCORE3, where each of the scores is an integer

  Write a program using the rand() function

Write a program using the rand() function and a large array to find the standard deviation, variance and mean as well as the min and max values of the array.

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