Instructions
Requirements and Specifications
- You must use the function prototypes as outlined in the DNA.h and Sequencer.h header file. Do not edit the header files.
- There are several input files to test including proj3_case1.txt, proj3_case2.txt, proj3_case3.txt, and proj3_case4.txt. There may be more added later to test additional edge cases. There is no defined maximum number of suspects or evidence and no defined length of the sequence itself. Do not hard code any lengths in this project. Figure 2 below shows an example input file although it could have many suspects and many evidence sequences.
- The DNA is the linked list in this project. The insert and getters are straightforward but the ReverseSequence and CompareSequence are challenging.
- All user inputs will be assumed to be the correct data type. For example, if you ask the user for an integer, they will provide an integer.
- Regardless of the sample output below, all user input must be validated. If you ask for a number between 1 and 5 with the user entering an 8, the user should be re-prompted.
Source Code
#include "DNA.h"
// Create a DNA
DNA::DNA()
: m_head(nullptr), m_tail(nullptr), m_size(0)
{
}
// Create a DNA
DNA::DNA(string name)
: m_name(name), m_head(nullptr), m_tail(nullptr), m_size(0)
{
}
// Delete all pointers
DNA::~DNA()
{
for (Node *curr = m_head; curr != nullptr;)
{
Node *next = curr->m_next;
delete curr;
curr = next;
}
m_head = m_tail = nullptr;
m_size = 0;
}
// Add a new dna node at the end of the list
void DNA::InsertEnd(char data)
{
if (m_size == 0)
{
m_head = new Node();
m_head->m_data = data;
m_head->m_next = nullptr;
m_tail = m_head;
m_size++;
return;
}
m_tail->m_next = new Node();
m_tail = m_tail->m_next;
m_tail->m_data = data;
m_tail->m_next = nullptr;
m_size++;
}
// Return name
string DNA::GetName()
{
return m_name;
}
// Return size
int DNA::GetSize()
{
return m_size;
}
// Reverse DNA sequence
void DNA::ReverseSequence()
{
Node *prev = nullptr;
for (Node *curr = m_head; curr != nullptr;)
{
Node *next = curr->m_next;
curr->m_next = prev;
prev = curr;
curr = next;
}
Node *prevHead = m_head;
m_head = prev;
m_tail = prevHead;
}
// Check if this sequence contains the other DNA sequence
bool DNA::CompareSequence(DNA &evidence)
{
if (m_size == 0 || evidence.m_size == 0)
return false;
for (Node *curr = m_head; curr != nullptr; curr = curr->m_next)
{
// Check for a starting point
if (curr->m_data != evidence.m_head->m_data)
continue;
// If starting point is the same, check the rest for equality
Node *j = evidence.m_head;
for (Node *i = curr; i != nullptr; i = i->m_next, j = j->m_next)
{
if (j == nullptr || i->m_data != j->m_data)
break;
}
if (j == nullptr)
return true;
}
return false;
}
// Get DNA data at a node number
char DNA::GetData(int nodeNum)
{
if (nodeNum >= 0 && nodeNum < m_size)
{
Node *curr = m_head;
for (int i = 0; i < nodeNum; i++)
curr = curr->m_next;
return curr->m_data;
}
return 0;
}
// Output the DNA
ostream &operator<< (ostream &output, DNA &myDNA)
{
output << myDNA.m_name << "\n";
for (Node *curr = myDNA.m_head; curr != nullptr; curr = curr->m_next)
output << curr->m_data << "->";
output << "END";
return output;
}
Remove Property object from the array
protected void removeProperty(int position) {
System.out.println(getCurrent(position).getFullAddress() + " Removed");
properties.remove(position);
}//removeProperty
// **************
// SEARCH METHODS
// **************
// Return index position of property or number = -1 if not found
protected int findPropertyByStreet(String street) {
boolean found = false;
int index = 0, position = -1;
// Keep checking until the street is found or all properties have been checked
do {
// Check if the street at the index position equals the street passed as the parameter
if (properties.get(index).getStreet().equals(street)) {
found = true;
position = index;
}
index++;
} while ((!found) && (index < properties.size()));
// Return the index position of the property with the required street (or -1 if not found)
return position;
}//findPropertyByStreet
// Method to find properties by their town
// Return a range of indices or an empty list if none are found
protected ArrayList findPropertyByTown(String town) {
ArrayList result = new ArrayList();
for (int index = 0; index < properties.size(); index++) {
if (properties.get(index).getTown().equals(town)) {
result.add(index);
}//if
}//for
return result;
}//findPropertyByTown
// *************
// PRINT METHODS
// *************
protected void displayAProperty(int index) {
properties.get(index).displayProperty();
}//displayMember
protected void displayAllProperties() {
for (Property aPerson : properties) {
aPerson.displayProperty();
}//for
}//displayEveryone
}