You are on page 1of 12

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

Quest #8

NEW ENGLAND INSTITUTE OF TECHNOLOGY


Information Technology Department

Quest #8
Data Structures and Algorithms (GDS 252)
Due: Week #9

Timothy Brandt
Developer
12-9-14
Date
George Saban
Instructor

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

Quest #8

Requirements:
Instructions:
According to some research, industry values
documentation, and
excellent written and oral
communication skills.
The purpose of this part
of the class is to
encourage you to gain
these skills.
Backup your work to your USB drive for this material may come
out as part of your examination.
Make a copy of this entire document and add your work into it.
Submit to Blackboard at the same link where you got this
document.
Points will be deducted if submitted on the wrong place, or if these
instructions are not followed.

You can earn up to a maximum of 55 points for this lab. Refer to


the syllabus for late point deductions.

Problem Statement
Part I:

This will reinforce your knowledge of Sorting.

Create an array of 10 player objects. Each player objects must at least include age
and name attributes with its complementary setters and getters. You can add other
attributes but to a minimum it should have age and name.
a.) Sort the array by players age.
b.) Sort the array by players name.

Hints:
-

You should complete the exercises first before doing this quest.

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

Quest #8

Code Development:
Please highlight in green your code to sort by players age, and highlight in
yellow your code to sort by players name.
#include <iostream>
#include <string>
using namespace std;
class Player
{
private:
string name;
double age;
public:
void setName(string newName)
{
name = newName;
}
string getName()
{
return name;
}
void setAge(double newAge)
{
age = newAge;
}
double getAge()
{
return age;
}
};
//

4
Player *data[5] = {NULL, NULL, NULL, NULL, NULL};
void swap(int first, int second)
{
Player *temp = new Player();
temp = data[first];
data[first] = data[second];
data[second] = temp;
}

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

Quest #8

void displayData()
{
for (int i=0; i<10; i++)
{
cout << "Name: "<< data[i]->getName() << " Age: " << data[i]>getAge() << endl;
}
}
void quicksortName(int first, int last)
{
int lower = first + 1;
int upper = last;
swap(first, (first+last)/2);
Player *bound = data[first];
while (lower <= upper)
{
while (bound->getName() > data[lower]->getName() )
{
lower++;
}
while (bound->getName() < data[upper]->getName() )
{
upper--;
}
if (lower < upper)
swap(lower++, upper--);
else
lower++;
}
swap(upper, first);
if (first < upper-1)
quicksortName(first, upper-1);
if(upper+1 < last)
quicksortName(upper+1, last);
}

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

void quicksortAge(int first, int last)


{
int lower = first + 1;
int upper = last;
swap(first, (first+last)/2);
Player *bound = data[first];
while (lower <= upper)
{
while (bound->getAge() > data[lower]->getAge() )
{
lower++;
}
while (bound->getAge() < data[upper]->getAge() )
{
upper--;
}
if (lower < upper)
swap(lower++, upper--);
else
lower++;
}
swap(upper, first);
if (first < upper-1)
quicksortAge(first, upper-1);
if(upper+1 < last)
quicksortAge(upper+1, last);
}
void quicksortName(int arraySize)
{
if (arraySize < 2)
return;
int max = 0;
//find largest element and put at end of data
for (int i=1; i < arraySize; i++)
{

Quest #8

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

if(data[max]->getName() < data[i]->getName() )


max = i;
}
swap(arraySize-1, max);
quicksortName(0, arraySize-2);
}
void quicksortAge(int arraySize)
{
if (arraySize < 2)
return;
int max = 0;
//find largest element and put at end of data
for (int i=1; i < arraySize; i++)
{
if(data[max]->getAge() < data[i]->getAge() )
max = i;
}
swap(arraySize-1, max);
quicksortAge(0, arraySize-2);
}
void main()
{
Player *akarin = new Player();
akarin->setName("Akari");
akarin->setAge(12);
Player *konata = new Player();
konata->setName("Konata");
konata->setAge(20);
Player *yui = new Player();
yui->setName("Yui");
yui->setAge(18);
Player *mugi = new Player();
mugi->setName("Mugi");
mugi->setAge(19);

Quest #8

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

Player *yukko = new Player();


yukko->setName("Yukko");
yukko->setAge(16);
Player *mio = new Player();
mio->setName("Mio");
mio->setAge(16);
Player *ritsu = new Player();
ritsu->setName("Ritsu");
ritsu->setAge(15);
Player *tsukasa = new Player();
tsukasa->setName("Tsukasa");
tsukasa->setAge(14);
Player *akazi = new Player();
akazi->setName("Akazi");
akazi->setAge(25);
Player *shimada = new Player();
shimada->setName("Shimada");
shimada->setAge(30);
data[0] = yukko;
data[1] = konata;
data[2] = yui;
data[3] = mugi;
data[4] = tsukasa;
data[5] = shimada;
data[6] = akazi;
data[7] = akarin;
data[8] = ritsu;
data[9] = mio;
cout << "\nData before sorting:" << endl;
displayData();
cout << "\nSorting by name..." << endl;
quicksortName(10);
cout << "\n\nData after sorting:" << endl;
displayData();
cout << "\nData before sorting:" << endl;
displayData();
cout << "\nSorting by age..." << endl;

Quest #8

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

Quest #8

quicksortAge(10);
cout << "\n\nData after sorting:" << endl;
displayData();
system("pause");
}

Testing:
What is testing for? Every program you wrote, you are responsible for unit
testing it. The first thing to do, once you have a program that basically works, is to
try to break it. Try to feed your program input(s) in the hope of getting it to
misbehave. By hope means that the challenge here is to find as many errors as
possible, so that you can fix the errors before anybody else finds them. If you go into
this exercise with the attitude that my program works, and I dont make errors!,
then you wont find many bugs, and you will feel bad when you do find one or when
someone finds one. Youd be playing head games with yourself! The right attitude
when testing is, Ill break it! Im smarter than any program--even my own!
Feed (or try) a few such problematic inputs to your program and try to figure
out in how many ways you can get it to misbehave. Can you get the program to
crash? Testing is a very important part of game development, and can actually be fun.
You may input data that is not sensible. A program ideally catches all errors, not
just the sensible ones--this will make your program resilient against strange input.
As a goal, you would like the test to exercise every statement in your program, at
least once. Test both positive and negative scenario. One example of positive testing
is--if you have an input that requires an integer value, would it work if you give it the
numeral 7? Moreover, as an example of negative testing: what happens if you give
the previous program a string input of seven (instead of the numerical 7)? Identify
if your test results are Passed or Failed. Use the table below, and add at least five
test cases of your own!
[Type at least 5 test cases and what was the result? Did the result pass or fail? Do
a negative test case too!]
Test #
Test Description
Result
(Passed/Faile
d)
1
Example positive testing: Typed the number 7 as input
Passed
for health field.
2

Example negative testing: Type the word seven as


input for health field.

Failed

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

1
2
3
4
5

akarin->setName(7);
akarin->setAge("twnetyfive");
yui->setAge('A');
quicksortName(11);
yui->setAge(A);

Quest #8

Failed
Failed
Passed
Failed
Failed

Add as many rows as needed.

Production Deployment:
[Paste all your own final screens in this section.] Make sure your output screen
shot is readable, magnify if necessary so the instructor can easily read it. A sample
magnified output is shown below; replace this with your own.

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

Quest #8

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

Quest #8

GRADING RUBRIC
3

GDS 252

Data Structures and Algorithms

Instructor: George Saban

New England Institute of Technology

Grading Criteria

Quest #8

Exceeds

Meets

Partially Meets

Does Not Meet

Excellent
Epic Wow
+20-Code is
excellent, comments
are added, and
program works.
+10-Outputs are
correct, and
provided additional
output cases.
+10-Test cases were
excellent, and
provided more test
cases than required.

Satisfactory
O.K.
+15-Code is O.K.,
and program works.

Below Expectations
Not Yet
+10-Code works, but
still needs
improvement.

Unacceptable
Fail
Unfortunately, no
coding.

+8-Output meets
requirements and is
readable.

Unfortunately, no
output.

Documentation

+10-Excellent
documentation.

+8-Documentation
meets requirements.

Late

Excellent, you
submitted it before
the deadline.

-5, for submitting


after the deadline.

+6-There is output,
but not readable,
and/or needs
improvement.
+6-Test needs
improvement, did not
make sense, and did
not meet minimum
test case
requirements.
+6-Documentation
has a misspelling, or
syntax issues, or not
clear, or needs
improvement.
-10, for submitting
several weeks after
the deadline.

Coding

Output

Testing

+8-Provided valid
tests, and meets
minimum test case
requirements.

Unfortunately, no
testing.

Unfortunately, no
documentation.

-15, unfortunately,
for submitting very
late.

You might also like