diff --git a/LineCounterApp/input1.txt b/LineCounterApp/input1.txt index 431e68d..e791da4 100644 --- a/LineCounterApp/input1.txt +++ b/LineCounterApp/input1.txt @@ -1,3 +1,59 @@ +/* + * File: BloomFilter.h + * Author: Jason + * + * Created on May 31, 2021, 6:42 PM + */ + + +#ifndef BLOOMFILTER_H +#define BLOOMFILTER_H +#include "Game.h" + + +/******************************************************************************\ + BloomFilter Class + This Class will check to see if a player has played the game before by + storing all usernames in a bloom filter bit vector. If the user has played + a welcome back will be displayed. If the user has not played the rules + menu option will be encouraged +\******************************************************************************/ +#define BFarrSize 512 + +class BloomFilter +{ + +private: + bool *bitarray; + void getBloomData();//reads the bloom filter form text file + void pushBloomData();//pushes bloom data to the file + +public: + BloomFilter(); + ~BloomFilter(); + void setBFname(string s); + // search the bloom filter for user case + bool bfSearch(string s); + // set the bloom filter in the event there is a new user case + void bfPush(string s); + unsigned int ELFHash(const std::string& str); + unsigned int APHash(const std::string& str); + }; + + inline BloomFilter::BloomFilter() + { + bitarray = new bool[BFarrSize]; + for (int i = 0; i < BFarrSize; i++) + bitarray[i] = false; + getBloomData(); + } + inline BloomFilter::~BloomFilter() + { + pushBloomData(); + delete[] bitarray; + } + +#endif /* BLOOMFILTER_H */ /* * File: Card.h * Author: Jason @@ -21,6 +77,7 @@ struct Card { string suit; // cards suit int cPower; // power of the card to determine who will win the round + Card() {} Card(string s, int p)// assign the power and suit when card is created { suit = s; @@ -145,6 +202,8 @@ private: public: Deck(); // default constructor will create the deck when instantiated. void dealCards(Player &currPlayer); // deals the card 26 per player. + void merge(vector &arr, int l, int m, int r); + void mergeSort(vector &arr, int l, int r); }; #endif /* DECK_H */ /* @@ -170,6 +229,8 @@ public: #include "Game.h" #include "Deck.h" #include "Player.h" +#include "ScoreTree.h" +#include "BloomFilter.h" /*****************************************************************************\ * Game * * This class is a designed to hold all the attributes of the game. This will * @@ -184,21 +245,30 @@ public: { readScoresFromFile(); } + ~Game() + { + delete sBoard; + } multimap highScores; // high scores container. + ScoreTree* sBoard; void displayWelcome(); // displays the welcome intro. void mainMenu(); // displays the main menu and begins to gain user input. void gameLoop(); // the main game loop. void rules(); // displays the rules. double readInput(int userChoice); // checks if user input is valid for main menu. void countAces(Player p1); - void war(Player &p1, Player &cpu, int &playCount); // runs the logic for war loop. - void playerShuffleIn(Player &p1, Player &cpu); // shuffles cards from won cards and puts them into the hand in play. - void scoreBoard(); // displays the score board. + void war(Player &p1, Player &cpu, int &playCount, bool &gameOver); // runs the logic for war loop. + // shuffles cards from won cards and puts them into the hand in play. + void playerShuffleIn(Player &p1, Player &cpu); + void highScoresBoard(); // displays the score board. + void printScoreRecords(Node* root); // will print the entire score records. void readScoresFromFile(); // reads scores from the file and populates the score board multimap void writeScoresToFile(); // writes scores from the multimap to file void displayWar(); // displays was acsii art to reduce redundancy. - void testCounters(Player p1, Player cpu, int playCount); // test function to count all cards in their respective containers. + // test function to count all cards in their respective containers. + void testCounters(Player p1, Player cpu, int playCount); + }; #endif /* GAME_H */ /* @@ -253,6 +323,176 @@ public: }; #endif /* PLAYER_H */ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * File: ScoreTree.h + * Author: Jason + * + * Created on May 31, 2021, 12:38 PM + */ + +#ifndef SCORETREE_H +#define SCORETREE_H + +struct Node +{ + int score; + string name; + Node *left; + Node *right; + + Node(int fScore, string fName) + { + score = fScore; + name = fName; + left = NULL; + right = NULL; + } + + void insert(Node *player) + { + if (player->score < this->score) + { + if (this->left == NULL) + { + this->left = player; + } + else + { + this->left->insert(player); + } + } + else + { + if (this->right == NULL) + { + this->right = player; + } + else + { + this->right->insert(player); + } + } + } +}; + +class ScoreTree +{ +private: + Node* root; +public: + ScoreTree() + { + root = NULL; + } + void insert(int score, string name) + { + if (root == NULL) + { + root = new Node(score, name); + } + else + { + Node* player = new Node(score, name); + root->insert(player); + } + } + //Node* getRoot() + //{ + // return root; + //} + void printScoreRecords() + { + printScoreRecords(root); + } + void printScoreRecords(Node* root) + { + if (root == NULL) + return; + printScoreRecords(root->left); + cout << "Name: " << root->name << "\nScore: " << root->score << endl <right); + } +}; + + +#endif /* SCORETREE_H */ + +/* + * File: BloomFilter.cpp + * Author: Jason + * + * Created on May 31, 2021, 6:43 PM + */ +#include "BloomFilter.h" +/******************************************************************************\ +bloomFilterPush + +\******************************************************************************/ +bool BloomFilter::bfSearch(string s) +{ + return (bitarray[ELFHash(s) % BFarrSize] && bitarray[APHash(s) % BFarrSize]); +} + +/******************************************************************************\ +bloomFilterPush + +\******************************************************************************/ +void BloomFilter::bfPush(string s) +{ + bitarray[ELFHash(s) % BFarrSize] = true; + bitarray[APHash(s) % BFarrSize] = true; +} + +unsigned int BloomFilter::ELFHash(const std::string& str) +{ + unsigned int hash = 0; + unsigned int x = 0; + + for (std::size_t i = 0; i < str.length(); i++) + { + hash = (hash << 4) + str[i]; + if ((x = hash & 0xF0000000L) != 0) + { + hash ^= (x >> 24); + } + hash &= ~x; + } + + return hash; +} + +unsigned int BloomFilter::APHash(const std::string& str) +{ + unsigned int hash = 0xAAAAAAAA; + + for (std::size_t i = 0; i < str.length(); i++) + { + hash ^= ((i & 1) == 0) ? ((hash << 7) ^ str[i] * (hash >> 3)) : + (~((hash << 11) + (str[i] ^ (hash >> 5)))); + } + + return hash; +} + +void BloomFilter::getBloomData() +{ + ifstream file ("bloomFilter.bin", ios::binary|ios::in); + file.read(reinterpret_cast(bitarray), sizeof(bool) * BFarrSize); + file.close(); +} + +void BloomFilter::pushBloomData() +{ + ofstream file ("bloomFilter.bin", ios::binary|ios::out); + file.write(reinterpret_cast(bitarray), sizeof(bool) * BFarrSize); + file.close(); +} /* * File: Deck.cpp * Author: Jason @@ -264,9 +504,9 @@ public: #include "Deck.h" /*****************************************************************************\ - * Deck Constructor * - * The default constructor will create the 52 cards using the card class * - * elements * + Deck Constructor + The default constructor will create the 52 cards using the card class + elements \*****************************************************************************/ Deck::Deck() { @@ -284,14 +524,18 @@ Deck::Deck() } } // once the deck is populated it is then shuffled for play. + + //Sort using a recurisive mergeSort + mergeSort(currDeck, 0, currDeck.size()-1); + // using the random access iterator random_shuffle(currDeck.begin(), currDeck.end()); } /*****************************************************************************\ - * dealCards * - * This function will take the deck of 52 cards and populate each players hand * - * with 26 cards each. * + dealCards + This function will take the deck of 52 cards and populate each players hand + with 26 cards each. \*****************************************************************************/ void Deck::dealCards(Player &currPlayer) { @@ -304,6 +548,82 @@ void Deck::dealCards(Player &currPlayer) currDeck.pop_back(); } } + +/*****************************************************************************\ +merge + +\*****************************************************************************/ +void Deck::merge(vector &arr, int l, int m, int r) +{ + int n1 = m - l + 1; + int n2 = r - m; + + // Create temp vectors + vector L(n1); + vector R(n2); + + // Copy data to temp arrays L[] and R[] + for (int i = 0; i < n1; i++) + L[i] = arr[l + i]; + for (int j = 0; j < n2; j++) + R[j] = arr[m + 1 + j]; + + // Merge the temp arrays back into arr[l..r] + + // Initial index of first subarray + int i = 0; + + // Initial index of second subarray + int j = 0; + + // Initial index of merged subarray + int k = l; + + while (i < n1 && j < n2) { + if (L[i].cPower <= R[j].cPower) { + arr[k] = L[i]; + i++; + } + else { + arr[k] = R[j]; + j++; + } + k++; + } + + // Copy the remaining elements of + // L[], if there are any + while (i < n1) { + arr[k] = L[i]; + i++; + k++; + } + + // Copy the remaining elements of + // R[], if there are any + while (j < n2) { + arr[k] = R[j]; + j++; + k++; + } +} + + +/*****************************************************************************\ +mergeSort + l is for left index and r is right index of the sub-array of arr to be sorted + + +\*****************************************************************************/ +void Deck::mergeSort(vector &arr, int l, int r) { + if (l < r) + { + int m = l + (r - l) / 2; + mergeSort(arr, l, m); + mergeSort(arr, m + 1, r); + merge(arr, l, m, r); + } +} /* * File: Game.cpp * Author: Jason @@ -311,22 +631,24 @@ void Deck::dealCards(Player &currPlayer) * Created on April 4, 2021, 9:04 PM * * Game.cpp will contain the games main loop and all the games functions + * Add: + * graphs */ #include "Game.h" - /****************************************************************************\ - * mainMenu * - * This function will display the main menu. The use will have options to * - * play war, see the rules, check the score board and exit the game. * - * Variables: userChoice holds the users menu choice, userName holds the user * - * name for high scores, * - \****************************************************************************/ +/****************************************************************************\ +mainMenu +This function will display the main menu. The use will have options to +play war, see the rules, check the score board and exit the game. +Variables: userChoice holds the users menu choice, userName holds the user +name for high scores, +\****************************************************************************/ void Game::mainMenu() { srand(time(0)); // Random seed for the shuffle algorithm. int userChoice = 0; // Sets the user choice outside the range of the menu. - while(userChoice != 4) + while(userChoice != 5) { //Main menu output cout << "---------------------------\n"; @@ -334,8 +656,9 @@ void Game::mainMenu() cout << "---------------------------\n"; cout << "1) Play WAR\n"; cout << "2) Rules\n"; - cout << "3) Score Board\n"; - cout << "4) Exit Game "; + cout << "3) High Score Board\n"; + cout << "4) Score Records\n"; + cout << "5) Exit Game "; cout << string(3, '\n'); //moves menu up a bit from the bottom // Takes user input for main menu uses input validation. @@ -350,19 +673,24 @@ void Game::mainMenu() gameLoop(); break; } - case 2: // display the rules. { rules(); break; } - case 3: // display the Score Board. { - scoreBoard(); + highScoresBoard(); break; } - case 4: // end the game and exit. + case 4: // display the rules. + { + sBoard->printScoreRecords(); + //sBoard->printScoreRecords(sBoard->getRoot()); + //printScoreRecords(sBoard); + break; + } + case 5: // end the game and exit. { cout << string(5, '\n'); cout << "Thank you for playing,\n"<< endl; @@ -373,17 +701,17 @@ void Game::mainMenu() } } - /****************************************************************************\ - * gameLoop * - * This function holds the game loop and logic for the game. The game loop * - * will run on a do while loop with an end of game condition gameover true * - \****************************************************************************/ +/****************************************************************************\ +gameLoop +This function holds the game loop and logic for the game. The game loop +will run on a do while loop with an end of game condition game over true +\****************************************************************************/ void Game::gameLoop() { // Deck class instantiation refer to Deck.h for build and implementation. Deck gameDeck; - // Creating the instance of the player and cpu player, refer to the + // Creating the instance of the player and CPU player, refer to the // Player.h for build and implementation. Player p1; Player cpu; @@ -404,9 +732,29 @@ void Game::gameLoop() cin.ignore(); // gather the user input for the userName. getline(cin, userName); + // create an instance of the Bloom filter + BloomFilter BF; + + // if the username hash has set the bitvector then check the map to verify if + if (BF.bfSearch(userName)) { + for (auto& it : highScores) { + if (it.second == userName) { + cout << "Welcome back " << userName << ", get ready for War!" << endl; + } + } + } + else { + // push the username to the bloom filter + BF.bfPush(userName); + cout << "Welcome, " << userName << " to War the Card game,\nPlease read the rules before playing." << endl; + } + + // use the setter to set name. p1.setName(userName); + + cout << "Dealing Cards...\n\n"; // dealCards() is called and deal the deck 26 cards to each player. @@ -422,8 +770,6 @@ void Game::gameLoop() // The do while loop is the main game loop that will contain all the game logic. do { - - countAces(p1); // Output the card total for each player. cout << "You have " << p1.cardsWon.size()+p1.handInPlay.size() << " cards total\n"; @@ -494,43 +840,8 @@ void Game::gameLoop() // if the cards are equal then go to war. else - { - // The war queue will hold the face two war cards - // and the two face down cards - // Push the war cards onto the war queue and pop them - // off the hands to move onto the war offerings - p1.war.push(p1Top); - p1.handInPlay.pop(); - cpu.war.push(cpuTop); - cpu.handInPlay.pop(); - - // condition for war within a war. - while ((p1Top.cPower == cpuTop.cPower) && gameOver == false) - { - // temporarily change the top cards to carry on with the war - // by not continuing the while loop. - p1Top.cPower = -1; - cpuTop.cPower = -2; - - // check if p1 has enough cards for war. - if (p1.handInPlay.size() + p1.cardsWon.size() <= 2) - { - cout << "You do not have Cards to go to war with.\n" << "You must forfeit the game." << endl; - gameOver = true; // end game loop. - } - - // check if cpu has enough cards for war. - else if (cpu.handInPlay.size() + cpu.cardsWon.size() <= 2) - { - cout << "The CPU has no Cards to go to war with.\n" << "The CPU must forfeit the Game." << endl; - gameOver = true; // end game loop - } - // call war loop. - if(gameOver == false) - { - war(p1, cpu, playCount); - } - } + { + war(p1, cpu, playCount, gameOver); } // check to see if players have cards to play the game. @@ -557,6 +868,7 @@ void Game::gameLoop() // write the statistics to the multimap that holds the high scores to be // written to the text file. highScores.insert(pair (playCount, userName)); + sBoard->insert(playCount, userName); cout << "Thank you for playing WAR\n"; cout << "Press Enter to return to main" << endl; cin.ignore(numeric_limits::max(), '\n'); @@ -567,6 +879,7 @@ void Game::gameLoop() cout << "You lost the game of WAR" << endl; cout << "This game took " << playCount << " hands to complete." << endl; highScores.insert(pair (playCount, userName)); + sBoard->insert(playCount, userName); cout << "Thank you for playing WAR\n"; cout << "Press Enter to return to main" << endl; cin.ignore(numeric_limits::max(), '\n'); @@ -575,13 +888,39 @@ void Game::gameLoop() writeScoresToFile(); } - /****************************************************************************\ - * war * - * This function hold the logic of a war instance. When the cards are equal * - * the war function is called. * - \****************************************************************************/ -void Game::war(Player &p1, Player &cpu, int &playCount) +/****************************************************************************\ +war +This function hold the logic of a war instance. When the cards are equal +the war function is called. +\****************************************************************************/ +void Game::war(Player &p1, Player &cpu, int &playCount, bool &gameOver) { + // The war queue will hold the face two war cards + // and the two face down cards + // Push the war cards onto the war queue and pop them + // off the hands to move onto the war offerings + p1.war.push(p1.handInPlay.top()); + p1.handInPlay.pop(); + cpu.war.push(cpu.handInPlay.top()); + cpu.handInPlay.pop(); + + // check if p1 has enough cards for war. + if (p1.handInPlay.size() + p1.cardsWon.size() <= 2) + { + cout << "You do not have Cards to go to war with.\n" << "You must forfeit the game." << endl; + gameOver = true; // end game loop. + } + + // check if cpu has enough cards for war. + else if (cpu.handInPlay.size() + cpu.cardsWon.size() <= 2) + { + cout << "The CPU has no Cards to go to war with.\n" << "The CPU must forfeit the Game." << endl; + gameOver = true; // end game loop + } + + if(gameOver == true) + return; + // Check current handsSize to see if any player still has cards // to play with if not shuffle the cards won and repopulate // the current hand stack @@ -687,13 +1026,17 @@ void Game::war(Player &p1, Player &cpu, int &playCount) p1.handInPlay.pop(); cpu.handInPlay.pop(); } + else + { // recursive war loop + war(p1, cpu, playCount, gameOver); + } } - /****************************************************************************\ - * readInput * - * Takes the user input and tests it to see if its an integer within range. * - * Precondition: int userChoice 0 * - * Postcondition: dependent upon the user input, valid options are 1,2,3,4 * - \****************************************************************************/ +/****************************************************************************\ +readInput +Takes the user input and tests it to see if its an integer within range. +Precondition: int userChoice 0 +Postcondition: dependent upon the user input, valid options are 1,2,3,4 +\****************************************************************************/ double Game::readInput(int userChoice) { // temporarily set choice to -1 @@ -725,12 +1068,12 @@ double Game::readInput(int userChoice) return (choice); } - /****************************************************************************\ - * countAces * - * This function will count the number of aces that the player has. This will * - * show the player that the aces may not be the determining factor of who * - * will win the game of war. * - \****************************************************************************/ +/****************************************************************************\ +countAces +This function will count the number of aces that the player has. This will +show the player that the aces may not be the determining factor of who +will win the game of war. +\****************************************************************************/ void Game::countAces(Player p1) { // create a temporary card that will be used for the count algorithm. @@ -752,10 +1095,10 @@ void Game::countAces(Player p1) // display the total aces at the players disposal. cout << "You Have " << tmp << " Aces" << endl; } - /****************************************************************************\ - * rules * - * This function will display the rules of the game * - \****************************************************************************/ +/****************************************************************************\ +rules +This function will display the rules of the game +\****************************************************************************/ void Game::rules() { @@ -808,14 +1151,37 @@ void Game::rules() cin.ignore(numeric_limits::max(), '\n'); } - /****************************************************************************\ - * scoreBoard * - * This function will display the rules of the game * - \****************************************************************************/ -void Game::scoreBoard() +/****************************************************************************\ +compMap +This function will compare two pairs and return the result of the smaller +of the two +\****************************************************************************/ +bool compMap(pair a, pair b) +{ + return a.first < b.first; +} + +/****************************************************************************\ +highScoresBoard +This function will display the top ten shortest and longest games +\****************************************************************************/ +void Game::highScoresBoard() { + cout << string (100, '\n'); + + // declare two maps that will be used to implement the max and min algorithm + // two iterators that are being used are bidirectional and the compMap function + pair max = *max_element(highScores.begin(),highScores.end(), compMap); + pair min = *min_element(highScores.begin(),highScores.end(), compMap); + cout << "The Hall of Fame:" << endl; + cout << "Longest Game of all Time" << endl; + // print the name ans the score + cout << max.second << ": "<< max.first << endl << endl; + cout << "Shortest Game of all Time" << endl; + cout << min.second << ": "<< min.first << endl << endl; + int count = 0; - cout << "The Longest Games Hand Count:" << endl; + cout << "The 10 Longest Games:" << endl; // The for loop will traverse the list from the end of the list to a count // of 10 this will display the top ten highest hand count games. In order // to do this a reverse_iterator is used to start at the end of the multi map. @@ -826,7 +1192,7 @@ void Game::scoreBoard() } count = 0; - cout << "The Shortest Games Hand Count:" << endl; + cout << "The 10 Shortest Games:" << endl; // The for loop will traverse the list from the beginning of the list to a count // of 10 this will display the top ten lowest hand count games. In order // to do this a iterator is used to start at the beginning of the multi map. @@ -835,20 +1201,23 @@ void Game::scoreBoard() cout << "Name: " << itr->second << endl; cout << "Score: " << itr->first << endl << endl; } - - } - - /****************************************************************************\ - * playerShuffleIn - * This function is called periodically in the game to check if the player/cpu* - * has depleted the cards in their hand in play. If the stack in play is * - * empty the function calls shuffle in (part of the Player class) which * - * shuffles the cards won pile and moves it to the hand in play. * - * Precondition: hand in play state * - * Postcondition: if hand in play is not 0 same, otherwise repopulates the * - * hand in play with cards won shuffled. * - \****************************************************************************/ +/****************************************************************************\ + scoreBoard + This function will display the top ten shortest and longest games +\****************************************************************************/ + + +/****************************************************************************\ +playerShuffleIn +This function is called periodically in the game to check if the player/cpu +has depleted the cards in their hand in play. If the stack in play is +empty the function calls shuffle in (part of the Player class) which +shuffles the cards won pile and moves it to the hand in play. +Precondition: hand in play state +Postcondition: if hand in play is not 0 same, otherwise repopulates the +hand in play with cards won shuffled. +\****************************************************************************/ void Game::playerShuffleIn(Player &p1, Player &cpu) { // if player hand is 0 call shuffleIn @@ -864,15 +1233,16 @@ void Game::playerShuffleIn(Player &p1, Player &cpu) } } - /****************************************************************************\ - * readScoresFromFile * - * This function is called when the user selects the score board option on * - * the main menu. When called it will read the contents from the save file * - * and populate the high scores multimap * - \****************************************************************************/ +/****************************************************************************\ +readScoresFromFile +This function is called when the user selects the score board option on +the main menu. When called it will read the contents from the save file +and populate the high scores multimap +\****************************************************************************/ void Game::readScoresFromFile() { ifstream inFile("scoreBoard.txt"); + sBoard = new ScoreTree(); if(inFile.is_open()) { @@ -906,21 +1276,24 @@ void Game::readScoresFromFile() // Populate the map from the files saved scores. pair tmp = make_pair(curScore, curName); - highScores.insert(tmp); + highScores.insert(tmp); + + sBoard->insert(curScore, curName); } } else { cout << "File is not open." << endl; } + inFile.close(); } - /****************************************************************************\ - * writeScoresFromFile * - * This function is called when a game has ended and a new score needs to be * - * saved. * - \****************************************************************************/ +/****************************************************************************\ +writeScoresFromFile +This function is called when a game has ended and a new score needs to be +saved. +\****************************************************************************/ void Game::writeScoresToFile() { ofstream outFile("scoreBoard.txt"); @@ -943,11 +1316,23 @@ void Game::writeScoresToFile() outFile.close(); } - /****************************************************************************\ - * displayWar * - * This function will simply display the word war this is used in the welcome * - * message and the war game loop. * - \****************************************************************************/ +/****************************************************************************\ +sortTree +\****************************************************************************/ +/*void Game::printScoreRecords(ScoreTree *root) +{ + if (root == NULL) + return; + printScoreRecords(root->left); + cout << root->name << " " << root->score; + printScoreRecords(root->right); +}*/ + +/****************************************************************************\ +displayWar +This function will simply display the word war this is used in the welcome +message and the war game loop. +\****************************************************************************/ void Game::displayWar() { cout << "\t`7MMF' A `7MF' db `7MM''''Mq. \n"; @@ -959,10 +1344,10 @@ void Game::displayWar() cout << "\t VF VF .AMA. .AMMA..JMML. .JMM. \n\n"; } - /****************************************************************************\ - * displayWelcome * - * This function will simply display the welcome screen and message. * - \****************************************************************************/ +/****************************************************************************\ +displayWelcome +This function will simply display the welcome screen and message. +\****************************************************************************/ void Game::displayWelcome() { cout << string(50, '\n'); @@ -998,11 +1383,11 @@ void Game::displayWelcome() this_thread::sleep_for (chrono::seconds(1)); cout << string(100, '\n'); } - /****************************************************************************\ - * testCounters * - * This function is called to test the specific number of cards each container* - * has. This was used for testing to validate the game loop logic. * - \****************************************************************************/ +/****************************************************************************\ +testCounters +This function is called to test the specific number of cards each container +has. This was used for testing to validate the game loop logic. +\****************************************************************************/ void testCounters(int playCount, Player p1, Player cpu) { // print play count @@ -1018,7 +1403,7 @@ void testCounters(int playCount, Player p1, Player cpu) // print the card count in the war queue. cout << "WAR queue " << p1.war.size() + cpu.war.size() << endl; // add all the cards up and print them. - cout << "Total cards in play " << p1.cardsWon.size()+p1.handInPlay.size() + cpu.cardsWon.size()+cpu.handInPlay.size() + p1.war.size() + cpu.war.size() << '\n'; + cout << "Total cards in play " << p1.cardsWon.size()+p1.handInPlay.size() + cpu.cardsWon.size() + cpu.handInPlay.size() + p1.war.size() + cpu.war.size() << '\n'; // print the suit, value and ascii art for all card held by player. cout << "Your Cards" << endl; p1.printHand(); @@ -1026,6 +1411,38 @@ void testCounters(int playCount, Player p1, Player cpu) cout << "cpu's cards" << endl; cpu.printHand(); } + + /* + * File: main.cpp + * Author: Jason Jones + * Created on April 01, 2021, 10:14 AM + * + * Cis17c Project1.0 WAR + * + /*****************************************************************************\ + * This program will consist of the card game War. One of my favorite card * + * games growing up War has a special place in my memories. This program will * + * demonstrate the use of concepts in the Object Orientated methodology of * + * programming and the use of the Standard Template Library. * + \*****************************************************************************/ + +#include "Card.h" +#include "Player.h" +#include "Deck.h" +#include "Game.h" + +int main(int argc, char** argv) +{ + + // Creates a new games instance. + Game curGame; + // Display the welcome ASCII art message. + curGame.displayWelcome(); + // Calls the main menu for the game. + curGame.mainMenu(); + // Exit the program + return 0; +} /* * File: Player.h * Author: Jason @@ -1134,37 +1551,7 @@ string Player::getName() return playerName; } -/* - * File: main.cpp - * Author: Jason Jones - * Created on April 01, 2021, 10:14 AM - * - * Cis17c Project1.0 WAR - * - /*****************************************************************************\ - * This program will consist of the card game War. One of my favorite card * - * games growing up War has a special place in my memories. This program will * - * demonstrate the use of concepts in the Object Orientated methodology of * - * programming and the use of the Standard Template Library. * - \*****************************************************************************/ -#include "Card.h" -#include "Player.h" -#include "Deck.h" -#include "Game.h" - -int main(int argc, char** argv) -{ - - // Creates a new games instance. - Game curGame; - // Display the welcome ASCII art message. - curGame.displayWelcome(); - // Calls the main menu for the game. - curGame.mainMenu(); - // Exit the program - return 0; -} diff --git a/LineCounterApp/nbproject/private/private.xml b/LineCounterApp/nbproject/private/private.xml index aef7ea3..8ab3e7b 100644 --- a/LineCounterApp/nbproject/private/private.xml +++ b/LineCounterApp/nbproject/private/private.xml @@ -6,6 +6,8 @@ - + + file:/C:/Users/Jason/OneDrive/Documents/GitHub/Cis17c2021/LineCounterApp/main.cpp + diff --git a/cis17cLabBloomFilter1.1.zip b/cis17cLabBloomFilter1.1.zip deleted file mode 100644 index be351b2..0000000 Binary files a/cis17cLabBloomFilter1.1.zip and /dev/null differ diff --git a/cis17cLabBloomFilter1.1/dist/Debug/Cygwin-Windows/cis17clabbloomfilter1.1 b/cis17cLabBloomFilter1.1/dist/Debug/Cygwin-Windows/cis17clabbloomfilter1.1 index ed5d2a2..ecdc3d7 100644 Binary files a/cis17cLabBloomFilter1.1/dist/Debug/Cygwin-Windows/cis17clabbloomfilter1.1 and b/cis17cLabBloomFilter1.1/dist/Debug/Cygwin-Windows/cis17clabbloomfilter1.1 differ diff --git a/cis17cLabBloomFilter1.1/nbproject/private/private.xml b/cis17cLabBloomFilter1.1/nbproject/private/private.xml index aef7ea3..ab84910 100644 --- a/cis17cLabBloomFilter1.1/nbproject/private/private.xml +++ b/cis17cLabBloomFilter1.1/nbproject/private/private.xml @@ -2,7 +2,7 @@ 1 - 0 + 1 diff --git a/cis17cProject1.5/Game.cpp b/cis17cProject1.5/Game.cpp index b1fbddf..7a87174 100644 --- a/cis17cProject1.5/Game.cpp +++ b/cis17cProject1.5/Game.cpp @@ -117,7 +117,9 @@ void Game::gameLoop() do { - + //p1.printHand(); + //cpu.printHand(); + countAces(p1); // Output the card total for each player. cout << "You have " << p1.cardsWon.size()+p1.handInPlay.size() << " cards total\n"; diff --git a/cis17cProject1.5/dist/Debug/Cygwin-Windows/cis17cproject1.5 b/cis17cProject1.5/dist/Debug/Cygwin-Windows/cis17cproject1.5 index bfaa2c6..fd2a991 100644 Binary files a/cis17cProject1.5/dist/Debug/Cygwin-Windows/cis17cproject1.5 and b/cis17cProject1.5/dist/Debug/Cygwin-Windows/cis17cproject1.5 differ diff --git a/cis17cProject2.0/BloomFilter.cpp b/cis17cProject2.0/BloomFilter.cpp new file mode 100644 index 0000000..825a2ce --- /dev/null +++ b/cis17cProject2.0/BloomFilter.cpp @@ -0,0 +1,70 @@ +/* + * File: BloomFilter.cpp + * Author: Jason + * + * Created on May 31, 2021, 6:43 PM + */ +#include "BloomFilter.h" +/******************************************************************************\ +bloomFilterPush + +\******************************************************************************/ +bool BloomFilter::bfSearch(string s) +{ + return (bitarray[ELFHash(s) % BFarrSize] && bitarray[APHash(s) % BFarrSize]); +} + +/******************************************************************************\ +bloomFilterPush + +\******************************************************************************/ +void BloomFilter::bfPush(string s) +{ + bitarray[ELFHash(s) % BFarrSize] = true; + bitarray[APHash(s) % BFarrSize] = true; +} + +unsigned int BloomFilter::ELFHash(const std::string& str) +{ + unsigned int hash = 0; + unsigned int x = 0; + + for (std::size_t i = 0; i < str.length(); i++) + { + hash = (hash << 4) + str[i]; + if ((x = hash & 0xF0000000L) != 0) + { + hash ^= (x >> 24); + } + hash &= ~x; + } + + return hash; +} + +unsigned int BloomFilter::APHash(const std::string& str) +{ + unsigned int hash = 0xAAAAAAAA; + + for (std::size_t i = 0; i < str.length(); i++) + { + hash ^= ((i & 1) == 0) ? ((hash << 7) ^ str[i] * (hash >> 3)) : + (~((hash << 11) + (str[i] ^ (hash >> 5)))); + } + + return hash; +} + +void BloomFilter::getBloomData() +{ + ifstream file ("bloomFilter.bin", ios::binary|ios::in); + file.read(reinterpret_cast(bitarray), sizeof(bool) * BFarrSize); + file.close(); +} + +void BloomFilter::pushBloomData() +{ + ofstream file ("bloomFilter.bin", ios::binary|ios::out); + file.write(reinterpret_cast(bitarray), sizeof(bool) * BFarrSize); + file.close(); +} \ No newline at end of file diff --git a/cis17cProject2.0/BloomFilter.h b/cis17cProject2.0/BloomFilter.h new file mode 100644 index 0000000..1bc138c --- /dev/null +++ b/cis17cProject2.0/BloomFilter.h @@ -0,0 +1,57 @@ +/* + * File: BloomFilter.h + * Author: Jason + * + * Created on May 31, 2021, 6:42 PM + */ + + +#ifndef BLOOMFILTER_H +#define BLOOMFILTER_H +#include "Game.h" + + +/******************************************************************************\ + BloomFilter Class + This Class will check to see if a player has played the game before by + storing all usernames in a bloom filter bit vector. If the user has played + a welcome back will be displayed. If the user has not played the rules + menu option will be encouraged +\******************************************************************************/ +#define BFarrSize 512 + +class BloomFilter +{ + +private: + bool *bitarray; + void getBloomData();//reads the bloom filter form text file + void pushBloomData();//pushes bloom data to the file + +public: + BloomFilter(); + ~BloomFilter(); + void setBFname(string s); + // search the bloom filter for user case + bool bfSearch(string s); + // set the bloom filter in the event there is a new user case + void bfPush(string s); + unsigned int ELFHash(const std::string& str); + unsigned int APHash(const std::string& str); + }; + + inline BloomFilter::BloomFilter() + { + bitarray = new bool[BFarrSize]; + for (int i = 0; i < BFarrSize; i++) + bitarray[i] = false; + getBloomData(); + } + inline BloomFilter::~BloomFilter() + { + pushBloomData(); + delete[] bitarray; + } + +#endif /* BLOOMFILTER_H */ + diff --git a/cis17cProject2.0/Card.h b/cis17cProject2.0/Card.h index 164455b..3b54608 100644 --- a/cis17cProject2.0/Card.h +++ b/cis17cProject2.0/Card.h @@ -21,6 +21,7 @@ struct Card { string suit; // cards suit int cPower; // power of the card to determine who will win the round + Card() {} Card(string s, int p)// assign the power and suit when card is created { suit = s; diff --git a/cis17cProject2.0/Deck.cpp b/cis17cProject2.0/Deck.cpp index d82e6cf..db48b1f 100644 --- a/cis17cProject2.0/Deck.cpp +++ b/cis17cProject2.0/Deck.cpp @@ -8,11 +8,11 @@ */ #include "Deck.h" - /*****************************************************************************\ - * Deck Constructor * - * The default constructor will create the 52 cards using the card class * - * elements * - \*****************************************************************************/ +/*****************************************************************************\ +Deck Constructor +The default constructor will create the 52 cards using the card class +elements +\*****************************************************************************/ Deck::Deck() { // Due to the decks private variable of suits being a list an iterator @@ -29,15 +29,19 @@ Deck::Deck() } } // once the deck is populated it is then shuffled for play. + + //Sort using a recurisive mergeSort + mergeSort(currDeck, 0, currDeck.size()-1); + // using the random access iterator random_shuffle(currDeck.begin(), currDeck.end()); } - /*****************************************************************************\ - * dealCards * - * This function will take the deck of 52 cards and populate each players hand * - * with 26 cards each. * - \*****************************************************************************/ +/*****************************************************************************\ +dealCards +This function will take the deck of 52 cards and populate each players hand +with 26 cards each. +\*****************************************************************************/ void Deck::dealCards(Player &currPlayer) { // for loop deals the cards to each player 26 to each player @@ -50,3 +54,78 @@ void Deck::dealCards(Player &currPlayer) } } +/*****************************************************************************\ +merge + +Merges two subvectorss of vec[] First subvectors is vec[l..m] Second subvectors is +vec[m+1..r] +\*****************************************************************************/ +void Deck::merge(vector &vec, int l, int m, int r) +{ + int n1 = m - l + 1; + int n2 = r - m; + + // Create temp vectors + vector L(n1); + vector R(n2); + + // Copy data to temp vectors + for (int i = 0; i < n1; i++) + L[i] = vec[l + i]; + for (int j = 0; j < n2; j++) + R[j] = vec[m + 1 + j]; + + // Merge the temp vectors back into vec[l..r] + + // Initial index of first subvectors + int i = 0; + + // Initial index of second subvectors + int j = 0; + + // Initial index of merged subvectors + int k = l; + + while (i < n1 && j < n2) { + if (L[i].cPower <= R[j].cPower) { + vec[k] = L[i]; + i++; + } + else { + vec[k] = R[j]; + j++; + } + k++; + } + + // Copy the remaining elements of + // L[], if there are any + while (i < n1) { + vec[k] = L[i]; + i++; + k++; + } + + // Copy the remaining elements of + // R[], if there are any + while (j < n2) { + vec[k] = R[j]; + j++; + k++; + } +} + + +/*****************************************************************************\ +mergeSort + l is for left index and r is right index of the subvectors of vec to be sorted +\*****************************************************************************/ +void Deck::mergeSort(vector &vec, int l, int r) { + if (l < r) + { + int m = l + (r - l) / 2; + mergeSort(vec, l, m); + mergeSort(vec, m + 1, r); + merge(vec, l, m, r); + } +} diff --git a/cis17cProject2.0/Deck.h b/cis17cProject2.0/Deck.h index 6dc1255..d2445b8 100644 --- a/cis17cProject2.0/Deck.h +++ b/cis17cProject2.0/Deck.h @@ -35,6 +35,8 @@ class Deck public: Deck(); // default constructor will create the deck when instantiated. void dealCards(Player &currPlayer); // deals the card 26 per player. + void merge(vector &vec, int l, int m, int r); + void mergeSort(vector &vec, int l, int r); }; #endif /* DECK_H */ diff --git a/cis17cProject2.0/Game.cpp b/cis17cProject2.0/Game.cpp index b1fbddf..e81ad11 100644 --- a/cis17cProject2.0/Game.cpp +++ b/cis17cProject2.0/Game.cpp @@ -5,22 +5,24 @@ * Created on April 4, 2021, 9:04 PM * * Game.cpp will contain the games main loop and all the games functions + * Add: + * graphs */ #include "Game.h" - /****************************************************************************\ - * mainMenu * - * This function will display the main menu. The use will have options to * - * play war, see the rules, check the score board and exit the game. * - * Variables: userChoice holds the users menu choice, userName holds the user * - * name for high scores, * - \****************************************************************************/ +/****************************************************************************\ +mainMenu +This function will display the main menu. The use will have options to +play war, see the rules, check the score board and exit the game. +Variables: userChoice holds the users menu choice, userName holds the user +name for high scores, +\****************************************************************************/ void Game::mainMenu() { srand(time(0)); // Random seed for the shuffle algorithm. int userChoice = 0; // Sets the user choice outside the range of the menu. - while(userChoice != 4) + while(userChoice != 5) { //Main menu output cout << "---------------------------\n"; @@ -28,8 +30,9 @@ void Game::mainMenu() cout << "---------------------------\n"; cout << "1) Play WAR\n"; cout << "2) Rules\n"; - cout << "3) Score Board\n"; - cout << "4) Exit Game "; + cout << "3) High Score Board\n"; + cout << "4) Score Records\n"; + cout << "5) Exit Game "; cout << string(3, '\n'); //moves menu up a bit from the bottom // Takes user input for main menu uses input validation. @@ -44,19 +47,24 @@ void Game::mainMenu() gameLoop(); break; } - case 2: // display the rules. { rules(); break; } - case 3: // display the Score Board. { - scoreBoard(); + highScoresBoard(); + break; + } + case 4: // display the rules. + { + sBoard->printScoreRecords(); + //sBoard->printScoreRecords(sBoard->getRoot()); + //printScoreRecords(sBoard); break; } - case 4: // end the game and exit. + case 5: // end the game and exit. { cout << string(5, '\n'); cout << "Thank you for playing,\n"<< endl; @@ -67,17 +75,17 @@ void Game::mainMenu() } } - /****************************************************************************\ - * gameLoop * - * This function holds the game loop and logic for the game. The game loop * - * will run on a do while loop with an end of game condition gameover true * - \****************************************************************************/ +/****************************************************************************\ +gameLoop +This function holds the game loop and logic for the game. The game loop +will run on a do while loop with an end of game condition game over true +\****************************************************************************/ void Game::gameLoop() { // Deck class instantiation refer to Deck.h for build and implementation. Deck gameDeck; - // Creating the instance of the player and cpu player, refer to the + // Creating the instance of the player and CPU player, refer to the // Player.h for build and implementation. Player p1; Player cpu; @@ -98,9 +106,29 @@ void Game::gameLoop() cin.ignore(); // gather the user input for the userName. getline(cin, userName); + // create an instance of the Bloom filter + BloomFilter BF; + + // if the username hash has set the bitvector then check the map to verify if + if (BF.bfSearch(userName)) { + for (auto& it : highScores) { + if (it.second == userName) { + cout << "Welcome back " << userName << ", get ready for War!" << endl; + } + } + } + else { + // push the username to the bloom filter + BF.bfPush(userName); + cout << "Welcome, " << userName << " to War the Card game,\nPlease read the rules before playing." << endl; + } + + // use the setter to set name. p1.setName(userName); + + cout << "Dealing Cards...\n\n"; // dealCards() is called and deal the deck 26 cards to each player. @@ -116,8 +144,6 @@ void Game::gameLoop() // The do while loop is the main game loop that will contain all the game logic. do { - - countAces(p1); // Output the card total for each player. cout << "You have " << p1.cardsWon.size()+p1.handInPlay.size() << " cards total\n"; @@ -188,43 +214,8 @@ void Game::gameLoop() // if the cards are equal then go to war. else - { - // The war queue will hold the face two war cards - // and the two face down cards - // Push the war cards onto the war queue and pop them - // off the hands to move onto the war offerings - p1.war.push(p1Top); - p1.handInPlay.pop(); - cpu.war.push(cpuTop); - cpu.handInPlay.pop(); - - // condition for war within a war. - while ((p1Top.cPower == cpuTop.cPower) && gameOver == false) - { - // temporarily change the top cards to carry on with the war - // by not continuing the while loop. - p1Top.cPower = -1; - cpuTop.cPower = -2; - - // check if p1 has enough cards for war. - if (p1.handInPlay.size() + p1.cardsWon.size() <= 2) - { - cout << "You do not have Cards to go to war with.\n" << "You must forfeit the game." << endl; - gameOver = true; // end game loop. - } - - // check if cpu has enough cards for war. - else if (cpu.handInPlay.size() + cpu.cardsWon.size() <= 2) - { - cout << "The CPU has no Cards to go to war with.\n" << "The CPU must forfeit the Game." << endl; - gameOver = true; // end game loop - } - // call war loop. - if(gameOver == false) - { - war(p1, cpu, playCount); - } - } + { + war(p1, cpu, playCount, gameOver); } // check to see if players have cards to play the game. @@ -251,6 +242,7 @@ void Game::gameLoop() // write the statistics to the multimap that holds the high scores to be // written to the text file. highScores.insert(pair (playCount, userName)); + sBoard->insert(playCount, userName); cout << "Thank you for playing WAR\n"; cout << "Press Enter to return to main" << endl; cin.ignore(numeric_limits::max(), '\n'); @@ -261,6 +253,7 @@ void Game::gameLoop() cout << "You lost the game of WAR" << endl; cout << "This game took " << playCount << " hands to complete." << endl; highScores.insert(pair (playCount, userName)); + sBoard->insert(playCount, userName); cout << "Thank you for playing WAR\n"; cout << "Press Enter to return to main" << endl; cin.ignore(numeric_limits::max(), '\n'); @@ -269,13 +262,39 @@ void Game::gameLoop() writeScoresToFile(); } - /****************************************************************************\ - * war * - * This function hold the logic of a war instance. When the cards are equal * - * the war function is called. * - \****************************************************************************/ -void Game::war(Player &p1, Player &cpu, int &playCount) +/****************************************************************************\ +war +This function hold the logic of a war instance. When the cards are equal +the war function is called. +\****************************************************************************/ +void Game::war(Player &p1, Player &cpu, int &playCount, bool &gameOver) { + // The war queue will hold the face two war cards + // and the two face down cards + // Push the war cards onto the war queue and pop them + // off the hands to move onto the war offerings + p1.war.push(p1.handInPlay.top()); + p1.handInPlay.pop(); + cpu.war.push(cpu.handInPlay.top()); + cpu.handInPlay.pop(); + + // check if p1 has enough cards for war. + if (p1.handInPlay.size() + p1.cardsWon.size() <= 2) + { + cout << "You do not have Cards to go to war with.\n" << "You must forfeit the game." << endl; + gameOver = true; // end game loop. + } + + // check if cpu has enough cards for war. + else if (cpu.handInPlay.size() + cpu.cardsWon.size() <= 2) + { + cout << "The CPU has no Cards to go to war with.\n" << "The CPU must forfeit the Game." << endl; + gameOver = true; // end game loop + } + + if(gameOver == true) + return; + // Check current handsSize to see if any player still has cards // to play with if not shuffle the cards won and repopulate // the current hand stack @@ -381,13 +400,17 @@ void Game::war(Player &p1, Player &cpu, int &playCount) p1.handInPlay.pop(); cpu.handInPlay.pop(); } + else + { // recursive war loop + war(p1, cpu, playCount, gameOver); + } } - /****************************************************************************\ - * readInput * - * Takes the user input and tests it to see if its an integer within range. * - * Precondition: int userChoice 0 * - * Postcondition: dependent upon the user input, valid options are 1,2,3,4 * - \****************************************************************************/ +/****************************************************************************\ +readInput +Takes the user input and tests it to see if its an integer within range. +Precondition: int userChoice 0 +Postcondition: dependent upon the user input, valid options are 1,2,3,4 +\****************************************************************************/ double Game::readInput(int userChoice) { // temporarily set choice to -1 @@ -401,7 +424,7 @@ double Game::readInput(int userChoice) cin >> choice; // if choice is an integer set loop condition to break and return the // user selection. - if (choice <=4 && choice > 0 && cin.good()) + if (choice <=5 && choice > 0 && cin.good()) { //user input choice was valid. valid = true; @@ -419,12 +442,12 @@ double Game::readInput(int userChoice) return (choice); } - /****************************************************************************\ - * countAces * - * This function will count the number of aces that the player has. This will * - * show the player that the aces may not be the determining factor of who * - * will win the game of war. * - \****************************************************************************/ +/****************************************************************************\ +countAces +This function will count the number of aces that the player has. This will +show the player that the aces may not be the determining factor of who +will win the game of war. +\****************************************************************************/ void Game::countAces(Player p1) { // create a temporary card that will be used for the count algorithm. @@ -446,10 +469,10 @@ void Game::countAces(Player p1) // display the total aces at the players disposal. cout << "You Have " << tmp << " Aces" << endl; } - /****************************************************************************\ - * rules * - * This function will display the rules of the game * - \****************************************************************************/ +/****************************************************************************\ +rules +This function will display the rules of the game +\****************************************************************************/ void Game::rules() { @@ -502,21 +525,21 @@ void Game::rules() cin.ignore(numeric_limits::max(), '\n'); } - /****************************************************************************\ - * compMap * - * This function will compare two pairs and return the result of the smaller * - * of the two * - \****************************************************************************/ +/****************************************************************************\ +compMap +This function will compare two pairs and return the result of the smaller +of the two +\****************************************************************************/ bool compMap(pair a, pair b) { return a.first < b.first; } - /****************************************************************************\ - * scoreBoard * - * This function will display the rules of the game * - \****************************************************************************/ -void Game::scoreBoard() +/****************************************************************************\ +highScoresBoard +This function will display the top ten shortest and longest games +\****************************************************************************/ +void Game::highScoresBoard() { cout << string (100, '\n'); @@ -552,20 +575,23 @@ void Game::scoreBoard() cout << "Name: " << itr->second << endl; cout << "Score: " << itr->first << endl << endl; } - } - - - /****************************************************************************\ - * playerShuffleIn - * This function is called periodically in the game to check if the player/cpu* - * has depleted the cards in their hand in play. If the stack in play is * - * empty the function calls shuffle in (part of the Player class) which * - * shuffles the cards won pile and moves it to the hand in play. * - * Precondition: hand in play state * - * Postcondition: if hand in play is not 0 same, otherwise repopulates the * - * hand in play with cards won shuffled. * - \****************************************************************************/ +/****************************************************************************\ + scoreBoard + This function will display the top ten shortest and longest games +\****************************************************************************/ + + +/****************************************************************************\ +playerShuffleIn +This function is called periodically in the game to check if the player/cpu +has depleted the cards in their hand in play. If the stack in play is +empty the function calls shuffle in (part of the Player class) which +shuffles the cards won pile and moves it to the hand in play. +Precondition: hand in play state +Postcondition: if hand in play is not 0 same, otherwise repopulates the +hand in play with cards won shuffled. +\****************************************************************************/ void Game::playerShuffleIn(Player &p1, Player &cpu) { // if player hand is 0 call shuffleIn @@ -581,15 +607,16 @@ void Game::playerShuffleIn(Player &p1, Player &cpu) } } - /****************************************************************************\ - * readScoresFromFile * - * This function is called when the user selects the score board option on * - * the main menu. When called it will read the contents from the save file * - * and populate the high scores multimap * - \****************************************************************************/ +/****************************************************************************\ +readScoresFromFile +This function is called when the user selects the score board option on +the main menu. When called it will read the contents from the save file +and populate the high scores multimap +\****************************************************************************/ void Game::readScoresFromFile() { ifstream inFile("scoreBoard.txt"); + sBoard = new ScoreTree(); if(inFile.is_open()) { @@ -623,21 +650,24 @@ void Game::readScoresFromFile() // Populate the map from the files saved scores. pair tmp = make_pair(curScore, curName); - highScores.insert(tmp); + highScores.insert(tmp); + + sBoard->insert(curScore, curName); } } else { cout << "File is not open." << endl; } + inFile.close(); } - /****************************************************************************\ - * writeScoresFromFile * - * This function is called when a game has ended and a new score needs to be * - * saved. * - \****************************************************************************/ +/****************************************************************************\ +writeScoresFromFile +This function is called when a game has ended and a new score needs to be +saved. +\****************************************************************************/ void Game::writeScoresToFile() { ofstream outFile("scoreBoard.txt"); @@ -660,11 +690,23 @@ void Game::writeScoresToFile() outFile.close(); } - /****************************************************************************\ - * displayWar * - * This function will simply display the word war this is used in the welcome * - * message and the war game loop. * - \****************************************************************************/ +/****************************************************************************\ +sortTree +\****************************************************************************/ +/*void Game::printScoreRecords(ScoreTree *root) +{ + if (root == NULL) + return; + printScoreRecords(root->left); + cout << root->name << " " << root->score; + printScoreRecords(root->right); +}*/ + +/****************************************************************************\ +displayWar +This function will simply display the word war this is used in the welcome +message and the war game loop. +\****************************************************************************/ void Game::displayWar() { cout << "\t`7MMF' A `7MF' db `7MM''''Mq. \n"; @@ -676,10 +718,10 @@ void Game::displayWar() cout << "\t VF VF .AMA. .AMMA..JMML. .JMM. \n\n"; } - /****************************************************************************\ - * displayWelcome * - * This function will simply display the welcome screen and message. * - \****************************************************************************/ +/****************************************************************************\ +displayWelcome +This function will simply display the welcome screen and message. +\****************************************************************************/ void Game::displayWelcome() { cout << string(50, '\n'); @@ -715,11 +757,11 @@ void Game::displayWelcome() this_thread::sleep_for (chrono::seconds(1)); cout << string(100, '\n'); } - /****************************************************************************\ - * testCounters * - * This function is called to test the specific number of cards each container* - * has. This was used for testing to validate the game loop logic. * - \****************************************************************************/ +/****************************************************************************\ +testCounters +This function is called to test the specific number of cards each container +has. This was used for testing to validate the game loop logic. +\****************************************************************************/ void testCounters(int playCount, Player p1, Player cpu) { // print play count @@ -735,11 +777,13 @@ void testCounters(int playCount, Player p1, Player cpu) // print the card count in the war queue. cout << "WAR queue " << p1.war.size() + cpu.war.size() << endl; // add all the cards up and print them. - cout << "Total cards in play " << p1.cardsWon.size()+p1.handInPlay.size() + cpu.cardsWon.size()+cpu.handInPlay.size() + p1.war.size() + cpu.war.size() << '\n'; + cout << "Total cards in play " << p1.cardsWon.size()+p1.handInPlay.size() + cpu.cardsWon.size() + cpu.handInPlay.size() + p1.war.size() + cpu.war.size() << '\n'; // print the suit, value and ascii art for all card held by player. cout << "Your Cards" << endl; p1.printHand(); // print the suit, value and ascii art for all card held by cpu. cout << "cpu's cards" << endl; cpu.printHand(); -} \ No newline at end of file +} + + \ No newline at end of file diff --git a/cis17cProject2.0/Game.h b/cis17cProject2.0/Game.h index 46ca9ab..34132cf 100644 --- a/cis17cProject2.0/Game.h +++ b/cis17cProject2.0/Game.h @@ -21,6 +21,8 @@ #include "Game.h" #include "Deck.h" #include "Player.h" +#include "ScoreTree.h" +#include "BloomFilter.h" /*****************************************************************************\ * Game * * This class is a designed to hold all the attributes of the game. This will * @@ -35,21 +37,30 @@ class Game { readScoresFromFile(); } + ~Game() + { + delete sBoard; + } multimap highScores; // high scores container. + ScoreTree* sBoard; void displayWelcome(); // displays the welcome intro. void mainMenu(); // displays the main menu and begins to gain user input. void gameLoop(); // the main game loop. void rules(); // displays the rules. double readInput(int userChoice); // checks if user input is valid for main menu. void countAces(Player p1); - void war(Player &p1, Player &cpu, int &playCount); // runs the logic for war loop. - void playerShuffleIn(Player &p1, Player &cpu); // shuffles cards from won cards and puts them into the hand in play. - void scoreBoard(); // displays the score board. + void war(Player &p1, Player &cpu, int &playCount, bool &gameOver); // runs the logic for war loop. + // shuffles cards from won cards and puts them into the hand in play. + void playerShuffleIn(Player &p1, Player &cpu); + void highScoresBoard(); // displays the score board. + void printScoreRecords(Node* root); // will print the entire score records. void readScoresFromFile(); // reads scores from the file and populates the score board multimap void writeScoresToFile(); // writes scores from the multimap to file void displayWar(); // displays was acsii art to reduce redundancy. - void testCounters(Player p1, Player cpu, int playCount); // test function to count all cards in their respective containers. + // test function to count all cards in their respective containers. + void testCounters(Player p1, Player cpu, int playCount); + }; #endif /* GAME_H */ diff --git a/cis17cProject2.0/ScoreTree.cpp b/cis17cProject2.0/ScoreTree.cpp new file mode 100644 index 0000000..a9d4fb1 --- /dev/null +++ b/cis17cProject2.0/ScoreTree.cpp @@ -0,0 +1,6 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + diff --git a/cis17cProject2.0/ScoreTree.h b/cis17cProject2.0/ScoreTree.h new file mode 100644 index 0000000..093a7bc --- /dev/null +++ b/cis17cProject2.0/ScoreTree.h @@ -0,0 +1,100 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * File: ScoreTree.h + * Author: Jason + * + * Created on May 31, 2021, 12:38 PM + */ + +#ifndef SCORETREE_H +#define SCORETREE_H + +struct Node +{ + int score; + string name; + Node *left; + Node *right; + + Node(int fScore, string fName) + { + score = fScore; + name = fName; + left = NULL; + right = NULL; + } + + void insert(Node *player) + { + if (player->score < this->score) + { + if (this->left == NULL) + { + this->left = player; + } + else + { + this->left->insert(player); + } + } + else + { + if (this->right == NULL) + { + this->right = player; + } + else + { + this->right->insert(player); + } + } + } +}; + +class ScoreTree +{ +private: + Node* root; +public: + ScoreTree() + { + root = NULL; + } + void insert(int score, string name) + { + if (root == NULL) + { + root = new Node(score, name); + } + else + { + Node* player = new Node(score, name); + root->insert(player); + } + } + //Node* getRoot() + //{ + // return root; + //} + void printScoreRecords() + { + printScoreRecords(root); + } + void printScoreRecords(Node* root) + { + if (root == NULL) + return; + printScoreRecords(root->left); + cout << "Name: " << root->name << "\nScore: " << root->score << endl <right); + } +}; + + +#endif /* SCORETREE_H */ + diff --git a/cis17cProject2.0/bloomFilter.bin b/cis17cProject2.0/bloomFilter.bin new file mode 100644 index 0000000..848ead3 Binary files /dev/null and b/cis17cProject2.0/bloomFilter.bin differ diff --git a/cis17cProject2.0/dist/Debug/Cygwin-Windows/cis17cproject2.0 b/cis17cProject2.0/dist/Debug/Cygwin-Windows/cis17cproject2.0 new file mode 100644 index 0000000..28d10a0 Binary files /dev/null and b/cis17cProject2.0/dist/Debug/Cygwin-Windows/cis17cproject2.0 differ diff --git a/cis17cProject2.0/nbproject/Makefile-Debug.mk b/cis17cProject2.0/nbproject/Makefile-Debug.mk index 471f1ec..ac554c2 100644 --- a/cis17cProject2.0/nbproject/Makefile-Debug.mk +++ b/cis17cProject2.0/nbproject/Makefile-Debug.mk @@ -35,9 +35,11 @@ OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} # Object Files OBJECTFILES= \ + ${OBJECTDIR}/BloomFilter.o \ ${OBJECTDIR}/Deck.o \ ${OBJECTDIR}/Game.o \ ${OBJECTDIR}/Player.o \ + ${OBJECTDIR}/ScoreTree.o \ ${OBJECTDIR}/main.o @@ -65,6 +67,11 @@ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cproject2.0.exe: ${OBJECTFILES} ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cproject2.0 ${OBJECTFILES} ${LDLIBSOPTIONS} +${OBJECTDIR}/BloomFilter.o: BloomFilter.cpp + ${MKDIR} -p ${OBJECTDIR} + ${RM} "$@.d" + $(COMPILE.c) -g -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/BloomFilter.o BloomFilter.cpp + ${OBJECTDIR}/Deck.o: Deck.cpp ${MKDIR} -p ${OBJECTDIR} ${RM} "$@.d" @@ -80,6 +87,11 @@ ${OBJECTDIR}/Player.o: Player.cpp ${RM} "$@.d" $(COMPILE.cc) -g -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/Player.o Player.cpp +${OBJECTDIR}/ScoreTree.o: ScoreTree.cpp + ${MKDIR} -p ${OBJECTDIR} + ${RM} "$@.d" + $(COMPILE.c) -g -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ScoreTree.o ScoreTree.cpp + ${OBJECTDIR}/main.o: main.cpp ${MKDIR} -p ${OBJECTDIR} ${RM} "$@.d" diff --git a/cis17cProject2.0/nbproject/Makefile-Release.mk b/cis17cProject2.0/nbproject/Makefile-Release.mk index b35508c..8be8820 100644 --- a/cis17cProject2.0/nbproject/Makefile-Release.mk +++ b/cis17cProject2.0/nbproject/Makefile-Release.mk @@ -35,9 +35,11 @@ OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM} # Object Files OBJECTFILES= \ + ${OBJECTDIR}/BloomFilter.o \ ${OBJECTDIR}/Deck.o \ ${OBJECTDIR}/Game.o \ ${OBJECTDIR}/Player.o \ + ${OBJECTDIR}/ScoreTree.o \ ${OBJECTDIR}/main.o @@ -65,6 +67,11 @@ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cproject2.0.exe: ${OBJECTFILES} ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17cproject2.0 ${OBJECTFILES} ${LDLIBSOPTIONS} +${OBJECTDIR}/BloomFilter.o: BloomFilter.cpp + ${MKDIR} -p ${OBJECTDIR} + ${RM} "$@.d" + $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/BloomFilter.o BloomFilter.cpp + ${OBJECTDIR}/Deck.o: Deck.cpp ${MKDIR} -p ${OBJECTDIR} ${RM} "$@.d" @@ -80,6 +87,11 @@ ${OBJECTDIR}/Player.o: Player.cpp ${RM} "$@.d" $(COMPILE.cc) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/Player.o Player.cpp +${OBJECTDIR}/ScoreTree.o: ScoreTree.cpp + ${MKDIR} -p ${OBJECTDIR} + ${RM} "$@.d" + $(COMPILE.c) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/ScoreTree.o ScoreTree.cpp + ${OBJECTDIR}/main.o: main.cpp ${MKDIR} -p ${OBJECTDIR} ${RM} "$@.d" diff --git a/cis17cProject2.0/nbproject/configurations.xml b/cis17cProject2.0/nbproject/configurations.xml index 6b325dc..7a5d1c4 100644 --- a/cis17cProject2.0/nbproject/configurations.xml +++ b/cis17cProject2.0/nbproject/configurations.xml @@ -4,10 +4,12 @@ + BloomFilter.h Card.h Deck.h Game.h Player.h + ScoreTree.h + BloomFilter.cpp Deck.cpp Game.cpp Player.cpp + ScoreTree.cpp main.cpp + + + + @@ -58,6 +66,10 @@ + + + + @@ -83,6 +95,10 @@ 5 + + + + @@ -97,6 +113,10 @@ + + + + diff --git a/cis17cProject2.0/scoreBoard.txt b/cis17cProject2.0/scoreBoard.txt index 5c8b738..16d25cc 100644 --- a/cis17cProject2.0/scoreBoard.txt +++ b/cis17cProject2.0/scoreBoard.txt @@ -3,22 +3,29 @@ 89,Ansh 113,Superman 137,Mark +159,Spiderman 160,Mickey 162,Mark 186,Norco +186, 188,Cal Poly 192,Taylor 197,Mark 208,Jason Jones +224,Jason 232,Jay 245,Batman 258,Goofy 295,Jason +300,Flash +326,Jason 373,JJ 374,Taylor 390,Omar 397,Mark 410,Costco +416,Jason +432,Ansh 442,Superman 449,Dr.Lehr 473,JJ @@ -26,8 +33,10 @@ 506,Mark 654,Jason 695,Mark +706,Superman 759,JJ 811,JJ 916,Jas 966,Batman 1186,Omar +1231,Taylor diff --git a/cis17cTree1.0/nbproject/private/private.xml b/cis17cTree1.0/nbproject/private/private.xml index dad4ad0..aef7ea3 100644 --- a/cis17cTree1.0/nbproject/private/private.xml +++ b/cis17cTree1.0/nbproject/private/private.xml @@ -6,9 +6,6 @@ - - file:/C:/Users/Jason/OneDrive/Documents/GitHub/Cis17c2021/cis17cTree1.0/AVLTree.h - file:/C:/Users/Jason/OneDrive/Documents/GitHub/Cis17c2021/cis17cTree1.0/main.cpp - + diff --git a/cis17cTree1.1/dist/Debug/Cygwin-Windows/cis17ctree1.1 b/cis17cTree1.1/dist/Debug/Cygwin-Windows/cis17ctree1.1 index ad7b568..2fdf22c 100644 Binary files a/cis17cTree1.1/dist/Debug/Cygwin-Windows/cis17ctree1.1 and b/cis17cTree1.1/dist/Debug/Cygwin-Windows/cis17ctree1.1 differ diff --git a/cis17cTree1.2/.dep.inc b/cis17cTree1.2/.dep.inc new file mode 100644 index 0000000..38ba445 --- /dev/null +++ b/cis17cTree1.2/.dep.inc @@ -0,0 +1,5 @@ +# This code depends on make tool being used +DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES} ${TESTOBJECTFILES})) +ifneq (${DEPFILES},) +include ${DEPFILES} +endif diff --git a/cis17cTree1.2/AVLTree.h b/cis17cTree1.2/AVLTree.h new file mode 100644 index 0000000..1f7f10d --- /dev/null +++ b/cis17cTree1.2/AVLTree.h @@ -0,0 +1,293 @@ +/* + * File: BNTnode.h + * Modified: from http://www.sanfoundry.com/cpp-program-implement-AVL-trees/ + * Created on May 23, 2021, 9:14 PM + * Purpose: An Binary Tree using an AVL balancing technique + */ + +#ifndef AVLTREE_H +#define AVLTREE_H + +#include +#include +#include +#include + +using namespace std; + +#include "BNTnode.h" + +template +class AVLTree{ + public: + BNTnode *root; //Root node + int height(BNTnode *); //Tree height + int diff(BNTnode *); //Difference of right/left subtrees + BNTnode *rr_rotation(BNTnode *); //Right-Right rotation + BNTnode *ll_rotation(BNTnode *); //Left-Left rotation + BNTnode *lr_rotation(BNTnode *); //Left-Right rotation + BNTnode *rl_rotation(BNTnode *); //Right-Left rotation + BNTnode* balance(BNTnode *); //Balance subtrees with diff > 1 + BNTnode* insert(BNTnode *, int );//Insert and balance the tree + BNTnode* delNode(BNTnode *, int);//Delete a node and balance + void display(BNTnode *, int); //Funky display root left to right + void inorder(BNTnode *); //In order display + void preorder(BNTnode *); //Pre order display + void postorder(BNTnode *); //Post order display + void levelOrder(BNTnode *); //Level order display + AVLTree(){root = NULL;} //Constructor +}; + +//****************************************************************************** +// Height of AVL Sub Trees +//****************************************************************************** +template +int AVLTree::height(BNTnode *temp){ + int h = 0; + if (temp != NULL){ + int l_height = height (temp->left); + int r_height = height (temp->right); + int max_height = max (l_height, r_height); + h = max_height + 1; + } + return h; +} + +//****************************************************************************** +// Height Difference of AVL Sub Trees +//****************************************************************************** +template +int AVLTree::diff(BNTnode *temp){ + int l_height = height (temp->left); + int r_height = height (temp->right); + int b_factor= l_height - r_height; + return b_factor; +} + +//****************************************************************************** +// Right-Right Rotations of Sub Trees +//****************************************************************************** +template +BNTnode *AVLTree::rr_rotation(BNTnode *parent){ + BNTnode *temp; + temp = parent->right; + parent->right = temp->left; + temp->left = parent; + return temp; +} + +//****************************************************************************** +// Left-Left Rotations of Sub Trees +//****************************************************************************** +template +BNTnode *AVLTree::ll_rotation(BNTnode *parent){ + BNTnode *temp; + temp = parent->left; + parent->left = temp->right; + temp->right = parent; + return temp; +} + +//****************************************************************************** +// Left-Right Rotations of Sub Trees +//****************************************************************************** +template +BNTnode *AVLTree::lr_rotation(BNTnode *parent){ + BNTnode *temp; + temp = parent->left; + parent->left = rr_rotation (temp); + return ll_rotation (parent); +} + +//****************************************************************************** +// Right-Left Rotations of Sub Trees +//****************************************************************************** +template +BNTnode *AVLTree::rl_rotation(BNTnode *parent){ + BNTnode *temp; + temp = parent->right; + parent->right = ll_rotation (temp); + return rr_rotation (parent); +} + +//****************************************************************************** +// Balancing of Sub Trees +//****************************************************************************** +template +BNTnode *AVLTree::balance(BNTnode *temp){ + int bal_factor = diff (temp); + if (bal_factor > 1){ + if (diff (temp->left) > 0) + temp = ll_rotation (temp); + else + temp = lr_rotation (temp); + }else if (bal_factor < -1){ + if (diff (temp->right) > 0) + temp = rl_rotation (temp); + else + temp = rr_rotation (temp); + } + return temp; +} + +//****************************************************************************** +// Insert the Data into the Sub Trees +//****************************************************************************** +template +BNTnode *AVLTree::insert(BNTnode *root, int value){ + if (root == NULL){ + root = new BNTnode; + root->data = value; + root->left = NULL; + root->right = NULL; + return root; + }else if (value < root->data){ + root->left = insert(root->left, value); + root = balance (root); + }else if (value >= root->data){ + root->right = insert(root->right, value); + root = balance (root); + } + return root; +} +//****************************************************************************** +// Delete a node from the tree +//****************************************************************************** +template +BNTnode *AVLTree::delNode(BNTnode *root, int x){ + //standard delete + if (root == NULL) + return root; + //if x is smaller than root->data then it is in the left subTree + if (x < root->data){ + root->left = delNode(root->left, x); + } + //if x is greater than root->data then it is in the right subTree + else if (x < root->data){ + root->right = delNode(root->right, x); + } + //if x = root->data delete node + else + { + //node with one or no child + if ((root->left == NULL) || (root->right == NULL)){ + BNTnode *temp = root->left ? root->left : root->right; + //no child + if (temp == NULL){ + temp = root; + root == NULL; + } + else //one child + *root = *temp; + + free(temp); + } + else{ + //node with two children get the inOrder successor + //(smallest in the right subTree) + BNTnode* current = root; + //loop down to find the leftMost leaf + while (current->left != NULL) + current = current->left; + + //copy the inOrder successors data to this node + root->data = current->data; + //delete the inOrder successor + root->right = delNode(root->right, current->data); + } + } + //if tree had one node + if (root == NULL) + return root; + + root = balance(root); + + return root; +} + + +//****************************************************************************** +// Display all Sub Trees +//****************************************************************************** +template +void AVLTree::display(BNTnode *ptr, int level){ + int i; + if (ptr!=NULL){ + display(ptr->right, level + 1); + cout< "; + for (i = 0; i < level && ptr != root; i++) + cout<<" "; + cout<data; + display(ptr->left, level + 1); + } +} + +//****************************************************************************** +// In-order Output of Tree +//****************************************************************************** +template +void AVLTree::inorder(BNTnode *tree){ + if (tree == NULL) + return; + inorder (tree->left); + cout<data<<" "; + inorder (tree->right); +} + +//****************************************************************************** +// Pre-order Output of Tree +//****************************************************************************** +template +void AVLTree::preorder(BNTnode *tree){ + if (tree == NULL) + return; + cout<data<<" "; + preorder (tree->left); + preorder (tree->right); +} + +//****************************************************************************** +// Post-order Output of Tree +//****************************************************************************** +template +void AVLTree::postorder(BNTnode *tree){ + if (tree == NULL) + return; + postorder ( tree ->left ); + postorder ( tree ->right ); + cout<data<<" "; +} +//****************************************************************************** +// Level-order Output of Tree +//****************************************************************************** +template +void AVLTree::levelOrder(BNTnode *root){ + // Base Case + if (root == NULL) return; + + // Create an empty queue for level order traversal + queue q; + + // Enqueue Root and initialize height + q.push(root); + + while (q.empty() == false) + { + // Print front of queue and remove it from queue + BNTnode *node = q.front(); + cout << node->data << " "; + q.pop(); + + /* Enqueue left child */ + if (node->left != NULL) + q.push(node->left); + + /*Enqueue right child */ + if (node->right != NULL) + q.push(node->right); + } + +} +#endif /* AVLTREE_H */ \ No newline at end of file diff --git a/cis17cTree1.2/BNTnode.h b/cis17cTree1.2/BNTnode.h new file mode 100644 index 0000000..b31e8b4 --- /dev/null +++ b/cis17cTree1.2/BNTnode.h @@ -0,0 +1,17 @@ +/* + * File: BNTnode.h + * Modified: from http://www.sanfoundry.com/cpp-program-implement-avl-trees/ + * Created on May 23, 2021, 9:14 PM + * Purpose: A binary tree node + */ + +#ifndef BNTNODE_H +#define BNTNODE_H + +struct BNTnode{ + int data; + struct BNTnode *left; + struct BNTnode *right; +}; + +#endif /* BNTNODE_H */ \ No newline at end of file diff --git a/cis17cTree1.2/Makefile b/cis17cTree1.2/Makefile new file mode 100644 index 0000000..05de621 --- /dev/null +++ b/cis17cTree1.2/Makefile @@ -0,0 +1,128 @@ +# +# There exist several targets which are by default empty and which can be +# used for execution of your targets. These targets are usually executed +# before and after some main targets. They are: +# +# .build-pre: called before 'build' target +# .build-post: called after 'build' target +# .clean-pre: called before 'clean' target +# .clean-post: called after 'clean' target +# .clobber-pre: called before 'clobber' target +# .clobber-post: called after 'clobber' target +# .all-pre: called before 'all' target +# .all-post: called after 'all' target +# .help-pre: called before 'help' target +# .help-post: called after 'help' target +# +# Targets beginning with '.' are not intended to be called on their own. +# +# Main targets can be executed directly, and they are: +# +# build build a specific configuration +# clean remove built files from a configuration +# clobber remove all built files +# all build all configurations +# help print help mesage +# +# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and +# .help-impl are implemented in nbproject/makefile-impl.mk. +# +# Available make variables: +# +# CND_BASEDIR base directory for relative paths +# CND_DISTDIR default top distribution directory (build artifacts) +# CND_BUILDDIR default top build directory (object files, ...) +# CONF name of current configuration +# CND_PLATFORM_${CONF} platform name (current configuration) +# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) +# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) +# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) +# CND_PACKAGE_DIR_${CONF} directory of package (current configuration) +# CND_PACKAGE_NAME_${CONF} name of package (current configuration) +# CND_PACKAGE_PATH_${CONF} path to package (current configuration) +# +# NOCDDL + + +# Environment +MKDIR=mkdir +CP=cp +CCADMIN=CCadmin + + +# build +build: .build-post + +.build-pre: +# Add your pre 'build' code here... + +.build-post: .build-impl +# Add your post 'build' code here... + + +# clean +clean: .clean-post + +.clean-pre: +# Add your pre 'clean' code here... + +.clean-post: .clean-impl +# Add your post 'clean' code here... + + +# clobber +clobber: .clobber-post + +.clobber-pre: +# Add your pre 'clobber' code here... + +.clobber-post: .clobber-impl +# Add your post 'clobber' code here... + + +# all +all: .all-post + +.all-pre: +# Add your pre 'all' code here... + +.all-post: .all-impl +# Add your post 'all' code here... + + +# build tests +build-tests: .build-tests-post + +.build-tests-pre: +# Add your pre 'build-tests' code here... + +.build-tests-post: .build-tests-impl +# Add your post 'build-tests' code here... + + +# run tests +test: .test-post + +.test-pre: build-tests +# Add your pre 'test' code here... + +.test-post: .test-impl +# Add your post 'test' code here... + + +# help +help: .help-post + +.help-pre: +# Add your pre 'help' code here... + +.help-post: .help-impl +# Add your post 'help' code here... + + + +# include project implementation makefile +include nbproject/Makefile-impl.mk + +# include project make variables +include nbproject/Makefile-variables.mk diff --git a/cis17cTree1.2/dist/Debug/Cygwin-Windows/cis17ctree1.0 b/cis17cTree1.2/dist/Debug/Cygwin-Windows/cis17ctree1.0 new file mode 100644 index 0000000..298a399 Binary files /dev/null and b/cis17cTree1.2/dist/Debug/Cygwin-Windows/cis17ctree1.0 differ diff --git a/cis17cTree1.2/dist/Debug/Cygwin-Windows/cis17ctree1.1 b/cis17cTree1.2/dist/Debug/Cygwin-Windows/cis17ctree1.1 new file mode 100644 index 0000000..2fdf22c Binary files /dev/null and b/cis17cTree1.2/dist/Debug/Cygwin-Windows/cis17ctree1.1 differ diff --git a/cis17cTree1.2/main.cpp b/cis17cTree1.2/main.cpp new file mode 100644 index 0000000..b01632d --- /dev/null +++ b/cis17cTree1.2/main.cpp @@ -0,0 +1,97 @@ +/* + * Modified: from http://www.sanfoundry.com/cpp-program-implement-avl-trees/ + * Created on May 23, 2021, 9:14 PM + * Purpose: Example of using rotations to balance a tree + */ + +//System Libraries +#include +#include +using namespace std; + +//User Libraries +#include "AVLTree.h" + +//Global Constants + +//Function Prototypes +void menu(); + +//Execution Begins Here! +int main(){ + int choice, item, size, x; + AVLTree avl; + //Set the random number seed + srand(static_cast(time(0))); + + do{ + menu(); + cin>>choice; + switch(choice){ + case 1: + cout<<"Enter value to be inserted: "; + cin>>item; + avl.root = avl.insert(avl.root, item); + break; + case 2: + cout<<"Enter number of elements to randomly fill the Tree: "; + cin>>size; + for (int i=0; i>x; + avl.root = avl.delNode(avl.root, x); + break; + case 5: + cout<<"InOrder Traversal:"<=0&&choice<=8); + + //Exit stage right! + return 0; +} + +void menu(){ + cout<<"\n---------------------"< Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf + + +# clean +.clean-impl: .clean-pre .validate-impl .depcheck-impl + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf + + +# clobber +.clobber-impl: .clobber-pre .depcheck-impl + @#echo "=> Running $@..." + for CONF in ${ALLCONFS}; \ + do \ + "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf; \ + done + +# all +.all-impl: .all-pre .depcheck-impl + @#echo "=> Running $@..." + for CONF in ${ALLCONFS}; \ + do \ + "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf; \ + done + +# build tests +.build-tests-impl: .build-impl .build-tests-pre + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-tests-conf + +# run tests +.test-impl: .build-tests-impl .test-pre + @#echo "=> Running $@... Configuration=$(CONF)" + "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .test-conf + +# dependency checking support +.depcheck-impl: + @echo "# This code depends on make tool being used" >.dep.inc + @if [ -n "${MAKE_VERSION}" ]; then \ + echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES} \$${TESTOBJECTFILES}))" >>.dep.inc; \ + echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ + echo "include \$${DEPFILES}" >>.dep.inc; \ + echo "endif" >>.dep.inc; \ + else \ + echo ".KEEP_STATE:" >>.dep.inc; \ + echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ + fi + +# configuration validation +.validate-impl: + @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ + then \ + echo ""; \ + echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \ + echo "See 'make help' for details."; \ + echo "Current directory: " `pwd`; \ + echo ""; \ + fi + @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ + then \ + exit 1; \ + fi + + +# help +.help-impl: .help-pre + @echo "This makefile supports the following configurations:" + @echo " ${ALLCONFS}" + @echo "" + @echo "and the following targets:" + @echo " build (default target)" + @echo " clean" + @echo " clobber" + @echo " all" + @echo " help" + @echo "" + @echo "Makefile Usage:" + @echo " make [CONF=] [SUB=no] build" + @echo " make [CONF=] [SUB=no] clean" + @echo " make [SUB=no] clobber" + @echo " make [SUB=no] all" + @echo " make help" + @echo "" + @echo "Target 'build' will build a specific configuration and, unless 'SUB=no'," + @echo " also build subprojects." + @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no'," + @echo " also clean subprojects." + @echo "Target 'clobber' will remove all built files from all configurations and," + @echo " unless 'SUB=no', also from subprojects." + @echo "Target 'all' will will build all configurations and, unless 'SUB=no'," + @echo " also build subprojects." + @echo "Target 'help' prints this message." + @echo "" + diff --git a/cis17cTree1.2/nbproject/Makefile-variables.mk b/cis17cTree1.2/nbproject/Makefile-variables.mk new file mode 100644 index 0000000..2db77a0 --- /dev/null +++ b/cis17cTree1.2/nbproject/Makefile-variables.mk @@ -0,0 +1,35 @@ +# +# Generated - do not edit! +# +# NOCDDL +# +CND_BASEDIR=`pwd` +CND_BUILDDIR=build +CND_DISTDIR=dist +# Debug configuration +CND_PLATFORM_Debug=Cygwin-Windows +CND_ARTIFACT_DIR_Debug=dist/Debug/Cygwin-Windows +CND_ARTIFACT_NAME_Debug=cis17ctree1.2 +CND_ARTIFACT_PATH_Debug=dist/Debug/Cygwin-Windows/cis17ctree1.2 +CND_PACKAGE_DIR_Debug=dist/Debug/Cygwin-Windows/package +CND_PACKAGE_NAME_Debug=cis17ctree1.2.tar +CND_PACKAGE_PATH_Debug=dist/Debug/Cygwin-Windows/package/cis17ctree1.2.tar +# Release configuration +CND_PLATFORM_Release=GNU-MacOSX +CND_ARTIFACT_DIR_Release=dist/Release/GNU-MacOSX +CND_ARTIFACT_NAME_Release=treetest +CND_ARTIFACT_PATH_Release=dist/Release/GNU-MacOSX/treetest +CND_PACKAGE_DIR_Release=dist/Release/GNU-MacOSX/package +CND_PACKAGE_NAME_Release=treetest.tar +CND_PACKAGE_PATH_Release=dist/Release/GNU-MacOSX/package/treetest.tar +# +# include compiler specific variables +# +# dmake command +ROOT:sh = test -f nbproject/private/Makefile-variables.mk || \ + (mkdir -p nbproject/private && touch nbproject/private/Makefile-variables.mk) +# +# gmake command +.PHONY: $(shell test -f nbproject/private/Makefile-variables.mk || (mkdir -p nbproject/private && touch nbproject/private/Makefile-variables.mk)) +# +include nbproject/private/Makefile-variables.mk diff --git a/cis17cTree1.2/nbproject/Package-Debug.bash b/cis17cTree1.2/nbproject/Package-Debug.bash new file mode 100644 index 0000000..775d635 --- /dev/null +++ b/cis17cTree1.2/nbproject/Package-Debug.bash @@ -0,0 +1,76 @@ +#!/bin/bash -x + +# +# Generated - do not edit! +# + +# Macros +TOP=`pwd` +CND_PLATFORM=Cygwin-Windows +CND_CONF=Debug +CND_DISTDIR=dist +CND_BUILDDIR=build +CND_DLIB_EXT=dll +NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging +TMPDIRNAME=tmp-packaging +OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cis17ctree1.2 +OUTPUT_BASENAME=cis17ctree1.2 +PACKAGE_TOP_DIR=cis17ctree1.2/ + +# Functions +function checkReturnCode +{ + rc=$? + if [ $rc != 0 ] + then + exit $rc + fi +} +function makeDirectory +# $1 directory path +# $2 permission (optional) +{ + mkdir -p "$1" + checkReturnCode + if [ "$2" != "" ] + then + chmod $2 "$1" + checkReturnCode + fi +} +function copyFileToTmpDir +# $1 from-file path +# $2 to-file path +# $3 permission +{ + cp "$1" "$2" + checkReturnCode + if [ "$3" != "" ] + then + chmod $3 "$2" + checkReturnCode + fi +} + +# Setup +cd "${TOP}" +mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package +rm -rf ${NBTMPDIR} +mkdir -p ${NBTMPDIR} + +# Copy files and create directories and links +cd "${TOP}" +makeDirectory "${NBTMPDIR}/cis17ctree1.2/bin" +copyFileToTmpDir "${OUTPUT_PATH}.exe" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}.exe" 0755 + + +# Generate tar file +cd "${TOP}" +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cis17ctree1.2.tar +cd ${NBTMPDIR} +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cis17ctree1.2.tar * +checkReturnCode + +# Cleanup +cd "${TOP}" +rm -rf ${NBTMPDIR} diff --git a/cis17cTree1.2/nbproject/Package-Release.bash b/cis17cTree1.2/nbproject/Package-Release.bash new file mode 100644 index 0000000..78828ce --- /dev/null +++ b/cis17cTree1.2/nbproject/Package-Release.bash @@ -0,0 +1,76 @@ +#!/bin/bash -x + +# +# Generated - do not edit! +# + +# Macros +TOP=`pwd` +CND_PLATFORM=GNU-MacOSX +CND_CONF=Release +CND_DISTDIR=dist +CND_BUILDDIR=build +CND_DLIB_EXT=dylib +NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging +TMPDIRNAME=tmp-packaging +OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/treetest +OUTPUT_BASENAME=treetest +PACKAGE_TOP_DIR=treetest/ + +# Functions +function checkReturnCode +{ + rc=$? + if [ $rc != 0 ] + then + exit $rc + fi +} +function makeDirectory +# $1 directory path +# $2 permission (optional) +{ + mkdir -p "$1" + checkReturnCode + if [ "$2" != "" ] + then + chmod $2 "$1" + checkReturnCode + fi +} +function copyFileToTmpDir +# $1 from-file path +# $2 to-file path +# $3 permission +{ + cp "$1" "$2" + checkReturnCode + if [ "$3" != "" ] + then + chmod $3 "$2" + checkReturnCode + fi +} + +# Setup +cd "${TOP}" +mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package +rm -rf ${NBTMPDIR} +mkdir -p ${NBTMPDIR} + +# Copy files and create directories and links +cd "${TOP}" +makeDirectory "${NBTMPDIR}/treetest/bin" +copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 + + +# Generate tar file +cd "${TOP}" +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/treetest.tar +cd ${NBTMPDIR} +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/treetest.tar * +checkReturnCode + +# Cleanup +cd "${TOP}" +rm -rf ${NBTMPDIR} diff --git a/cis17cTree1.2/nbproject/configurations.xml b/cis17cTree1.2/nbproject/configurations.xml new file mode 100644 index 0000000..27bec87 --- /dev/null +++ b/cis17cTree1.2/nbproject/configurations.xml @@ -0,0 +1,76 @@ + + + + + AVLTree.h + BNTnode.h + + + + + main.cpp + + + + + Makefile + + + Makefile + + + + default + true + false + + + + + + + + + + + + + default + true + false + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + + + + diff --git a/cis17cTree1.2/nbproject/private/Makefile-variables.mk b/cis17cTree1.2/nbproject/private/Makefile-variables.mk new file mode 100644 index 0000000..a64183e --- /dev/null +++ b/cis17cTree1.2/nbproject/private/Makefile-variables.mk @@ -0,0 +1,7 @@ +# +# Generated - do not edit! +# +# NOCDDL +# +# Debug configuration +# Release configuration diff --git a/cis17cTree1.2/nbproject/private/c_standard_headers_indexer.c b/cis17cTree1.2/nbproject/private/c_standard_headers_indexer.c new file mode 100644 index 0000000..c2548d2 --- /dev/null +++ b/cis17cTree1.2/nbproject/private/c_standard_headers_indexer.c @@ -0,0 +1,75 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + */ + +// List of standard headers was taken in http://en.cppreference.com/w/c/header + +#include // Conditionally compiled macro that compares its argument to zero +#include // Functions to determine the type contained in character data +#include // Macros reporting error conditions +#include // Limits of float types +#include // Sizes of basic types +#include // Localization utilities +#include // Common mathematics functions +#include // Nonlocal jumps +#include // Signal handling +#include // Variable arguments +#include // Common macro definitions +#include // Input/output +#include // String handling +#include // General utilities: memory management, program utilities, string conversions, random numbers +#include // Time/date utilities +#include // (since C95) Alternative operator spellings +#include // (since C95) Extended multibyte and wide character utilities +#include // (since C95) Wide character classification and mapping utilities +#ifdef _STDC_C99 +#include // (since C99) Complex number arithmetic +#include // (since C99) Floating-point environment +#include // (since C99) Format conversion of integer types +#include // (since C99) Boolean type +#include // (since C99) Fixed-width integer types +#include // (since C99) Type-generic math (macros wrapping math.h and complex.h) +#endif +#ifdef _STDC_C11 +#include // (since C11) alignas and alignof convenience macros +#include // (since C11) Atomic types +#include // (since C11) noreturn convenience macros +#include // (since C11) Thread library +#include // (since C11) UTF-16 and UTF-32 character utilities +#endif diff --git a/cis17cTree1.2/nbproject/private/configurations.xml b/cis17cTree1.2/nbproject/private/configurations.xml new file mode 100644 index 0000000..043f4f4 --- /dev/null +++ b/cis17cTree1.2/nbproject/private/configurations.xml @@ -0,0 +1,72 @@ + + + Makefile + + + + localhost + 3 + + + + + + + + + + + + + + + gdb + + + + "${OUTPUT_PATH}" + + "${OUTPUT_PATH}" + + true + 0 + 0 + + + + + + + localhost + 4 + + + + + + + + + + + + + + + gdb + + + + "${OUTPUT_PATH}" + + "${OUTPUT_PATH}" + + true + 0 + 0 + + + + + + diff --git a/cis17cTree1.2/nbproject/private/cpp_standard_headers_indexer.cpp b/cis17cTree1.2/nbproject/private/cpp_standard_headers_indexer.cpp new file mode 100644 index 0000000..04f6fa6 --- /dev/null +++ b/cis17cTree1.2/nbproject/private/cpp_standard_headers_indexer.cpp @@ -0,0 +1,135 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + */ + +// List of standard headers was taken in http://en.cppreference.com/w/cpp/header + +#include // General purpose utilities: program control, dynamic memory allocation, random numbers, sort and search +#include // Functions and macro constants for signal management +#include // Macro (and function) that saves (and jumps) to an execution context +#include // Handling of variable length argument lists +#include // Runtime type information utilities +#include // std::bitset class template +#include // Function objects, designed for use with the standard algorithms +#include // Various utility components +#include // C-style time/date utilites +#include // typedefs for types such as size_t, NULL and others +#include // Low-level memory management utilities +#include // Higher level memory management utilities +#include // limits of integral types +#include // limits of float types +#include // standardized way to query properties of arithmetic types +#include // Exception handling utilities +#include // Standard exception objects +#include // Conditionally compiled macro that compares its argument to zero +#include // Macro containing the last error number +#include // functions to determine the type contained in character data +#include // functions for determining the type of wide character data +#include // various narrow character string handling functions +#include // various wide and multibyte string handling functions +#include // std::basic_string class template +#include // std::vector container +#include // std::deque container +#include // std::list container +#include // std::set and std::multiset associative containers +#include // std::map and std::multimap associative containers +#include // std::stack container adaptor +#include // std::queue and std::priority_queue container adaptors +#include // Algorithms that operate on containers +#include // Container iterators +#include // Common mathematics functions +#include // Complex number type +#include // Class for representing and manipulating arrays of values +#include // Numeric operations on values in containers +#include // forward declarations of all classes in the input/output library +#include // std::ios_base class, std::basic_ios class template and several typedefs +#include // std::basic_istream class template and several typedefs +#include // std::basic_ostream, std::basic_iostream class templates and several typedefs +#include // several standard stream objects +#include // std::basic_fstream, std::basic_ifstream, std::basic_ofstream class templates and several typedefs +#include // std::basic_stringstream, std::basic_istringstream, std::basic_ostringstream class templates and several typedefs +#include // std::strstream, std::istrstream, std::ostrstream(deprecated) +#include // Helper functions to control the format or input and output +#include // std::basic_streambuf class template +#include // C-style input-output functions +#include // Localization utilities +#include // C localization utilities +#include // empty header. The macros that appear in iso646.h in C are keywords in C++ +#if __cplusplus >= 201103L +#include // (since C++11) std::type_index +#include // (since C++11) Compile-time type information +#include // (since C++11) C++ time utilites +#include // (since C++11) std::initializer_list class template +#include // (since C++11) std::tuple class template +#include // (since C++11) Nested allocator class +#include // (since C++11) fixed-size types and limits of other types +#include // (since C++11) formatting macros , intmax_t and uintmax_t math and conversions +#include // (since C++11) defines std::error_code, a platform-dependent error code +#include // (since C++11) C-style Unicode character conversion functions +#include // (since C++11) std::array container +#include // (since C++11) std::forward_list container +#include // (since C++11) std::unordered_set and std::unordered_multiset unordered associative containers +#include // (since C++11) std::unordered_map and std::unordered_multimap unordered associative containers +#include // (since C++11) Random number generators and distributions +#include // (since C++11) Compile-time rational arithmetic +#include // (since C++11) Floating-point environment access functions +#include // (since C++11) Unicode conversion facilities +#include // (since C++11) Classes, algorithms and iterators to support regular expression processing +#include // (since C++11) Atomic operations library +#include // (since C++11)(deprecated in C++17) simply includes the header +#include // (since C++11)(deprecated in C++17) simply includes the headers (until C++17) (since C++17) and : the overloads equivalent to the contents of the C header tgmath.h are already provided by those headers +#include // (since C++11)(deprecated in C++17) defines one compatibility macro constant +#include // (since C++11)(deprecated in C++17) defines one compatibility macro constant +#include // (since C++11) std::thread class and supporting functions +#include // (since C++11) mutual exclusion primitives +#include // (since C++11) primitives for asynchronous computations +#include // (since C++11) thread waiting conditions +#endif +#if __cplusplus >= 201300L +#include // (since C++14) shared mutual exclusion primitives +#endif +#if __cplusplus >= 201500L +#include // (since C++17) std::any class template +#include // (since C++17) std::optional class template +#include // (since C++17) std::variant class template +#include // (since C++17) Polymorphic allocators and memory resources +#include // (since C++17) std::basic_string_view class template +#include // (since C++17) Predefined execution policies for parallel versions of the algorithms +#include // (since C++17) std::path class and supporting functions +#endif diff --git a/cis17cTree1.2/nbproject/private/launcher.properties b/cis17cTree1.2/nbproject/private/launcher.properties new file mode 100644 index 0000000..6cc2127 --- /dev/null +++ b/cis17cTree1.2/nbproject/private/launcher.properties @@ -0,0 +1,40 @@ +# Launchers File syntax: +# +# [Must-have property line] +# launcher1.runCommand= +# [Optional extra properties] +# launcher1.displayName= +# launcher1.buildCommand= +# launcher1.runDir= +# launcher1.symbolFiles= +# launcher1.env.= +# (If this value is quoted with ` it is handled as a native command which execution result will become the value) +# [Common launcher properties] +# common.runDir= +# (This value is overwritten by a launcher specific runDir value if the latter exists) +# common.env.= +# (Environment variables from common launcher are merged with launcher specific variables) +# common.symbolFiles= +# (This value is overwritten by a launcher specific symbolFiles value if the latter exists) +# +# In runDir, symbolFiles and env fields you can use these macroses: +# ${PROJECT_DIR} - project directory absolute path +# ${OUTPUT_PATH} - linker output path (relative to project directory path) +# ${OUTPUT_BASENAME}- linker output filename +# ${TESTDIR} - test files directory (relative to project directory path) +# ${OBJECTDIR} - object files directory (relative to project directory path) +# ${CND_DISTDIR} - distribution directory (relative to project directory path) +# ${CND_BUILDDIR} - build directory (relative to project directory path) +# ${CND_PLATFORM} - platform name +# ${CND_CONF} - configuration name +# ${CND_DLIB_EXT} - dynamic library extension +# +# All the project launchers must be listed in the file! +# +# launcher1.runCommand=... +# launcher2.runCommand=... +# ... +# common.runDir=... +# common.env.KEY=VALUE + +# launcher1.runCommand= \ No newline at end of file diff --git a/cis17cTree1.2/nbproject/private/private.xml b/cis17cTree1.2/nbproject/private/private.xml new file mode 100644 index 0000000..aef7ea3 --- /dev/null +++ b/cis17cTree1.2/nbproject/private/private.xml @@ -0,0 +1,11 @@ + + + + 1 + 0 + + + + + + diff --git a/cis17cTree1.2/nbproject/project.xml b/cis17cTree1.2/nbproject/project.xml new file mode 100644 index 0000000..fc31e6e --- /dev/null +++ b/cis17cTree1.2/nbproject/project.xml @@ -0,0 +1,28 @@ + + + org.netbeans.modules.cnd.makeproject + + + cis17cTree1.2 + cpp + + h + UTF-8 + + + + + Debug + 1 + + + Release + 1 + + + + false + + + + diff --git a/test/main.cpp b/test/main.cpp index 0d9a209..80671b0 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,37 +1,38 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - /* * File: main.cpp - * Author: Jason - * - * Created on May 14, 2021, 11:05 PM + * Author: Dr. Mark E. Lehr + * Created on June 2nd, 2021, 8:11 AM */ #include -#include +#include #include - +#include using namespace std; -/* - * - */ -int main(int argc, char** argv) { - - int n = 1; - int x = 1; - - while(n*x <= 1000) - { - x++; - n*=x; - } - cout << n << " " << x << endl; +float h(float); +float g(float); +int main(int argc, char** argv) { + //Testing out recursive trig functions + float angDeg=45; + float angRad=angDeg*atan(1)/45; + cout<<"Angle = "<