CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Help with math algorithm [Split]

  1. #1
    Join Date
    Nov 2012

    Help with math algorithm [Split]

    I need someone to help me.contact via my email.

    Sorting & Searching

    The purpose of sorting is to put a sequence of data records in ascending or descending order based on a sorting key. For example, to sort student records based on last name, or sort football player records based on batting average. The problem of sorting data has been around a long, long time. The purpose of this assignment is to evaluate the performance of two well known sorting algorithms: bubble sort and selection sort. We will do this by calculating the CPU times to sort different types of input data (unsorted, semi-sorted, and sorted). There are two ways to generate unsorted data for sorting experiments. The first way is to use a random number generator and create N values within a range [L..H]. This is like rolling dice over and over again. The second method starts with sorted data and randomly shuffles data around to create unsorted data. This is essentially what we do when we shuffle a deck of cards. Once the sorted data re produced, a specified value (the input "key") within the sorted data can be found by employing different searching techniques.

    Program Specification

    You are required to design, implement and test a program in C++ to generate N values within a certain range [L..H]. The well known sorting algorithms, bubble sort and selection sort are then applied to the unsorted set of data. The performances of these methods are measured by calculation the CPU running time of each. Given an input key, a specified data can then be searched within the sorted data. The developed program should perform the following operations :

    a) Random Generation of Unsorted Values

    Using a number generator, the program is to create N values within a range [L..H]. You will need to define a function for generating random numbers. The function will then be called within the main program.

    Example input/output might be: ( the output is in italic)

    Enter the number of values to be generated: 6

    Enter the range : 50

    The unsorted generated sequence is :

    34 12 6 47 22 19

    b) Sorting

    You will need to add two functions to your program to sort the list generated in part (a), using bubble sort and selection sort algorithms. Since the output of both algorithms will be the same (sorted list), you will need to only display the result for one of them.

    Example input/output might be:

    The sorted list is now:
    6 12 19 22 34 47

    c) Measuring the running-time

    The performance of two sorting algorithms should be compared by calculating the CPU time of each algorithm for the same set of data. Calculate the run times for N=1000. If the times are too small to measure, increase N as needed until you can get a CPU time greater than a few seconds. Stop your program if it uses more than a minute of CPU time and decrease N accordingly.

    Example input/output might be:

    Enter the number of values to be generated: 5000

    Enter the range: 100

    The unsorted generated sequence is:

    34 88 61 47 22 19 77 12 93.............

    The sorted list is now:

    12 19 22 34 47 61 77 88 93.....

    The bubble sort-algorithms sorted the 5000 value in 2.34 second
    The selection sort-algorithms sorted the 5000 value in 2.05 second

    d) Shuffle the Sorted List

    You will need to add a function named, Shuffle to your program, to allow for shuffling the sorted list in part (b). By shuffling the sorted list, we create a semi-sorted list. Shuffling data values inside data array is done by swapping random pairs of values. For example, shuffling three times, will swap 3 random pairs of values. Try a few different values of the "shuffles" parameter to create data that looks semi-sorted (some sequences of values are in the correct order, but others are out of order. Try a few different values of the "shuffles" parameter to choose a value that creates data that looks semi-sorted (some sequences of values are in the correct order, but others are out of order).

    Example input/output might be:

    How many times would you like to shuffle the sorted list? 2

    The semi-sorted list is now:

    6 12 19 22 34 47

    6 19 12 22 47 34

    e) Searching for a Specific value

    You will need to add a function named, Search to your program to allow searching for a specific vale in the sorted list. You are recommended to use the Binary Search algorithm because of its efficiency. Once the function is called within the main program, specifying the key value, the function should return the first occurrence of the value in the list. Your program should also calculate the time for finding the key value.

    Example input/output might be:

    The sorted list is now:
    6 12 19 22 34 47

    Enter the key value to be searched: 22
    The first occurrence of 22 is at position 4
    It took 0.0 4 second s to find the value.

    Task 1: Algorithm Design

    You are required to produce a top-level design for your program using pseudocode or flowcharts. In addition to your design, a Function Table should also be provided.

    Task 2: Program Development

    You are required to implement your designs in C++ Programming Language. Your program should be properly laid out and should be modular, making sure that software engineering aspects of modularity and reusability are fully considered.

    Task 3: Program Testing & Documentation (10%)

    Devise a test plan carefully, making sure that the purpose of the particular test is clearly stated, the data for each test is specified (that is, any inputs expected from the user or the programmer), and a description of the expected result from the test are also provided.

    Use the test plan to test your program and document your findings. You should provide a hard copy of the actual output from your program, in the same order as your test plan and cross-referenced to it.

    You may like to test some functions separately. Any aspects of your program which you do not test will be assumed not to work.

    Your program must handle incorrect input data. Your testing should then include incorrect input data.

    You are required to provide an annotated code listing in addition to your proof of testing.

    Task 4: Program Evaluation

    You should evaluate your program, carefully identifying its strengths, weaknesses, and possible areas of improvement. You should also comment on the extent to which your solution correctly satisfies the specification.

    Tasks 1 to 4 should be attempted in the order given.

    For Task 1, only the final stage of pseudocode/flowchart design must be provided.

    An annotated program listing with meaningful and informative comments must be provided.

    A detailed test plan and full details of the results should be included in final documentation. For each error uncovered, explain how the problem was detected and what you did to correct it.

    Also, an evaluation of the solution covering the strengths, weaknesses and suggestions for enhancements should be provided.

  2. #2
    Join Date
    Jun 2005
    JHB South Africa

    Re: Help with math algorithm [Split]

    [Split Topic]

    Hi mukama..

    Welcome to Codeguru. However there are a few things..

    This is an open forum and no one will engage in Email communication to help you solve your homework..

    Homework: we do assist in solving issues with code written for homework, HOWEVER, no one here will do it for you.. Try it yourself, using the methods shown by the teacher, previous few chapters in the workbook, and you should get it.. if there's an issue you cant get right, post your code (using code tags), explain the problem, and someone will 'POINT YOU' in the right direction..

    If you are unable to complete simple tasks like this, how are you going to complete the final exams...

    Email: this is an open discussion forum, where many people search and refer to previous issues, in order to solve current ones, in such all correspondence is done via the forum, so that it benefits the forum...

    And Lastly.. Please use the 'New Topic' to ask your questions and not 'hijack' someone else's question, we try to keep the forum in a one thread, one question format...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Nov 2003

    Re: Help with math algorithm [Split]

    See this FAQ.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  4. #4
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: Help with math algorithm [Split]

    I'm still waiting for the first person to ask on here:
    I accepted this job as a programmer, but I never did my coursework, you guys on codeguru always solved my work for me, so now I need some someone to do my job for me without pay so I can get a big fat wad of cash (yeah right) myself.

    P.S. Since I have enough spare time on my hands... I'm already looking for a couple freelance programming jobs for some more pocket money I want you guys to solve as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)