Project Issue

Discussion in 'Programming General' started by Sorwind, Sep 22, 2011.

Project Issue
  1. Unread #1 - Sep 22, 2011 at 5:57 PM
  2. Sorwind
    Joined:
    Jan 3, 2011
    Posts:
    9
    Referrals:
    0
    Sythe Gold:
    0

    Sorwind Newcomer

    Project Issue

    I've pasted my project description, but the only issue i've run into thus far is trying to take my sorted array of integers and placing them into two separate arrays (one array containing the separate ints, the the other containing the amount of times that particular int occurs). I'm not sure why, but my two arrays are not setting correctly. I'm not really new to programming, only the syntax of C++. My code is here http://pastie.org/2576163. I considered originally using a 2D array, but that was also giving me issues
    Project description:

    Goals:
    • To learn unit testing
    • To develop test drivers
    • To use arrays and file I/O to write a C/C++ program.

    Description:
    Write and test a program that reads a list of integers from a file and stores integers in an
    array of type int. Your program determines how many entries are used. The output is a
    file containing a two-column list. The first column is a list of the distinct array elements;
    the second column is the count of the number of occurrences of each element. The list
    should be sorted on entries in the first column, largest to smallest.
    For example, if the input file contains the following list of integers:
    12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12
    then, the output file should be
    N Count
    4 2
    3 3
    2 2
    1 4
    -1 1
    -12 4
    Your program also must respond to the following queries. Note: each query should be
    respond by one function in your program.
    • How many different integers occur in the list?
    • What is the average frequency of occurrence for each integer?
    • Which integer is the largest?
    • Which integer is the smallest?
    • Which integer appears the most often? How many times?
    • Which integer appears the least often? How many times?


    You must provide the following user interface. The user input is depicted as Bold, but
    you do not need to display user input in bold. Please replace “Xiao Qin” with your name.

















    Your program must follow the style of the above user interface.

    Unit Testing:
    A unit test verifies that a function or set of functions under test meet the requirements.
    You need to isolate a single function and test only that function.

    Since you have to treat each function as a separate unit, you transform one big task into
    a series of smaller, more manageable tasks. You must test functions outside the
    program (i.e., your first program). Therefore, you need to write a separate (i.e., a
    second one) program called driver program to test all the functions implemented in first
    program. The second program contains test drivers for your first program.

    A sample driver program is illustrated in the next section.

    A Sample Driver Program:
    The following code shows you how to write a program to test the function unitPrice().
    Programs like this one are called driver programs. These driver programs are temporary
    tools and can be quite minimal. They need not have fancy input routines. They need not
    perform all the calculations the final program will perform. All they need do is obtain
    reasonable values for the function arguments in as simple a way as possible—typically
    from the user—then execute the function and show the result.
    *** Welcome to Xiao Qin’s word count program ***
    Enter the first input file name: input.txt
    The list of integers in file input.txt is:
    12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12 -12

    The following list will be sorted in a file:
    N Count
    4 2
    3 3
    2 2
    1 4
    -1 1
    -12 5

    How many different integers occur in the list? 17
    What is the average frequency of occurrence for each integer? 2.83
    Which integer is the largest? 4
    Which integer is the smallest? -12
    Which integer appears the most often? How many times? -12 5
    Which integer appears the least often? How many times? -1 1

    *** Goodbye. ***



    Programming Environment:
    Write a short program in C++. Compile and run it using the g++ compiler on a Linux box
    (either in Shop 3, computer labs in Shelby, your home Linux machine, a Linux box on a
    virtual machine, or using an emulator like Cygwin). If your program is not compiled by
    g++ in Linux, you will receive no point.

    Requirements:
    Note: If your program contains compilation errors, you will lose all 20 points
    because the TA will not grade your homework assignment.
    1. (1 point) Use comments to provide a heading at the top of your code containing
    your name, Auburn Userid, filename, and how to compile your code. Also
    describe any help or sources that you used (as per the syllabus).
    2. (1 point) Your source code file should be named as “<username>_hw6.cpp” and
    “<username>_hw6_driver.cpp” (for example, mine would read
    “xzq0001_hw6.cpp” and “xzq0001_hw6_driver.cpp”).
    3. (1 point) Usability of your program (e.g., user interface)
    4. (8 points) Correctness of your first program
    5. (8 points) Correctness of your test driver
    6. (1 points) Readability of your source code.

    You will lose points if you: do not use the specific program file name, or do not have
    a comment block on EVERY program you hand in.


    Deliverables:
    • Submit your first program’s source code called “<username>_hw6.cpp” through
    the Blackboard system.
    • Submit your driver program’s source code file named as
    “<username>_hw6_driver.cpp” through the Blackboard system.
    Rebuttal period:
    You will be given a period of 72 hours to read and respond to the comments and
    grades of your homework assignment. The TA may use this opportunity to
    address any concern and question you have. The TA also may ask for additional
    information from you regarding your homework. After the rebuttal period, your
    grad Rebuttals may be at most 2500 words long, but effective rebuttals are likely
    to be brief, of course.
     
  3. Unread #2 - Sep 23, 2011 at 12:15 AM
  4. blindkilla
    Joined:
    Jun 22, 2005
    Posts:
    1,896
    Referrals:
    0
    Sythe Gold:
    6
    Discord Unique ID:
    282000633404456960
    Discord Username:
    sogord

    blindkilla Guru
    $25 USD Donor New

    Project Issue

    The easiest way I can think of to go about this is to use a hash table. It would only require one iteration through the array, two 2 since you mentioned them needing to be sorted.

    Go through each int, throw it into the hash table. The actual int will be your key. If a value for the key doesn't exist, add one for that key. If a value already exists for a given key (int) then you've come across it before and just increase the value for that key by 1.

    Since you're only sorting a small amount of numbers, you don't need any efficient fancy sorting algorithms and should probably just stick to a simple bubble sort.

    If you need help actually coding up a solution let me know.
     
  5. Unread #3 - Sep 23, 2011 at 5:25 PM
  6. wackywamba
    Joined:
    Jul 14, 2005
    Posts:
    1,358
    Referrals:
    0
    Sythe Gold:
    1

    wackywamba Guru

    Project Issue

    Dear God no, haha. I agree with everything blind said, but just consider using a better sorting algorithm, i.e. quicksort. Not that you have to use it, but just for good practice.
     
  7. Unread #4 - Sep 27, 2011 at 8:47 PM
  8. The Fat Controller
    Joined:
    Aug 16, 2007
    Posts:
    1,003
    Referrals:
    0
    Sythe Gold:
    1

    The Fat Controller Guru

    Project Issue

    You'd be better off using STL algorithms like sort(), unique() and count() for this kind of task. If your project isn't over yet and their use is permitted then see if they're for you:

    http://www.cplusplus.com/reference/algorithm/
     
< Need Forum For DICE - RSGP | Best In Selling Fresh Cc Dumps Fullz Bank Logins Shop Admin And Wu Trf.............. >

Users viewing this thread
1 guest


 
 
Adblock breaks this site