1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
// Needed to search case insensitive strings
#include <boost/algorithm/string/predicate.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <map>
int main() {
// mMembersList contains Key:String, Value:Contact
// For all intensive purposes, Value is not important here
std::map<std::string, int> mMembersList;
// mMembersList is populated from a file, since file isn't available
// Create basic map with random keys:value
mMembersList.insert(std::pair<std::string, int> ("Bob Jordan", 2));
mMembersList.insert(std::pair<std::string, int> ("George Jeremy", 2));
mMembersList.insert(std::pair<std::string, int> ("Donald Richardson", 3));
mMembersList.insert(std::pair<std::string, int> ("Robert Newman", 8));
mMembersList.insert(std::pair<std::string, int> ("John Doe", 20));
mMembersList.insert(std::pair<std::string, int> ("Richard Stevenson", 12));
mMembersList.insert(std::pair<std::string, int> ("Steve Davidson", 1));
//mPersonalResults contains Key:String, Value:Vector<Float>
std::map<std::string, std::vector<float>> mPersonalResults;
// mMembersList is populated from a file, since file isn't available
// Create basic map with random keys:value
mPersonalResults.insert(std::pair<std::string, std::vector<float>> ("Bob Jordan", {60.5, 17.3, 15.4}));
mPersonalResults.insert(std::pair<std::string, std::vector<float>> ("Donald Richardson", {60.6, 17.3, 12.7}));
mPersonalResults.insert(std::pair<std::string, std::vector<float>> ("John Doe", {59.2, 20.1}));
/* NOT INCLUDED IN MAIN PROGARM */
// Display members in list
std::cout << "Members:\n";
for (auto it : mMembersList)
std::cout << "\t" << it.first << "\n";
// Display members already entered
std::cout << "\nMembers that already completed event:\n";
for (auto it : mPersonalResults)
std::cout << "\t" << it.first << "\n";
/* INCLUDED IN MAIN PROGRAM */
// Create variable for number of participants
int iParticipants;
// Ask user for number of members in <EVENT NAME>
std::cout << "How many members are participating in <EVENT NAME>? ";
// Store number of participants in iParticipants
std::cin >> iParticipants;
std::cin.ignore(80, '\n');
do {
// Create a vector to store found names
std::vector<std::string> vFoundNames;
// Create a strSearch used to find any valid keys in mMembersList
std::string strSearch;
do {
std::cout << "\nPlease enter a name to search for: ";
getline(std::cin, strSearch);
// Search mMembersList
for (auto member : mMembersList)
// If a member matched the search
if (boost::algorithm::icontains(member.first, strSearch))
// Make sure member doesn't exist in mPersonalResults
if (mPersonalResults.find(member.first) == mPersonalResults.end())
// Add unused members to vFoundNames
vFoundNames.push_back(member.first);
} while (!vFoundNames.size());
// Used to store which member to select
int iMember;
// If more than one name was found
if (vFoundNames.size() > 1) {
// Display vFoundNames
for (unsigned int i = 0; i < vFoundNames.size(); i ++)
std::cout << i + 1 << ") " << vFoundNames[i] << "\n";
// Let used select name they want
std::cin >> iMember;
std::cin.ignore(80, '\n');
}
// Otherwise, automatically select the only member
else
iMember = 1;
// Create int to hold number of fish
int iFish;
// Ask the user how many fish <MEMBER> caught
std::cout << "\nHow many fish did " << vFoundNames[iMember - 1] << " catch? ";
// Store number of fish in iFish
std::cin >> iFish;
std::cin.ignore(80, '\n');
// Create int to hold number of dead fish
int iDeadFish;
// Ask the user how many dead fish <MEMBER> caught
std::cout << "\nHow many dead fish did " << vFoundNames[iMember - 1] << " have? ";
// Store number of dead fish in iDeadFish
std::cin >> iDeadFish;
std::cin.ignore(80, '\n');
// Create vector to hold fish's weight
std::vector<float> vFishWeight;
// Notify user to enter weights for the member they selected, or only member
std::cout << "Enter Weights for " << vFoundNames[iMember - 1] << ":\n";
// Allow up to 5 fish's weight to be entered
for (int i = 0; i < 3; i ++) {
// Enter total weight first
if (i == 0)
std::cout << "\tEnter total weight: ";
// Enter largest fish after
else
// Notify the user which fish they're entering weights for
std::cout << "\tLargest Fish " << i << ": ";
// Create a temporary variable to store the fish's weight
float fFishWeight;
// Have the user enter the weight
std::cin >> fFishWeight;
std::cin.ignore(80, '\n');
// If the weight was 0 or less
if (fFishWeight <= 0)
// Break the loop since it's not a valid weight
break;
// Add the weight to the vector
vFishWeight.push_back(fFishWeight);
}
// Add member and fish weights to mPersonResults
mPersonalResults.insert(std::pair<std::string, std::vector<float>> (vFoundNames[iMember - 1], vFishWeight));
} while (mPersonalResults.size() < iParticipants);
// Display mPersonal Results
for (auto it : mPersonalResults) {
// Display Key
std::cout << "\n" << it.first << ":\n";
// Make sure member caught fish
if (it.second.size() != 0)
// Display weights
for (auto it2 : it.second)
std::cout << "\t" << it2;
// Otherwise
else
std::cout << "\tDidn't catch any fish!";
}
return 0;
}
|