Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
Project Issue
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-22-2011, 10:57 PM
Newcomer
 
Join Date: Jan 2011
Posts: 9
Default 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.
__________________
Vouches :]
Reply With Quote
  #2  
Old 09-23-2011, 05:15 AM
Guru
 
Join Date: Jun 2005
Location: Canada
Posts: 1,844
Default Re: 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.
__________________

Reply With Quote
  #3  
Old 09-23-2011, 10:25 PM
Guru
 
Join Date: Jul 2005
Posts: 1,355
Send a message via MSN to wackywamba
Default Re: Project Issue

Quote:
Originally Posted by blindkilla View Post
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..
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.
__________________

Last edited by wackywamba : 09-23-2011 at 10:27 PM.
Reply With Quote
  #4  
Old 09-28-2011, 01:47 AM
The Fat Controller's Avatar
Apprentice
 
Join Date: Aug 2007
Posts: 998
Default Re: 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/
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 09:43 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1