Stehpen Corya 5 ماه پیش
کامیت
8e26fb4c0f
77فایلهای تغییر یافته به همراه2884 افزوده شده و 0 حذف شده
  1. 54 0
      01 - Pointers and Bubbles/bubble.c
  2. 50 0
      02 - First C++ Program/numberGuess.cpp
  3. BIN
      03 - OOP with Horsepower/a.out
  4. 143 0
      03 - OOP with Horsepower/horseRace.cpp
  5. BIN
      04 - Makefiles/04 - Makefiles.zip
  6. 23 0
      04 - Makefiles/Book.cpp
  7. 17 0
      04 - Makefiles/Book.h
  8. 21 0
      04 - Makefiles/Library.cpp
  9. 17 0
      04 - Makefiles/Library.h
  10. 21 0
      04 - Makefiles/Main.cpp
  11. 20 0
      04 - Makefiles/Makefile
  12. BIN
      05 - Parsing and File I-O/05_parsing.zip
  13. 8 0
      05 - Parsing and File I-O/05_parsing/Makefile
  14. 35 0
      05 - Parsing and File I-O/05_parsing/myparser.cpp
  15. 8 0
      05 - Parsing and File I-O/Makefile
  16. 10 0
      05 - Parsing and File I-O/input.txt
  17. 35 0
      05 - Parsing and File I-O/myparser.cpp
  18. BIN
      06 - Heap of Students/06_heap-of-students.zip
  19. 43 0
      06 - Heap of Students/06_heap-of-students/Address.cpp
  20. 20 0
      06 - Heap of Students/06_heap-of-students/Address.h
  21. 15 0
      06 - Heap of Students/06_heap-of-students/Date.cpp
  22. 16 0
      06 - Heap of Students/06_heap-of-students/Date.h
  23. 110 0
      06 - Heap of Students/06_heap-of-students/Main.cpp
  24. 26 0
      06 - Heap of Students/06_heap-of-students/Makefile
  25. 57 0
      06 - Heap of Students/06_heap-of-students/Student.cpp
  26. 35 0
      06 - Heap of Students/06_heap-of-students/Student.h
  27. 51 0
      06 - Heap of Students/06_heap-of-students/students.dat
  28. 43 0
      06 - Heap of Students/Address.cpp
  29. 20 0
      06 - Heap of Students/Address.h
  30. 15 0
      06 - Heap of Students/Date.cpp
  31. 16 0
      06 - Heap of Students/Date.h
  32. 110 0
      06 - Heap of Students/Main.cpp
  33. 26 0
      06 - Heap of Students/Makefile
  34. 57 0
      06 - Heap of Students/Student.cpp
  35. 35 0
      06 - Heap of Students/Student.h
  36. 51 0
      06 - Heap of Students/students.dat
  37. 44 0
      07 - The Perfect Pet/Main.java
  38. 14 0
      07 - The Perfect Pet/Makefile
  39. 124 0
      07 - The Perfect Pet/Pet.java
  40. BIN
      07 - The Perfect Pet/perfectpet.zip
  41. 44 0
      07 - The Perfect Pet/perfectpet/Main.java
  42. 14 0
      07 - The Perfect Pet/perfectpet/Makefile
  43. 124 0
      07 - The Perfect Pet/perfectpet/Pet.java
  44. BIN
      08 - Inheritance Animation/08_inheritance-animation.zip
  45. 86 0
      08 - Inheritance Animation/08_inheritance-animation/AsciiAnim.java
  46. 59 0
      08 - Inheritance Animation/08_inheritance-animation/AsciiCanvas.java
  47. 41 0
      08 - Inheritance Animation/08_inheritance-animation/FNode.java
  48. 86 0
      08 - Inheritance Animation/AsciiAnim.java
  49. 59 0
      08 - Inheritance Animation/AsciiCanvas.java
  50. 41 0
      08 - Inheritance Animation/FNode.java
  51. BIN
      09 - Final Project/09_final-project.zip
  52. BIN
      09 - Final Project/09_final-project/09_final-project.zip
  53. 34 0
      09 - Final Project/09_final-project/Horse.cpp
  54. 18 0
      09 - Final Project/09_final-project/Horse.h
  55. 96 0
      09 - Final Project/09_final-project/Main.cpp
  56. 23 0
      09 - Final Project/09_final-project/Makefile
  57. 127 0
      09 - Final Project/09_final-project/Race.cpp
  58. 32 0
      09 - Final Project/09_final-project/Race.h
  59. BIN
      09 - Final Project/09_final-project/Untitled 1.odt
  60. BIN
      09 - Final Project/09_final-project/docs.odt
  61. 143 0
      09 - Final Project/09_final-project/horseRace.cpp
  62. BIN
      09 - Final Project/09_final-project/hrtui_docs.pdf
  63. BIN
      09 - Final Project/09_final-project/project_proposal.pdf
  64. 34 0
      09 - Final Project/Horse.cpp
  65. 18 0
      09 - Final Project/Horse.h
  66. 92 0
      09 - Final Project/Main.cpp
  67. 23 0
      09 - Final Project/Makefile
  68. 127 0
      09 - Final Project/Race.cpp
  69. 30 0
      09 - Final Project/Race.h
  70. BIN
      09 - Final Project/Untitled 1.odt
  71. BIN
      09 - Final Project/docs.odt
  72. BIN
      09 - Final Project/horse.o
  73. 143 0
      09 - Final Project/horseRace.cpp
  74. BIN
      09 - Final Project/hrtui
  75. BIN
      09 - Final Project/hrtui_docs.pdf
  76. BIN
      09 - Final Project/project_proposal.pdf
  77. BIN
      09 - Final Project/race.o

+ 54 - 0
01 - Pointers and Bubbles/bubble.c

@@ -0,0 +1,54 @@
+//bubble.c
+//famous bubble sort
+//implement the swap algorithm with pointers
+
+#include <stdio.h>
+#define MAX 9
+
+//function prototypes
+void printValues();
+void sort();
+void swap(int*, int*);
+
+int values[] = {7, 3, 9, 4, 6, 1, 2, 8, 5};
+
+int main(){
+  printf("Before: \n");
+  printValues();
+  sort();
+  printf("After: \n");
+  printValues();
+
+  return(0);
+} // end main
+
+// prints values[] by increasing index
+void printValues(){
+	printf("[");
+	int i = 0;
+	for (i = 0; i < MAX; i++){
+		printf("%d ", values[i]);
+	}
+	printf("]\n");
+}
+
+// implements ascending order bubble sort on values[]
+void sort(){
+	int i, j = 0;
+	for (i = 0; i < MAX - 1; i++){
+		for (j = 0; j < MAX - 1; j++){
+			if (values[j] > values [j + 1]){
+				swap(&values[j], &values[j + 1]);
+				printValues();
+			}
+		}
+	}
+}
+
+// swap function
+void swap(int* a, int* b){
+	int t = 0;
+	t = *a;
+	*a = *b;
+	*b = t;
+}

+ 50 - 0
02 - First C++ Program/numberGuess.cpp

@@ -0,0 +1,50 @@
+#include <iostream>
+#include <string>
+#include <cstdlib>
+using namespace std;
+
+//number guessing program.
+//computer generates a random number
+//user guesses a number
+//computer responds with "high, low, or correct"
+//continue until user has guessed the number
+
+int main(){
+
+    int turn = 0;
+    int guess = 50;
+	int diff = 25;
+	bool correct = 0;
+	string input = "";
+	
+	cout << "pick a number from 1 to 100" << endl;
+	cout << "the computer will attempt to guess your number" << endl;
+	cout << "enter \"low\", \"high\" or \"correct\"" << endl;
+	
+    while(!correct){
+    
+        turn++; // start with turn 1
+        cout << turn << ": " << guess << endl; // present user with guess
+        
+        getline(cin, input); // high, low, or correct
+        
+        if (!input.compare("low")){ // user entered "low"
+            guess = guess + diff; // guess higher
+        } else if (!input.compare("high")){ // user entered "high"
+            guess = guess - diff; // guess lower
+    	} else if(!input.compare("correct")) { // user entered "correct"
+    		correct = 1;  // exit the loop
+        } else { // invalid response
+        	cout << "please enter a valid response" << endl;
+        	turn--; // turn does not count
+        }// end if
+
+        diff = (diff / 2) + (diff % 2); // diff cannot be zero
+
+    } // end while
+    cout << guess << " is correct!" << endl;
+    cout << "It took " << turn << " turns." << endl;
+    return EXIT_SUCCESS;
+} // end main
+
+

BIN
03 - OOP with Horsepower/a.out


+ 143 - 0
03 - OOP with Horsepower/horseRace.cpp

@@ -0,0 +1,143 @@
+#include <iostream>
+#include <string>
+#include <cstdlib>
+
+using namespace std;
+
+// horse class
+class Horse{
+	public:
+		// constructor
+		Horse(){
+			position = 0;
+		}
+		
+		// access private position
+		int getPosition(){
+			return position;
+		}
+		
+		// flips a coin, advances ~50% of times
+		void advance(){
+			if (rand() % 2){ // either 0 or 1
+				position++;
+			}
+		}
+	
+	private:
+		int position; // position of horse on track
+};
+
+// race as in event and race as in track
+class Race{
+	public:
+		// constructors
+		Race(){
+			length = 32; // default length
+			numHorses = 4; // default number of horses
+			horses = new Horse[numHorses]; // make some horses
+		}
+		Race(int length){
+			this->length = length; // defined length
+			this->numHorses = 4; // default number of horses
+			horses = new Horse[numHorses]; // make some horses
+		}
+		
+		// get me those horses
+		Horse *getHorses(){
+			return horses;
+		}
+		
+		// prints one lane
+		void printLane(int lane){ // which lane
+			int i = 0;
+			for (i = 0; i < length; i++){
+				// prints the horses number at its latest position
+				if (i == horses[lane].getPosition()){
+					cout << lane;
+				// prints a lane visual
+				} else {
+					cout << ".";
+				} // end if
+			} // end for
+			cout << endl; // newline and stream flush
+		}
+		
+		// all the horses flip a coin and advance accordingly
+		void step(){
+			int i = 0;
+			// all horses in the race
+			for (i = 0; i < numHorses; i++){
+				horses[i].advance(); // horses know how to advance
+			}			
+		}
+		
+		// prints each lane
+		void printAllLanes(){
+			int i = 0;
+			for (i = 0; i < numHorses; i++){
+				printLane(i);
+			}			
+		}
+		
+		// checks if any horses have won or tied
+		bool isFinished(){
+			int i = 0;
+			// all horses in the race
+			for (i = 0; i < numHorses; i++){
+				if (horses[i].getPosition() == length){
+					return true; // one or more winners
+				}
+			}
+			return false;
+		}
+		
+		// this function is not used
+		// it was mentioned in the UML diagram
+		// I prefer to include the run loop in the main function
+		// start the race
+		void start(){
+			while (!this->isFinished()){ // stop if there's a winner
+				this->printAllLanes(); // update CLI
+				this->step(); // all horses advance...
+				cin.ignore(); // ...when the user presses enter
+			}
+		}
+		
+		// prints winner(s)
+		void printWinners(){
+			cout << "horse(s)";
+			int i = 0;
+			// check all the horses
+			for (i = 0; i < numHorses; i++){
+				// if horse at i finished...
+				if (horses[i].getPosition() == length){
+					cout << " " << i; // ...horse at i won!
+				}
+			}
+			cout << " won (tied)!" << endl;
+		}
+		
+	private:
+		Horse *horses; // horses
+		int numHorses; // number of horses (size of array)
+		int length; // length of the track
+};
+
+
+int main(){
+	// random number seed
+	srand(time(NULL));
+	// crate a race
+	Race race = Race();
+	// while the race is underway
+	while(!race.isFinished()){
+		race.printAllLanes(); // update CLI
+		race.step();  // all horses advance...
+		// tell the user what to do
+		cout << "Press enter for another turn:";
+		cin.ignore(); // ...when the user presses enter
+	}
+	race.printWinners(); // print the winners
+    return EXIT_SUCCESS;
+} // end main

BIN
04 - Makefiles/04 - Makefiles.zip


+ 23 - 0
04 - Makefiles/Book.cpp

@@ -0,0 +1,23 @@
+#include <string>
+
+#include "Book.h"
+
+Book::Book(){ // default constructor
+	title = ""; // no title
+	author = ""; // no author
+	pageNum = 0; // zero pages
+} // makes "books" without pages
+
+Book::Book(std::string title, int pageNum){ // useful constructor
+	this->title = title; // set title
+	this->pageNum = pageNum; // set number of pages
+	author = ""; // still no author
+}
+
+std::string Book::getTitle(){ // get the book's title
+	return title;
+}
+
+int Book::getPageNum(){ // get the number of pages
+	return pageNum;
+}

+ 17 - 0
04 - Makefiles/Book.h

@@ -0,0 +1,17 @@
+#ifndef _BOOK_H
+#define _BOOK_H
+
+class Book {
+	public:
+		Book(); // default constructor
+		Book(std::string title, int pageNum); // constructer with title and pages
+		std::string getTitle(); // acces private string title
+		int getPageNum(); // access private int pageNum
+		
+	private:
+		std::string title; // title of book
+		std::string author; // author of book
+		int pageNum; // number of pages in book
+};
+
+#endif

+ 21 - 0
04 - Makefiles/Library.cpp

@@ -0,0 +1,21 @@
+#include <iostream>
+
+#include "Library.h"
+
+// there is no means of adding books to the library
+
+Library::Library(){ // constructor
+	bookNum = 10; // how many places for books
+	b = new Book[bookNum]; // book array
+}
+
+void Library::printTitles(){ // prints the book titles
+	int i = 0;
+	for(i = 0; i < bookNum; i++){
+		std::cout << b[i].getTitle() << std::endl;
+	}
+}
+
+int Library::getBookNum(){ // gets the number of places for books
+	return bookNum;
+}

+ 17 - 0
04 - Makefiles/Library.h

@@ -0,0 +1,17 @@
+#ifndef _LIBRARY_H
+#define _LIBRARY_H
+
+#include "Book.h"
+
+class Library {
+	public:
+		Library(); // constructor
+		int getBookNum(); // public function to access private int
+		void printTitles(); // prints book titles (untested)
+		
+	private:
+		Book *b; // pointer to array of books
+		int bookNum; // size of book array
+};
+
+#endif

+ 21 - 0
04 - Makefiles/Main.cpp

@@ -0,0 +1,21 @@
+#include <iostream>
+#include <cstdlib>
+
+#include "Book.h"
+#include "Library.h"
+
+using namespace std;
+
+int main(){
+	// check that the book handles as expected
+	Book book = Book("MyBookTitle", 70);
+	cout << "Book title: " << book.getTitle() << endl;
+	cout << "Pages: " << book.getPageNum() << endl;
+
+	// check that the library handles as expected
+	Library library = Library();
+	cout << "Book spaces: " << library.getBookNum() << endl;
+	// library.printTitles(); // there are no books in the library
+
+	return EXIT_SUCCESS;
+}

+ 20 - 0
04 - Makefiles/Makefile

@@ -0,0 +1,20 @@
+# compiler
+CC = g++
+
+# compiler flags
+CFLAGS = -Wall -Werror
+
+# make first entry first
+all: main
+
+main: book.o library.o
+	$(CC) $(CFLAGS) -o main Main.cpp book.o library.o
+	
+book.o: Book.cpp Book.h
+	$(CC) $(CFLAGS) -c Book.cpp -o book.o
+	
+library.o: Library.cpp Library.h
+	$(CC) $(CFLAGS) -c Library.cpp -o library.o
+	
+clean:
+	rm main *.o

BIN
05 - Parsing and File I-O/05_parsing.zip


+ 8 - 0
05 - Parsing and File I-O/05_parsing/Makefile

@@ -0,0 +1,8 @@
+default:
+	g++ -Wall -Werror myparser.cpp -o myparser
+
+run: default
+	./myparser
+
+clean:
+	rm myparser output.txt

+ 35 - 0
05 - Parsing and File I-O/05_parsing/myparser.cpp

@@ -0,0 +1,35 @@
+#include <cstdlib>
+#include <fstream>
+#include <string>
+
+using namespace std;
+
+int main(){
+	int addend = 0, sum = 0, i = 0; // initialize variables
+	string word = ""; // initialize string object
+	ifstream fin ("input.txt"); // input file at ./input.txt
+	ofstream fout ("output.txt"); // create or overwrite output file at ./output.txt
+	
+	while (fin >> addend){ // run until end of file / get first int
+		sum = 0; // reset the sum for each word
+		sum += addend; // add first int to sum
+		fin.ignore(); // skip the first comma
+		
+		fin >> addend; // get second int
+		sum += addend; // add second int to sum
+		fin.ignore(); // skip the second comma
+		
+		fin >> addend; // get third int
+		sum += addend; // add third int to sum
+		fin.ignore(); // skip the \n
+		
+		getline(fin, word); // get the word on the line below its ints
+		
+		for (i = 0; i < sum - 1; i++){ // for each specified time
+			fout << word << ","; // print the word with a comma
+		} fout << word << endl; // no comma at the end
+	}
+			
+	fin.close();
+	fout.close();
+}

+ 8 - 0
05 - Parsing and File I-O/Makefile

@@ -0,0 +1,8 @@
+default:
+	g++ -Wall -Werror myparser.cpp -o myparser
+
+run: default
+	./myparser
+
+clean:
+	rm myparser output.txt

+ 10 - 0
05 - Parsing and File I-O/input.txt

@@ -0,0 +1,10 @@
+0,0,1
+one
+0,1,1
+two
+1,1,1
+three
+1,1,2
+four
+1,2,2
+five

+ 35 - 0
05 - Parsing and File I-O/myparser.cpp

@@ -0,0 +1,35 @@
+#include <cstdlib>
+#include <fstream>
+#include <string>
+
+using namespace std;
+
+int main(){
+	int addend = 0, sum = 0, i = 0; // initialize variables
+	string word = ""; // initialize string object
+	ifstream fin ("input.txt"); // input file at ./input.txt
+	ofstream fout ("output.txt"); // create or overwrite output file at ./output.txt
+	
+	while (fin >> addend){ // run until end of file / get first int
+		sum = 0; // reset the sum for each word
+		sum += addend; // add first int to sum
+		fin.ignore(); // skip the first comma
+		
+		fin >> addend; // get second int
+		sum += addend; // add second int to sum
+		fin.ignore(); // skip the second comma
+		
+		fin >> addend; // get third int
+		sum += addend; // add third int to sum
+		fin.ignore(); // skip the \n
+		
+		getline(fin, word); // get the word on the line below its ints
+		
+		for (i = 0; i < sum - 1; i++){ // for each specified time
+			fout << word << ","; // print the word with a comma
+		} fout << word << endl; // no comma at the end
+	}
+			
+	fin.close();
+	fout.close();
+}

BIN
06 - Heap of Students/06_heap-of-students.zip


+ 43 - 0
06 - Heap of Students/06_heap-of-students/Address.cpp

@@ -0,0 +1,43 @@
+#include <string>
+
+#include "Address.h"
+
+Address::Address(){ // default constructor
+	line1 = "";
+	line2 = "";
+	city = "";
+	state = "";
+	zip = "";
+} 
+
+Address::Address(	std::string line1, 
+					std::string line2, 
+					std::string city, 
+					std::string state, 
+					std::string zip		){ 
+	this->line1 = line1;
+	this->line2 = line2;
+	this->city = city;
+	this->state = state;
+	this->zip = zip;
+};
+
+std::string Address::getLine1(){
+	return line1;
+}
+
+std::string Address::getLine2(){
+	return line2;
+}
+
+std::string Address::getCity(){
+	return city;
+}
+
+std::string Address::getState(){
+	return state;
+}
+
+std::string Address::getZip(){
+	return zip;
+}

+ 20 - 0
06 - Heap of Students/06_heap-of-students/Address.h

@@ -0,0 +1,20 @@
+#ifndef ADDRESS_H
+#define ADDRESS_H
+
+#include <string>
+
+class Address {
+	private:
+		std::string line1, line2, city, state, zip;
+	
+	public:
+		Address();
+		Address(std::string, std::string, std::string, std::string, std::string);
+		std::string getLine1();
+		std::string getLine2();
+		std::string getCity();
+		std::string getState();
+		std::string getZip();
+};
+
+#endif

+ 15 - 0
06 - Heap of Students/06_heap-of-students/Date.cpp

@@ -0,0 +1,15 @@
+#include <string>
+
+#include "Date.h"
+
+Date::Date(){ // default constructor
+	date = "";
+}
+
+Date::Date(std::string date){
+	this->date = date;
+}
+
+std::string Date::getDate(){
+	return date;
+}

+ 16 - 0
06 - Heap of Students/06_heap-of-students/Date.h

@@ -0,0 +1,16 @@
+#ifndef DATE_H
+#define DATE_H
+
+#include <string>
+
+class Date {
+	private:
+		std::string date;
+		
+	public:
+		Date();
+		Date(std::string);
+		std::string getDate();
+};
+
+#endif

+ 110 - 0
06 - Heap of Students/06_heap-of-students/Main.cpp

@@ -0,0 +1,110 @@
+#include <cstdlib>
+#include <fstream>
+#include <string>
+#include <cstdio>
+#include <iostream>
+
+#include "Address.h"
+#include "Date.h"
+#include "Student.h"
+
+using namespace std;
+
+const int NUM_STUDENTS = 50;
+
+int main(){
+
+	// create arrays to store info
+	Address * addresses[NUM_STUDENTS];
+	Date * birthdays[NUM_STUDENTS];
+	Date * graddays[NUM_STUDENTS]; 
+	Student * students[NUM_STUDENTS]; 
+	string names[NUM_STUDENTS];
+	
+	// create objects to read and write files
+	ifstream fin ("students.dat");
+	ofstream fullReport ("fullReport.txt");
+	ofstream shortReport ("shortReport.txt");
+	ofstream alphaReport ("alphaReport.txt");
+
+	// create strings for everything and read the first line
+	string lname = "";		getline(fin, lname, ',');
+	string fname = "";		getline(fin, fname, ',');		
+	string line1 = "";		getline(fin, line1, ',');		
+	string line2 = "";		getline(fin, line2, ',');		
+	string city = "";		getline(fin, city, ',');		
+	string state = "";		getline(fin, state, ',');		
+	string zip = "";		getline(fin, zip, ',');		
+	string birthday = "";	getline(fin, birthday, ',');	
+	string gradday = "";	getline(fin, gradday, ',');		
+	string gpa = "";		getline(fin, gpa, ',');		
+	string credits = "";	getline(fin, credits);
+	
+	int i, j = 0;
+	// for each student...
+	for(i = 0; i < NUM_STUDENTS; i++){
+		// ... read the information, ...
+		getline(fin, lname, ',');
+		getline(fin, fname, ',');
+		getline(fin, line1, ',');
+		getline(fin, line2, ',');
+		getline(fin, city, ',');
+		getline(fin, state, ',');
+		getline(fin, zip, ',');
+		getline(fin, birthday, ',');
+		getline(fin, gradday, ',');
+		getline(fin, gpa, ',');
+		getline(fin, credits);
+		
+		// ... create objects with the information, ...
+		addresses[i] = new Address(line1, line2, city, state, zip);
+		birthdays[i] = new Date(birthday);
+		graddays[i] = new Date(gradday);
+		students[i] = new Student(fname, lname, birthdays[i],
+					 graddays[i], addresses[i], gpa, credits);
+		names[i] = students[i]->getLname() + "," + students[i]->getFname();
+		
+		// ... write the information full report, ...
+		fullReport 	<< students[i]->getLname() 				<< ","
+					<< students[i]->getFname() 				<< ","
+					<< students[i]->getAddress().getLine1() << ","
+					<< students[i]->getAddress().getLine2()	<< ","
+					<< students[i]->getAddress().getCity()	<< ","
+					<< students[i]->getAddress().getState()	<< ","
+					<< students[i]->getAddress().getZip()	<< ","
+					<< students[i]->getBirthday().getDate()	<< ","
+					<< students[i]->getGradday().getDate()	<< ","
+					<< students[i]->getGpa()				<< ","
+					<< students[i]->getCredits()			<< endl;
+		
+		// ... and write the short report.
+		shortReport << students[i]->getLname() << "," 
+					<< students[i]->getFname() << endl;
+	}
+	
+	// bubble sort
+	string hold = ""; // temporary variable
+	for(i = 0; i < NUM_STUDENTS - 1; i++){
+		for(j = 0; j < NUM_STUDENTS - 1; j++){
+			if(names[j].compare(names[j + 1]) > 0){
+				hold = names[j];
+				names[j] = names[j + 1];
+				names[j + 1] = hold;
+			}
+		}
+	}
+	
+	for(i = 0; i < NUM_STUDENTS; i++){
+		alphaReport << names[i] << endl; // write the alphabetical report
+		delete addresses[i]; // free memory
+		delete birthdays[i]; // free memory
+		delete graddays[i]; // free memory
+		delete students[i]; // free memory
+	}
+	
+	// close file streams
+	fin.close();
+	fullReport.close();
+	shortReport.close();
+	alphaReport.close();
+}

+ 26 - 0
06 - Heap of Students/06_heap-of-students/Makefile

@@ -0,0 +1,26 @@
+# compiler
+CC = g++
+
+# compiler flags
+CFLAGS = -Wall -Werror
+
+# make first entry first
+all: main
+
+run: all
+	./main
+
+main: address.o date.o student.o
+	$(CC) $(CFLAGS) -o main Main.cpp address.o date.o student.o
+
+address.o: Address.cpp Address.h
+	$(CC) $(CFLAGS) -c Address.cpp -o address.o
+
+date.o: Date.cpp Date.h
+	$(CC) $(CFLAGS) -c Date.cpp -o date.o
+	
+student.o: Student.cpp Student.h
+	$(CC) $(CFLAGS) -c Student.cpp -o student.o
+
+clean:
+	rm main address.o date.o student.o fullReport.txt shortReport.txt alphaReport.txt

+ 57 - 0
06 - Heap of Students/06_heap-of-students/Student.cpp

@@ -0,0 +1,57 @@
+#include <string>
+
+#include "Student.h"
+
+Student::Student(){
+	fname = "";
+	lname = "";
+	Date birthday;
+	Date gradday;
+	Address address;
+	gpa = "";
+	credits = "";
+}
+
+Student::Student(std::string fname,
+				std::string lname,
+				Date * birthday,
+				Date * gradday,
+				Address * address,
+				std::string gpa,
+				std::string credits){
+	this->fname = fname;
+	this->lname = lname;
+	this->birthday = * birthday;
+	this->gradday = * gradday;
+	this->address = * address;
+	this->gpa = gpa;
+	this->credits = credits;
+};
+
+std::string Student::getFname(){
+	return fname;
+}
+
+std::string Student::getLname(){ 
+	return lname;
+}
+
+Date Student::getBirthday(){
+	return birthday;
+}
+
+Date Student::getGradday(){
+	return gradday;
+}
+
+Address Student::getAddress(){
+	return address;
+}
+
+std::string Student::getGpa(){
+	return gpa;
+}
+
+std::string Student::getCredits(){
+	return credits;
+}

+ 35 - 0
06 - Heap of Students/06_heap-of-students/Student.h

@@ -0,0 +1,35 @@
+#ifndef STUDENT_H
+#define STUDENT_H
+
+#include <string>
+
+#include "Address.h"
+#include "Date.h"
+
+class Student {
+	private:
+		std::string fname, lname;
+		Date birthday, gradday;
+		Address address;
+		std::string gpa;
+		std::string credits;
+		
+	public:
+		Student();
+		Student(	std::string, 
+					std::string, 
+					Date::Date *, 
+					Date::Date *, 
+					Address::Address *, 
+					std::string, 
+					std::string			);
+		std::string getFname();
+		std::string getLname();
+		Date getBirthday();
+		Date getGradday();
+		Address getAddress();
+		std::string getGpa();
+		std::string getCredits();
+};
+
+#endif

+ 51 - 0
06 - Heap of Students/06_heap-of-students/students.dat

@@ -0,0 +1,51 @@
+Surname,GivenName,StreetAddress,Address 2,City,State,ZipCode,Birthday,Graduation,GPA,Credit Hours Complete
+Florence,Forrest,1843 Glenview Drive,,Corpus Christi,TX,78401,10/12/1992,5/14/2012,3.215,127
+Casey,Roberta,3668 Thunder Road,,Palo Alto,CA,94306,2/13/1983,5/14/2014,2.978,95
+Koch,Sandra,2707 Waterview Lane,Apt 302,Las Vegas,NM,87701,6/6/1972,12/14/2015,2.546,69
+Dover,Darrel,845 Dola Mine Road,,Wendell,NC,27591,3/31/1968,5/14/2012,3.958,75
+Turner,Doris,4489 Tully Street,Apt B,Detroit,MI,48219,5/21/1988,5/14/2014,2.127,187
+Hernandez,Juan,2656 Creekside Lane,,Goleta,CA,93117,7/21/1979,12/14/2015,1.598,156
+Moon,Sandy,1125 Joyce Street,,Mobile,AL,36693,12/28/1977,5/14/2012,3.995,124
+Reid,Andre,1225 Gnatty Creek Road,,Westbury,NY,11590,12/19/1986,5/14/2014,2.985,112
+Cracraft,Tara,3479 Austin Avenue,,Brunswick,GA,31520,2/4/1973,12/14/2015,3.256,162
+Valadez,Vincent,1740 Parkview Drive,,Sugar Land,TX,77478,9/23/1975,5/14/2012,3.127,106
+Howard,William,816 Wayside Lane,,Hayward,CA,94545,4/9/1971,5/14/2014,3.568,95
+Mills,Gary,2888 Rowes Lane,,Irvington,KY,40146,4/22/1990,12/14/2015,3.759,127
+Lett,Victoria,4250 Pringle Drive,,Chicago,IL,60606,8/13/1987,5/14/2012,3.862,95
+Brice,William,4332 Larry Street,Apt 456,New Berlin,WI,53151,1/11/1974,5/14/2014,3.215,69
+Hutchison,Craig,3704 Green Street,,Nashville,TN,37211,9/27/1969,12/14/2015,2.978,75
+Taylor,Danielle,4900 Hudson Street,,Haledon,NJ,7508,7/17/1983,5/14/2012,2.546,162
+Gingerich,Ermelinda,3834 Milford Street,Apt F,Sunapee,NH,3782,12/17/1973,5/14/2014,3.958,106
+Moody,Derek,264 Tetrick Road,,Bowling Green,FL,33834,10/23/1980,12/14/2015,2.127,95
+Howell,Sonja,1093 Olen Thomas Drive,P.O. Box 552,Wichita Falls,TX,76301,9/18/1984,5/14/2012,1.598,124
+Miser,Michael,1532 South Street,,Midland,TX,79701,10/25/1967,5/14/2014,3.995,75
+Davenport,Robin,4174 Columbia Mine Road,,Wheeling,WV,26003,3/9/1971,12/14/2015,2.985,187
+Langley,Joycelyn,1254 Woodland Drive,,Omaha,NE,68114,2/8/1979,5/14/2012,3.256,156
+Bryant,Ann,1334 Progress Way,,Minneapolis,MN,55401,2/28/1977,5/14/2014,3.127,124
+Barnett,Patrick,2432 Warner Street,,Casper,WY,82601,7/28/1977,12/14/2015,3.568,95
+Knepp,Christopher,1012 Oakmound Road,,Chicago,IL,60623,2/21/1968,5/14/2012,3.759,127
+Canfield,Reginald,4212 Coal Street,,Somerset,PA,15501,3/21/1988,5/14/2014,3.862,95
+Lippert,Margarita,781 Hillcrest Lane,,Fullerton,CA,93632,6/8/1978,12/14/2015,1.598,69
+Kist,Barbara,2103 Mapleview Drive,,Jackson,TN,38301,11/3/1980,5/14/2012,3.995,75
+Waters,Ladonna,68 Oak Ridge Drive,,Mexico,MO,65265,4/4/1969,5/14/2014,2.985,187
+Shepherd,Julio,2446 Camden Street,,Reno,NV,89502,6/23/1978,12/14/2015,3.256,156
+Hernandez,Antonio,3232 Fairmont Avenue,,Kansas City,MO,64106,3/12/1980,5/14/2012,3.127,124
+Ridge,Sharon,3964 Stoney Lane,P.O. Box 549,Dallas,TX,75247,1/8/1991,5/14/2014,3.568,112
+Lambert,Michael,2174 Kyle Street,,Venango,NE,69168,10/6/1982,12/14/2015,3.759,162
+Tapp,Michael,4569 Shobe Lane,,Greeley,CO,80634,3/12/1972,5/14/2012,3.862,106
+Lewis,Peggy,1601 Hall Valley Drive,,Wheeling,WV,26003,5/1/1981,5/14/2014,1.598,127
+Smith,Darren,2836 Briarwood Road,,Springfield,MO,65804,5/26/1968,12/14/2015,3.995,95
+Adair,Jeffrey,4478 Hillside Street,,Phoenix,AZ,85016,7/3/1986,5/14/2012,2.985,69
+Greene,Eric,569 Pine Garden Lane,,Norcross,GA,30091,8/10/1972,5/14/2014,3.256,75
+Gilham,Mike,3543 Ventura Drive,Apt H,Marina,CA,93933,9/27/1980,12/14/2015,2.546,162
+Dorsey,Tammy,2111 Liberty Avenue,,Los Angeles,CA,90017,10/19/1969,5/14/2012,3.958,106
+Lewis,Robert,2253 Brannon Avenue,,Jacksonville,FL,32216,8/6/1979,5/14/2014,2.127,95
+Petitt,Craig,2397 My Drive,,Garden City,NY,11530,6/15/1971,12/14/2015,1.598,124
+Quarles,Helen,98 Mount Tabor,,New York,NY,10013,9/5/1980,5/14/2012,3.995,75
+Frey,Catherine,1504 Shobe Lane,,Loveland,CO,80537,4/5/1981,5/14/2014,2.985,69
+Ortiz,Sophie,977 Seltice Way,Apt 56,Boise,ID,83704,8/6/1976,12/14/2015,3.256,75
+McAbee,Michael,959 Hall Street,,Las Vegas,NV,89119,3/7/1991,5/14/2012,3.127,187
+Herrera,David,3084 Hart Country Lane,,Norcross,GA,30093,6/19/1981,5/14/2014,2.127,156
+Parry,Paul,3425 Valley Street,,Vineland,NJ,8360,12/17/1973,12/14/2015,1.598,124
+Carter,Lisa,1809 Oak Ridge Drive,,Rolla,MO,65401,2/25/1989,5/14/2012,3.995,112
+Barbee,James,4756 Mapleview Drive,,Ripley,TN,38063,12/27/1983,5/14/2014,2.985,162

+ 43 - 0
06 - Heap of Students/Address.cpp

@@ -0,0 +1,43 @@
+#include <string>
+
+#include "Address.h"
+
+Address::Address(){ // default constructor
+	line1 = "";
+	line2 = "";
+	city = "";
+	state = "";
+	zip = "";
+} 
+
+Address::Address(	std::string line1, 
+					std::string line2, 
+					std::string city, 
+					std::string state, 
+					std::string zip		){ 
+	this->line1 = line1;
+	this->line2 = line2;
+	this->city = city;
+	this->state = state;
+	this->zip = zip;
+};
+
+std::string Address::getLine1(){
+	return line1;
+}
+
+std::string Address::getLine2(){
+	return line2;
+}
+
+std::string Address::getCity(){
+	return city;
+}
+
+std::string Address::getState(){
+	return state;
+}
+
+std::string Address::getZip(){
+	return zip;
+}

+ 20 - 0
06 - Heap of Students/Address.h

@@ -0,0 +1,20 @@
+#ifndef ADDRESS_H
+#define ADDRESS_H
+
+#include <string>
+
+class Address {
+	private:
+		std::string line1, line2, city, state, zip;
+	
+	public:
+		Address();
+		Address(std::string, std::string, std::string, std::string, std::string);
+		std::string getLine1();
+		std::string getLine2();
+		std::string getCity();
+		std::string getState();
+		std::string getZip();
+};
+
+#endif

+ 15 - 0
06 - Heap of Students/Date.cpp

@@ -0,0 +1,15 @@
+#include <string>
+
+#include "Date.h"
+
+Date::Date(){ // default constructor
+	date = "";
+}
+
+Date::Date(std::string date){
+	this->date = date;
+}
+
+std::string Date::getDate(){
+	return date;
+}

+ 16 - 0
06 - Heap of Students/Date.h

@@ -0,0 +1,16 @@
+#ifndef DATE_H
+#define DATE_H
+
+#include <string>
+
+class Date {
+	private:
+		std::string date;
+		
+	public:
+		Date();
+		Date(std::string);
+		std::string getDate();
+};
+
+#endif

+ 110 - 0
06 - Heap of Students/Main.cpp

@@ -0,0 +1,110 @@
+#include <cstdlib>
+#include <fstream>
+#include <string>
+#include <cstdio>
+#include <iostream>
+
+#include "Address.h"
+#include "Date.h"
+#include "Student.h"
+
+using namespace std;
+
+const int NUM_STUDENTS = 50;
+
+int main(){
+
+	// create arrays to store info
+	Address * addresses[NUM_STUDENTS];
+	Date * birthdays[NUM_STUDENTS];
+	Date * graddays[NUM_STUDENTS]; 
+	Student * students[NUM_STUDENTS]; 
+	string names[NUM_STUDENTS];
+	
+	// create objects to read and write files
+	ifstream fin ("students.dat");
+	ofstream fullReport ("fullReport.txt");
+	ofstream shortReport ("shortReport.txt");
+	ofstream alphaReport ("alphaReport.txt");
+
+	// create strings for everything and read the first line
+	string lname = "";		getline(fin, lname, ',');
+	string fname = "";		getline(fin, fname, ',');		
+	string line1 = "";		getline(fin, line1, ',');		
+	string line2 = "";		getline(fin, line2, ',');		
+	string city = "";		getline(fin, city, ',');		
+	string state = "";		getline(fin, state, ',');		
+	string zip = "";		getline(fin, zip, ',');		
+	string birthday = "";	getline(fin, birthday, ',');	
+	string gradday = "";	getline(fin, gradday, ',');		
+	string gpa = "";		getline(fin, gpa, ',');		
+	string credits = "";	getline(fin, credits);
+	
+	int i, j = 0;
+	// for each student...
+	for(i = 0; i < NUM_STUDENTS; i++){
+		// ... read the information, ...
+		getline(fin, lname, ',');
+		getline(fin, fname, ',');
+		getline(fin, line1, ',');
+		getline(fin, line2, ',');
+		getline(fin, city, ',');
+		getline(fin, state, ',');
+		getline(fin, zip, ',');
+		getline(fin, birthday, ',');
+		getline(fin, gradday, ',');
+		getline(fin, gpa, ',');
+		getline(fin, credits);
+		
+		// ... create objects with the information, ...
+		addresses[i] = new Address(line1, line2, city, state, zip);
+		birthdays[i] = new Date(birthday);
+		graddays[i] = new Date(gradday);
+		students[i] = new Student(fname, lname, birthdays[i],
+					 graddays[i], addresses[i], gpa, credits);
+		names[i] = students[i]->getLname() + "," + students[i]->getFname();
+		
+		// ... write the information full report, ...
+		fullReport 	<< students[i]->getLname() 				<< ","
+					<< students[i]->getFname() 				<< ","
+					<< students[i]->getAddress().getLine1() << ","
+					<< students[i]->getAddress().getLine2()	<< ","
+					<< students[i]->getAddress().getCity()	<< ","
+					<< students[i]->getAddress().getState()	<< ","
+					<< students[i]->getAddress().getZip()	<< ","
+					<< students[i]->getBirthday().getDate()	<< ","
+					<< students[i]->getGradday().getDate()	<< ","
+					<< students[i]->getGpa()				<< ","
+					<< students[i]->getCredits()			<< endl;
+		
+		// ... and write the short report.
+		shortReport << students[i]->getLname() << "," 
+					<< students[i]->getFname() << endl;
+	}
+	
+	// bubble sort
+	string hold = ""; // temporary variable
+	for(i = 0; i < NUM_STUDENTS - 1; i++){
+		for(j = 0; j < NUM_STUDENTS - 1; j++){
+			if(names[j].compare(names[j + 1]) > 0){
+				hold = names[j];
+				names[j] = names[j + 1];
+				names[j + 1] = hold;
+			}
+		}
+	}
+	
+	for(i = 0; i < NUM_STUDENTS; i++){
+		alphaReport << names[i] << endl; // write the alphabetical report
+		delete addresses[i]; // free memory
+		delete birthdays[i]; // free memory
+		delete graddays[i]; // free memory
+		delete students[i]; // free memory
+	}
+	
+	// close file streams
+	fin.close();
+	fullReport.close();
+	shortReport.close();
+	alphaReport.close();
+}

+ 26 - 0
06 - Heap of Students/Makefile

@@ -0,0 +1,26 @@
+# compiler
+CC = g++
+
+# compiler flags
+CFLAGS = -Wall -Werror
+
+# make first entry first
+all: main
+
+run: all
+	./main
+
+main: address.o date.o student.o
+	$(CC) $(CFLAGS) -o main Main.cpp address.o date.o student.o
+
+address.o: Address.cpp Address.h
+	$(CC) $(CFLAGS) -c Address.cpp -o address.o
+
+date.o: Date.cpp Date.h
+	$(CC) $(CFLAGS) -c Date.cpp -o date.o
+	
+student.o: Student.cpp Student.h
+	$(CC) $(CFLAGS) -c Student.cpp -o student.o
+
+clean:
+	rm main address.o date.o student.o fullReport.txt shortReport.txt alphaReport.txt

+ 57 - 0
06 - Heap of Students/Student.cpp

@@ -0,0 +1,57 @@
+#include <string>
+
+#include "Student.h"
+
+Student::Student(){
+	fname = "";
+	lname = "";
+	Date birthday;
+	Date gradday;
+	Address address;
+	gpa = "";
+	credits = "";
+}
+
+Student::Student(std::string fname,
+				std::string lname,
+				Date * birthday,
+				Date * gradday,
+				Address * address,
+				std::string gpa,
+				std::string credits){
+	this->fname = fname;
+	this->lname = lname;
+	this->birthday = * birthday;
+	this->gradday = * gradday;
+	this->address = * address;
+	this->gpa = gpa;
+	this->credits = credits;
+};
+
+std::string Student::getFname(){
+	return fname;
+}
+
+std::string Student::getLname(){ 
+	return lname;
+}
+
+Date Student::getBirthday(){
+	return birthday;
+}
+
+Date Student::getGradday(){
+	return gradday;
+}
+
+Address Student::getAddress(){
+	return address;
+}
+
+std::string Student::getGpa(){
+	return gpa;
+}
+
+std::string Student::getCredits(){
+	return credits;
+}

+ 35 - 0
06 - Heap of Students/Student.h

@@ -0,0 +1,35 @@
+#ifndef STUDENT_H
+#define STUDENT_H
+
+#include <string>
+
+#include "Address.h"
+#include "Date.h"
+
+class Student {
+	private:
+		std::string fname, lname;
+		Date birthday, gradday;
+		Address address;
+		std::string gpa;
+		std::string credits;
+		
+	public:
+		Student();
+		Student(	std::string, 
+					std::string, 
+					Date::Date *, 
+					Date::Date *, 
+					Address::Address *, 
+					std::string, 
+					std::string			);
+		std::string getFname();
+		std::string getLname();
+		Date getBirthday();
+		Date getGradday();
+		Address getAddress();
+		std::string getGpa();
+		std::string getCredits();
+};
+
+#endif

+ 51 - 0
06 - Heap of Students/students.dat

@@ -0,0 +1,51 @@
+Surname,GivenName,StreetAddress,Address 2,City,State,ZipCode,Birthday,Graduation,GPA,Credit Hours Complete
+Florence,Forrest,1843 Glenview Drive,,Corpus Christi,TX,78401,10/12/1992,5/14/2012,3.215,127
+Casey,Roberta,3668 Thunder Road,,Palo Alto,CA,94306,2/13/1983,5/14/2014,2.978,95
+Koch,Sandra,2707 Waterview Lane,Apt 302,Las Vegas,NM,87701,6/6/1972,12/14/2015,2.546,69
+Dover,Darrel,845 Dola Mine Road,,Wendell,NC,27591,3/31/1968,5/14/2012,3.958,75
+Turner,Doris,4489 Tully Street,Apt B,Detroit,MI,48219,5/21/1988,5/14/2014,2.127,187
+Hernandez,Juan,2656 Creekside Lane,,Goleta,CA,93117,7/21/1979,12/14/2015,1.598,156
+Moon,Sandy,1125 Joyce Street,,Mobile,AL,36693,12/28/1977,5/14/2012,3.995,124
+Reid,Andre,1225 Gnatty Creek Road,,Westbury,NY,11590,12/19/1986,5/14/2014,2.985,112
+Cracraft,Tara,3479 Austin Avenue,,Brunswick,GA,31520,2/4/1973,12/14/2015,3.256,162
+Valadez,Vincent,1740 Parkview Drive,,Sugar Land,TX,77478,9/23/1975,5/14/2012,3.127,106
+Howard,William,816 Wayside Lane,,Hayward,CA,94545,4/9/1971,5/14/2014,3.568,95
+Mills,Gary,2888 Rowes Lane,,Irvington,KY,40146,4/22/1990,12/14/2015,3.759,127
+Lett,Victoria,4250 Pringle Drive,,Chicago,IL,60606,8/13/1987,5/14/2012,3.862,95
+Brice,William,4332 Larry Street,Apt 456,New Berlin,WI,53151,1/11/1974,5/14/2014,3.215,69
+Hutchison,Craig,3704 Green Street,,Nashville,TN,37211,9/27/1969,12/14/2015,2.978,75
+Taylor,Danielle,4900 Hudson Street,,Haledon,NJ,7508,7/17/1983,5/14/2012,2.546,162
+Gingerich,Ermelinda,3834 Milford Street,Apt F,Sunapee,NH,3782,12/17/1973,5/14/2014,3.958,106
+Moody,Derek,264 Tetrick Road,,Bowling Green,FL,33834,10/23/1980,12/14/2015,2.127,95
+Howell,Sonja,1093 Olen Thomas Drive,P.O. Box 552,Wichita Falls,TX,76301,9/18/1984,5/14/2012,1.598,124
+Miser,Michael,1532 South Street,,Midland,TX,79701,10/25/1967,5/14/2014,3.995,75
+Davenport,Robin,4174 Columbia Mine Road,,Wheeling,WV,26003,3/9/1971,12/14/2015,2.985,187
+Langley,Joycelyn,1254 Woodland Drive,,Omaha,NE,68114,2/8/1979,5/14/2012,3.256,156
+Bryant,Ann,1334 Progress Way,,Minneapolis,MN,55401,2/28/1977,5/14/2014,3.127,124
+Barnett,Patrick,2432 Warner Street,,Casper,WY,82601,7/28/1977,12/14/2015,3.568,95
+Knepp,Christopher,1012 Oakmound Road,,Chicago,IL,60623,2/21/1968,5/14/2012,3.759,127
+Canfield,Reginald,4212 Coal Street,,Somerset,PA,15501,3/21/1988,5/14/2014,3.862,95
+Lippert,Margarita,781 Hillcrest Lane,,Fullerton,CA,93632,6/8/1978,12/14/2015,1.598,69
+Kist,Barbara,2103 Mapleview Drive,,Jackson,TN,38301,11/3/1980,5/14/2012,3.995,75
+Waters,Ladonna,68 Oak Ridge Drive,,Mexico,MO,65265,4/4/1969,5/14/2014,2.985,187
+Shepherd,Julio,2446 Camden Street,,Reno,NV,89502,6/23/1978,12/14/2015,3.256,156
+Hernandez,Antonio,3232 Fairmont Avenue,,Kansas City,MO,64106,3/12/1980,5/14/2012,3.127,124
+Ridge,Sharon,3964 Stoney Lane,P.O. Box 549,Dallas,TX,75247,1/8/1991,5/14/2014,3.568,112
+Lambert,Michael,2174 Kyle Street,,Venango,NE,69168,10/6/1982,12/14/2015,3.759,162
+Tapp,Michael,4569 Shobe Lane,,Greeley,CO,80634,3/12/1972,5/14/2012,3.862,106
+Lewis,Peggy,1601 Hall Valley Drive,,Wheeling,WV,26003,5/1/1981,5/14/2014,1.598,127
+Smith,Darren,2836 Briarwood Road,,Springfield,MO,65804,5/26/1968,12/14/2015,3.995,95
+Adair,Jeffrey,4478 Hillside Street,,Phoenix,AZ,85016,7/3/1986,5/14/2012,2.985,69
+Greene,Eric,569 Pine Garden Lane,,Norcross,GA,30091,8/10/1972,5/14/2014,3.256,75
+Gilham,Mike,3543 Ventura Drive,Apt H,Marina,CA,93933,9/27/1980,12/14/2015,2.546,162
+Dorsey,Tammy,2111 Liberty Avenue,,Los Angeles,CA,90017,10/19/1969,5/14/2012,3.958,106
+Lewis,Robert,2253 Brannon Avenue,,Jacksonville,FL,32216,8/6/1979,5/14/2014,2.127,95
+Petitt,Craig,2397 My Drive,,Garden City,NY,11530,6/15/1971,12/14/2015,1.598,124
+Quarles,Helen,98 Mount Tabor,,New York,NY,10013,9/5/1980,5/14/2012,3.995,75
+Frey,Catherine,1504 Shobe Lane,,Loveland,CO,80537,4/5/1981,5/14/2014,2.985,69
+Ortiz,Sophie,977 Seltice Way,Apt 56,Boise,ID,83704,8/6/1976,12/14/2015,3.256,75
+McAbee,Michael,959 Hall Street,,Las Vegas,NV,89119,3/7/1991,5/14/2012,3.127,187
+Herrera,David,3084 Hart Country Lane,,Norcross,GA,30093,6/19/1981,5/14/2014,2.127,156
+Parry,Paul,3425 Valley Street,,Vineland,NJ,8360,12/17/1973,12/14/2015,1.598,124
+Carter,Lisa,1809 Oak Ridge Drive,,Rolla,MO,65401,2/25/1989,5/14/2012,3.995,112
+Barbee,James,4756 Mapleview Drive,,Ripley,TN,38063,12/27/1983,5/14/2014,2.985,162

+ 44 - 0
07 - The Perfect Pet/Main.java

@@ -0,0 +1,44 @@
+import java.util.Scanner;
+
+public class Main{
+	public static void main (String[] args){
+	
+		// read user input
+		Scanner input = new Scanner(System.in);
+		char userinput = 'c';
+		
+		// load existing pet if there is one
+		Pet mypet = Pet.loadFromDisk();
+		if(mypet == null){
+			mypet = new Pet();
+		}
+		
+		// main game loop
+		System.out.println("Welcome to \"The Pet Simulator.\"");
+		while(userinput != 'q' && mypet.isAlive()){
+			System.out.println("Here are your pet's stats:");
+			mypet.printStatus();
+			System.out.println("Enter \'f,\' \'w,\' or \'r\' to feed, water, or rest your pet.");
+			System.out.println("Enter \'q\' to save and quit.");
+			userinput = input.next().charAt(0);
+			if(userinput == 'f'){
+				mypet.feed();
+			}
+			if(userinput == 'w'){
+				mypet.water();
+			}
+			if(userinput == 'r'){
+				mypet.rest();
+			}
+		}
+		
+		// present the bad news
+		if(!mypet.isAlive()){
+			System.out.println("This pet has died.");
+		}
+		
+		// clean up
+		mypet.saveToDisk();
+		input.close();
+	}
+}

+ 14 - 0
07 - The Perfect Pet/Makefile

@@ -0,0 +1,14 @@
+# compiler
+JAVAC = javac
+
+# make first entry first
+all: main
+
+run: all
+	java Main
+
+main:
+	$(JAVAC) *.java
+
+clean:
+	rm *.class

+ 124 - 0
07 - The Perfect Pet/Pet.java

@@ -0,0 +1,124 @@
+import java.io.*;
+
+public class Pet implements java.io.Serializable {
+
+	// serializable version number
+	private static final long serialVersionUID = 1;
+
+	// the pet's stats
+	private int hunger;
+	private int thirst;
+	private int energy;
+	private boolean life;
+	
+	// everything starts off good
+	public Pet(){
+		hunger = 0;
+		thirst = 0;
+		energy = 100;
+		life = true;
+	}
+	
+	// reset the pet's hunger
+	public void feed(){
+		hunger = 0;
+		thirst += 5;
+		energy -= 5;
+		if(hunger > 100 || thirst > 100 || energy < 0){
+			this.kill();
+		}
+	}
+	
+	// reset the pet's thirst
+	public void water(){
+		hunger += 5;
+		thirst = 0;
+		energy -= 5;
+		if(hunger > 100 || thirst > 100 || energy < 0){
+			this.kill();
+		}
+	}
+	
+	// reset the pet's energy
+	public void rest(){
+		hunger += 5;
+		thirst += 5;
+		energy = 100;
+		if(hunger > 100 || thirst > 100 || energy < 0){
+			this.kill();
+		}
+	}
+	
+	// kill the pet
+	public void kill(){
+		hunger = 0;
+		thirst = 0;
+		energy = 0;
+		life = false;
+	}
+	
+	// do nothing
+	public void neglect(){
+		hunger += 5;
+		thirst += 5;
+		energy -= 5;
+		if(hunger > 100 || thirst > 100 || energy < 0){
+			this.kill();
+		}
+	}
+	
+	// print the pet's stats
+	public void printStatus(){
+		if(life){
+			System.out.println("\tHunger: " + hunger);
+			System.out.println("\tThirst: " + thirst);
+			System.out.println("\tEnergy: " + energy);
+		} else{
+			System.out.println("This pet died.");
+		}
+	}
+
+	// helper methods
+	public int getHunger(){
+		return hunger;
+	}
+	public int getThirst(){
+		return thirst;
+	}
+	public int getEnergy(){
+		return energy;
+	}
+	public boolean isAlive(){
+		return life;
+	}
+	
+	// save the current pet to the disk
+	public void saveToDisk(){
+		try{
+			FileOutputStream fos = new FileOutputStream("pet.pet");
+			ObjectOutputStream oos = new ObjectOutputStream(fos);
+			oos.writeObject(this);
+			oos.close();
+			fos.close();
+		}catch(IOException ioe){
+			ioe.printStackTrace();
+		}
+	}
+	
+	// read a pet from the disk
+	public static Pet loadFromDisk(){
+		Pet pet = null;
+		try{
+			FileInputStream fin = new FileInputStream("pet.pet");
+			ObjectInputStream oin = new ObjectInputStream(fin);
+			pet = (Pet) oin.readObject();
+			oin.close();
+			fin.close();
+		}catch(IOException ioe){
+			// ioe.printStackTrace();
+		}catch(ClassNotFoundException cnfe){
+			cnfe.printStackTrace();
+		}
+		return pet;
+	}
+}

BIN
07 - The Perfect Pet/perfectpet.zip


+ 44 - 0
07 - The Perfect Pet/perfectpet/Main.java

@@ -0,0 +1,44 @@
+import java.util.Scanner;
+
+public class Main{
+	public static void main (String[] args){
+	
+		// read user input
+		Scanner input = new Scanner(System.in);
+		char userinput = 'c';
+		
+		// load existing pet if there is one
+		Pet mypet = Pet.loadFromDisk();
+		if(mypet == null){
+			mypet = new Pet();
+		}
+		
+		// main game loop
+		System.out.println("Welcome to \"The Pet Simulator.\"");
+		while(userinput != 'q' && mypet.isAlive()){
+			System.out.println("Here are your pet's stats:");
+			mypet.printStatus();
+			System.out.println("Enter \'f,\' \'w,\' or \'r\' to feed, water, or rest your pet.");
+			System.out.println("Enter \'q\' to save and quit.");
+			userinput = input.next().charAt(0);
+			if(userinput == 'f'){
+				mypet.feed();
+			}
+			if(userinput == 'w'){
+				mypet.water();
+			}
+			if(userinput == 'r'){
+				mypet.rest();
+			}
+		}
+		
+		// present the bad news
+		if(!mypet.isAlive()){
+			System.out.println("This pet has died.");
+		}
+		
+		// clean up
+		mypet.saveToDisk();
+		input.close();
+	}
+}

+ 14 - 0
07 - The Perfect Pet/perfectpet/Makefile

@@ -0,0 +1,14 @@
+# compiler
+JAVAC = javac
+
+# make first entry first
+all: main
+
+run: all
+	java Main
+
+main:
+	$(JAVAC) *.java
+
+clean:
+	rm *.class

+ 124 - 0
07 - The Perfect Pet/perfectpet/Pet.java

@@ -0,0 +1,124 @@
+import java.io.*;
+
+public class Pet implements java.io.Serializable {
+
+	// serializable version number
+	private static final long serialVersionUID = 1;
+
+	// the pet's stats
+	private int hunger;
+	private int thirst;
+	private int energy;
+	private boolean life;
+	
+	// everything starts off good
+	public Pet(){
+		hunger = 0;
+		thirst = 0;
+		energy = 100;
+		life = true;
+	}
+	
+	// reset the pet's hunger
+	public void feed(){
+		hunger = 0;
+		thirst += 5;
+		energy -= 5;
+		if(hunger > 100 || thirst > 100 || energy < 0){
+			this.kill();
+		}
+	}
+	
+	// reset the pet's thirst
+	public void water(){
+		hunger += 5;
+		thirst = 0;
+		energy -= 5;
+		if(hunger > 100 || thirst > 100 || energy < 0){
+			this.kill();
+		}
+	}
+	
+	// reset the pet's energy
+	public void rest(){
+		hunger += 5;
+		thirst += 5;
+		energy = 100;
+		if(hunger > 100 || thirst > 100 || energy < 0){
+			this.kill();
+		}
+	}
+	
+	// kill the pet
+	public void kill(){
+		hunger = 0;
+		thirst = 0;
+		energy = 0;
+		life = false;
+	}
+	
+	// do nothing
+	public void neglect(){
+		hunger += 5;
+		thirst += 5;
+		energy -= 5;
+		if(hunger > 100 || thirst > 100 || energy < 0){
+			this.kill();
+		}
+	}
+	
+	// print the pet's stats
+	public void printStatus(){
+		if(life){
+			System.out.println("\tHunger: " + hunger);
+			System.out.println("\tThirst: " + thirst);
+			System.out.println("\tEnergy: " + energy);
+		} else{
+			System.out.println("This pet died.");
+		}
+	}
+
+	// helper methods
+	public int getHunger(){
+		return hunger;
+	}
+	public int getThirst(){
+		return thirst;
+	}
+	public int getEnergy(){
+		return energy;
+	}
+	public boolean isAlive(){
+		return life;
+	}
+	
+	// save the current pet to the disk
+	public void saveToDisk(){
+		try{
+			FileOutputStream fos = new FileOutputStream("pet.pet");
+			ObjectOutputStream oos = new ObjectOutputStream(fos);
+			oos.writeObject(this);
+			oos.close();
+			fos.close();
+		}catch(IOException ioe){
+			ioe.printStackTrace();
+		}
+	}
+	
+	// read a pet from the disk
+	public static Pet loadFromDisk(){
+		Pet pet = null;
+		try{
+			FileInputStream fin = new FileInputStream("pet.pet");
+			ObjectInputStream oin = new ObjectInputStream(fin);
+			pet = (Pet) oin.readObject();
+			oin.close();
+			fin.close();
+		}catch(IOException ioe){
+			// ioe.printStackTrace();
+		}catch(ClassNotFoundException cnfe){
+			cnfe.printStackTrace();
+		}
+		return pet;
+	}
+}

BIN
08 - Inheritance Animation/08_inheritance-animation.zip


+ 86 - 0
08 - Inheritance Animation/08_inheritance-animation/AsciiAnim.java

@@ -0,0 +1,86 @@
+//AsciiAnim.java
+
+import java.awt.*;
+import javax.swing.*;
+import java.awt.event.*;
+
+public class AsciiAnim extends JFrame implements ActionListener{
+  
+  AsciiCanvas cnvAnim = new AsciiCanvas();
+  JButton btnPrev = new JButton("prev");
+  JButton btnNext = new JButton("next");
+  JButton btnSave = new JButton("save");
+  JButton btnLoad = new JButton("load");
+  JButton btnAnim = new JButton("animate");
+
+  JPanel pnlSouth = new JPanel();
+  Timer timer = new Timer(100, this);
+
+  boolean animating = false;
+
+  public AsciiAnim(){
+    
+    this.setUpGUI(); 
+    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+    this.setVisible(true);
+    this.setSize(640, 480);
+  } // end constructor
+  
+  public void setUpGUI(){
+    //like it says, set up GUI
+    Container pnlMain = this.getContentPane();
+    
+    pnlSouth.setLayout(new FlowLayout());
+    pnlMain.add(cnvAnim, BorderLayout.CENTER);
+    pnlMain.add(pnlSouth, BorderLayout.SOUTH);
+
+    pnlSouth.add(btnPrev);
+    pnlSouth.add(btnNext);
+    pnlSouth.add(btnAnim);
+    pnlSouth.add(btnSave);
+    pnlSouth.add(btnLoad);
+
+    //add action listeners
+    btnPrev.addActionListener(this);
+    btnNext.addActionListener(this);
+    btnAnim.addActionListener(this);
+    btnSave.addActionListener(this);
+    btnLoad.addActionListener(this);
+
+  } // end setUpGUI
+
+  public void actionPerformed(ActionEvent e){
+    if (e.getSource() == btnPrev){
+      cnvAnim.prevFrame();
+    } else if (e.getSource() == btnNext){  
+      cnvAnim.nextFrame();
+    } else if (e.getSource() == btnAnim){
+      //change the animation status
+      if (timer.isRunning()){  
+        btnAnim.setText("animate");
+        timer.stop();
+        this.animating = false;
+      } else {
+        btnAnim.setText("stop");
+        timer.start();
+        this.animating = true;
+      } // end if
+    } else if (e.getSource() == btnSave){  
+      cnvAnim.save();
+    } else if (e.getSource() == btnLoad){  
+      cnvAnim.load();
+    } else if (this.animating == true){
+      cnvAnim.anim();  
+    } else {  
+      System.out.println("action not defined");
+    } // end if
+  } // end actionPerformed
+
+  public static void main(String[] args){
+    new AsciiAnim();
+  } // end main
+
+
+} // end class def
+
+

+ 59 - 0
08 - Inheritance Animation/08_inheritance-animation/AsciiCanvas.java

@@ -0,0 +1,59 @@
+import java.awt.*;
+import javax.swing.*;
+import java.awt.event.*;
+import java.io.*;
+
+public class AsciiCanvas extends JTextArea implements java.io.Serializable {
+	String[] frames;
+	int curr;
+	public AsciiCanvas(){
+		frames = new String[11];
+		curr = 5;
+	}
+	
+	public void prevFrame(){
+		if(frames.isEmpty()){
+			frames.add(getText());
+			li = frames.listIterator();
+		}
+		if(li.hasPrevious()){
+			System.out.println("Iterator at: " + li.previousIndex());
+		} else {
+			frames.add(getText());
+		}
+		System.out.println(frames.toString());
+		setText("");
+	}
+	
+	public void nextFrame(){
+		if(frames.isEmpty()){
+			frames.add(getText());
+			li = frames.listIterator();
+		}
+		if(li.hasNext()){
+			System.out.println(li.next());
+		} else {
+			frames.add(getText());
+		}
+		System.out.println(frames.toString());
+		setText("");
+	}
+	
+	public void save(){
+		try{
+			FileOutputStream fos = new FileOutputStream("data.dat");
+			ObjectOutputStream oos = new ObjectOutputStream(fos);
+			oos.writeObject(this);
+			oos.close();
+			fos.close();
+		}catch(IOException ioe){
+			ioe.printStackTrace();
+		}
+	}
+	
+	public void load(){
+	}
+	
+	public void anim(){
+	}
+}

+ 41 - 0
08 - Inheritance Animation/08_inheritance-animation/FNode.java

@@ -0,0 +1,41 @@
+public class FNode {
+	String data;
+	FNode next;
+	FNode prev;
+	
+	public FNode(){
+		this.data = "";
+		this.next = this;
+		this.prev = this;
+	}
+	
+	public FNode(String data){
+		this.data = data;
+		this.next = this;
+		this.prev = this;
+	}
+	
+	public void setData(String data){
+		this.data = data;
+	}
+	
+	public void setNext(FNode next){
+		this.next = next;
+	}
+	
+	public void setPrev(FNode prev){
+		this.prev = prev;
+	}
+	
+	public String getData(){
+		return data;
+	}
+	
+	public FNode getNext(){
+		return next;
+	}
+	
+	public FNode getPrev(){
+		return prev;
+	}
+}

+ 86 - 0
08 - Inheritance Animation/AsciiAnim.java

@@ -0,0 +1,86 @@
+//AsciiAnim.java
+
+import java.awt.*;
+import javax.swing.*;
+import java.awt.event.*;
+
+public class AsciiAnim extends JFrame implements ActionListener{
+  
+  AsciiCanvas cnvAnim = new AsciiCanvas();
+  JButton btnPrev = new JButton("prev");
+  JButton btnNext = new JButton("next");
+  JButton btnSave = new JButton("save");
+  JButton btnLoad = new JButton("load");
+  JButton btnAnim = new JButton("animate");
+
+  JPanel pnlSouth = new JPanel();
+  Timer timer = new Timer(100, this);
+
+  boolean animating = false;
+
+  public AsciiAnim(){
+    
+    this.setUpGUI(); 
+    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+    this.setVisible(true);
+    this.setSize(640, 480);
+  } // end constructor
+  
+  public void setUpGUI(){
+    //like it says, set up GUI
+    Container pnlMain = this.getContentPane();
+    
+    pnlSouth.setLayout(new FlowLayout());
+    pnlMain.add(cnvAnim, BorderLayout.CENTER);
+    pnlMain.add(pnlSouth, BorderLayout.SOUTH);
+
+    pnlSouth.add(btnPrev);
+    pnlSouth.add(btnNext);
+    pnlSouth.add(btnAnim);
+    pnlSouth.add(btnSave);
+    pnlSouth.add(btnLoad);
+
+    //add action listeners
+    btnPrev.addActionListener(this);
+    btnNext.addActionListener(this);
+    btnAnim.addActionListener(this);
+    btnSave.addActionListener(this);
+    btnLoad.addActionListener(this);
+
+  } // end setUpGUI
+
+  public void actionPerformed(ActionEvent e){
+    if (e.getSource() == btnPrev){
+      cnvAnim.prevFrame();
+    } else if (e.getSource() == btnNext){  
+      cnvAnim.nextFrame();
+    } else if (e.getSource() == btnAnim){
+      //change the animation status
+      if (timer.isRunning()){  
+        btnAnim.setText("animate");
+        timer.stop();
+        this.animating = false;
+      } else {
+        btnAnim.setText("stop");
+        timer.start();
+        this.animating = true;
+      } // end if
+    } else if (e.getSource() == btnSave){  
+      cnvAnim.save();
+    } else if (e.getSource() == btnLoad){  
+      cnvAnim.load();
+    } else if (this.animating == true){
+      cnvAnim.anim();  
+    } else {  
+      System.out.println("action not defined");
+    } // end if
+  } // end actionPerformed
+
+  public static void main(String[] args){
+    new AsciiAnim();
+  } // end main
+
+
+} // end class def
+
+

+ 59 - 0
08 - Inheritance Animation/AsciiCanvas.java

@@ -0,0 +1,59 @@
+import java.awt.*;
+import javax.swing.*;
+import java.awt.event.*;
+import java.io.*;
+
+public class AsciiCanvas extends JTextArea implements java.io.Serializable {
+	String[] frames;
+	int curr;
+	public AsciiCanvas(){
+		frames = new String[11];
+		curr = 5;
+	}
+	
+	public void prevFrame(){
+		if(frames.isEmpty()){
+			frames.add(getText());
+			li = frames.listIterator();
+		}
+		if(li.hasPrevious()){
+			System.out.println("Iterator at: " + li.previousIndex());
+		} else {
+			frames.add(getText());
+		}
+		System.out.println(frames.toString());
+		setText("");
+	}
+	
+	public void nextFrame(){
+		if(frames.isEmpty()){
+			frames.add(getText());
+			li = frames.listIterator();
+		}
+		if(li.hasNext()){
+			System.out.println(li.next());
+		} else {
+			frames.add(getText());
+		}
+		System.out.println(frames.toString());
+		setText("");
+	}
+	
+	public void save(){
+		try{
+			FileOutputStream fos = new FileOutputStream("data.dat");
+			ObjectOutputStream oos = new ObjectOutputStream(fos);
+			oos.writeObject(this);
+			oos.close();
+			fos.close();
+		}catch(IOException ioe){
+			ioe.printStackTrace();
+		}
+	}
+	
+	public void load(){
+	}
+	
+	public void anim(){
+	}
+}

+ 41 - 0
08 - Inheritance Animation/FNode.java

@@ -0,0 +1,41 @@
+public class FNode {
+	String data;
+	FNode next;
+	FNode prev;
+	
+	public FNode(){
+		this.data = "";
+		this.next = this;
+		this.prev = this;
+	}
+	
+	public FNode(String data){
+		this.data = data;
+		this.next = this;
+		this.prev = this;
+	}
+	
+	public void setData(String data){
+		this.data = data;
+	}
+	
+	public void setNext(FNode next){
+		this.next = next;
+	}
+	
+	public void setPrev(FNode prev){
+		this.prev = prev;
+	}
+	
+	public String getData(){
+		return data;
+	}
+	
+	public FNode getNext(){
+		return next;
+	}
+	
+	public FNode getPrev(){
+		return prev;
+	}
+}

BIN
09 - Final Project/09_final-project.zip


BIN
09 - Final Project/09_final-project/09_final-project.zip


+ 34 - 0
09 - Final Project/09_final-project/Horse.cpp

@@ -0,0 +1,34 @@
+#include <iostream>
+#include <string>
+#include <cstdlib>
+#include <time.h>
+
+#include "Horse.h"
+
+Horse::Horse(){
+	position = 0;
+	isRacing = true;
+}
+
+int Horse::getPosition(){
+	return position;
+}
+
+// flips a coin, advances ~50% of times
+void Horse::advance(){
+	if (rand() % 2){ // either 0 or 1
+		position++;
+	}
+}
+
+bool Horse::getRacing(){
+	return isRacing;
+}
+
+void Horse::race(){
+	isRacing = true;
+}
+
+void Horse::dontRace(){
+	isRacing = false;
+}

+ 18 - 0
09 - Final Project/09_final-project/Horse.h

@@ -0,0 +1,18 @@
+#ifndef _HORSE_H
+#define _HORSE_H
+
+class Horse {
+	public:
+		Horse(); // default constructor
+		bool getRacing();
+		int getPosition();
+		void race();
+		void dontRace();
+        void advance();
+
+	private:
+		int position;
+		bool isRacing;
+};
+
+#endif

+ 96 - 0
09 - Final Project/09_final-project/Main.cpp

@@ -0,0 +1,96 @@
+#include <iostream>
+#include <cstdlib>
+#include <ncurses.h>
+#include <chrono>
+#include <thread>
+#include <time.h>
+#include <cstring>
+
+#include "Horse.h"
+#include "Race.h"
+
+#define WIDTH 1
+#define HEIGHT 1
+
+using namespace std;
+
+int main()
+{
+	// initialize variables
+	Race race = Race();
+	WINDOW *menu_win;
+	int c;
+	startx = 0;
+	starty = 0;
+	menu_win = newwin(HEIGHT, WIDTH, starty, startx);
+	string cppstr = "";
+	char *cstr = 0;
+
+	// ncurses initialization
+	initscr(); // open ncurses virtual screen
+	clear(); // clear the virtual screen
+	noecho(); // disable input echo
+	cbreak(); // break for user input
+	keypad(menu_win, TRUE); // keys are special
+	curs_set(0); // hide the cursor
+
+	// TUI initialization
+	attron(A_STANDOUT); // highlight top row and keyboard shortcuts
+	mvprintw(0, 1, " Steve Corya's hrtui 1.0                     ");
+	mvprintw(5, 0, "^B");
+	mvprintw(5, 20, "^D");
+	mvprintw(5, 40, "^E");
+	attroff(A_STANDOUT); // don't highlight the rest
+	mvprintw(5, 3, "begin race");
+	mvprintw(5, 23, "delete tallys");
+	mvprintw(5, 43, "exit");
+											//	_____
+	cppstr = race.raceToString(); //			|   /	this bit prints the
+	cstr = new char[cppstr.length() + 1]; //	|  / 	race track
+	strcpy(cstr, cppstr.c_str()); //			| /
+	mvprintw(1, 0, cstr); //					|/
+	refresh();
+
+	// main TUI loop
+	while (1)
+	{
+		c = wgetch(menu_win); // get user input
+		switch (c)
+		{
+			case 2: // ^B
+				mvprintw(7, 0, "                             "); // clear
+				srand(time(NULL)); // new random seed every time
+				race = Race();
+				while(!race.isFinished()){ // run the race
+					cppstr = race.raceToString();
+					cstr = new char[cppstr.length() + 1];
+					strcpy(cstr, cppstr.c_str());
+					mvprintw(1, 0, cstr); // output the race
+					race.step();  // all horses advance...
+					std::this_thread::sleep_for(std::chrono::milliseconds(85));
+					refresh(); // print to ncurses
+				}
+				race.logWinner(); // output logfile
+				mvprintw(race.getWinner(), 36, "Horse #%d is the winner!", race.getWinner());
+				refresh();
+				break;
+			case 4: // ^D
+				if(!remove("winners.log")){ // delete the log file
+					mvprintw(7, 0, "log file successfully deleted");
+				}
+				refresh(); // print success
+				break;
+			default: // only three controls
+				break;
+		}
+		if(c == 5){ // exit the TUI loop and the program
+			break;
+		}
+	}
+				 //	____
+	clrtoeol(); //	|  /	ncurses things
+	refresh(); //	| /
+	endwin(); //	|/
+
+	return 0; // the deed is done
+}

+ 23 - 0
09 - Final Project/09_final-project/Makefile

@@ -0,0 +1,23 @@
+# compiler
+CC = g++
+
+# compiler flags
+CFLAGS = -Wall -Werror -std=c++11
+
+# linked libraries
+LL = -lncurses
+
+# make first entry first
+all: main
+
+main: horse.o race.o
+	$(CC) $(CFLAGS) -o hrtui Main.cpp horse.o race.o $(LL)
+
+horse.o: Horse.cpp Horse.h
+	$(CC) $(CFLAGS) -c Horse.cpp -o horse.o
+
+race.o: Race.cpp Race.h
+	$(CC) $(CFLAGS) -c Race.cpp -o race.o
+
+clean:
+	rm main *.o

+ 127 - 0
09 - Final Project/09_final-project/Race.cpp

@@ -0,0 +1,127 @@
+#include <iostream>
+#include <string>
+#include <cstdlib>
+#include <chrono>
+#include <thread>
+#include <fstream>
+
+#include "Race.h"
+#include "Horse.h"
+
+// race as in event and race as in track
+Race::Race(){
+	length = 32; // default length
+	numHorses = 4; // default number of horses
+	horses = new Horse[numHorses]; // make some horses
+}
+
+Race::Race(int length){
+	this->length = length; // defined length
+	this->numHorses = 4; // default number of horses
+	horses = new Horse[numHorses]; // make some horses
+}
+
+// formatted output
+std::string Race::raceToString(){
+	std::string out = "";
+	int i = 0;
+	for (i = 0; i < numHorses; i++){
+		out = out + laneToString(i) + "\n";
+	}
+	return out;
+}
+
+std::string Race::laneToString(int lane){
+	std::string out = "";
+	out = out + std::to_string(lane + 1) + "|";
+	int i = 0;
+	for (i = 0; i < length; i++){
+		// prints the horses number at its latest position
+		if (i == horses[lane].getPosition()){
+			out = out + std::to_string(lane + 1);
+		// prints a lane visual
+		} else {
+			out = out + "-";
+		} // end if
+	} // end for
+	out = out + "|";
+	// out = out + std::endl; // newline and stream flush
+	return out;
+}
+
+// prints one lane
+void Race::printLane(int lane){ // which lane
+	int i = 0;
+	for (i = 0; i < length; i++){
+		// prints the horses number at its latest position
+		if (i == horses[lane].getPosition()){
+			std::cout << lane;
+		// prints a lane visual
+		} else {
+			std::cout << "-";
+		} // end if
+	} // end for
+	std::cout << std::endl; // newline and stream flush
+}
+
+// all the horses flip a coin and advance accordingly
+void Race::step(){
+	int i = 0;
+	// all horses in the race
+	for (i = 0; i < numHorses; i++){
+		horses[i].advance(); // horses know how to advance
+	}
+}
+
+// prints each lane
+void Race::printAllLanes(){
+	int i = 0;
+	for (i = 0; i < numHorses; i++){
+		printLane(i);
+	}
+}
+
+// checks if any horses have won or tied
+bool Race::isFinished(){
+	int i = 0;
+	// all horses in the race
+	for (i = 0; i < numHorses; i++){
+		if (horses[i].getPosition() == length){
+			return true; // one or more winners
+		}
+	}
+	return false;
+}
+
+// who won the race?
+int Race::getWinner(){
+	int i = 0;
+	for (i = 0; i < numHorses; i++){
+		// if horse at i finished...
+		if (horses[i].getPosition() == length){
+			return (i + 1); // winner by number
+		}
+	}
+	return -1;
+}
+
+// prints winner(s)
+void Race::printWinners(){
+	std::cout << "horse(s)";
+	int i = 0;
+	// check all the horses
+	for (i = 0; i < numHorses; i++){
+		// if horse at i finished...
+		if (horses[i].getPosition() == length){
+			std::cout << " " << i; // ...horse at i won!
+		}
+	}
+	std::cout << " won (tied)!" << std::endl;
+}
+
+// log the winner
+void Race::logWinner(){
+	std::ofstream fout ("winners.log", std::ios::app);
+	fout << std::to_string(getWinner()); // log by number not index
+	fout.close();
+}

+ 32 - 0
09 - Final Project/09_final-project/Race.h

@@ -0,0 +1,32 @@
+#ifndef _RACE_H
+#define _RACE_H
+
+#include <list>
+
+#include "Horse.h"
+
+class Race {
+	public:
+		Race(); // default constructor
+		Race(int length); // custom length
+		std::string raceToString(); // formatted output
+		std::string laneToString(int lane); // formatted output
+		bool pause();
+		bool resume();
+		void printLane(int lane);
+        void step();
+        void printAllLanes();
+        bool isFinished();
+        void start();
+		void printWinners();
+		int getWinner();
+		void logWinner(); // opens output file
+
+	private:
+        Horse *horses; // horses
+		bool interrupt;
+        int numHorses; // number of horses (size of array)
+        int length; // length of the track
+};
+
+#endif

BIN
09 - Final Project/09_final-project/Untitled 1.odt


BIN
09 - Final Project/09_final-project/docs.odt


+ 143 - 0
09 - Final Project/09_final-project/horseRace.cpp

@@ -0,0 +1,143 @@
+#include <iostream>
+#include <string>
+#include <cstdlib>
+
+using namespace std;
+
+// horse class
+class Horse{
+	public:
+		// constructor
+		Horse(){
+			position = 0;
+		}
+		
+		// access private position
+		int getPosition(){
+			return position;
+		}
+		
+		// flips a coin, advances ~50% of times
+		void advance(){
+			if (rand() % 2){ // either 0 or 1
+				position++;
+			}
+		}
+	
+	private:
+		int position; // position of horse on track
+};
+
+// race as in event and race as in track
+class Race{
+	public:
+		// constructors
+		Race(){
+			length = 32; // default length
+			numHorses = 4; // default number of horses
+			horses = new Horse[numHorses]; // make some horses
+		}
+		Race(int length){
+			this->length = length; // defined length
+			this->numHorses = 4; // default number of horses
+			horses = new Horse[numHorses]; // make some horses
+		}
+		
+		// get me those horses
+		Horse *getHorses(){
+			return horses;
+		}
+		
+		// prints one lane
+		void printLane(int lane){ // which lane
+			int i = 0;
+			for (i = 0; i < length; i++){
+				// prints the horses number at its latest position
+				if (i == horses[lane].getPosition()){
+					cout << lane;
+				// prints a lane visual
+				} else {
+					cout << ".";
+				} // end if
+			} // end for
+			cout << endl; // newline and stream flush
+		}
+		
+		// all the horses flip a coin and advance accordingly
+		void step(){
+			int i = 0;
+			// all horses in the race
+			for (i = 0; i < numHorses; i++){
+				horses[i].advance(); // horses know how to advance
+			}			
+		}
+		
+		// prints each lane
+		void printAllLanes(){
+			int i = 0;
+			for (i = 0; i < numHorses; i++){
+				printLane(i);
+			}			
+		}
+		
+		// checks if any horses have won or tied
+		bool isFinished(){
+			int i = 0;
+			// all horses in the race
+			for (i = 0; i < numHorses; i++){
+				if (horses[i].getPosition() == length){
+					return true; // one or more winners
+				}
+			}
+			return false;
+		}
+		
+		// this function is not used
+		// it was mentioned in the UML diagram
+		// I prefer to include the run loop in the main function
+		// start the race
+		void start(){
+			while (!this->isFinished()){ // stop if there's a winner
+				this->printAllLanes(); // update CLI
+				this->step(); // all horses advance...
+				cin.ignore(); // ...when the user presses enter
+			}
+		}
+		
+		// prints winner(s)
+		void printWinners(){
+			cout << "horse(s)";
+			int i = 0;
+			// check all the horses
+			for (i = 0; i < numHorses; i++){
+				// if horse at i finished...
+				if (horses[i].getPosition() == length){
+					cout << " " << i; // ...horse at i won!
+				}
+			}
+			cout << " won (tied)!" << endl;
+		}
+		
+	private:
+		Horse *horses; // horses
+		int numHorses; // number of horses (size of array)
+		int length; // length of the track
+};
+
+
+int main(){
+	// random number seed
+	srand(time(NULL));
+	// crate a race
+	Race race = Race();
+	// while the race is underway
+	while(!race.isFinished()){
+		race.printAllLanes(); // update CLI
+		race.step();  // all horses advance...
+		// tell the user what to do
+		cout << "Press enter for another turn:";
+		cin.ignore(); // ...when the user presses enter
+	}
+	race.printWinners(); // print the winners
+    return EXIT_SUCCESS;
+} // end main

BIN
09 - Final Project/09_final-project/hrtui_docs.pdf


BIN
09 - Final Project/09_final-project/project_proposal.pdf


+ 34 - 0
09 - Final Project/Horse.cpp

@@ -0,0 +1,34 @@
+#include <iostream>
+#include <string>
+#include <cstdlib>
+#include <time.h>
+
+#include "Horse.h"
+
+Horse::Horse(){
+	position = 0;
+	isRacing = true;
+}
+
+int Horse::getPosition(){
+	return position;
+}
+
+// flips a coin, advances ~50% of times
+void Horse::advance(){
+	if (rand() % 2){ // either 0 or 1
+		position++;
+	}
+}
+
+bool Horse::getRacing(){
+	return isRacing;
+}
+
+void Horse::race(){
+	isRacing = true;
+}
+
+void Horse::dontRace(){
+	isRacing = false;
+}

+ 18 - 0
09 - Final Project/Horse.h

@@ -0,0 +1,18 @@
+#ifndef _HORSE_H
+#define _HORSE_H
+
+class Horse {
+	public:
+		Horse(); // default constructor
+		bool getRacing();
+		int getPosition();
+		void race();
+		void dontRace();
+        void advance();
+
+	private:
+		int position;
+		bool isRacing;
+};
+
+#endif

+ 92 - 0
09 - Final Project/Main.cpp

@@ -0,0 +1,92 @@
+#include <iostream>
+#include <cstdlib>
+#include <ncurses.h>
+#include <chrono>
+#include <thread>
+#include <time.h>
+#include <cstring>
+
+#include "Horse.h"
+#include "Race.h"
+
+#define WIDTH 1
+#define HEIGHT 1
+using namespace std;
+
+int main()
+{
+	Race race = Race();
+	WINDOW *menu_win;
+	int c;
+	int startx = 0;
+	int starty = 0;
+	menu_win = newwin(HEIGHT, WIDTH, starty, startx);
+	string cppstr = "";
+	char *cstr = 0;
+
+	initscr();
+	clear();
+	noecho();
+	cbreak();
+	keypad(menu_win, TRUE);
+
+	curs_set(0);
+	// refresh();
+	attron(A_STANDOUT);
+	mvprintw(0, 1, " Steve Corya's hrtui 1.0                     ");
+	mvprintw(5, 0, "^B");
+	mvprintw(5, 20, "^D");
+	mvprintw(5, 40, "^E");
+	attroff(A_STANDOUT);
+	mvprintw(5, 3, "begin race");
+	mvprintw(5, 23, "delete tallys");
+	mvprintw(5, 43, "exit");
+	cppstr = race.raceToString();
+	cstr = new char[cppstr.length() + 1];
+	// strcpy(cstr, cppstr.c_str());
+	// mvprintw(1, 0, cstr);
+	refresh();
+
+	while (1)
+	{
+		c = wgetch(menu_win);
+		switch (c)
+		{
+			// case 2:
+			// 	mvprintw(7, 0, "                             ");
+			// 	// srand(time(NULL));
+			// 	race = Race();
+			// 	while(!race.isFinished()){
+			// 		cppstr = race.raceToString();
+			// 		cstr = new char[cppstr.length() + 1];
+			// 		strcpy(cstr, cppstr.c_str());
+			// 		mvprintw(1, 0, cstr);
+			// 		race.step();  // all horses advance...
+			// 		std::this_thread::sleep_for(std::chrono::milliseconds(85));
+			// 		refresh();
+			// 	}
+			// 	race.logWinner();
+			// 	mvprintw(race.getWinner(), 36, "Horse #%d is the winner!", race.getWinner());
+			// 	refresh();
+			// 	break;
+			case 4:
+				if(!remove("winners.log")){
+					mvprintw(7, 0, "log file successfully deleted");
+				}
+				refresh();
+				break;
+			case 5:
+				break;
+			default:
+				mvprintw(7, 0, "character entered is %d", c);
+				break;
+		}
+		if(c == 5){
+			break;
+		}
+	}
+	clrtoeol();
+	refresh();
+	endwin();
+	return 0;
+}

+ 23 - 0
09 - Final Project/Makefile

@@ -0,0 +1,23 @@
+# compiler
+CC = g++
+
+# compiler flags
+CFLAGS = -Wall -Werror -std=c++11
+
+# linked libraries
+LL = -lncurses
+
+# make first entry first
+all: main
+
+main: horse.o race.o
+	$(CC) $(CFLAGS) -o hrtui Main.cpp horse.o race.o $(LL)
+
+horse.o: Horse.cpp Horse.h
+	$(CC) $(CFLAGS) -c Horse.cpp -o horse.o
+
+race.o: Race.cpp Race.h
+	$(CC) $(CFLAGS) -c Race.cpp -o race.o
+
+clean:
+	rm hrtui winners.log *.o

+ 127 - 0
09 - Final Project/Race.cpp

@@ -0,0 +1,127 @@
+#include <iostream>
+#include <string>
+#include <cstdlib>
+#include <chrono>
+#include <thread>
+#include <fstream>
+
+#include "Race.h"
+#include "Horse.h"
+
+// race as in event and race as in track
+Race::Race(){
+	length = 32; // default length
+	numHorses = 4; // default number of horses
+	horses = new Horse[numHorses]; // make some horses
+}
+
+Race::Race(int length){
+	this->length = length; // defined length
+	this->numHorses = 4; // default number of horses
+	horses = new Horse[numHorses]; // make some horses
+}
+
+// formatted output
+std::string Race::raceToString(){
+	std::string out = "";
+	int i = 0;
+	for (i = 0; i < numHorses; i++){
+		out = out + laneToString(i) + "\n";
+	}
+	return out;
+}
+
+std::string Race::laneToString(int lane){
+	std::string out = "";
+	out = out + std::to_string(lane + 1) + "|";
+	int i = 0;
+	for (i = 0; i < length; i++){
+		// prints the horses number at its latest position
+		if (i == horses[lane].getPosition()){
+			out = out + std::to_string(lane + 1);
+		// prints a lane visual
+		} else {
+			out = out + "-";
+		} // end if
+	} // end for
+	out = out + "|";
+	// out = out + std::endl; // newline and stream flush
+	return out;
+}
+
+// prints one lane
+void Race::printLane(int lane){ // which lane
+	int i = 0;
+	for (i = 0; i < length; i++){
+		// prints the horses number at its latest position
+		if (i == horses[lane].getPosition()){
+			std::cout << lane;
+		// prints a lane visual
+		} else {
+			std::cout << "-";
+		} // end if
+	} // end for
+	std::cout << std::endl; // newline and stream flush
+}
+
+// all the horses flip a coin and advance accordingly
+void Race::step(){
+	int i = 0;
+	// all horses in the race
+	for (i = 0; i < numHorses; i++){
+		horses[i].advance(); // horses know how to advance
+	}
+}
+
+// prints each lane
+void Race::printAllLanes(){
+	int i = 0;
+	for (i = 0; i < numHorses; i++){
+		printLane(i);
+	}
+}
+
+// checks if any horses have won or tied
+bool Race::isFinished(){
+	int i = 0;
+	// all horses in the race
+	for (i = 0; i < numHorses; i++){
+		if (horses[i].getPosition() == length){
+			return true; // one or more winners
+		}
+	}
+	return false;
+}
+
+// who won the race?
+int Race::getWinner(){
+	int i = 0;
+	for (i = 0; i < numHorses; i++){
+		// if horse at i finished...
+		if (horses[i].getPosition() == length){
+			return (i + 1); // winner by number
+		}
+	}
+	return -1;
+}
+
+// prints winner(s)
+void Race::printWinners(){
+	std::cout << "horse(s)";
+	int i = 0;
+	// check all the horses
+	for (i = 0; i < numHorses; i++){
+		// if horse at i finished...
+		if (horses[i].getPosition() == length){
+			std::cout << " " << i; // ...horse at i won!
+		}
+	}
+	std::cout << " won (tied)!" << std::endl;
+}
+
+// log the winner
+void Race::logWinner(){
+	std::ofstream fout ("winners.log", std::ios::app);
+	fout << std::to_string(getWinner()); // log by number not index
+	fout.close();
+}

+ 30 - 0
09 - Final Project/Race.h

@@ -0,0 +1,30 @@
+#ifndef _RACE_H
+#define _RACE_H
+
+#include "Horse.h"
+
+class Race {
+	public:
+		Race(); // default constructor
+		Race(int length); // custom length
+		std::string raceToString(); // formatted output
+		std::string laneToString(int lane); // formatted output
+		bool pause();
+		bool resume();
+		void printLane(int lane);
+        void step();
+        void printAllLanes();
+        bool isFinished();
+        void start();
+		void printWinners();
+		int getWinner();
+		void logWinner(); // opens output file
+
+	private:
+        Horse *horses; // horses
+		bool interrupt;
+        int numHorses; // number of horses (size of array)
+        int length; // length of the track
+};
+
+#endif

BIN
09 - Final Project/Untitled 1.odt


BIN
09 - Final Project/docs.odt


BIN
09 - Final Project/horse.o


+ 143 - 0
09 - Final Project/horseRace.cpp

@@ -0,0 +1,143 @@
+#include <iostream>
+#include <string>
+#include <cstdlib>
+
+using namespace std;
+
+// horse class
+class Horse{
+	public:
+		// constructor
+		Horse(){
+			position = 0;
+		}
+		
+		// access private position
+		int getPosition(){
+			return position;
+		}
+		
+		// flips a coin, advances ~50% of times
+		void advance(){
+			if (rand() % 2){ // either 0 or 1
+				position++;
+			}
+		}
+	
+	private:
+		int position; // position of horse on track
+};
+
+// race as in event and race as in track
+class Race{
+	public:
+		// constructors
+		Race(){
+			length = 32; // default length
+			numHorses = 4; // default number of horses
+			horses = new Horse[numHorses]; // make some horses
+		}
+		Race(int length){
+			this->length = length; // defined length
+			this->numHorses = 4; // default number of horses
+			horses = new Horse[numHorses]; // make some horses
+		}
+		
+		// get me those horses
+		Horse *getHorses(){
+			return horses;
+		}
+		
+		// prints one lane
+		void printLane(int lane){ // which lane
+			int i = 0;
+			for (i = 0; i < length; i++){
+				// prints the horses number at its latest position
+				if (i == horses[lane].getPosition()){
+					cout << lane;
+				// prints a lane visual
+				} else {
+					cout << ".";
+				} // end if
+			} // end for
+			cout << endl; // newline and stream flush
+		}
+		
+		// all the horses flip a coin and advance accordingly
+		void step(){
+			int i = 0;
+			// all horses in the race
+			for (i = 0; i < numHorses; i++){
+				horses[i].advance(); // horses know how to advance
+			}			
+		}
+		
+		// prints each lane
+		void printAllLanes(){
+			int i = 0;
+			for (i = 0; i < numHorses; i++){
+				printLane(i);
+			}			
+		}
+		
+		// checks if any horses have won or tied
+		bool isFinished(){
+			int i = 0;
+			// all horses in the race
+			for (i = 0; i < numHorses; i++){
+				if (horses[i].getPosition() == length){
+					return true; // one or more winners
+				}
+			}
+			return false;
+		}
+		
+		// this function is not used
+		// it was mentioned in the UML diagram
+		// I prefer to include the run loop in the main function
+		// start the race
+		void start(){
+			while (!this->isFinished()){ // stop if there's a winner
+				this->printAllLanes(); // update CLI
+				this->step(); // all horses advance...
+				cin.ignore(); // ...when the user presses enter
+			}
+		}
+		
+		// prints winner(s)
+		void printWinners(){
+			cout << "horse(s)";
+			int i = 0;
+			// check all the horses
+			for (i = 0; i < numHorses; i++){
+				// if horse at i finished...
+				if (horses[i].getPosition() == length){
+					cout << " " << i; // ...horse at i won!
+				}
+			}
+			cout << " won (tied)!" << endl;
+		}
+		
+	private:
+		Horse *horses; // horses
+		int numHorses; // number of horses (size of array)
+		int length; // length of the track
+};
+
+
+int main(){
+	// random number seed
+	srand(time(NULL));
+	// crate a race
+	Race race = Race();
+	// while the race is underway
+	while(!race.isFinished()){
+		race.printAllLanes(); // update CLI
+		race.step();  // all horses advance...
+		// tell the user what to do
+		cout << "Press enter for another turn:";
+		cin.ignore(); // ...when the user presses enter
+	}
+	race.printWinners(); // print the winners
+    return EXIT_SUCCESS;
+} // end main

BIN
09 - Final Project/hrtui


BIN
09 - Final Project/hrtui_docs.pdf


BIN
09 - Final Project/project_proposal.pdf


BIN
09 - Final Project/race.o