void searchByCategory(Data* data){ clearScreen(); string answer; cout << "\nInsert what category you would like to search for\n" "( Agriculture, Animals, BabyAndChildren, Fashion, Home, Job, Leisure,\n" "PhonesAndTablets, RealEstate, Services, Sports, Technology, Vehicles,\n" "Others ) : "; getline(cin, answer); vector<Advertisement* > results; if (validCategory(answer)){ Category searchCategory=stringToCategory(answer); results=data->searchForAdsCategory(searchCategory); saleOrPurchase(results,data); SearchMenu menu(data, results); menu.createMenu(); } else { cout<<"Invalid Category\n" "Do you want to search again?(Y/N)?\n"; getline(cin, answer); if (answer=="y"||answer=="Y") searchByCategory(data); else if(data->getSignedInUser() != NULL) signedInMenu(data); else mainMenu(data); } if(data->getSignedInUser() != NULL) signedInMenu(data); else mainMenu(data); }
void createBuyingAd(Data* data){ clearScreen(); string title, description = "", tmp = "", category, condition; float price; time_t t = time(0); // get time now struct tm * now = localtime( & t ); int year=now->tm_year + 1900; int month=now->tm_mon + 1 ; int day= now->tm_mday; Date creationDate(day,month,year); cout << "\nTitle: "; getline(cin, title); cout << "\nCategory: \n ( Agriculture, Animals, BabyAndChildren, Fashion, Home, Job, Leisure,\n" "PhonesAndTablets, RealEstate, Services, Sports, Technology, Vehicles,\n" "Others ) : "; getline(cin,category); while (!validCategory(category)) { cout<<"\nWrite a valid Category: "; getline(cin,category); } Category cat = stringToCategory(category); cout << "\nDescription: "; getline(cin, description); cout << "\nPrice: "; cin >> price; cin.ignore(); cin.clear(); Advertisement* ad = new Purchase(data->getSignedInUser(), title, cat, description, price); ad->setCreationDate(creationDate); cout << "\nIs the price negotiable? (Y/N)\n"; string answer; unsigned int i = 0; do{ if(i > 0) cout << "Please introduce a valid option. (Y/N)\n"; getline(cin,answer); if(answer == "N" || answer == "n") ad->setNegotiable(false); i++; }while(answer != "Y" && answer != "y" && answer != "N" && answer != "n"); data->addAdvertisement(ad); cout << "Ad has been successfully created\n"; signedInMenu(data); }
CDDB::Result Submit::submit( CDInfo cdInfo, const TrackOffsetList& offsetList) { // If it was an inexact math from the server the discid might // be different, so recalculate it cdInfo.id = trackOffsetListToId(offsetList); makeDiskData( cdInfo, offsetList ); if (!validCategory(cdInfo.category)) return InvalidCategory; KIO::Job* job = createJob(cdInfo); if (!job) return UnknownError; return runJob(job); }
void AdDisplayMenu::createMenu() { clearScreen(); AdDisplayMenu::print(); int input; string title, description, category, answer; unsigned int i = 0; cout << "What option would you like to choose?" << endl; if (data->getSignedInUser() == ad->getOwner()) { do { if (i > 0) { cout << "Please introduce a valid option." << endl; } cin >> input; cin.ignore(); cin.clear(); i++; } while (input < 1 || input > 6); switch (input) { case 1: cout << "Please introduce the new title." << endl; getline(cin, title); ad->setTitle(title); break; case 2: cout << "Please introduce the new description." << endl; getline(cin, description); ad->setDescription(description); break; case 3: cout << "Please introduce the new category." << endl; getline(cin, category); do { if (validCategory(category)) { ad->setCategory(stringToCategory(category)); break; } else { cout << "Invalid category, try again. Press 1 to exit." << endl; getline(cin, category); if (category == "1") break; } } while (true); break; case 4: cout << "Please introduce the new price." << endl; float newPrice; cin >> newPrice; cin.ignore(); cin.clear(); ad->setPrice(newPrice); cout << "Please introduce if it is negotiable or not(Y/N)." << endl; getline(cin, answer); if (answer == "Y" || answer == "y") ad->setNegotiable(true); else ad->setNegotiable(false); break; case 5: ad->getOwner()->removeAdvertisement(ad); data->removeAdvertisement(ad); signedInMenu(data); break; case 6: signedInMenu(data); break; default: AdDisplayMenu::createMenu(); break; } } else { do { if (i > 0)