You are on page 1of 10

INFO3063 Assignment #3

Winter 2007
Instructor: Michael Feeney
Due: 11:59pm Wednesday, March 28th, 2007

Overview:
You are to write a console application in C++ that will read some information from a file,
and process the data based on some command line parameters.

About the options:

There really are a few options to this project, but only with respect to the type of data that is
being manipulated, not in the overall scope.

Details:
You are provided with a file containing information pertaining to a particular set of entitles
(i.e. data that is grouped together). The specific entity choices are listed later in the
document.

Your program is to take a command and the name of one or more files from the command
prompt. Examples of valid command parameters are listed later in this document.

If no command line parameters are listed, or not enough, the program should print an error
message.

Your program should then load all the information from all the files into a single vector (or
other STL container) of struct/class instances.

Depending on the command given and the data being manipulated, your program should
print out (to the screen or to a file), the results of the command.

The commands include:


1. Sorting by one of the attributes of the data, and
2. locating (and printing out, if found) one or more of the matching entities, based on
one of the entities’ properties
Example Entities and commands:
There are four different types of entitles each with different properties.

You are to pick ONE of the following for your program to manage.

Entity type Properties Data types Enumeration (if applicable)


Sneetches StarState string “Star” or “Plain”
Money double
Height double Always positive
ZipCode int Five digits, like the American
zip code (i.e. 90210, 31451,
etc.)

Wizards FirstName string


LastName string
Grade int Would be a positive number,
between 1 and 13
WandWeight double Always positive

Pets Name string


Type string This would be a single word
with no spaces, like “Cat”,
“Dog”, “Fish”, etc.
Weight double
Colour string Only single word colours, like
“Red”, “Green”, “Yellow”, etc.

Students FirstName string


MiddleName string
LastName string
StudentNumber int
PhoneNumber string Must be in the nine (9) digit
format with appropriate
brackets, and a hyphen.
For example: (519)555-1212
HighestGrade double
Commands and command line parameters:

These are the command line words that you place on the “command line” when you run
your program. Some parts are common to all the entities, while some are specific to the
entity you have chosen.

There are only two main commands: “sort” and “search” (lower case). With both you need
to specify which property you are sorting or searching on. If you are searching, you need to
specify what you are searching for.

NOTE: None of the data will be more than one number or word long. In other words, you
will never be searching for words with “white space” in them, like “Harry Potter”.

There are several common parts:


1. the command (which is “search” or “sort”
2. property the command works on (from the table above)
3. optional search parameter (if “search” is used)
4. output to screen or file (with is “screen” or “file”)
5. optional file name if output is to a file
6. the input files being used (any number; no spaces)

The “property the command works on” is specific to the type of data that was chosen for
your entities. For example, if you chose “Pets” as your entity, you would only sort or search
based on the four entities: “Name”, “Type”, “Weight”, or “Colour”.

Assume that the commands are case sensitive.

Assume that the search criterion is case sensitive. That means that “Harry” is different
from “harry” and that if your file contained the name “Harry,” searching for “harry” would
return nothing.

Assume that the sorting is case insensitive. This means that these could be in any order:
“Harry”, “harry”, “hARRY”. Another way to look at this that you can assume everything is in
upper or lower case when sorting.
Example commands:
Here are a number of examples to clarify what types of commands you are expected to
process. All the examples assume you program is called “myprog.exe”.

Note: These would all be on one line, not multiple lines as shown.

Entity choice: Sneetches

• Sort the sneetches by money in ascending order (least to greatest), using the input
file “sneetchData.txt” and print to the screen:

myprog.exe sort ascending Money screen sneetchData.txt

• Sort by zip code, in descending order, using the input files “S1.txt” and “S2.txt”, and
outputting to the file “sorted.dat”:

myprog.exe sort descending ZipCode file sorted.dat S1.txt


S2.txt

• Search the sneetches for all the ones with stars. Output to the screen, and input
from files “S1.dat”, “S2.txt”, and “S3.dat”:

myprog.exe search StarState Star screen S1.dat S2.txt S3.dat

Entity choice: Pets

• Find all the brown pets from the “mypets.dat” file, outputting to the screen:

myprog.exe search Colour brown screen mypets.dat

• Some command as above, but output to the file “results.txt”

myprog.exe search Colour brown file results.txt mypets.dat

• Some command as above, but data coming from the files “P1.dat”, “P2.dat”,
“P3.bat”, and “SallysPets.txt”:

myprog.exe search Colour brown file results.txt P1.dat P2.dat


P3.bat SallysPets.txt
Note how the commands are broken down:

myprog.exe sort ascending Money screen sneetchData.txt

Executable name output


Property command Input file(s)
works on Output to file
command “results.txt”
Search for “brown”

myprog.exe search Colour brown file results.txt

P1.dat P2.dat P3.bat SallysPets.txt

File and screen output:

You are to use the same format as the input file, as listed below.

Note that the output does not have to be exactly the same in terms of white space or new
lines, but has to output the properties in the same order. In other words, the amount of
white space is ignored with the output, though there should be at least one space between
properties, and there should be at least a new line between entities.

You can use any number of decimal places.


File format:

Here is the specific format for the various entities. All the files will end with an end of file
character – i.e. there is no “sentinel” value at the end of the file; it will simply end.

You can assume that there is no “bad” data in the file.

You should assume that the file contains much more data than shown here.

Sneetches:
(StarState, Money, Height, ZipCode)
Plain 2.39 2.3 82783
Plain 13.43 2.4 29384
Star 9.23 3.1 29839

Wizards:
(FirstName, LastName, Grade, WandWeight)
Harry Potter 5 1.2
Hermione Granger 5 1.21
Ginny Weasley 4 1.12
Fred Weasley 7 1.7

Pets:
(Name, Type, Weight, Colour)
Bob Cat 12.33 Red
Rufus Dog 23.2 Brown
Thor Fish 0.23 Silver
Jacob Cow 3430.34 Purple
Fraser Rat 0.88 White
Robin Bunny 2.8 White
BobbyJoe Whale 3948.0 Blue

Students:
(FirstName, MiddleName, LastName, StudentNumber, PhoneNumber, HighestGrade)
Bob Frederick Jones 1987263 (519)672-2939 98.2
Sally Jane Smith 183747 (905)282-9283 87.2
Sasha Robyn Westwood 1827382 (213)892-2932 67.4
Technical Guidelines:
For below, note that:
• The “entity” refers to the struct/class that will hold your information
• A “container” refers to a vector – but a vector is only one of the many STL containers
available.

You program must:


• Be a console application
• Use structs or classes to hold the type of information (i.e. the entity)
• Use a single vector (or another STL container) to hold the struct/class information.
You must have a container of structs or classes. You can not have multiple
containers for each property of the entity you are storing.
• You must use iterators for all access to the container when searching
• You may use iterators or indexes for the sort (indexes can NOT be used for search)
• You may not use arrays
• Be able to be built using Visual Studio 2005 with the standard C++ console
project/linker settings (as we’ve been doing in class)
• Use the C++ stream operators (cout, cin, fstream, etc.)
• May not use any C specific items (examples include printf, scanf, char array
manipulation, etc.). If you are unsure, ask me.
• Must take the information from the command prompt.
• Project must be broken into multiple files, have a reasonable number of “meaningful”
functions, and use appropriate (and correct) header files, etc.

BONUS:
You can receive a 15% bonus (each) by incorporating any of the following:
(in other words, you get 15% bonus for each of the following – i.e. if you do them all, you
would receive 15% x 5 or a 75% bonus)

• All the sorting is done using the quick-sort algorithm (you must implement this, not
just use the STL quick-sort)

• You can have multiple commands available at the same time.


Examples include (these are worth 15% each, so 30% for both):
o Sorting by two parameters, where you sort by the first parameter, then the
second parameter. You must be able to sort by different orders (i.e. first
ascending and second descending for example). See below for command line
example.
o Searching by two to five parameters. For example, searching for a particular
colour, size, and weight of pet. See below for command line example.

• Searching interpretation involving more complex operators. This would involve


“greater than”, “less than”, etc. (>, <, >=, <=, ==, and !=). However, you can’t use “>”
and “<” on the command line (the operating system will interpret these as
“redirection” commands). Instead, please use the following:
o GT for “>” (as in “Greater Than”)
o LT for “<” (as in “Less Than”)
o LE for “<=” (as in “Less than or Equal to”)
o GE for “>=” (as in “Greater than or Equal to”)
o EQ for “==” (as in “EQual to”)
o NE for “!=” (as in “Not Equal to”)
• You can get another 15% for adding this feature to all the parameters.

NOTE: You must have no other significant errors (i.e. you can’t get the bonus
without achieving at least an A (80%) on the rest of the project.)

Bonus command line examples:

• Search the sneetches for all the ones with stars, that live in zip code 90210, and
have $10.00, output to the screen, and input from files “S1.dat”, “S2.txt”, and
“S3.dat”:

myprog.exe search StarState Star ZipCode 90210 Money 10.00


screen S1.dat S2.txt S3.dat

• Sort the wizards by lastname, then firstname, taking data from the file hogwarts.txt,
and outputting to a file called hogsort.dat:

myprog.exe sort ascending FirstName ascending LastName file


hogsort.dat hogwarts.txt

• Taking data from the mypets.txt file, output to the screen all the pets that have a
weight greater than or equal to 2.0:

myprog.exe search Weight GE 2.0 screen mypets.txt

• Same as above, but looking for all the pets that aren’t white, outputting to
notalbino.txt, and getting data from the bobspets.dat, johnspets.dat, and
maryspets.dat files:

myprog.exe search Colour NE White file notalbino.txt


bobspets.dat johnspets.dat maryspets.dat
Marking Scheme:

In general, you will start with full marks, and then lose marks as things don’t work or are not
implemented.

Things that will cause you to loose many marks very quickly:

• Your program doesn’t build (compile and link). You get zero if this happens. If you
can’t get it all done, get what you can to work, then submit that.
• If you use anything that is directly from the “C” language only. Examples include
printf, or “C” style file operations. If you are unsure, ask me before you submit it.

• If it does all the things in the marking scheme correctly, you will get 100%. No
tricks. Seriously.

Stuck?
• Ask a fellow student. They might know or be stuck on the same thing.
• ASK ME! I just may know the answer, or help you find it yourself.
• Check out your text
• Check out that cool thing called “The Internet”
• Check out MSDN

Notes about Collaboration, Cheating, and using the posted example:

• You must submit your project individually.

• While you may use the code that is on Fanshawe OnLine, PLEASE collaborate and
help each other, it is extremely unlikely that two individuals (or groups) will come up
with exactly (or almost exactly) the same program. I’ll likely be able to tell. Really.

• If I’m suspicious “something is up,” I’ll use various code comparison tools to see if
the code is similar or identical. If they are “too” close, everyone involved will receive
a mark of zero and be reported for plagiarism

• Please remember that you will be writing the exams all by yourself. If you are
unable to do the project by yourself, you will have no hope during the exams.
Think about it.
Detailed marking scheme:
Here’s the marking scheme I will use. Really. If you hit all the points, you get 100%
No joke. No tricks. No hidden agenda.

INFO3063 Project 3 Marking Scheme Grade 0.0%


Student:
Student Number:

Item Mark Out of


Program builds (Yes or No - if No, then mark = zero)

Takes command arguments 10


Reads data from file 10
Reads data from multiple, specified files 30
Uses a struct to hold the data 50
Uses a SINGLE STL container to hold the struct instances 50
Reads data from file (i.e. opens the file) 30

Command parameters
Interprets command line parameters for the input files 50
Interprets the "sort" command 20
Interprets it correctly and sorts items (20% to 25% of this portion per property,
depending on the entity chosen) 100
Interprets the "search" command correctly 20
Interprets it correctly and returns correctly found items (20% to 25% of this portion per
property, depending on the entity chosen) 100
Interprets the "screen" command 20
Interprets the "screen" command correctly 30
Interprets the "file" command with the file name 30
Interprets the "file" command correctly 100
Outputs the file contents in correct format (i.e. as file input format) 50

Technical details
Any run time errors (-50 per occurrence) 0
C functions used instead of C++ (-50 per use) 0
Use of multiple STL containers instead of one (-100) 0
Use of indexes instead of iterators (-100) 0
Project broken into appropriate functions (-100 for no functions) 0
Project broken into appropriate files and files used correctly (-50 for each violation) 0

Sub total: 0 700

BONUS
Uses quicksort for all sorting 0 15%
Sorting by two parameters, by first param then second param 0 15%
Searching by multiple parameters - must sort by up to all 4 or 5 parameters 0 15%
Complex sorting using >, <, >=, <=, and != (and equality) for one parameter 0 15%
Complex sorting using >, <, >=, <=, and != (and equality) for all (4 to 5) parameters 0 15%

Grand total: 0 700

Percentage grade: 0.0%