Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.48 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5. #include <time.h>
  6. #include <sstream>
  7. #include <fstream>
  8. #include <iomanip>
  9. #include <algorithm>
  10. #include <cstdlib>
  11. #include <sstream>
  12.  
  13. #include "Customer.h"
  14. #include "Campaign.h"
  15. #include "Ad.h"
  16. #include "AdServingEngine.h"
  17.  
  18. using namespace std;
  19.  
  20. void GetYYYYMMDD(string YYYYMMDD, int* YYYY, int* MM, int* DD)
  21. {
  22.  
  23. string dateString = YYYYMMDD;
  24. replace(dateString.begin(), dateString.end(), '/', ' ');
  25.  
  26. vector<int> dateInts;
  27. stringstream dateStream(dateString);
  28. int temp;
  29. while (dateStream >> temp)
  30. dateInts.push_back(temp);
  31.  
  32. *YYYY = dateInts[0];
  33. *MM = dateInts[1];
  34. *DD = dateInts[2];
  35. }
  36.  
  37. void CreateNewCustomer(string name, int idIndex, AdServingEngine ase)
  38. {
  39. cout << "Enter customer name: ";
  40. cin >> name;
  41. idIndex++;
  42. ase.AddCustomer(name, idIndex);
  43. }
  44.  
  45. 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)
  46. {
  47. cout << "Enter the campaign name: ";
  48. cin >> name;
  49.  
  50. string fromDateString;
  51. cout << "Give start date of campaign YYYY/MM/DD: ";
  52. cin >> fromDateString;
  53. GetYYYYMMDD(fromDateString, &fromYear, &fromMonth, &fromDay);
  54. fromDate.tm_year = fromYear - 1900;
  55. fromDate.tm_mon = fromMonth + 1;
  56. fromDate.tm_mday = fromDay;
  57. fromDate.tm_hour = 0;
  58. fromDate.tm_min = 0;
  59. fromDate.tm_sec = 0;
  60. time_t from = mktime(&fromDate);
  61.  
  62. string toDateString;
  63. cout << "Give end date of campaign YYYY/MM/DD: ";
  64. cin >> toDateString;
  65. GetYYYYMMDD(toDateString, &toYear, &toMonth, &toDay);
  66. toDate.tm_year = toYear - 1900;
  67. toDate.tm_mon = toMonth + 1;
  68. toDate.tm_mday = toDay;
  69. toDate.tm_hour = 0;
  70. toDate.tm_min = 0;
  71. toDate.tm_sec = 0;
  72. time_t to = mktime(&toDate);
  73.  
  74. cout << "Enter the campaign cost: ";
  75. cin >> campaignCost;
  76. idIndex++;
  77.  
  78. customer->AddCampaign(name, from, to, campaignCost, idIndex);
  79. }
  80.  
  81. void CreateNewAd(Campaign* campaign, string name, string adText, int adTypeInt, AdType adType, int idIndex)
  82. {
  83. cout << "Enter ad name: ";
  84. cin >> name;
  85. cout << "Enter ad text: ";
  86. cin >> adText;
  87. cin.ignore();
  88. cout << "1. Scroll.\n2. Blink.\n3. PlainText.\nEnter ad type: ";
  89. cin >> adTypeInt;
  90. switch (adType)
  91. {
  92. case 1:
  93. {
  94. adType = AdType::scroll;
  95. }
  96. case 2:
  97. {
  98. adType = AdType::blink;
  99. }
  100. case 3:
  101. {
  102. adType = AdType::plainText;
  103. }
  104. }
  105. idIndex++;
  106. campaign->AddAd(name, adText, adType, idIndex);
  107. }
  108.  
  109. Customer* GetChosenCustomer(vector<Customer> listOfCustomers, AdServingEngine ase, string name, int menuPosition, int givenMenuPosition)
  110. {
  111. listOfCustomers = ase.GetListOfCustomer();
  112. for (auto cust : listOfCustomers)
  113. {
  114. name = cust.GetCustomerName();
  115. cout << menuPosition << ". " << name << endl;
  116. menuPosition++;
  117. }
  118. cout << "Enter for which customers: ";
  119. cin >> givenMenuPosition;
  120. int givenMenuIndex = givenMenuPosition - 1;
  121. Customer* chosenCustomer;
  122. chosenCustomer = ase.GetCustomer(givenMenuIndex);
  123. return chosenCustomer;
  124. }
  125.  
  126. Campaign* GetChosenCampaign(vector<Campaign> listOfCampaigns, Customer* customer, string name, int menuPosition, int givenMenuPosition)
  127. {
  128. listOfCampaigns = customer->GetCampaignList();
  129. for (int i = 0; i < listOfCampaigns.size(); i++)
  130. {
  131. name = listOfCampaigns[i].GetCampaignName();
  132. cout << menuPosition << ". " << name << endl;
  133. menuPosition++;
  134. }
  135. cout << "Enter for which campaign: ";
  136. cin >> givenMenuPosition;
  137. int givenMenuIndex = givenMenuPosition - 1;
  138. Campaign* chosenCampaign;
  139. chosenCampaign = customer->GetCampaign(givenMenuIndex);
  140. return chosenCampaign;
  141. }
  142.  
  143. Ad* GetChosenAd(vector<Ad> listOfAds, Campaign* campaign, string name, int menuPosition, int givenMenuPosition)
  144. {
  145. listOfAds = campaign->GetAdList();
  146. for (int i = 0; i < listOfAds.size(); i++)
  147. {
  148. name = listOfAds[i].GetAdName();
  149. cout << menuPosition << ". " << name << endl;
  150. menuPosition++;
  151. }
  152. cout << "Enter for which ad: ";
  153. cin >> givenMenuPosition;
  154. int givenMenuIndex = givenMenuPosition - 1;
  155. Ad* chosenAd;
  156. chosenAd = campaign->GetAd(givenMenuIndex);
  157. return chosenAd;
  158. }
  159.  
  160. void UpdateCustomerMenu(Customer* customer, string name)
  161. {
  162. cout << "New name: ";
  163. cin >> name;
  164. customer->UpdateCustomer(name);
  165. }
  166.  
  167. 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)
  168. {
  169. cout << "Enter the campaign name: ";
  170. cin >> name;
  171.  
  172. string fromDateString;
  173. cout << "Give start date of campaign YYYY/MM/DD: ";
  174. cin >> fromDateString;
  175. GetYYYYMMDD(fromDateString, &fromYear, &fromMonth, &fromDay);
  176. fromDate.tm_year = fromYear - 1900;
  177. fromDate.tm_mon = fromMonth + 1;
  178. fromDate.tm_mday = fromDay;
  179. fromDate.tm_hour = 0;
  180. fromDate.tm_min = 0;
  181. fromDate.tm_sec = 0;
  182. time_t from = mktime(&fromDate);
  183.  
  184. string toDateString;
  185. cout << "Give end date of campaign YYYY/MM/DD: ";
  186. cin >> toDateString;
  187. GetYYYYMMDD(toDateString, &toYear, &toMonth, &toDay);
  188. toDate.tm_year = toYear - 1900;
  189. toDate.tm_mon = toMonth + 1;
  190. toDate.tm_mday = toDay;
  191. toDate.tm_hour = 0;
  192. toDate.tm_min = 0;
  193. toDate.tm_sec = 0;
  194. time_t to = mktime(&toDate);
  195.  
  196. cout << "Enter the campaign cost: ";
  197. cin >> campaignCost;
  198.  
  199. campaign->UpdateCampaign(name, from, to, campaignCost);
  200. }
  201.  
  202. void UpdateAdMenu(Ad* ad, string name, string adText, int adType, AdType nextAdType, int idIndex)
  203. {
  204. cout << "Enter ad name: ";
  205. cin >> name;
  206. cout << "Enter ad text: ";
  207. cin >> adText;
  208. cin.ignore();
  209. cout << "1. Scroll.\n2. Blink.\n3. PlainText.\nEnter ad type: ";
  210. cin >> adType;
  211. switch (adType)
  212. {
  213. case 1:
  214. {
  215. nextAdType = AdType::scroll;
  216. }
  217. case 2:
  218. {
  219. nextAdType = AdType::blink;
  220. }
  221. case 3:
  222. {
  223. nextAdType = AdType::plainText;
  224. }
  225. ad->UpdateAd(name, adText, nextAdType);
  226. }
  227. return;
  228. }
  229.  
  230. void PrintNextAd(AdServingEngine ase)
  231. {
  232. Ad ad = ase.GetNextAd();
  233. string adText = ad.GetAdText();
  234. AdType adType = ad.GetAdType();
  235. if (adType == AdType::scroll)
  236. cout << "Scrolling: " << adText << endl;
  237. else if (adType == AdType::blink)
  238. cout << "Blinking: " << adText << endl;
  239. else if (adType == AdType::plainText)
  240. cout << adText << endl;
  241. }
  242.  
  243. int main()
  244. {
  245. int idIndexCustomer = 0, idIndexCampaign = 0, idIndexAd = 0;
  246. AdServingEngine ase;
  247. while (true)
  248. {
  249. int selection;
  250. 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";
  251. cin >> selection;
  252.  
  253. string newCustomerName, newCampaignName, newAdName, newAdText;
  254. float newCampaignCost;
  255. int newAdTypeInt;
  256. AdType newAdType;
  257.  
  258. string updatedCustomerName, updatedCampaignName, updatedAdName, updatedAdText;
  259. float updatedCampaignCost;
  260. int updatedAdTypeInt;
  261. AdType updatedAdType;
  262.  
  263. string customerName, campaignName, adName;
  264.  
  265. int fromYear, fromMonth, fromDay, toYear, toMonth, toDay;
  266. struct tm fromDate, toDate;
  267.  
  268. int updatedFromYear, updatedFromMonth, updatedFromDay, updatedToYear, updatedToMonth, updatedToDay;
  269. struct tm updatedFromDate, updatedToDate;
  270.  
  271. vector<Customer> listOfCustomers;
  272. vector<Campaign> listOfCampaigns;
  273. vector<Ad> listOfAds;
  274.  
  275. int customerMenuPosition = 1, campaignMenuPosition = 1, adMenuPosition = 1;
  276. int givenCustomerMenuPosition, givenCampaignMenuPosition, givenAdMenuPosition;
  277.  
  278. switch (selection)
  279. {
  280. case 1:
  281. {
  282. CreateNewCustomer(newCustomerName, idIndexCustomer, ase);
  283. break;
  284. }
  285. case 2:
  286. {
  287. Customer* chosenCustomer1 = GetChosenCustomer(listOfCustomers, ase, customerName, customerMenuPosition, givenCustomerMenuPosition);
  288. if (chosenCustomer1)
  289. {
  290. CreateNewCampaign(chosenCustomer1, newCampaignName, idIndexCampaign, fromDate, toDate, fromYear, fromMonth, fromDay, toYear, toMonth, toDay, newCampaignCost);
  291. }
  292. else
  293. {
  294. cout << "Customer not found." << endl;
  295. }
  296. break;
  297. }
  298. case 3:
  299. {
  300. Customer* chosenCustomer2 = GetChosenCustomer(listOfCustomers, ase, customerName, customerMenuPosition, givenCustomerMenuPosition);
  301. if (chosenCustomer2)
  302. {
  303. Campaign* chosenCampaign = GetChosenCampaign(listOfCampaigns, chosenCustomer2, campaignName, campaignMenuPosition, givenCampaignMenuPosition);
  304. if (chosenCampaign)
  305. {
  306. CreateNewAd(chosenCampaign, newAdName, newAdText, newAdTypeInt, newAdType, idIndexAd);
  307. }
  308. else
  309. {
  310. cout << "Campaign not found." << endl;
  311. }
  312. }
  313. else
  314. {
  315. cout << "Customer not found." << endl;
  316. }
  317. break;
  318. }
  319. case 4:
  320. {
  321. Customer* chosenCustomer3 = GetChosenCustomer(listOfCustomers, ase, customerName, customerMenuPosition, givenCustomerMenuPosition);
  322. if (chosenCustomer3)
  323. {
  324. UpdateCustomerMenu(chosenCustomer3, updatedCustomerName);
  325. }
  326. else
  327. {
  328. cout << "Customer not found." << endl;
  329. }
  330. break;
  331. }
  332. case 5:
  333. {
  334. Customer* chosenCustomer4 = GetChosenCustomer(listOfCustomers, ase, customerName, customerMenuPosition, givenCustomerMenuPosition);
  335. if (chosenCustomer4)
  336. {
  337. Campaign* chosenCampaign3 = GetChosenCampaign(listOfCampaigns, chosenCustomer4, campaignName, campaignMenuPosition, givenCampaignMenuPosition);
  338. if (chosenCampaign3)
  339. {
  340. UpdateCampaignMenu(chosenCampaign3, updatedCampaignName, idIndexCampaign, updatedFromDate, updatedToDate, updatedFromYear, updatedFromMonth, updatedFromDay, updatedToYear, updatedToMonth, updatedToDay, updatedCampaignCost);
  341. }
  342. else
  343. {
  344. cout << "Campaign not found." << endl;
  345. }
  346. }
  347. else
  348. {
  349. cout << "Customer not found." << endl;
  350. }
  351. break;
  352. }
  353. case 6:
  354. {
  355. Customer* chosenCustomer5 = GetChosenCustomer(listOfCustomers, ase, customerName, customerMenuPosition, givenCustomerMenuPosition);
  356. if (chosenCustomer5)
  357. {
  358. Campaign* chosenCampaign4 = GetChosenCampaign(listOfCampaigns, chosenCustomer5, campaignName, campaignMenuPosition, givenCampaignMenuPosition);
  359. if (chosenCampaign4)
  360. {
  361. Ad* chosenAd = GetChosenAd(listOfAds, chosenCampaign4, adName, adMenuPosition, givenAdMenuPosition);
  362. if (chosenAd)
  363. {
  364. UpdateAdMenu(chosenAd, updatedAdName, updatedAdText, updatedAdTypeInt, updatedAdType, idIndexAd);
  365. }
  366. }
  367. else
  368. {
  369. cout << "Campaign not found." << endl;
  370. }
  371. }
  372. else
  373. {
  374. cout << "Customer not found." << endl;
  375. }
  376. break;
  377. }
  378. case 7:
  379. {
  380. PrintNextAd(ase);
  381. }
  382. case 8:
  383. return 0;
  384. default:
  385. cout << "Wrong format!" << endl;
  386. break;
  387. }
  388. }
  389. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement