This assignment is due by Thursday, June 20, 2019, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: LXC
.
· Instructions · Rubric · Submission ·
The Purpose
The Person Class
- first name (string)
- last name (string)
- gender (character)
- age (integer)
- height (double)
- likes monster movies (bool)
- likes cantaloupe (bool)
- A default constructor. You can decide what to initialize the private data members to.
- You do not need to add getters and setters for every data member.
Instead, only add accessor functions that you actually use in your
main()
. - An
input
function that reads in the data members, in the order listed above. The function should allow the user to send in either the standard input stream or a file input stream as an argument to the function, depending on the user's choice. (An example call would beperson.input(cin);
.) - An
output
function that writes the data members, in the order listed above. Provide appropriate text so reading the output makes sense. The function should allow the user to send in either the standard output stream or a file output stream as an argument to the function, depending on the user's choice. (An example call would beperson.output(cout);
.) - A
validate
function that tests whether a person's data meets your criteria for a potential coding partner. You should choose the gender (male or female), with an age between 18 and 40 (inclusive), the height under 7.5 feet (else the 'person' is likely a monster), and someone who likes to eat cantaloupe while watching monster movies.
Your
main()
Requirements:
main()
requirements into steps. We suggest you throughly test each step before
moving to the next step.
Step 1: How many valid people are in the file?
- Create an integer called
validCount
, and a pointer to this integer. To receive full credit for this assignment, you must ONLY access this variable for counting through the pointer to your counting variable. (We know, kind of silly ... but the point is to give you more pointer practice!) - Create a Person object.
- Open the file PersonFile.dat,
a file that was created by 11-year old Emma Camp-Oberhauser. Until
the end of file, read each person within the file (using your
Person's
input()
function), and test whether the Person details read in are valid or not (using your Person'svalidate()
function). If valid, add one tovalidCount
(via your pointer tovalidCount
). - Take a moment to print the number of valid People in the file. It should be an odd number, between 12 and 14.
Step 2: Add valid people to your new people array.
- Use dynamic memory to allocate an array of people on the heap that is large enough to hold the number of valid people determined in Step 1. Do not over-allocate the array to hold all the people in the data file.
- We now need to rewind the reading location of PersonFile.dat to the
beginning of the file. To do this, you could
close()
the file, and then re-open it; but doesn't that seem a bit foolish? Thus, instead, useclear()
andseekg(0,ios::beg)
functions on your input file stream. These two functions will clear the 'end of file reached' and set the next position to read from equal to the top of the file. - Declare a new integer variable with initial value zero; this variable will represent the current element offset inside your dynamic array.
- In a loop (until the end of file):
- Read each person within the file (using your Person's
input()
function). - Test whether the Person details read in are valid or not (using
your Person's
validate()
function). - If valid, assign that Person to the array (and increment your new integer variable).
- If not valid, print that Person's details to the screen (using
your Person's
output()
function).
- Read each person within the file (using your Person's
Step 3: Sorting your people array.
selectionSort()
algorithm (a simple sorting algorithm), and provided brief pseudocode
for implementing it. Put the function prototypes above
your
main()
and function implementations below. Create these prototypes and
function headers so that they operate on your People array, with the
end goal of sorting your valid People array by each person's height.
For full credit, you should pass a pointer to the array to your
selectionSort()
function, and use this pointer within the function to access array
elements. However, we suggest you first implement the sorting feature
using the
[ ]
notation that you are familiar with, and then (if desired) modify the
function to use pointers (not
[ ]
). NOTE: getting the function to work with [ ]
is worth
one point; getting the function to work with *
is worth
two points.
Step 4: Print a few valid people.
output()
function, print the following three valid people:
- the person with the smallest height (first element in your array)
- the person with the median height (the middle element in your array; we've already confirmed that the number of elements is odd)
- the person with the largest height (last element in your array)
Step 5: Good practice.
delete[]
operation, not
delete
without
[]
.
Grading Rubric
Your submission will be graded according to the following rubric.
Points | Requirement Description |
2 | All code submitted properly. |
2 | All labs completed and submitted LXC |
11 | Assignment created with dynamic arrays and meets requirements above. |
3 | Functional requirements above met. |
2 | (1) Comments used (2) Coding style followed (3) Appropriate variable names, constants, and data types used (4) Instructions followed |
20 | Total Points |
This assignment is due by Thursday, June 20, 2019, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: LXC
.
Submission
Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available. The following instructions are copied from How to Submit Homework.
Submission Instructions
- File and folder names are extremely important in this process.
Please double-check carefully, to ensure things are named correctly.
- The top-level folder of your project must be named
SetXC
- Inside
SetXC
, create 2 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g.LXC
, andAXC
). - Copy your
main.cpp
, additional header & source files () plus the
CMakeLists.txt
file into the subdirectories ofSetXC
(steps 1-2), zip thisSetXC
folder (steps 3-4), and then submit the zipped file (steps 5-11) to Canvas. - For example, when you zip/submit
SetXC
, there will be 2 sub-folders calledLXC
, andAXC
inside theSetXC
folder, and each of these sub-folders will have a file calledmain.cpp
, additional header & source files, plus the CMakeLists.txt file .
- The top-level folder of your project must be named
- Using Windows Explorer (not to be confused with Internet Explorer), find the file
named
"main.cpp"
located inside the folder for the particular lab or homework assignment you will submit.
STOP: Are you really sure you are viewing the correct assignment's folder?
- Now, for AXC, right click on the
main.cpp
to copy the file. Then, return to theSetXC/AXC
folder and right click to paste the file. In other words, put a copy of your homework'smain.cpp
source code into theSetXC/AXC
folder. Repeat this for each additional header & source file you have with this assignment, plus CMakeLists.txt.
Follow the same steps for LXC, to put a copy of your lab'smain.cpp
into theSetXC/LXC
folder.
STOP: Are you sure yourSetXC
folder now has all your code to submit?
- Now, right-click on the
"SetXC"
folder.- In the pop-up menu that opens, move the mouse
"Send to..."
and expand the sub-menu. - In the sub-menu that opens, select
"Compressed (zipped) folder"
.
STOP: Are you really sure you are zipping aSetXC
folder with sub-folders that each contain amain.cpp
file in it?
- In the pop-up menu that opens, move the mouse
- After the previous step, you should now see a
"SetXC.zip"
file.
- Now visit the Canvas page for this course
and click the
"Assignments"
button in the sidebar.
- Find SetXC, click on it, find the
"Submit Assignment"
area, and then click the"Choose File"
button.
- Find the
"SetXC.zip"
file created earlier and click the"Open"
button.
STOP: Are you really sure you are selecting the right homework assignment? Are you double-sure?
- WAIT! There's one more super-important step. Click on the blue
"Submit Assignment"
button to submit your homework.
- No, really, make sure you click the
"Submit Assignment"
button to actually submit your homework. Clicking the"Choose File"
button in the previous step kind of makes it feel like you're done, but you must click the Submit button as well! And you must allow the file time to upload before you turn off your computer!
- Canvas should say "Submitted!". Click "Submission Details" and you can download the zip file you just submitted. In other words, verify you submitted what you think you submitted!
"SetXC"
folder
and only the "SetXC"
folder, this zip folder must have several sub-folders, you must name all these folders correctly, you must submit the correct zip file for this
homework, and you must click the "Submit Assignment"
button. Not doing these steps is like bringing your
homework to class but forgetting to hand it in. No concessions will be made for
incorrectly submitted work. If you incorrectly submit your homework, we will not be able to
give you full credit. And that makes us unhappy. This assignment is due by Thursday, June 20, 2019, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: .