Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <vector>
- #include <string>
- #include <time.h>
- #include <sstream>
- #include <fstream>
- #include <iomanip>
- #include <algorithm>
- #include <cstdlib>
- #include <sstream>
- #include "Customer.h"
- #include "Campaign.h"
- #include "Ad.h"
- #include "AdServingEngine.h"
- using namespace std;
- void GetYYYYMMDD(string YYYYMMDD, int* YYYY, int* MM, int* DD)
- {
- string dateString = YYYYMMDD;
- replace(dateString.begin(), dateString.end(), '/', ' ');
- vector<int> dateInts;
- stringstream dateStream(dateString);
- int temp;
- while (dateStream >> temp)
- dateInts.push_back(temp);
- *YYYY = dateInts[0];
- *MM = dateInts[1];
- *DD = dateInts[2];
- }
- void CreateNewCustomer(string name, int idIndex, AdServingEngine ase)
- {
- cout << "Enter customer name: ";
- cin >> name;
- idIndex++;
- ase.AddCustomer(name, idIndex);
- }
- void CreateNewCampaign(Customer* customer, string name, int idIndex, struct tm fromDate, struct tm toDate, int fromYear, int fromMonth, int fromDay, int toYear, int toMonth, int toDay, float campaignCost)
- {
- cout << "Enter the campaign name: ";
- cin >> name;
- string fromDateString;
- cout << "Give start date of campaign YYYY/MM/DD: ";
- cin >> fromDateString;
- GetYYYYMMDD(fromDateString, &fromYear, &fromMonth, &fromDay);
- fromDate.tm_year = fromYear - 1900;
- fromDate.tm_mon = fromMonth + 1;
- fromDate.tm_mday = fromDay;
- fromDate.tm_hour = 0;
- fromDate.tm_min = 0;
- fromDate.tm_sec = 0;
- time_t from = mktime(&fromDate);
- string toDateString;
- cout << "Give end date of campaign YYYY/MM/DD: ";
- cin >> toDateString;
- GetYYYYMMDD(toDateString, &toYear, &toMonth, &toDay);
- toDate.tm_year = toYear - 1900;
- toDate.tm_mon = toMonth + 1;
- toDate.tm_mday = toDay;
- toDate.tm_hour = 0;
- toDate.tm_min = 0;
- toDate.tm_sec = 0;
- time_t to = mktime(&toDate);
- cout << "Enter the campaign cost: ";
- cin >> campaignCost;
- idIndex++;
- customer->AddCampaign(name, from, to, campaignCost, idIndex);
- }
- void CreateNewAd(Campaign* campaign, string name, string adText, int adTypeInt, AdType adType, int idIndex)
- {
- cout << "Enter ad name: ";
- cin >> name;
- cout << "Enter ad text: ";
- cin >> adText;
- cin.ignore();
- cout << "1. Scroll.\n2. Blink.\n3. PlainText.\nEnter ad type: ";
- cin >> adTypeInt;
- switch (adType)
- {
- case 1:
- {
- adType = AdType::scroll;
- }
- case 2:
- {
- adType = AdType::blink;
- }
- case 3:
- {
- adType = AdType::plainText;
- }
- }
- idIndex++;
- campaign->AddAd(name, adText, adType, idIndex);
- }
- Customer* GetChosenCustomer(vector<Customer> listOfCustomers, AdServingEngine ase, string name, int menuPosition, int givenMenuPosition)
- {
- listOfCustomers = ase.GetListOfCustomer();
- for (auto cust : listOfCustomers)
- {
- name = cust.GetCustomerName();
- cout << menuPosition << ". " << name << endl;
- menuPosition++;
- }
- cout << "Enter for which customers: ";
- cin >> givenMenuPosition;
- int givenMenuIndex = givenMenuPosition - 1;
- Customer* chosenCustomer;
- chosenCustomer = ase.GetCustomer(givenMenuIndex);
- return chosenCustomer;
- }
- Campaign* GetChosenCampaign(vector<Campaign> listOfCampaigns, Customer* customer, string name, int menuPosition, int givenMenuPosition)
- {
- listOfCampaigns = customer->GetCampaignList();
- for (int i = 0; i < listOfCampaigns.size(); i++)
- {
- name = listOfCampaigns[i].GetCampaignName();
- cout << menuPosition << ". " << name << endl;
- menuPosition++;
- }
- cout << "Enter for which campaign: ";
- cin >> givenMenuPosition;
- int givenMenuIndex = givenMenuPosition - 1;
- Campaign* chosenCampaign;
- chosenCampaign = customer->GetCampaign(givenMenuIndex);
- return chosenCampaign;
- }
- Ad* GetChosenAd(vector<Ad> listOfAds, Campaign* campaign, string name, int menuPosition, int givenMenuPosition)
- {
- listOfAds = campaign->GetAdList();
- for (int i = 0; i < listOfAds.size(); i++)
- {
- name = listOfAds[i].GetAdName();
- cout << menuPosition << ". " << name << endl;
- menuPosition++;
- }
- cout << "Enter for which ad: ";
- cin >> givenMenuPosition;
- int givenMenuIndex = givenMenuPosition - 1;
- Ad* chosenAd;
- chosenAd = campaign->GetAd(givenMenuIndex);
- return chosenAd;
- }
- void UpdateCustomerMenu(Customer* customer, string name)
- {
- cout << "New name: ";
- cin >> name;
- customer->UpdateCustomer(name);
- }
- void UpdateCampaignMenu(Campaign* campaign, string name, int idIndex, struct tm fromDate, struct tm toDate, int fromYear, int fromMonth, int fromDay, int toYear, int toMonth, int toDay, float campaignCost)
- {
- cout << "Enter the campaign name: ";
- cin >> name;
- string fromDateString;
- cout << "Give start date of campaign YYYY/MM/DD: ";
- cin >> fromDateString;
- GetYYYYMMDD(fromDateString, &fromYear, &fromMonth, &fromDay);
- fromDate.tm_year = fromYear - 1900;
- fromDate.tm_mon = fromMonth + 1;
- fromDate.tm_mday = fromDay;
- fromDate.tm_hour = 0;
- fromDate.tm_min = 0;
- fromDate.tm_sec = 0;
- time_t from = mktime(&fromDate);
- string toDateString;
- cout << "Give end date of campaign YYYY/MM/DD: ";
- cin >> toDateString;
- GetYYYYMMDD(toDateString, &toYear, &toMonth, &toDay);
- toDate.tm_year = toYear - 1900;
- toDate.tm_mon = toMonth + 1;
- toDate.tm_mday = toDay;
- toDate.tm_hour = 0;
- toDate.tm_min = 0;
- toDate.tm_sec = 0;
- time_t to = mktime(&toDate);
- cout << "Enter the campaign cost: ";
- cin >> campaignCost;
- campaign->UpdateCampaign(name, from, to, campaignCost);
- }
- void UpdateAdMenu(Ad* ad, string name, string adText, int adType, AdType nextAdType, int idIndex)
- {
- cout << "Enter ad name: ";
- cin >> name;
- cout << "Enter ad text: ";
- cin >> adText;
- cin.ignore();
- cout << "1. Scroll.\n2. Blink.\n3. PlainText.\nEnter ad type: ";
- cin >> adType;
- switch (adType)
- {
- case 1:
- {
- nextAdType = AdType::scroll;
- }
- case 2:
- {
- nextAdType = AdType::blink;
- }
- case 3:
- {
- nextAdType = AdType::plainText;
- }
- ad->UpdateAd(name, adText, nextAdType);
- }
- return;
- }
- void PrintNextAd(AdServingEngine ase)
- {
- Ad ad = ase.GetNextAd();
- string adText = ad.GetAdText();
- AdType adType = ad.GetAdType();
- if (adType == AdType::scroll)
- cout << "Scrolling: " << adText << endl;
- else if (adType == AdType::blink)
- cout << "Blinking: " << adText << endl;
- else if (adType == AdType::plainText)
- cout << adText << endl;
- }
- int main()
- {
- int idIndexCustomer = 0, idIndexCampaign = 0, idIndexAd = 0;
- AdServingEngine ase;
- while (true)
- {
- int selection;
- cout << "1. Create customer.\n2. Create campaign.\n3. Create ad.\n4. Update customer. \n5. Update campaign.\n6. Update ad. \n7. Print next ad.\n8. Exit.\n";
- cin >> selection;
- string newCustomerName, newCampaignName, newAdName, newAdText;
- float newCampaignCost;
- int newAdTypeInt;
- AdType newAdType;
- string updatedCustomerName, updatedCampaignName, updatedAdName, updatedAdText;
- float updatedCampaignCost;
- int updatedAdTypeInt;
- AdType updatedAdType;
- string customerName, campaignName, adName;
- int fromYear, fromMonth, fromDay, toYear, toMonth, toDay;
- struct tm fromDate, toDate;
- int updatedFromYear, updatedFromMonth, updatedFromDay, updatedToYear, updatedToMonth, updatedToDay;
- struct tm updatedFromDate, updatedToDate;
- vector<Customer> listOfCustomers;
- vector<Campaign> listOfCampaigns;
- vector<Ad> listOfAds;
- int customerMenuPosition = 1, campaignMenuPosition = 1, adMenuPosition = 1;
- int givenCustomerMenuPosition, givenCampaignMenuPosition, givenAdMenuPosition;
- switch (selection)
- {
- case 1:
- {
- CreateNewCustomer(newCustomerName, idIndexCustomer, ase);
- break;
- }
- case 2:
- {
- Customer* chosenCustomer1 = GetChosenCustomer(listOfCustomers, ase, customerName, customerMenuPosition, givenCustomerMenuPosition);
- if (chosenCustomer1)
- {
- CreateNewCampaign(chosenCustomer1, newCampaignName, idIndexCampaign, fromDate, toDate, fromYear, fromMonth, fromDay, toYear, toMonth, toDay, newCampaignCost);
- }
- else
- {
- cout << "Customer not found." << endl;
- }
- break;
- }
- case 3:
- {
- Customer* chosenCustomer2 = GetChosenCustomer(listOfCustomers, ase, customerName, customerMenuPosition, givenCustomerMenuPosition);
- if (chosenCustomer2)
- {
- Campaign* chosenCampaign = GetChosenCampaign(listOfCampaigns, chosenCustomer2, campaignName, campaignMenuPosition, givenCampaignMenuPosition);
- if (chosenCampaign)
- {
- CreateNewAd(chosenCampaign, newAdName, newAdText, newAdTypeInt, newAdType, idIndexAd);
- }
- else
- {
- cout << "Campaign not found." << endl;
- }
- }
- else
- {
- cout << "Customer not found." << endl;
- }
- break;
- }
- case 4:
- {
- Customer* chosenCustomer3 = GetChosenCustomer(listOfCustomers, ase, customerName, customerMenuPosition, givenCustomerMenuPosition);
- if (chosenCustomer3)
- {
- UpdateCustomerMenu(chosenCustomer3, updatedCustomerName);
- }
- else
- {
- cout << "Customer not found." << endl;
- }
- break;
- }
- case 5:
- {
- Customer* chosenCustomer4 = GetChosenCustomer(listOfCustomers, ase, customerName, customerMenuPosition, givenCustomerMenuPosition);
- if (chosenCustomer4)
- {
- Campaign* chosenCampaign3 = GetChosenCampaign(listOfCampaigns, chosenCustomer4, campaignName, campaignMenuPosition, givenCampaignMenuPosition);
- if (chosenCampaign3)
- {
- UpdateCampaignMenu(chosenCampaign3, updatedCampaignName, idIndexCampaign, updatedFromDate, updatedToDate, updatedFromYear, updatedFromMonth, updatedFromDay, updatedToYear, updatedToMonth, updatedToDay, updatedCampaignCost);
- }
- else
- {
- cout << "Campaign not found." << endl;
- }
- }
- else
- {
- cout << "Customer not found." << endl;
- }
- break;
- }
- case 6:
- {
- Customer* chosenCustomer5 = GetChosenCustomer(listOfCustomers, ase, customerName, customerMenuPosition, givenCustomerMenuPosition);
- if (chosenCustomer5)
- {
- Campaign* chosenCampaign4 = GetChosenCampaign(listOfCampaigns, chosenCustomer5, campaignName, campaignMenuPosition, givenCampaignMenuPosition);
- if (chosenCampaign4)
- {
- Ad* chosenAd = GetChosenAd(listOfAds, chosenCampaign4, adName, adMenuPosition, givenAdMenuPosition);
- if (chosenAd)
- {
- UpdateAdMenu(chosenAd, updatedAdName, updatedAdText, updatedAdTypeInt, updatedAdType, idIndexAd);
- }
- }
- else
- {
- cout << "Campaign not found." << endl;
- }
- }
- else
- {
- cout << "Customer not found." << endl;
- }
- break;
- }
- case 7:
- {
- PrintNextAd(ase);
- }
- case 8:
- return 0;
- default:
- cout << "Wrong format!" << endl;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement