Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-----------------------------------------------------------------
- System Name: Zoinkers!
- Artifact Name: Zoinkers.h
- Create Date: March 25, 2018
- Author: Shah Ohm, oshah@kent.edu
- Version: 2.0
- ------------------------------------------------------------------*/
- #include "Zoinkers.hpp"
- //============[Animal Functions]=====================
- Animal::Animal(int ID, int AniID, std::string str){
- EID = ID;
- AID = AniID;
- name = str;
- }
- //============[Schedule Functions]===================
- //============[User Functions]====================
- void User::updateFav(){
- }
- void User::checkDiscount(){
- }
- void User::dateParse(){
- std::vector<int> vect;
- std::stringstream ss(date);
- int i;
- while (ss >> i)
- {
- vect.push_back(i);
- if (ss.peek() == '-')
- ss.ignore();
- }
- month = vect.at(0);
- day = vect.at(1);
- year = vect.at(2);
- //std::cout << month << day << year;
- /* if(month <= 12 || month < 0) {
- std::cout << "\nPlease Enter Date as the Following Format 12-31-2018 \nPlease Enter a Date: ";
- std::cin >> date;
- //dateParse();
- }
- if(day <= 31 || day < 0){
- std::cout << "\nPlease Enter Date as the Following Format 12-31-2018 \nPlease Enter a Date: ";
- std::cin >> date;
- //dateParse();
- }
- if(year < 2050 || year <= 2018){ // must be this year or following years
- std::cout << "\nPlease Enter Date as the Following Format 12-31-2018 \nPlease Enter a Date: ";
- std::cin >> date;
- //dateParse();
- } */ //fix this issue with inputs
- }
- void User::checkBudget(){
- char ans;
- std::cout << "Your Budget is: "<<budget<<" is this correct(y/n): ";
- std::cin >> ans;
- if (ans == 'y') return;
- else
- std::cout << "Please Enter a Budget: "; std::cin >> budget; //Budget is set
- checkBudget();
- }
- void User::displayOptions(User userone, Zoink& zoinker){
- int input;
- std::cout << "1. Generate Order Plan"; //Options
- std::cout << "Select your option: ";
- std::cin >> input;
- switch (input) {
- case 1:
- generateSched(userone, zoinker);
- break;
- //add more cases in later iterations
- default:
- break;
- }
- }
- bool User::checkUser(std::string name, std::string pass){
- if(pass == testPass && name == testUser) {// Hardcoded for 2.0
- std::cout << "Success! \n";
- return true;
- }
- //Update to check for invalid
- return false;
- }
- User::User(std::string user, std::string pass, int tmpRole){
- username = user;
- password = pass;
- role = tmpRole;
- Favorability fav1(1, 5);
- favanimal.push_back(fav1);
- Favorability fav2(2, 4);
- favanimal.push_back(fav2);
- Favorability fav3(3, 2);
- favanimal.push_back(fav3);
- }
- void User::avgFavExhibit(Zoink& zoinker){
- int i = 0;
- double avg = 0;
- int total = 0;
- while(i < zoinker.getNumExhib()){
- std::vector<int> exhibitAnimals = zoinker.getAnimalWithEID(i);
- for(int x = 0; x < exhibitAnimals.size(); ++x){
- for(int y = 0; y < favanimal.size(); ++y){
- if(favanimal[y].returnID() == exhibitAnimals[x]){
- avg += favanimal[y].returnFav();
- ++total;
- }
- }
- }
- ++i;
- }
- avg = avg/total;
- Favorability tmp(1, avg);
- exhibitFav.push_back(tmp);
- //std::cout << "in avg fav exhibit exhibitFav.size(): " << exhibitFav.size();
- }
- User createUser(std::string name, std::string pass){
- User NewUser(name,pass,1);
- return NewUser;
- }
- std::string User::generateSched(User userone, Zoink& zoinker){
- // Needs to Obtain a Buget X
- // Needs to Obtain a Date X
- // Add option for update fav X
- // Account for Discount Code X
- std::cout << "Please Enter a Budget: "; std::cin >> budget; //Budget is set
- checkBudget();
- std::cout << "\nPlease Enter Date as the Following Format 12-31-2018 \nPlease Enter a Date: ";
- std::cin >> date;
- dateParse();
- int time = 0;
- std::cout << "How long did you want to spend at the Zoo? ";
- std::cin >> time;
- //implement a time check not needed for phase 2
- std::string sched;
- //If you are here assume date and budget are valid
- //char ans;
- //std::cout << "\nWould you like to update favorability (y/n)? ";
- //std::cin >> ans;
- //if(ans == 'y') updateFav(); //Implement update of Favorability
- //avgFavExhibit(); Implement this in a loop to create averages of all exhibits you have
- //std::cout << "\nDo you have a Discount code(y/n)? ";
- //std::cin >> ans;
- //if(ans == 'y') checkDiscount(); //Implement the Discount Check
- //Now assume Fav and Discount are valid
- //Got time expected
- std::vector<int> tmpExhibitFav;
- std::vector<int> able; // Exhibit IDS
- //std::cout << userone.getExhibitSize() << " subtract 1\n" << zoinker.getNumExhib() << "<-- this is num of exhibits in
- //directory";
- for(int i = 0; i < zoinker.getNumExhib() - 1; ++i){
- tmpExhibitFav.push_back(userone.getExhibitFav(i)); //accessor to exhibit's favorability
- }
- std::sort(tmpExhibitFav.begin(), tmpExhibitFav.end()); // Sorted lowest to highest
- int tempTotalPrice = 0;
- double totalp = 0;
- for(long i = tmpExhibitFav.size(); i >= 0; --i){ //iteratte backwards highest to lowest
- tempTotalPrice += zoinker.getPriceByEID(exhibitFav[i].returnID()); //use id to get price
- double totalp = tempTotalPrice * time;
- if(totalp <= budget){
- able.push_back(exhibitFav[i].returnID());
- }
- else {
- tempTotalPrice -= zoinker.getPriceByEID(exhibitFav[i].returnID());
- break;
- }
- }
- //std::cout << "able.size(): " << able.size() << '\n'; //getting 0
- std::cout << "exhibitFav.size(): " << exhibitFav.size() << '\n';
- std::cout << "Here is your recommended viewing Schedule:\n";
- std::cout << "Exhibit ";
- zoinker.getNameByEID(able);
- std::cout << "\nHere is your total price: " << totalp << '\n';
- return sched;
- }
- //============[Zoink Functions]====================
- void Zoink::getNameByEID(std::vector<int> IDs){
- //std::cout << "Size: " << IDs.size() << "\n"; // gives me 3
- //std::cerr << "exhibits.size(): " << exhibits.size() << "\n"; // gives me 4
- for(int i = 0; i < IDs.size(); ++i){
- std::cout << exhibits[i].getName() << " ";
- }
- }
- std::vector<int> Zoink::getAnimalWithEID(int ExID){
- int index = 0;
- for(int i = 0; i < exhibits.size(); ++i){
- if(ExID == exhibits[i].returnEID()) {
- index = i;
- }
- }
- return exhibits[index].getAnimalWithinExibit();
- }
- int Zoink::getPriceByEID(int ExID){
- int index = 0;
- for(int i = 0; i < exhibits.size(); ++i){
- if(ExID == exhibits[i].returnEID()){
- index = i;
- }
- }
- return exhibits[index].getPrice();
- }
- //============[Favorability Functions]=============
- //============[Exhibit Functions]==================
- Exhibit::Exhibit(int ID,std::string name,int p){
- EID = ID;
- exhibitName = name;
- price = p;
- }
- std::vector<int> Exhibit::getAnimalWithinExibit() {
- std::vector<int> tmpVect;
- for(int i = 0; i < animals.size(); ++i){
- tmpVect.push_back(animals[i].returnAID());
- }
- return tmpVect;
- }
- //=================================================
- int main(){
- Zoink zoinker;
- std::string userInput, userPass; //Mimicing Login
- std::cout << "Username: ";
- std::cin >> userInput;
- std::cout << "Password: ";
- std::cin >> userPass;
- //Login Completed
- User NewUser(userInput,userPass, 1);
- NewUser.avgFavExhibit(zoinker);
- std::string testStr = NewUser.generateSched(NewUser, zoinker);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement