Commit 716e44ae authored by Rachel Wil Sha Singh's avatar Rachel Wil Sha Singh 💬
Browse files

2020-09-21 class stuff

parent 46ef8353
#ifndef _NODE_HPP
#define _NODE_HPP
#include <iomanip>
#include <iostream>
using namespace std;
template <typename T>
class Node
{
public:
Node()
{
ptrPrev = nullptr;
ptrNext = nullptr;
}
void Display()
{
cout << left
<< setw( 10 ) << data
<< setw( 20 ) << ptrPrev
<< setw( 20 ) << ptrNext << endl;
}
T data;
Node* ptrNext;
Node* ptrPrev;
};
#endif
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Nodes" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Nodes" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Nodes" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="Node.hpp" />
<Unit filename="main.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Nodes" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Nodes" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Nodes" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="Node.hpp" />
<Unit filename="main.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="640" topLine="21" />
</Cursor>
</File>
<File name="Node.hpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="376" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include "Node.hpp"
void OneNode()
{
cout << endl << "ONE NODE" << endl;
cout << left
<< setw( 10 ) << "data"
<< setw( 20 ) << "prev"
<< setw( 20 ) << "next" << endl;
cout << "----------------------------------------------" << endl;
Node<string> node;
node.data = "one node";
node.Display();
}
void TwoNodes()
{
cout << endl << "TWO NODES" << endl;
cout << left
<< setw( 10 ) << "data"
<< setw( 20 ) << "prev"
<< setw( 20 ) << "next" << endl;
cout << "----------------------------------------------" << endl;
Node<string> node1, node2;
node1.data = "first";
node2.data = "second";
node1.ptrNext = &node2;
node2.ptrPrev = &node1;
node1.Display();
node2.Display();
}
void ThreeNodes()
{
cout << endl << "THREE NODES" << endl;
cout << left
<< setw( 10 ) << "data"
<< setw( 20 ) << "prev"
<< setw( 20 ) << "next" << endl;
cout << "----------------------------------------------" << endl;
Node<string> node1, node2, node3;
node1.data = "first";
node2.data = "second";
node3.data = "third";
node1.ptrNext = &node2;
node2.ptrPrev = &node1;
node2.ptrNext = &node3;
node3.ptrPrev = &node2;
node1.Display();
node2.Display();
node3.Display();
}
int main()
{
OneNode();
TwoNodes();
ThreeNodes();
return 0;
}
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="SearchSortLab" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/SearchSortLab" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/SearchSortLab" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="animal.cpp" />
<Unit filename="animal.hpp" />
<Unit filename="main.cpp" />
<Unit filename="menu.hpp" />
<Unit filename="parser.cpp" />
<Unit filename="parser.hpp" />
<Unit filename="search.cpp" />
<Unit filename="search.hpp" />
<Unit filename="sort.cpp" />
<Unit filename="sort.hpp" />
<Unit filename="timer.hpp" />
<Extensions>
<code_completion />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>
# depslib dependency file v1.0
1593112728 source:/home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/main.cpp
"search.hpp"
"sort.hpp"
"parser.hpp"
"menu.hpp"
1593110098 /home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/search.hpp
<string>
<vector>
"animal.hpp"
1593111257 /home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/sort.hpp
<vector>
<string>
"animal.hpp"
1593110025 /home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/helpers.hpp
<iostream>
<fstream>
<string>
<vector>
"timer.hpp"
"animal.hpp"
1593109727 source:/home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/search.cpp
"search.hpp"
1593111599 source:/home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/sort.cpp
"sort.hpp"
<iostream>
"menu.hpp"
1593108102 /home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/timer.hpp
<chrono>
1593108496 /home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/menu.hpp
<iostream>
<string>
<vector>
<cstdlib>
<limits>
1593109843 source:/home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/helpers.cpp
"helpers.hpp"
1593111593 source:/home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/animal.cpp
"animal.hpp"
<iostream>
1593111584 /home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/animal.hpp
<string>
1593110188 source:/home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/parser.cpp
"parser.hpp"
1593110061 /home/wilsha/TEACHING/cs200-concepts-of-progamming-algorithms/2020/Labs/08 Search and Sort/SearchSortLab/parser.hpp
<iostream>
<fstream>
<string>
<vector>
"timer.hpp"
"animal.hpp"
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="parser.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1273" topLine="30" />
</Cursor>
</File>
<File name="sort.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1909" topLine="51" />
</Cursor>
</File>
<File name="timer.hpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="192" topLine="5" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="136" topLine="12" />
</Cursor>
</File>
<File name="search.hpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="115" topLine="0" />
</Cursor>
</File>
<File name="animal.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1147" topLine="27" />
</Cursor>
</File>
<File name="parser.hpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="39" topLine="0" />
</Cursor>
</File>
<File name="sort.hpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="203" topLine="0" />
</Cursor>
</File>
<File name="menu.hpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3340" topLine="136" />
</Cursor>
</File>
<File name="animal.hpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="39" topLine="0" />
</Cursor>
</File>
<File name="search.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="670" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
#include "animal.hpp"
#include <iostream>
using namespace std;
void Animal::Display()
{
cout << endl;
cout << "Animal ID: " << id << endl
<< "Shelter: " << shelter << endl
<< "Intake date: " << intakeDate << endl
<< "Intake type: " << intakeType << endl
<< "Intake condition: " << intakeCondition << endl
<< "Animal type: " << type << endl
<< "Group: " << group << endl
<< "Breed: " << breed << endl;
cout << endl;
}
Animal& Animal::operator=( const Animal& other )
{
this->id = other.id;
this->breed = other.breed;
this->type = other.type;
return *this;
}
bool operator==( Animal& a1, Animal& a2 )
{
return ( a1.id == a2.id );
}
bool operator!=( Animal& a1, Animal& a2 )
{
return !( a1.id == a2.id );
}
bool operator<( Animal& a1, Animal& a2 )
{
return ( a1.id < a2.id );
}
bool operator>( Animal& a1, Animal& a2 )
{
return ( a1.id > a2.id );
}
bool operator<=( Animal& a1, Animal& a2 )
{
return ( a1.id <= a2.id );
}
bool operator>=( Animal& a1, Animal& a2 )
{
return ( a1.id >= a2.id );
}
#ifndef _ANIMAL_HPP
#define _ANIMAL_HPP
#include <string>
using namespace std;
class Animal
{
public:
string id;
string shelter;
string type;
string breed;
string intakeDate;
string intakeType;
string intakeCondition;
string group;
void Display();
Animal& operator=( const Animal& other );
friend bool operator==( Animal& a1, Animal& a2 );
friend bool operator!=( Animal& a1, Animal& a2 );
friend bool operator<( Animal& a1, Animal& a2 );
friend bool operator>( Animal& a1, Animal& a2 );
friend bool operator<=( Animal& a1, Animal& a2 );
friend bool operator>=( Animal& a1, Animal& a2 );
};
#endif
https://catalog.data.gov/dataset/animal-services-intake-data-57f73
#include "search.hpp"
#include "sort.hpp"
#include "parser.hpp"
#include "menu.hpp"
int main()
{
vector<Animal> animals;
LoadCsvData( "data/Animal_Services_Intake_Data.csv", animals );
bool done = false;
while ( !done )
{
Menu::Header( "Main Menu" );
int choice = Menu::ShowIntMenuWithPrompt( {
"Sort animals",
"Search for animal by ID"
} );
if ( choice == 1 )
{
Menu::Header( "Sort animal IDs" );
int sortChoice = Menu::ShowIntMenuWithPrompt( {
"Insertion sort",
"Selection sort",
"Merge sort"
} );
if ( sortChoice == 1 )
{
Timer timer;
timer.Start();
cout << "Beginning Insertion Sort..." << endl;
InsertionSort( animals );
cout << "* Sort completed (" << timer.GetElapsedMilliseconds() << " milliseconds)" << endl;
}
else if ( sortChoice == 2 )
{
Timer timer;
timer.Start();
cout << "Beginning Selection Sort..." << endl;
SelectionSort( animals );
cout << "* Sort completed (" << timer.GetElapsedMilliseconds() << " milliseconds)" << endl;
}
else
{
Timer timer;
timer.Start();
cout << "Beginning Merge Sort..." << endl;
MergeSort( animals, 0, animals.size() - 1 );
cout << "* Sort completed (" << timer.GetElapsedMilliseconds() << " milliseconds)" << endl;
}
}
else if ( choice == 2 )
{
Menu::Header( "Search for animal by ID" );
string id = Menu::GetStringChoice( "Enter the Animal ID" );
int searchChoice = Menu::ShowIntMenuWithPrompt( {
"Linear search",
"Binary search"
} );
int foundIndex = -1;
if ( searchChoice == 1 )
{
Timer timer;
timer.Start();
cout << "Beginning L