#include #include #include #include "apvector.h" #include "fish.h" #include "position.h" #include "randGen.h" // lsmf.cpp // Program Worksheet apa8.2 #1 // G. Volger // 2.21.01 void LoadVector(apvector & lotsOfFish); // post: Creates a vector with fish in ascending order in it // Create 10 fish with ID's 1 through 10 // Look in the fish class on how to create Fish - The position // of the Fish is NOT used in this assingment! void RandomizeVector(apvector & lotsOfFish); // pre: vector is filled with fish in ascending order // post: vector is filled with fish in no particular order // Algorithm: // 1. Loop around 100 times, selecting two random locations // within the vector each time. // 2. If the random locations are different, swap the fish // at those locations. // Look in the randGen.h header file to determine how to create // a random number genreator, and how to call it. void DisplayVector(const apvector & lotsOfFish); // pre: vector is filled with fish in no particular order // post: Fish are display from least to greatest vector locations // The display should look like: // Fish: 6 4 2 5 1 7 3 10 9 8 int GetFish(); // post: Returns a valid Fish id - integer value from 1 - 20 inclusively // entered by the user (1 to twice the length of the vector) int LSMF(apvector & lotsOfFish, int key); // pre: lotsOfFish is a vector filled with fish in no particular order // key is a defined fish id // post: If key is found in vector, the key is moved forward one position // (if possible) in the vector and the new location is returned. // Otherwise if the key is not found -1 is returned int main() { apvector lotsOfFish; LoadVector(lotsOfFish); RandomizeVector(lotsOfFish); DisplayVector(lotsOfFish); do { int key = GetFish(); int loc = LSMF(lotsOfFish, key); if (loc != -1) cout << "Found " << key << " at location " << loc << endl; else cout << key << " not found" << endl; DisplayVector(lotsOfFish); } while (true); return 0; } void LoadVector(apvector & lotsOfFish) // post: Creates a vector with fish in ascending order in it // Create 10 fish with ID's 1 through 10 // Look in the fish class on how to create Fish - The position // of the Fish is NOT used in this assingment! { } void RandomizeVector(apvector & lotsOfFish) // pre: vector is filled with fish in ascending order // post: vector is filled with fish in no particular order // Algorithm: // 1. Loop around 100 times, selecting two random locations // within the vector each time. // 2. If the random locations are different, swap the fish // at those locations. // Look in the randGen.h header file to determine how to create // a random number genreator, and how to call it. { } void DisplayVector(const apvector & lotsOfFish) // pre: vector is filled with fish in no particular order // post: Fish are display from least to greatest vector locations // The display should look like: // Fish: 6 4 2 5 1 7 3 10 9 8 { } int GetFish() // post: Returns a valid Fish id - integer value from 1 - 20 inclusively // entered by the user (1 to twice the length of the vector) { } int LSMF(apvector & lotsOfFish, int key) // pre: vector is filled with fish // key is a defined fish // post: If key is found in vector, key is moved forward one position // (if possible) and the new location is returned // otherwise if the key is not found -1 is returned { }