@@ -0,0 +1,29 @@
#include <stdio.h>
int isPrime(long i);

main() {
long number = 600851475143;
long i;

//This will factor

//This will find out if a number is divisible
for(i = 2L; i < number/2; i++) {
if(number % i == 0 && isPrime(i)) {
printf("%ld", i);
}
}
}//End main()

int isPrime(long i) {
long n;

//Will return 0 if the number is not prime.
for (n = 2L; n*n <= i; n++) {
if (i % n == 0) {
return 0;
}
}
return 1;
} //End isPrime()

@@ -0,0 +1,18 @@
#include <stdio.h>

//Function signatures
int isOdd(int n);

main() {
int i;

printf("n | odd?\n");
for(i = 0; i <= 10; i++) {
printf("%d | %d\n", i, isOdd(i));
}

} //End main()

int isOdd(int n) {
return n % 2;
} //end isOdd
@@ -0,0 +1,31 @@
#include <stdio.h>

main() {
int i;
int total = 0;

//This will run isPrime() for 1 to 1000
for (i = 1; i <= 1000; i++) {
if (isPrime(i)) {
total += 1;
printf("%d ", i);
if (total % 10 == 0) {
printf("\n");
}
}
}
printf("\n");
} //End main()

int isPrime(int i) {
int n;

//Will return 0 if the number is not prime.
for (n = 2; n <= i/2; n++) {
if (i % n == 0) {
return 0;
}
}
return 1;
} //End isPrime()

@@ -0,0 +1,68 @@
#include <stdio.h>

//Function table of contents
int strlen(char* s); //Ln. 49
char* strcpy(char* s1, char* s2); //Ln. 54
char* strcat(char* s1, char* s2); //Ln. 61

void main() {
char s1[100];
char s2[100];
char s3[100];
char catLine[100] = "Hello ";

//Demonstrate strlen(), prints name length.
printf("Enter first name: ");
printf("The name length is: %d\n", strlen(gets(s1)));

//Demonstrate strcpy(), copys a string and prints both
printf("Enter name: ");
strcpy(s2, gets(s1));
printf("s1 = ");
puts(s1);
printf("s2 = ");
puts(s2);

//Demonstrates strcat(), prints the concatonated lines
printf("Enter Name: ");
gets(s1);
printf("Enter Last Name: ");
gets(s2);
printf("Enter RedID: ");
gets(s3);

puts(s1); //This part prints out strings
puts(s2);
puts(s3);

s2[strlen(s2) + 1] = '\0'; //This part appends spaces.
s2[strlen(s2)] = ' ';
s1[strlen(s1) + 1] = '\0';
s1[strlen(s1)] = ' ';

strcat(s2, s3); //This part runs strcat() to combine strings.
strcat(s1, s2);
strcat(catLine, s1);
puts(catLine);
} //End main()

//This will return the numbers of char in the string
int strlen(char* s) {
return (*s == '\0') ? 0 : 1 + strlen(s + 1);
} //End strlen()

//This will copy s2 into s1 and return the address
char* strcpy(char* s1, char* s2) {
int i;

for(i = 0; i <= strlen(s2); i++) s1[i] = s2[i];
} //End strcpy()

//This will concatenate s2 into s1 and return the address of s1
char* strcat(char* s1, char* s2) {
int startpnt = strlen(s1);
int i;

for(i = 0; i <= strlen(s2); i++) s1[i + startpnt] = s2[i];
} //End strcat()

@@ -0,0 +1,23 @@
#include <stdio.h>
#include <wiringPi.h>

#define LED 1

main() {
//Run the initialization for the output
setup();

//This will blink the led at second intervals
while(1) {
digitalWrite(LED, 1);
delay(1000);
digitalWrite(LED, 0);
delay(1000);
}
} //End main()

//This is the setup function to set up the Pi for this program.
void setup() {
if(wiringPiSetup() == -1) exit();
pinMode(LED, output);
} //End setup()
@@ -0,0 +1,30 @@
#include <stdio.h>
int pow(int n, int m);

int main() {
int n;
int m;

printf("Enter n (entering 0 will exit the program): ");
scanf("%d", &n);
//Exit if n is 0
if (n == 0) {
return 0;
}
printf("Enter m: ");
scanf("%d", &m);

//Run power function and return to top
printf("%d\n", pow(n, m));
main();
} //End main()

int pow(int n, int m) {
int total = 1;
int i;

for (i = 1; i <= m; i++) {
total = total * n;
}
return total;
} //End pow()
@@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>

int main() {
int line, n;

for(line=1; line<=10; n++) {
for(line=1; line<=n; line++) {
printf("*");
}
printf("\n");
}
return 0;
}



@@ -0,0 +1,18 @@

#include <stdio.h>
#include <stdlib.h>

int main() {
printf("*\n");
printf("**\n");
printf("***\n");
printf("****\n");
printf("*****\n");
printf("******\n");
printf("*******\n");
printf("********\n");
printf("*********\n");
printf("**********\n");

return 0;
}
@@ -0,0 +1,25 @@
#include <stdio.h>
#include <stdlib.h>

int main()
{
int line=1;
int n;

while(line <= 10) {
n=1;

while(n <= line) {
printf("*");
n++;
}
line++;
printf("\n");
};

return 0;
}




@@ -0,0 +1,14 @@
#include <stdio.h>
int main(){
int rem;
int num;
printf("Enter int to be reversed: ");
scanf("%d", &num);
while(num >= 1){
rem = num % 10;
printf("%d", rem);
num = num / 10;
};
printf("\n");
return 0;
} // main
@@ -0,0 +1,28 @@
#include<stdio.h>

main(){
int n, i;
int sum = 0;

//Take input for max and store in n
printf("Please enter n: ");
scanf("%d", &n);

//Check to see if n is worth checking
while (n == 0){
printf("Please enter a number that's not 0: ");
scanf("%d", &n);
}


//Prepare equation
printf("Sum of squares: ");

//For every integer up to n, add the square
for(i = 1; i <= n; i++){
sum += i * i;
}

printf("%d\n", sum);
}

@@ -0,0 +1,56 @@
#include <stdio.h>
#include <string.h>

//Constants
#define KEYSIZE 6 //key WITH '\0'

//Function prototypes
void getMessage(char* message, FILE *input);
char decrypt(char enc, char key);
int getSize(FILE *file);

main() {
char *message;
char key[KEYSIZE] = "loser";
int i, length;
FILE *enc = fopen("encrypted.txt", "r");
FILE *plain = fopen("plain.txt", "w");

//Setting up message buffer.
message = malloc(1000);
getMessage(message, enc);
length = getSize(enc);

//Converting the ciphertext to plaintext
for(i = 0; i < length; i++) message[i] = decrypt(message[i], key[i % KEYSIZE]);

//Writing message into file
for(i = 0; i < length; i++) fputc(message[i], plain);

printf("Decryption finished.\n");
} //End main()

//Copies the file into the character buffer
void getMessage(char* message, FILE *input) {
int n, character;

while((character = fgetc(input)) != EOF) {
message[n++] = (char) character;
}
} //End getMessage()

//returns decrypted char
char decrypt(char enc, char key) {
return enc ^ key;
} //End encrypt()

//returns the size of the file in bytes
int getSize(FILE *file) {
int n;

fseek(file, 0, SEEK_END);
n = ftell(file);
fseek(file, 0, SEEK_SET);

return n;
} //End getSize()
@@ -0,0 +1,69 @@
#include <stdio.h>
#include <string.h>
#include <wiringPi.h>

//Constants
#define KEYSIZE 15 //key WITH '\0'
#define SUCCESS 0
#define FAILURE 1

//Function prototypes
char encrypt(char plain, char key);
void authenticate();

main() {
char *message;
char key[KEYSIZE] = "FiShEyEpLaCeBo";
int i, length;
FILE *enc = fopen("encrypted.txt", "w");

//WiringPi setup
wiringPiSetup();
pinMode(SUCCESS, INPUT);
pinMode(FAILURE, INPUT);

//Starts authentication process
printf("Please enter credentials on authentication device.\n");
delay(10);
authenticate();


//Setting up message buffer.
message = malloc(1000);
printf("Type message to encrypt: ");
fgets(message, 1000, stdin);
length = strlen(message);

//Converting the string to ciphertext
for(i = 0; i < length; i++) message[i] = encrypt(message[i], key[i % KEYSIZE]);

//Writing message into file
for(i = 0; i < length; i++) fputc(message[i], enc);

printf("Encryption finished.\n");
} //End main()

//returns encrypted char
char encrypt(char plain, char key) {
return plain ^ key;
} //End encrypt()

//Authenticates the user, exits program if authentication fails
void authenticate() {

//Wait for a success/failure signal from the FPGA
while(1) {
if (digitalRead(SUCCESS)) {
printf("==========AUTHORIZED==========\n"); delay(500);
printf("Encrypting/Decrypting message...\n"); delay(500);
return 1;
}
if (digitalRead(FAILURE)) {
printf("==========ACCESS DENIED=========\n"); delay(500);
printf("Intruder disposal drones have been dispatched...\n"); delay(500);
printf("Have a nice day.");
exit(1);
}
}
} //End authenticate()

Binary file not shown.
@@ -0,0 +1,118 @@
#include <iostream>
#include "BST.h"

/**Constructor**/
BST::BST() :
root(0)
{}
/**End constructor**/

//Inserts a node into the bst
bool BST::insert(int i) {
if(root==0) {
root = new TreeNode(i,0,0);
return true;
}
TreeNode* current = root;
TreeNode* previous = 0;
while(current!=0) {
if(i==current->getItem()) return false;
previous = current;
if(i>current->getItem()) current = current->rChild;
else current = current->lChild;
}
if(i>previous->getItem()) previous->rChild = new TreeNode(i,0,0);
else previous->lChild = new TreeNode(i,0,0);
return true;
} //End insert()

bool BST::remove(int i) {
if(!search(i)) return false;
TreeNode* previous = 0;
TreeNode* current = root;
while(current->getItem()!=i) {
previous = current;
current = (current->getItem()>i)?current->lChild : current->rChild;
}
//Case 1: leaf node
if(current->lChild==0 && current->rChild==0) {
if(previous==0) root = 0;
else if (i<previous->getItem())
previous->lChild=0;
else previous->rChild=0;
delete current;
}
//Case 2: one child
else if(current->lChild==0) {
if(previous==0) root = current->rChild;
else if (i<previous->getItem())
previous->lChild=current->rChild;
else previous->rChild=current->rChild;
delete current;
}
else if(current->rChild==0) {
if(previous==0) root = current->lChild;
else if (i<previous->getItem())
previous->lChild=current->lChild;
else previous->rChild=current->rChild;
delete current;
}
else {
int min = BST::findMin(current);
BST::remove(min);
current->item = min;
}
return true;
} //End remove()

//aux function for remove()
int BST::findMin(TreeNode* toFind) {
TreeNode* current = toFind->rChild;
while(current->lChild!=0) current = current->lChild;
return current->getItem();
} //End findMin()

//Returns true if the object is in the tree
bool BST::search(int i) {
return BST::searchNode(root, i);
} //End search()
bool BST::searchNode(TreeNode* cur, int i) {
if(cur==0) return false;
if(cur->getItem()==i) return true;
if(cur->getItem()>i)
return BST::searchNode(cur->lChild, i);
else return BST::searchNode(cur->rChild, i);
}


std::ostream& BST::travInOrder(std::ostream &out) {
return BST::inOrder(out, root) << std::endl;
}
std::ostream& BST::travPreOrder(std::ostream &out) {
return BST::preOrder(out, root) << std::endl;
}
std::ostream& BST::travPostOrder(std::ostream &out) {
return BST::postOrder(out, root) << std::endl;
}

std::ostream& BST::preOrder(std::ostream &out, TreeNode* cur) {
if(cur==0) return out;
out << " " << cur->getItem();
BST::preOrder(out, cur->lChild);
BST::preOrder(out, cur->rChild);
return out;
}
std::ostream& BST::inOrder(std::ostream &out, TreeNode* cur) {
if(cur==0) return out;
BST::inOrder(out, cur->lChild);
out << " " << cur->getItem();
BST::inOrder(out, cur->rChild);
return out;
}
std::ostream& BST::postOrder(std::ostream &out, TreeNode* cur) {
if(cur==0) return out;
BST::postOrder(out, cur->lChild);
BST::postOrder(out, cur->rChild);
out << " " << cur->getItem();
return out;
}
@@ -0,0 +1,25 @@
#include <iostream>
#include "TreeNode.h"

#ifndef BST_H
#define BST_H
class BST {
public:
BST();
bool insert(int i);
bool remove(int i);
bool search(int i);
std::ostream& travInOrder(std::ostream &out) ;
std::ostream& travPreOrder(std::ostream &out) ;
std::ostream& travPostOrder(std::ostream &out) ;

private:
TreeNode* root;
int findMin(TreeNode* toFind);
std::ostream& preOrder(std::ostream &out, TreeNode* cur) ;
std::ostream& inOrder(std::ostream &out, TreeNode* cur) ;
std::ostream& postOrder(std::ostream &out, TreeNode* cur) ;
bool searchNode(TreeNode* cur, int i);

};
#endif
@@ -0,0 +1,238 @@
#BST

##TreeNode.h

```cpp
class TreeNode {
friend class BST;
public:
TreeNode();
TreeNode(int i, TreeNode*R, TreeNode*L);
int getItem() const;
private:
int item;
TreeNode *lChild;
TreeNode *rChild;
};
TreeNode::TreeNode() {
lChild = rChild = NULL;
}
TreeNode::TreeNode(int i, TreeNode *L=0, TreeNode *R=0)
: item(i), lChild(L), rChild(R) { }
int TreeNode::getItem() const {
return item;
}
```

##BST.h

```cpp
#include <iostream>
#include "TreeNode.h"
#ifndef BST_H
#define BST_H
class BST {
public:
BST();
bool insert(int i);
bool remove(int i);
bool search(int i);
std::ostream& travInOrder(std::ostream &out) ;
std::ostream& travPreOrder(std::ostream &out) ;
std::ostream& travPostOrder(std::ostream &out) ;
private:
TreeNode* root;
int findMin(TreeNode* toFind);
std::ostream& preOrder(std::ostream &out, TreeNode* cur) ;
std::ostream& inOrder(std::ostream &out, TreeNode* cur) ;
std::ostream& postOrder(std::ostream &out, TreeNode* cur) ;
bool searchNode(TreeNode* cur, int i);
};
#endif
```

##BST.cpp

```cpp
#include <iostream>
#include "BST.h"
/**Constructor**/
BST::BST() :
root(0)
{}
/**End constructor**/
//Inserts a node into the bst
bool BST::insert(int i) {
if(root==0) {
root = new TreeNode(i,0,0);
return true;
}
TreeNode* current = root;
TreeNode* previous = 0;
while(current!=0) {
if(i==current->getItem()) return false;
previous = current;
if(i>current->getItem()) current = current->rChild;
else current = current->lChild;
}
if(i>previous->getItem()) previous->rChild = new TreeNode(i,0,0);
else previous->lChild = new TreeNode(i,0,0);
return true;
} //End insert()
bool BST::remove(int i) {
if(!search(i)) return false;
TreeNode* previous = 0;
TreeNode* current = root;
while(current->getItem()!=i) {
previous = current;
current = (current->getItem()>i)?current->lChild : current->rChild;
}
//Case 1: leaf node
if(current->lChild==0 && current->rChild==0) {
if(previous==0) root = 0;
else if (i<previous->getItem())
previous->lChild=0;
else previous->rChild=0;
delete current;
}
//Case 2: one child
else if(current->lChild==0) {
if(previous==0) root = current->rChild;
else if (i<previous->getItem())
previous->lChild=current->rChild;
else previous->rChild=current->rChild;
delete current;
}
else if(current->rChild==0) {
if(previous==0) root = current->lChild;
else if (i<previous->getItem())
previous->lChild=current->lChild;
else previous->rChild=current->rChild;
delete current;
}
else {
int min = BST::findMin(current);
BST::remove(min);
current->item = min;
}
return true;
} //End remove()
//aux function for remove()
int BST::findMin(TreeNode* toFind) {
TreeNode* current = toFind->rChild;
while(current->lChild!=0) current = current->lChild;
return current->getItem();
} //End findMin()
//Returns true if the object is in the tree
bool BST::search(int i) {
return BST::searchNode(root, i);
} //End search()
bool BST::searchNode(TreeNode* cur, int i) {
if(cur==0) return false;
if(cur->getItem()==i) return true;
if(cur->getItem()>i)
return BST::searchNode(cur->lChild, i);
else return BST::searchNode(cur->rChild, i);
}
std::ostream& BST::travInOrder(std::ostream &out) {
return BST::inOrder(out, root) << std::endl;
}
std::ostream& BST::travPreOrder(std::ostream &out) {
return BST::preOrder(out, root) << std::endl;
}
std::ostream& BST::travPostOrder(std::ostream &out) {
return BST::postOrder(out, root) << std::endl;
}
std::ostream& BST::preOrder(std::ostream &out, TreeNode* cur) {
if(cur==0) return out;
out << " " << cur->getItem();
BST::preOrder(out, cur->lChild);
BST::preOrder(out, cur->rChild);
return out;
}
std::ostream& BST::inOrder(std::ostream &out, TreeNode* cur) {
if(cur==0) return out;
BST::inOrder(out, cur->lChild);
out << " " << cur->getItem();
BST::inOrder(out, cur->rChild);
return out;
}
std::ostream& BST::postOrder(std::ostream &out, TreeNode* cur) {
if(cur==0) return out;
BST::postOrder(out, cur->lChild);
BST::postOrder(out, cur->rChild);
out << " " << cur->getItem();
return out;
}
```

##main.cpp

```cpp
#include <iostream>
#include <stdlib.h>
#include "BST.cpp"
using namespace std;
int main() {
BST* tree = new BST();
srand (time(NULL));
cout << "Testing insert, and inOrder Traversal" << endl;
for(int i=0; i<20; i++) {
int j = rand()%100;
if(!tree->insert(j))
cout<<"Unsuccessful addition: duplicate of " << j << endl;
}
cout << "testing inOrder transverse" << endl;
tree->travInOrder(cout);
cout << "testing preOrder traverse" << endl;
tree->travPreOrder(cout);
cout << "testing postOrder transverse" << endl;
tree->travPostOrder(cout);
cout << "Searching..." << "Found:" << endl;
for(int i=0; i<=100; i++)
if(tree->search(i)) cout << " "<< i;
cout << endl;
cout << "Deleting... Deleted: " <<endl;
for(int i=0; i<=100; i++)
if(tree->remove(i)) cout << " " << i;
cout << endl;
return 1;
}
```

##Output

```
Testing insert, and inOrder Traversal
Unsuccessful addition: duplicate of 89
testing inOrder transverse
1 7 14 24 25 29 33 37 38 44 52 62 68 76 85 87 89 94 95
testing preOrder traverse
52 29 14 7 1 24 25 38 37 33 44 94 85 76 68 62 87 89 95
testing postOrder transverse
1 7 25 24 14 33 37 44 38 29 62 68 76 89 87 85 95 94 52
Searching...Found:
1 7 14 24 25 29 33 37 38 44 52 62 68 76 85 87 89 94 95
Deleting... Deleted:
1 7 14 24 25 29 33 37 38 44 52 62 68 76 85 87 89 94 95
```
@@ -0,0 +1,31 @@
class TreeNode {
friend class BST;

public:
TreeNode();
TreeNode(int i, TreeNode*R, TreeNode*L);
int getItem() const;

private:
int item;
TreeNode *lChild;
TreeNode *rChild;
};

TreeNode::TreeNode() {
lChild = rChild = NULL;
}

TreeNode::TreeNode(int i, TreeNode *L=0, TreeNode *R=0)
: item(i), lChild(L), rChild(R) { }

int TreeNode::getItem() const {
return item;
}







BIN +13.1 KB compe260/BST/a.out
Binary file not shown.
@@ -0,0 +1,33 @@
#include <iostream>
#include <stdlib.h>
#include "BST.cpp"
using namespace std;

int main() {
BST* tree = new BST();
srand (time(NULL));
cout << "Testing insert, and inOrder Traversal" << endl;
for(int i=0; i<20; i++) {
int j = rand()%100;
if(!tree->insert(j))
cout<<"Unsuccessful addition: duplicate of " << j << endl;
}

cout << "testing inOrder transverse" << endl;
tree->travInOrder(cout);
cout << "testing preOrder traverse" << endl;
tree->travPreOrder(cout);
cout << "testing postOrder transverse" << endl;
tree->travPostOrder(cout);

cout << "Searching..." << "Found:" << endl;
for(int i=0; i<=100; i++)
if(tree->search(i)) cout << " "<< i;
cout << endl;
cout << "Deleting... Deleted: " <<endl;
for(int i=0; i<=100; i++)
if(tree->remove(i)) cout << " " << i;
cout << endl;

return 1;
}
@@ -0,0 +1,12 @@
Testing insert, and inOrder Traversal
Unsuccessful addition: duplicate of 89
testing inOrder transverse
1 7 14 24 25 29 33 37 38 44 52 62 68 76 85 87 89 94 95
testing preOrder traverse
52 29 14 7 1 24 25 38 37 33 44 94 85 76 68 62 87 89 95
testing postOrder transverse
1 7 25 24 14 33 37 44 38 29 62 68 76 89 87 85 95 94 52
Searching...Found:
1 7 14 24 25 29 33 37 38 44 52 62 68 76 85 87 89 94 95
Deleting... Deleted:
1 7 14 24 25 29 33 37 38 44 52 62 68 76 85 87 89 94 95
Binary file not shown.
@@ -0,0 +1,27 @@
class TreeNode {
friend BST;
public:
TreeNode();
TreeNode(int value, TreeNode* leftNode, TreeNode* rightNode);
int getItem() const;

private:
int i;
TreeNode *left, *right;
}; //End TreeNode

TreeNode::TreeNode() {
i = 0;
left = 0;
right = 0;
} //End Constructor
TreeNode::TreeNode(int value, TreeNode* leftNode, TreeNode* rightNode) {
i = value;
left = leftNode;
right = rightNode;
} //End Constructor

int TreeNode::getItem() const {
return i;
} //End getItem

Binary file not shown.
@@ -0,0 +1 @@
\relax
BIN +1.47 KB compe260/bst/lex.dvi
Binary file not shown.
@@ -0,0 +1,70 @@
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian) (format=pdflatex 2014.2.16) 4 NOV 2014 15:12
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**lex.tex
(./lex.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, lo
aded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo
File: size12.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
) (./lex.aux)
\openout1 = `lex.aux'.

LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 2.
LaTeX Font Info: ... okay on input line 2.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 2.
LaTeX Font Info: ... okay on input line 2.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 2.
LaTeX Font Info: ... okay on input line 2.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 2.
LaTeX Font Info: ... okay on input line 2.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 2.
LaTeX Font Info: ... okay on input line 2.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 2.
LaTeX Font Info: ... okay on input line 2.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <12> on input line 10.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <8> on input line 10.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <6> on input line 10.
[1

{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./lex.aux) )
Here is how much of TeX's memory you used:
229 strings out of 495059
2406 string characters out of 3182030
47148 words of memory out of 3000000
3486 multiletter control sequences out of 15000+200000
7651 words of font info for 27 fonts, out of 3000000 for 9000
14 hyphenation exceptions out of 8191
22i,4n,19p,150b,107s stack positions out of 5000i,500n,10000p,200000b,50000s
</usr/share/t
exlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb></usr/share/texlive
/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi12.pfb></usr/share/texlive/texmf
-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb></usr/share/texlive/texmf-dist/f
onts/type1/public/amsfonts/cm/cmsy10.pfb></usr/share/texlive/texmf-dist/fonts/t
ype1/public/amsfonts/cm/cmti12.pfb>
Output written on lex.pdf (1 page, 50775 bytes).
PDF statistics:
28 PDF objects out of 1000 (max. 8388607)
19 compressed objects within 1 object stream
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)

BIN +49.6 KB compe260/bst/lex.pdf
Binary file not shown.
@@ -0,0 +1,25 @@
\documentclass[a4paper,12pt]{article}
\begin{document}

The foundations of the rigorous study of \emph{analysis}
were laid in the nineteenth century, notably by the
mathematicians Cauchy and Weierstrass. Central to the
study of this subject are the formal definitions of
\emph{limits} and \emph{continuity}.

Let $D$ be a subset of $\bf R$ and let
$f \colon D \to \mathbf{R}$ be a real-valued function on
$D$. The function $f$ is said to be \emph{continuous} on
$D$ if, for all $\epsilon > 0$ and for all $x \in D$,
there exists some $\delta > 0$ (which may depend on $x$)
such that if $y \in D$ satisfies
\[ |y - x| < \delta \]
then
\[ |f(y) - f(x)| < \epsilon. \]

One may readily verify that if $f$ and $g$ are continuous
functions on $D$ then the functions $f+g$, $f-g$ and
$f.g$ are continuous. If in addition $g$ is everywhere
non-zero then $f/g$ is continuous.

\end{document}
@@ -0,0 +1,62 @@
#include <iostream>
#include <stdio.h>
using namespace std;

class Date {
/*PRIVATE*******
*FUNCTIONSPACE*/
private:
//Variable declarations
int month, day, year;

//Setting everything back to default
void setDefault() {
month = 1;
day = 1;
year = 2000;
}

/*PUBLIC********
*FUNCTIONSPACE*/
public:
//Constructors: default and specialized
Date() {
month = 1;
day = 1;
year = 2000;
}
Date(month, day, year) {
setMonth(month);
setDay(day);
setYear(2000);
}

//Accessor functions
int getMonth() {
return month;
}
int getDay() {
return day;
}
int getYear() {
return year
}

//Mutator functions.
//Will set to default if invalid.
void setMonth(int newMonth) {
month = newMonth;
if(newMonth > 12 || newMonth < 1)
setDefault();
}
void setDay(int newDay) {
day = newDay;
if(newDay > 31)
setDefault();
}
void setYear(int newYear) {
year = newYear;
if(newYear < 1)
setDefault();
}
}
Binary file not shown.
@@ -0,0 +1,146 @@
#Magic Square

Writeup by **Vincent Chan**, id **815909699**.

##Overview

Write a program that generates magic squares of an odd order. The program will take any odd number above 1 and generate a magic square using the following rules:

1. 1 will be places at the top row, in the middle.
1. Every number after 1 will be place one row up, one column right. The next number is k+1. In this case, 2.
1. If a number goes past the top of the rows and the *j*th column, place that number on the bottom row and the *j*th column.
1. if a number goest past the last column in the nth row, place that number on the leftest column and the nth row.
1. if a number goes past **both** the top row and the last column, place that number under the last number placed. If the space the number to be placed is occupied, place the number under the last number placed.

##magic\_square.cpp

```cpp
#include <iostream>
#include <iomanip>
using namespace std;
main () {
//This will ask for user input and
//verify that it is a valid input.
int order;
cout << "Magic Square Generator\n" << "=====================\n";
cout << "Enter Order of square: ";
cin >> order;
if(order==1 | order%2==0) {
cout << "Invalid number, please enter an odd number greater than 1.\n";
return 0;
}
//This will initialize the square, zeroing out the elements.
int square[order][order];
for(int i=0; i<order; i++)
for(int n=0; n<order; n++)
square[i][n] = 0;
square[0][order/2] = 1;
int nextRow = -1;
int nextColumn = (order/2)+1;
//This will populate the array,
//while also checking for special cases and adjusting.
for(int nextInt=2; nextInt<=(order*order); nextInt++) {
if(nextColumn>=order && nextRow<0) {
nextColumn -= 1;
nextRow += 2;
}
if(nextColumn>=order)
nextColumn = 0;
if(nextRow<0)
nextRow = order-1;
if(square[nextRow][nextColumn]!=0) {
nextColumn -= 1;
nextRow +=2;
}
square[nextRow][nextColumn] = nextInt;
nextRow--;
nextColumn++;
}
//This prints the array once the generation is complete.
for(int i=0; i<order; i++) {
for(int n=0; n<order; n++) {
cout << setw(5);
cout << square[i][n];
}
cout << endl;
}
} //End main
```

##Test Cases

This program was tested on 4 orders:

###Order 5

```
Magic Square Generator
=====================
Enter Order of square: 5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
```

###Order 7

```
Magic Square Generator
=====================
Enter Order of square: 7
30 39 48 1 10 19 28
38 47 7 9 18 27 29
46 6 8 17 26 35 37
5 14 16 25 34 36 45
13 15 24 33 42 44 4
21 23 32 41 43 3 12
22 31 40 49 2 11 20
```

###Order 9

```
Magic Square Generator
=====================
Enter Order of square: 9
47 58 69 80 1 12 23 34 45
57 68 79 9 11 22 33 44 46
67 78 8 10 21 32 43 54 56
77 7 18 20 31 42 53 55 66
6 17 19 30 41 52 63 65 76
16 27 29 40 51 62 64 75 5
26 28 39 50 61 72 74 4 15
36 38 49 60 71 73 3 14 25
37 48 59 70 81 2 13 24 35
```

###Order 11

```
Magic Square Generator
=====================
Enter Order of square: 11
68 81 94 107 120 1 14 27 40 53 66
80 93 106 119 11 13 26 39 52 65 67
92 105 118 10 12 25 38 51 64 77 79
104 117 9 22 24 37 50 63 76 78 91
116 8 21 23 36 49 62 75 88 90 103
7 20 33 35 48 61 74 87 89 102 115
19 32 34 47 60 73 86 99 101 114 6
31 44 46 59 72 85 98 100 113 5 18
43 45 58 71 84 97 110 112 4 17 30
55 57 70 83 96 109 111 3 16 29 42
56 69 82 95 108 121 2 15 28 41 54
```

##Maximum Order

On my computer, I have tested the order. It has shown to work until 1449. An order 1449 or above will trigger a segmentation error.
Binary file not shown.
@@ -0,0 +1,56 @@
#include <iostream>
#include <iomanip>

using namespace std;

main () {
//This will ask for user input and
//verify that it is a valid input.
int order;
cout << "Magic Square Generator\n" << "=====================\n";
cout << "Enter Order of square: ";
cin >> order;
if(order==1 | order%2==0) {
cout << "Invalid number, please enter an odd number greater than 1.\n";
return 0;
}

//This will initialize the square, zeroing out the elements.
int square[order][order];
for(int i=0; i<order; i++)
for(int n=0; n<order; n++)
square[i][n] = 0;
square[0][order/2] = 1;
int nextRow = -1;
int nextColumn = (order/2)+1;

//This will populate the array,
//while also checking for special cases and adjusting.
for(int nextInt=2; nextInt<=(order*order); nextInt++) {
if(nextColumn>=order && nextRow<0) {
nextColumn -= 1;
nextRow += 2;
}
if(nextColumn>=order)
nextColumn = 0;
if(nextRow<0)
nextRow = order-1;
if(square[nextRow][nextColumn]!=0) {
nextColumn -= 1;
nextRow +=2;
}
square[nextRow][nextColumn] = nextInt;
nextRow--;
nextColumn++;
}


//This prints the array once the generation is complete.
for(int i=0; i<order; i++) {
for(int n=0; n<order; n++) {
cout << setw(5);
cout << square[i][n];
}
cout << endl;
}
} //End main
@@ -0,0 +1,64 @@
###Order 5

```
Magic Square Generator
=====================
Enter Order of square: 5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
```

###Order 7

```
Magic Square Generator
=====================
Enter Order of square: 7
30 39 48 1 10 19 28
38 47 7 9 18 27 29
46 6 8 17 26 35 37
5 14 16 25 34 36 45
13 15 24 33 42 44 4
21 23 32 41 43 3 12
22 31 40 49 2 11 20
```

###Order 9

```
Magic Square Generator
=====================
Enter Order of square: 9
47 58 69 80 1 12 23 34 45
57 68 79 9 11 22 33 44 46
67 78 8 10 21 32 43 54 56
77 7 18 20 31 42 53 55 66
6 17 19 30 41 52 63 65 76
16 27 29 40 51 62 64 75 5
26 28 39 50 61 72 74 4 15
36 38 49 60 71 73 3 14 25
37 48 59 70 81 2 13 24 35
```

###Order 11

```
Magic Square Generator
=====================
Enter Order of square: 11
68 81 94 107 120 1 14 27 40 53 66
80 93 106 119 11 13 26 39 52 65 67
92 105 118 10 12 25 38 51 64 77 79
104 117 9 22 24 37 50 63 76 78 91
116 8 21 23 36 49 62 75 88 90 103
7 20 33 35 48 61 74 87 89 102 115
19 32 34 47 60 73 86 99 101 114 6
31 44 46 59 72 85 98 100 113 5 18
43 45 58 71 84 97 110 112 4 17 30
55 57 70 83 96 109 111 3 16 29 42
56 69 82 95 108 121 2 15 28 41 54
```

@@ -0,0 +1,19 @@
#include "Employee.h"

int Employee::getID() {
return employeeID;
}
char Employee::getType() {
return employeeType;
}
int Employee::getSalary() {
return salary;
}
float Employee::getShare() {
return profitShare;
}
std::string Employee::getName() {
return name;
}
float Employee::calculateSalary(int modifier){}

@@ -0,0 +1,29 @@
#include <iostream>
#include <string>

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
class Employee {
protected:
//Every employee will have an
//ID, Type, Salary, profit share, and name.
int employeeID;
char employeeType;
int salary;
float profitShare;
std::string name;
public:
//These will allow us to get the
//variables of the employee
int getID();
char getType();
int getSalary();
float getShare();
std::string getName();

//This is the virtual function to calculate
//salary. Every employee type has a different way of
//calculating salary.
virtual float calculateSalary(int modifier);
}; //End Employee
#endif
@@ -0,0 +1,60 @@
#include "Employee.h"
#include <iostream>
#include <string>

class Owner : public Employee {
public:
Owner(std::string newName) {
employeeType = 'O';
salary = 15000;
profitShare = .60;
employeeID = 1;
name = newName;
}

float calculateSalary(int modifier) {
return salary+(modifier*profitShare);
}
}; //End Owner

class Chef : public Employee {
private:
std::string specialty;
public:
Chef(std::string newName, std::string newSpecialty, int id) {
employeeType = 'C';
salary = 10000;
profitShare = .20;
employeeID = id;
name = newName;
specialty = newSpecialty;
}

float calculateSalary(int modifier) {
return salary+(modifier*profitShare);
}
std::string getSpecialty() {
return specialty;
}
}; //End Chef

class Waiter : public Employee {
private:
int yearsWorked;
public:
Waiter(std::string newName, int years, int id) {
employeeType = 'W';
salary = 3000;
profitShare = 0;
employeeID = id;
name = newName;
yearsWorked = years;
}

int getYearsWorked() {
return yearsWorked;
}
float calculateSalary(int modifier) {
return salary + modifier;
}
}; //End Waiter
@@ -0,0 +1,69 @@
#include "WorkerTypes.cpp"
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main() {
//=====EMPLOYEE INITIALIZATION=====
Employee *employeeDatabase[6] = {
new Owner("Vincent"), new Chef("Chirstina", "Italian", 2), new Chef("Braxel", "French", 3),
new Waiter("Kaitlyn", 3, 4), new Waiter("Daniel", 2, 5), new Waiter("Kathryn", 4, 6)
};

//=====EMPLOYEE LISTING=====
cout << setw(25) << setfill('=') << "" << endl;
cout << "Employee List" << endl;
cout << setw(25) << setfill('=') << "" << endl;
for(int i=0; i<6; i++) {
cout << i+1 <<". " << employeeDatabase[i]->getName() << " - " << employeeDatabase[i]->getType() << endl;
cout << "\t Salray: $" << employeeDatabase[i]->getSalary() << endl;
if(employeeDatabase[i]->getType() == 'C')
cout << "\t Specialty: " << ((Chef*)employeeDatabase[i])->getSpecialty() << endl;
else if(employeeDatabase[i]->getType() == 'W')
cout << "\t Years Worked: " << ((Waiter*)employeeDatabase[i])->getYearsWorked() << endl;
cout << setw(15) << setfill('-') << "" << endl;
}
cout << setw(25) << setfill('=') << "" << endl;
cout << endl;

//=====END OF MONTH REPORT=====
cout << setw(25) << setfill('=') << "" << endl;
cout << "End of Month report" << endl;
cout << setw(25) << setfill('=') << "" << endl;
cout<< "Profits: $6000" << endl;
cout << setw(15) << setfill('-') << "" << endl;

//=====CHEFS AND OWNER=====
for(int i=0; i<3; i++) {
cout << i+1 <<". " << employeeDatabase[i]->getName() << " - " << employeeDatabase[i]->getType() << endl;
cout << "\t Salray: $" << employeeDatabase[i]->getSalary() << endl;
cout << "\t Profit Share: %" << employeeDatabase[i]->getShare()*100 << endl;
cout << "\t Net Pay: $" << employeeDatabase[i]->calculateSalary(6000) << endl;
cout << setw(15) << setfill('-') << "" << endl;
}

//=====WAITERS=====
cout << "4. " << employeeDatabase[3]->getName() << " - " << employeeDatabase[3]->getType() << endl;
cout << "\t Salray: $" << employeeDatabase[3]->getSalary() << endl;
cout << "\t Tips earned: $1000" << endl;
cout << "\t Net Pay: $" << employeeDatabase[3]->calculateSalary(1000) << endl;
cout << setw(15) << setfill('-') << "" << endl;

cout << "5. " << employeeDatabase[4]->getName() << " - " << employeeDatabase[4]->getType() << endl;
cout << "\t Salray: $" << employeeDatabase[4]->getSalary() << endl;
cout << "\t Tips earned: $1500" << endl;
cout << "\t Net Pay: $" << employeeDatabase[4]->calculateSalary(1500) << endl;
cout << setw(15) << setfill('-') << "" << endl;

cout << "6. " << employeeDatabase[5]->getName() << " - " << employeeDatabase[5]->getType() << endl;
cout << "\t Salray: $" << employeeDatabase[5]->getSalary() << endl;
cout << "\t Tips earned: $1700" << endl;
cout << "\t Net Pay: $" << employeeDatabase[5]->calculateSalary(1700) << endl;
cout << setw(15) << setfill('-') << "" << endl;

cout << setw(25) << setfill('=') << "" << endl;
cout << endl;
}

Binary file not shown.
@@ -0,0 +1,65 @@
=========================
Employee List
=========================
1. Vincent - O
Salray: $15000
---------------
2. Chirstina - C
Salray: $10000
Specialty: Italian
---------------
3. Braxel - C
Salray: $10000
Specialty: French
---------------
4. Kaitlyn - W
Salray: $3000
Years Worked: 3
---------------
5. Daniel - W
Salray: $3000
Years Worked: 2
---------------
6. Kathryn - W
Salray: $3000
Years Worked: 4
---------------
=========================

=========================
End of Month report
=========================
Profits: $6000
---------------
1. Vincent - O
Salray: $15000
Profit Share: %60
Net Pay: $18600
---------------
2. Chirstina - C
Salray: $10000
Profit Share: %20
Net Pay: $11200
---------------
3. Braxel - C
Salray: $10000
Profit Share: %20
Net Pay: $11200
---------------
4. Kaitlyn - W
Salray: $3000
Tips earned: $1000
Net Pay: $4000
---------------
5. Daniel - W
Salray: $3000
Tips earned: $1500
Net Pay: $4500
---------------
6. Kathryn - W
Salray: $3000
Tips earned: $1700
Net Pay: $4700
---------------
=========================

BIN +13.1 KB compe260/staQue/a.out
Binary file not shown.
@@ -0,0 +1,72 @@
#include <iostream>
#include <iomanip>
#include "staQue.h"
using namespace std;

int main() {
staQue list;
list.insert(1);
list.insert(3);
list.insert(2);
list.insert(4);
list.insert(6);
list.insert(8);
list.insert(9);
cout << setw(15);
cout << "=====" << "Test1" << "====" << "\n";
cout << setw(12);
list.printQue();
cout << "[+] First remove from FRONT: " << list.popFront() << "\n";
cout << "[+] Second remove from FRONT: " << list.popFront() << "\n";
cout << "[+] Third remove from BACK: " << list.popBack() << "\n";
cout << endl;

staQue list1;
list1.insert(2);
list1.insert(51);
list1.insert(100);
list1.insert(191);
list1.insert(1337);
cout << setw(15);
cout << "=====" << "Test2" << "====" <<"\n";
cout << setw(11);
list1.printQue();
cout << "[+] First remove from FRONT: " << list1.popFront() << "\n";
cout << "[+] Second remove from BACK: " << list1.popBack() << "\n";
cout << "[+] Third remove from BACK: " << list1.popBack() << "\n";
cout << endl;

staQue list2;
list2.insert(20);
list2.insert(49);
list2.insert(30);
list2.insert(93);
cout << setw(15);
cout << "=====" << "Test3" << "====" <<"\n";
cout << setw(13);
list2.printQue();
cout << "[+] First remove from FRONT: " << list2.popFront() << "\n";
cout << "[+] Second remove from FRONT: " << list2.popFront() << "\n";
cout << "[+] Third remove from FRONT: " << list2.popFront() << "\n";
cout << endl;

staQue list3;
list3.insert(80);
list3.insert(9);
list3.insert(343);
list3.insert(23);
cout << setw(15);
cout << "=====" << "Test4" << "====" <<"\n";
cout << setw(13);
list3.printQue();
cout << "[+] First remove from BACK: " << list3.popBack() << "\n";
cout << "[+] Second remove from BACK: " << list3.popBack() << "\n";
cout << "[+] Third remove from BACK: " << list3.popBack() << "\n";
cout << endl;



return 1;
}


@@ -0,0 +1,24 @@
=====Test1====
8 6 4 2 1 3 9
[+] First remove from FRONT: 8
[+] Second remove from FRONT: 6
[+] Third remove from BACK: 9

=====Test2====
100 2 51 191 1337
[+] First remove from FRONT: 100
[+] Second remove from BACK: 1337
[+] Third remove from BACK: 191

=====Test3====
30 20 49 93
[+] First remove from FRONT: 30
[+] Second remove from FRONT: 20
[+] Third remove from FRONT: 49

=====Test4====
80 9 343 23
[+] First remove from BACK: 23
[+] Second remove from BACK: 343
[+] Third remove from BACK: 9

@@ -0,0 +1,73 @@
#include <iostream>
#include "staQue.h"

void staQue::insert(int data) {
(data%2)?addBack(data) : addFront(data);
} //End staQueue

void staQue::addFront(int data) {
Node *newData = new Node;
newData->data = data;
newData->prev = newData->next = 0;
if(size==0) head = tail = newData;
else {
head->prev = newData;
newData->next = head;
head = newData;
}
size++;
} //End addFront()

void staQue::addBack(int data) {
Node *newData = new Node;
newData->data = data;
newData->prev = newData->next = 0;
if(size==0) head = tail = newData;
else {
tail->next = newData;
newData->prev = tail;
tail = newData;
}
size++;
} //End addBack()

int staQue::popFront() {
if(size==0) return 0;
int temp = head->data;
Node *toDel = head;
head = head->next;
head->prev = 0;
size--;
delete toDel;
return temp;
} //End popFront()

int staQue::popBack() {
if(size==0) return 0;
int temp = tail->data;
Node *toDel = tail;
tail = tail->prev;
tail->next = 0;
size--;
delete toDel;
return temp;
} //End popBack()

void staQue::printQue() {
staQue::print(staQue::head);
} //End printQue()

void staQue::print(Node* node) {
if(node==0) {
std::cout << std::endl;
return;
}
int temp = node->data;
std::cout << temp << " ";
staQue::print(node->next);
} //End print()





@@ -0,0 +1,38 @@
#ifndef STAQUE_H
#define STAQUE_H
class staQue {
private:
class Node {
public:
int data;
Node *next, *prev;
};

public:
Node *head;
Node *tail;
int size;

//Constructor
staQue() {
size = 0;
} //End constructor

//Insert.
void insert(int data);
//Pop from the front
int popFront();
//Pop from the back
int popBack();
//Print the queue
void printQue();

private:
//Insert front
void addFront(int data);
//Insert back
void addBack(int data);
//The printing function
void print(Node*);
}; //End staQue
#endif
Binary file not shown.
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.1790745111">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.1790745111" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1790745111" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug">
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1790745111." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.53285750" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.308170894" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
<builder buildPath="${workspace_loc:/home4/Debug}" id="cdt.managedbuild.target.gnu.builder.exe.debug.909322083" managedBuildOn="true" name="Gnu Make Builder.Debug" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.727441446" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.731746302" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.1849797508" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.exe.debug.option.debugging.level.1962657753" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.633690757" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug">
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.916969948" superClass="gnu.c.compiler.exe.debug.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.exe.debug.option.debugging.level.991027062" superClass="gnu.c.compiler.exe.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1199765736" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.673492685" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug">
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.472273319" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.33808897" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug"/>
<tool id="cdt.managedbuild.tool.gnu.assembler.exe.debug.1581441013" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.2090603541" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.config.gnu.exe.release.1638191676">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.1638191676" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.1638191676" name="Release" parent="cdt.managedbuild.config.gnu.exe.release">
<folderInfo id="cdt.managedbuild.config.gnu.exe.release.1638191676." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.194670815" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.1958270982" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
<builder buildPath="${workspace_loc:/home4/Release}" id="cdt.managedbuild.target.gnu.builder.exe.release.440838344" managedBuildOn="true" name="Gnu Make Builder.Release" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1909778310" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.2066246863" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
<option id="gnu.cpp.compiler.exe.release.option.optimization.level.966454320" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
<option id="gnu.cpp.compiler.exe.release.option.debugging.level.2098845843" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.1370176007" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.218104847" superClass="gnu.c.compiler.exe.release.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.exe.release.option.debugging.level.1903312009" superClass="gnu.c.compiler.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1911297850" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.2120423750" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release">
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1403663945" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.1864374633" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release"/>
<tool id="cdt.managedbuild.tool.gnu.assembler.exe.release.154763964" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1207816684" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="home4.cdt.managedbuild.target.gnu.exe.509342949" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1638191676;cdt.managedbuild.config.gnu.exe.release.1638191676.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.1370176007;cdt.managedbuild.tool.gnu.c.compiler.input.1911297850">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1790745111;cdt.managedbuild.config.gnu.exe.debug.1790745111.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.633690757;cdt.managedbuild.tool.gnu.c.compiler.input.1199765736">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
</cproject>
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>home4</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,169 @@
.global _addLargeNumbers
_addLargeNumbers:
pushl %ebp
movl %esp, %ebp

//Pre-process first string
movl 8(%ebp), %esi
pushl %esi
call _strLen
pushl %eax
call _verifyString
cmp $0 , %eax
je notNum
call _shiftRight
addl $4, %esp
//Pre-process second string
movl 12(%ebp), %esi
pushl %esi
call _strLen
pushl %eax
call _verifyString
cmp $0 , %eax
je notNum
call _shiftRight
addl $4, %esp
//pop second string to %edx
popl %edx
popl %esi
movl 16(%ebp), %edi
// 2. left align after add
// 3. cleanup and return

//This part is for after the shift
//%esi = numbers 1, %edx = numbers 2
//%edi = result and %ecx = counter
movl $254, %ecx
addLoop:
cmp $0 , %ecx
jl doneAdding
movb (%esi,%ecx,1), %al
movb (%edx,%ecx,1), %ah
addb %al, %ah
movb %ah, (%edi,%ecx,1)
dec %ecx
jmp addLoop
//We will not account for overflows
//Note that should the most signifigant number
//overflow, the overflow will not be accounted for.
doneAdding:
movl $254, %ecx
doneAddingLoop:
cmp $0 , %ecx
je lastCheck
subb $48, (%edi,%ecx,1)
cmp $57, (%edi,%ecx,1)
jg overflow
dec %ecx
jmp doneAddingLoop
overflow:
subb $10, (%edi,%ecx,1)
dec %ecx
addb $1 , (%edi,%ecx,1)
jmp doneAddingLoop
lastCheck:
subb $48, (%edi,%ecx,1)
cmp $57, (%edi,%ecx,1)
jg lastOverflow
jmp cleanUp
lastOverflow:
subb $10, (%edi,%ecx,1)
jmp cleanUp
//Left shift
cleanUp:
cmp $48, (%edi,%ecx,1)
jg foundStart
inc %ecx
jmp cleanUp
foundStart:
xorl %ebx, %ebx
leftShift:
movb (%edi,%ecx,1), %al
movb %al, (%edi,%ebx,1)
inc %ebx
inc %ecx
cmp $255, %ecx
je allDone

allDone:
movl $0 , (%edi,%ecx,1)
leave
ret
notNum:
xorl %eax, %eax
leave
ret


//shiftRight
//uses: %esi, %ebx, %ecx
.global _shiftRight
_shiftRight:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %ebx
movl 12(%ebp), %esi
movl $255, %ecx
shift:
cmp $0 , %ebx
jl fill
movb (%esi,%ebx,1), %al
movb %al, (%esi,%ecx,1)
dec %ecx
dec %ebx
jmp shift
fill:
cmp $0 , %ecx
jl doneShift
movb $48, (%esi,%ecx,1)
dec %ecx
jmp fill
doneShift:
leave
ret

//This will return the string
//Length, index of null
//push string to be compared
.global _strLen
_strLen:
push %ebp
movl %esp, %ebp
movl 8(%ebp), %edi
movl $256, %ecx
movl $257, %eax
movb $0 , %al
cld
repne scasb
subl %ecx, %eax
dec %eax
leave
ret

//Verifies that the string
//is a number.
//push string, then counter.
.global _verifyString
_verifyString:
push %ebp
movl %esp, %ebp
movl 8(%ebp), %ecx
movl 12(%ebp), %edi
xorl %eax, %eax
dec %ecx
verifyNext:
cmp $0 , %ecx
jl done
cmpb $48, (%edi, %ecx, 1)
jl notAString
cmpb $57, (%edi, %ecx, 1)
jg notAString
dec %ecx
jmp verifyNext
done:
inc %eax
notAString:
leave
ret


@@ -0,0 +1,146 @@
.global _addLargeNumbers
_addLargeNumbers:

//ESI = numbers 1
//EBX = numbers 2
//EDI = RESULT
//EDX = numbers 1 last index
//EAX = numbers 2 last index
//ECX = result last index
push %ebp
movl %esp, %ebp
movl 8(%ebp), %esi
movl 12(%ebp), %ebx
//This section gets the string length and verifies that
//the string is a number.
pushl %esi
call _strLen
pushl %eax
call _verifyString
cmp $0, %eax
je notNum
popl %edx
addl $4, %esp

pushl %ebx
call _strLen
pushl %eax
call _verifyString
cmp $0, %eax
je notNum
popl %ecx
addl $4, %esp

//This will compare the strings
//copies the larger string to the result
//After this, ebx will be the adder string.
movl 16(%ebp), %edi
cmp %edx, %ecx
jg bGreater
xchg %edx, %ecx
jmp cpy
bGreater:
xchg %esi, %ebx
cpy:
pushl %edx
pushl %edi
pushl %esi
pushl %ecx
call _cpyStr
popl %ecx
addl $4, %esp
popl %edi
popl %edx
movl %ebx, %esi

//This will iterate through the arrays and add
//the numbers.
pushl %edx
addLoop:
cmp $0, %edx
jl postProcess
movb (%esi, %edx, 1), %al
movb (%edi, %ecx, 1), %ah
addb %al, %ah
movb %ah, (%edi, %ecx, 1)
subb $48, (%edi, %ecx, 1)
dec %ecx
dec %edx
jmp addLoop

postProcess:
popl %edx
processLoop:
cmp $0, %edx
je doneWithEverything
cmpb $57, (%edi,%edx,1)
jg overflow
dec %edx
jmp processLoop

overflow:
subb $10, (%edi,%edx,1)
dec %edx
addb $1, (%edi,%edx,1)
jmp processLoop

notNum:
xorl %eax, %eax
doneWithEverything:
movl %edi, %eax
leave
ret


.global _strLen
_strLen:
push %ebp
movl %esp, %ebp
movl 8(%ebp), %edi
movl $256, %ecx
movl $257, %eax
movb $0, %al
cld
repne scasb
subl %ecx, %eax
dec %eax
leave
ret


.global _verifyString
_verifyString:
push %ebp
movl %esp, %ebp
movl 8(%ebp), %ecx
movl 12(%ebp), %edi
xorl %eax, %eax
dec %ecx
verifyNext:
cmp $0, %ecx
jl done
cmpb $48, (%edi, %ecx, 1)
jl notAString
cmpb $57, (%edi, %ecx, 1)
jg notAString
dec %ecx
jmp verifyNext
done:
inc %eax
notAString:
leave
ret

.global _cpyStr
_cpyStr:
push %ebp
movl %esp, %ebp
movl 8(%ebp), %ecx
movl 12(%ebp), %esi
movl 16(%ebp), %edi
cld
rep movsb
leave
ret


@@ -0,0 +1,27 @@
.global _shiftRight
_shiftRight:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %esi
movl 12(%ebp), %ebx
movl $255, %ecx

shift:
cmp $0 , %ebx
jl fill
movb (%esi,%ebx,1), %al
movb %al, (%esi,%ecx,1)
dec %ecx
dec %ebx
jmp shift

fill:
cmp $0 , %ecx
jl doneShift
movb $48, (%esi,%ecx,1)
dec %ecx
jmp fill

doneShift:
leave
ret
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <string.h>

//Heap var
int *intPointer;

void main() {
int intVar1;
int intVar2;
short shortVar1;
short shortVar2;
float floatVar1;
float floatVar2;
char nameVar[30];
int intVar3;
char *charPointer;

//These variables are allocated onto the stack, and will have a high memory address
intVar1=1;
intVar2=2;
shortVar1=1;
shortVar2=2;
floatVar1=1;
floatVar2=4;
intVar3=10;

//These variables are allocated on the heap, and will have a low memory address
intPointer=(int*) malloc(1000);
charPointer=(char*) malloc(1000);
strcpy(charPointer,"Yusuf Ozturk");

//Print addresses of all variables
printf("Heap variables\n==============\n");
printf("[%014p] -> intPointer\n", intPointer);
printf("[%014p] -> charPointer\n", charPointer);
printf("\n");
printf("Stack variables\n==============\n");
printf("[%014p] -> intVar1\n", &intVar1);
printf("[%014p] -> intVar2\n", &intVar2);
printf("[%014p] -> shortVar1\n", &shortVar1);
printf("[%014p] -> shortVar2\n", &shortVar2);
printf("[%014p] -> floatVar1\n", &floatVar1);
printf("[%014p] -> floatVar2\n", &floatVar2);
printf("[%014p] -> nameVar\n", nameVar);
printf("[%014p] -> intVar3\n", &intVar3);
} //End main()

@@ -0,0 +1,55 @@
#include <stdio.h>

//Function Prototypes
int isNumber(char*); //Ln. 9
int compare(int, int); //Ln. 14
int countOnes(int); //Ln. 19
int twinPrimes(int*, int); //Ln. 24

//This will return 1 if the char is a number. 0 if not.
int isNumber(char *c) {
return ('0'<=c && c<='9');
} //End isNumber()

//This will compare two functions. Returns 1 if a>b, 0 if a==b, and -1 if a<b.
int compare(int a, int b) {
return (a>b)?1 : (a<b)?-1 : 0;
} //End compare()

//This will return the number of 1s in the binary form of the given int
int countOnes(int number) {
return (number==0)?0 : (unsigned)number%2 + countOnes((unsigned)number>>1);
} //End countOnes()

//Returns the address of an array containing twin primes up to the specified int b
int twinPrimes(int *twinPrimeNumbers, int numberofTwinPrimes) {
//These are the base conditions.
if(numberofTwinPrimes<1) return twinPrimeNumbers;
twinPrimeNumbers[0] = 5;

//This for loop will interate through twin primes and popular the array until the specified number is reached.
for(int i=1; i<numberofTwinPrimes; i++) {
int current = twinPrimeNumbers[i-1]+2;
int previous = current-2;

//This while loop will return the next twin prime.
while(666) {
//This is the prime check for the current
int primeCur = 1;
for(int j=2; j<current/2; j++)
if(current%j==0) primeCur=0;
int primePrev = 1;
for(int k=2; k<previous/2; k++)
if(previous%k==0) primePrev=0;

//This compares the two primes and breaks the while loop if they are a twin prime, and continues to the next iteration if not.
if(primeCur && primePrev) {
twinPrimeNumbers[i] = current;
break;
}
current++;
previous++;
}
}
return twinPrimeNumbers;
} //End twinPrimes()
@@ -0,0 +1,15 @@
#include "BitManipulations.h"

void invertBits(uint32_t *intData) {
*intData = ~(*intData);
} //End invertBits()

void writeinBinary(uint32_t inData) {
int i;
for(i=31; i>=0; i--)
printf("%d", (inData>>i)%2);
} //End writeinBinary()

void setBit(uint32_t *inData, uint32_t bitPosition, uint32_t value) {
*inData = (value==0)?*inData&~(1<<bitPosition-1) : *inData|(1<<bitPosition-1);
} //End setBit()
BIN +7.38 KB compe271/hw3/BitMan
Binary file not shown.
@@ -0,0 +1,39 @@
/*
* BitManipulations.c
*
* Created on: Feb 8, 2013
* Author: yozturk
*/

#include <stdio.h>
#include "BitManipulations.h"



void main(int *argc, char **argv)
{
uint32_t Number;
uint32_t bitPosition;
uint32_t value;


value = 0;
bitPosition = 30;
Number = 15345;

printf("Binary number:");
writeinBinary(Number) ; // Print the number in Binary
printf("\ninverted:");
invertBits(&Number); // Take 1's complement of the Number

writeinBinary(Number) ; // Print the number in Binary
printf("\nsetbit:");
setBit(&Number, bitPosition,value); // set bit in bitposition to value

writeinBinary(Number) ; // Print the number in Binary
printf("\n");



}

@@ -0,0 +1,17 @@
/*
* BitManipulations.h
*
* Created on: Feb 8, 2013
* Author: yozturk
*/

#ifndef BITMANIPULATIONS_H_
#define BITMANIPULATIONS_H_


typedef unsigned int uint32_t;
typedef unsigned short uint16_t;



#endif /* BITMANIPULATIONS_H_ */
@@ -0,0 +1,44 @@
.global _isNumber
_isNumber:
pushl %ebp
movl %esp, %ebp
xorl %eax, %eax
movl 8(%ebp), %ebx
cmp $9 , %ebx
jg done
cmp $0 , %ebx
jl done
inc %eax

done:
movl %ebp, %esp
popl %ebp
ret

.global _compare
_compare:
pushl %ebp
movl %esp, %ebp
xorl %eax, %eax
movl 8(%ebp), %ebx
movl 16(%ebp), %edx
cmp (%ebx), %edx
jg bGreater
jl aGreater
je done

bGreater:
dec %eax
jmp done

aGreater:
inc %eax

done:
movl %ebp, %esp
popl %ebp
ret

.global _countOnes
_countOnes:

@@ -0,0 +1,11 @@
#include <stdio.h>

extern int isNumber(char);

main () {
printf("%d", isNumber('c'));
printf("%d", isNumber('8'));
printf("%d", isNumber('9'));
printf("%d", isNumber('0'));
}

@@ -0,0 +1,20 @@
.section data

numAsc:
.long 48
.long 57


.text
.align

.global _isNumber:
_isNumber:
push %ebp
movl %esp, %ebp
lea 8(%ebp), (%eax)
leave
ret



Empty file.

Large diffs are not rendered by default.

@@ -0,0 +1,67 @@
abstract public class GameCharacter {

//Variable declarations that initialize the variables.
private int health = 100, weight = 50, happiness = 75;

//This will check and set the characteristic
public void modifyCharacteristic(int changeAmount, String characteristic) {
//This will check and modify the characteristics, if valid.
switch(characteristic.toLowerCase()) {
case "health":
isValid(changeAmount, health);
setHealth(changeAmount);
break;
case "weight":
isValid(changeAmount, weight);
setWeight(changeAmount);
break;
case "happiness":
isValid(changeAmount, happiness);
setHappiness(changeAmount);
break;
default:
throw new IllegalArgumentException("Invalid char.");
}
} //End modifyCharacteristic()

//These are the get functions
public int getHealth() {
return health;
} //End getHealth()
public int getWeight() {
return weight;
} //End getWeight()
public int getHappiness() {
return happiness;
} //End getHappiness()

//This are the set functions
private void setHealth(int changeAmount) {
this.health += changeAmount;
} //End setHealth()
private void setWeight(int changeAmount) {
this.weight += changeAmount;
} //End setWeight()
private void setHappiness(int changeAmount) {
this.happiness += changeAmount;
} //End setHappiness()

//This will throw an exception if illegal change happens
private boolean isValid(int changeAmount, int characteristic) {
if (0 <= (characteristic + changeAmount)
&& (characteristic + changeAmount) <= 100) {
return true;
} else {
throw new IllegalArgumentException("Exceeds bounds.");
}
} //End isValid()

//This will make a sad noise.
public void makeSadNoise() {
System.out.println(":(");
} //End makeSadNoise()

//A signature for makeHappyNoise()
abstract public void makeHappyNoise();

} //End class GameCharacter
@@ -0,0 +1,15 @@
public class GameCharacterTester2 {

public static void main(String[] args) {
//====Step 1: Create instances====
System.out.println("Creating new characters");
DogCharacter dixie = new DogCharacter();
CatCharacter nyan = new CatCharacter();
AlienCharacter et = new AlienCharacter();
DogCharacter dixie2 = new DogCharacter(50, 50, 50);
//Error, bound too low
System.out.println("Creating an already-dead alien");
AlienCharacter et2 = new AlienCharacter(-1, 50, 50);

} //End main()
} //End class GameCharacterTester
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
@@ -0,0 +1,59 @@
public class GameCharacter {

//Variable declarations that initialize the variables.
private int health = 100, weight = 50, happiness = 75;

//This will check and set the characteristic
public void modifyCharacteristic(int changeAmount, String characteristic) {
//This will check and modify the characteristics, if valid.
switch(characteristic.toLowerCase()) {
case "health":
isValid(changeAmount, health);
setHealth(changeAmount);
break;
case "weight":
isValid(changeAmount, weight);
setWeight(changeAmount);
break;
case "happiness":
isValid(changeAmount, happiness);
setWeight(changeAmount);
break;
default:
throw new IllegalArgumentException("Invalid char.");
}
} //End modifyCharacteristic()

//These are the get functions
public int getHealth() {
return health;
} //End getHealth()
public int getWeight() {
return weight;
} //End getWeight()
public int getHappiness() {
return happiness;
} //End getHappiness()

//This are the set functions
private void setHealth(int changeAmount) {
this.health += changeAmount;
} //End setHealth()
private void setWeight(int changeAmount) {
this.weight += changeAmount;
} //End setWeight()
private void setHappiness(int changeAmount) {
this.happiness += changeAmount;
} //End setHappiness()

//This will throw an exception if illegal change happens
private boolean isValid(int changeAmount, int characteristic) {
if (0 <= (characteristic + changeAmount)
&& (characteristic + changeAmount) <= 100) {
return true;
} else {
throw new IllegalArgumentException("Exceeds bounds.");
}
} //End isValid()

} //End class GameCharacter
@@ -0,0 +1,7 @@
public class GameCharacter {

//Variable declarations that initialize the variables.
private int health = 100, weight = 50, happiness = 75;

//The getter function. Returns the value of the requested variable.
}
@@ -0,0 +1,15 @@
public class CatCharacter extends GameCharacter {

//The constructors.
public CatCharacter() {
super();
}
public CatCharacter(int health, int happiness, int weight) {
super(health, happiness, weight);
} //End constructors.

public void makeHappyNoise() {
System.out.println("meow");
} //End makeHappyNoise

}
@@ -0,0 +1,7 @@
public class GameCharacterTester2 {

public static void main(String[] args) {
//Step 1: Create instances

} //End main()
} //End class GameCharacterTester
@@ -0,0 +1,30 @@
public class GameCharacterTester {

public static void main(String[] args) {

//Creating the space cowboy
GameCharacter spaceCowboy = new GameCharacter();

//Let's try changing stuff
spaceCowboy.modifyCharacteristic(-10, "Health"); //ouch
spaceCowboy.modifyCharacteristic(-5, "haPPiNess");
spaceCowboy.modifyCharacteristic(50, "weight");

//Get function
System.out.println("Health: " + spaceCowboy.getHealth());
System.out.println("Weight: " + spaceCowboy.getHappiness());
System.out.println("Happiness: " + spaceCowboy.getWeight());

//Test exception by shooting lazers at spaceCowboy
try {
spaceCowboy.modifyCharacteristic(-10, "healTH");
spaceCowboy.modifyCharacteristic(-40, "healTh");
spaceCowboy.modifyCharacteristic(-300, "health");
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
System.out.println(spaceCowboy.getHealth());
}

} //End main()
} //End class GameCharacterTester
@@ -0,0 +1,96 @@
import java.util.ArrayList;

public class Backpack<E> implements BackpackInterface<E> {

protected ArrayList<E>container;

/* Table of contents for Backpack():
* Constructor Ln. 19
* add() Ln. 24
* removeOne() Ln. 29
* printContents() Ln. 37
* contains() Ln. 44
* isEmpty() Ln. 49
* removeAll() Ln. 54
* allIndiciesOf() Ln. 66
* removeMultipleInstancesOf() Ln. 85
*/

//This is the constructor for backpack
public Backpack(){
container = new ArrayList<E>();
} //End constructor

//Adds element to backpack
public void add(E toAdd){
container.add(toAdd);
} //End add()

/*Removes first instance of specified item
* returns true if successful.
*/
public boolean removeOne(E toRemove){
boolean result = container.remove(toRemove);
return result;
} //End removeOne()

//Prints out all the contents of the backpack
public void printContents(){
for (E anObject : container)
System.out.print( anObject+" ");
System.out.println("");
} //End printContents()

//Returns true if backpack has the specified element.
public boolean contains(E itemSought) {
return container.contains(itemSought);
} //End contains()

//Returns true if backpack is empty.
public boolean isEmpty() {
return container.isEmpty();
} //Ends isEmpty()

/*Removes all matching elements in backpack
* returns true if successful
*/
public boolean removeAll(E itemSought) {
if (container.contains(itemSought)){
while(container.remove(itemSought)) {}
return true;
} else {
return false;
}
} //End removeAll()

//Returns an array with addresses to the elements
public int[] allIndicesOf(E itemSought) {
int i;
int[] returnList;
ArrayList<Integer> tempList = new ArrayList<Integer>();

for (i = 0; i < container.size(); i++) {
if (itemSought == container.get(i))
tempList.add(i);
}

returnList = new int[tempList.size()];
for (i = 0; i < tempList.size(); i++) {
returnList[i] = tempList.get(i);
}

return returnList;
} //End allIndiciesOf()

/* Will remove all instances of the specified element
* UNLESS the element appears once.
* returns True if at least one item was removed.
*/
public boolean removeMultipleInstancesOf(E toRemove) {
if (container.indexOf(toRemove) == container.lastIndexOf(toRemove))
return false;
else
return removeAll(toRemove);
} //End removeMultipleInstancesOf()

}
@@ -0,0 +1,87 @@
abstract public class GameCharacter {

//Variable declarations
private int health, weight, happiness;

//Constructors
public GameCharacter() {
this.health = 100;
this.happiness = 100;
this.weight = 100;
}
public GameCharacter(int health, int happiness, int weight) {
this.health = health;
this.happiness = happiness;
this.weight = weight;
//This will check and set defaults if invalid
if ((0 > health & health > 100) ||
(0 > happiness & happiness > 100) ||
(0 > weight & weight > 100)) {
System.out.println("Invalid parameter, using defaults.");
this.health = 100;
this.happiness = 100;
this.weight = 100;
}
} //End constructors

//This will check and set the characteristic
public void modifyCharacteristic(int changeAmount, String characteristic) {
//This will check and modify the characteristics, if valid.
switch(characteristic.toLowerCase()) {
case "health":
setHealth(changeAmount + health);
break;
case "weight":
setWeight(changeAmount + weight);
break;
case "happiness":
setHappiness(changeAmount + happiness);
break;
default:
throw new IllegalArgumentException("Invalid char.");
}
} //End modifyCharacteristic()

//These are the get functions
public int getHealth() {
return health;
} //End getHealth()
public int getWeight() {
return weight;
} //End getWeight()
public int getHappiness() {
return happiness;
} //End getHappiness()

//This are the set functions
private void setHealth(int amount) {
isValid(amount);
this.health = amount;
} //End setHealth()
private void setWeight(int amount) {
isValid(amount);
this.weight = amount;
} //End setWeight()
private void setHappiness(int amount) {
isValid(amount);
this.happiness = amount;
} //End setHappiness()

//This will throw an exception if illegal change happens
private boolean isValid(int amount) {
if (0 <= (amount) && (amount) <= 100) {
return true;
} else {
throw new IllegalArgumentException("Exceeds bounds.");
}
} //End isValid()

//This will make a sad noise.
public void makeSadNoise() {
System.out.println(":(");
} //End makeSadNoise()

//A signature for makeHappyNoise()
abstract public void makeHappyNoise();

} //End class GameCharacter
Empty file.
Empty file.
@@ -0,0 +1,16 @@
public class GameCharacterTester2 {

public static void main(String[] args) {
//====Step 1: Create instances====
System.out.println("Creating new characters");
DogCharacter dixie = new DogCharacter();
CatCharacter nyan = new CatCharacter();
AlienCharacter et = new AlienCharacter();
DogCharacter dixie2 = new DogCharacter(50, 50, 50);
//Error, bound too low
System.out.println("Creating an already-dead alien");
AlienCharacter et2 = new AlienCharacter(-1, 50, 50);
System.out.println(et2.getHealth());

} //End main()
} //End class GameCharacterTester