Files
cppcourse/397/SolutionEx71Bonus/main.cpp
T
2026-10-05 11:27:21 +02:00

82 lines
2.1 KiB
C++

#pragma warning(disable : 4786)
#include "CompanyEntry.h"
#include "CountVisitor.h"
#include "FindVisitor.h"
#include "GroupEntry.h"
#include "PersonEntry.h"
#include "PrintVisitor.h"
#include <iostream>
using namespace std;
int main() {
// declare an address book
GroupEntry addressbook("My addressbook");
// create some entries
PersonEntry Fred("Fred", "555 1234");
PersonEntry Gert("Gert", "555 1235");
PersonEntry Jim("Jim", "999 2445");
PersonEntry Sue("Sue", "456 2951");
PersonEntry Ingar("Ingar", "999 2345");
PersonEntry Lisa("Lisa", "443 4532");
CompanyEntry ShoeWorld("ShoeWorld", "Shoes", "234 4314");
CompanyEntry BestBurgers("BestBurgers", "Food", "456 4651");
CompanyEntry DreamPizza("DreamPizza", "Food", "935 2345");
CompanyEntry BestBooks("BestBooks", "Books", "345 3232");
// add some simple entries
addressbook.addEntry(Fred);
addressbook.addEntry(Gert);
addressbook.addEntry(ShoeWorld);
// make some groups
GroupEntry group1("My Best Food");
group1.addEntry(BestBurgers);
group1.addEntry(DreamPizza);
GroupEntry group2("Coworkers");
group2.addEntry(Jim);
group2.addEntry(Sue);
// make a nested group
GroupEntry group3("Favorites");
group3.addEntry(Ingar);
group3.addEntry(Lisa);
group3.addEntry(BestBooks);
group3.addEntry(group1);
addressbook.addEntry(group2);
addressbook.addEntry(group3);
cout << "\n\n";
cout << "*** Print using Composite print operation\n";
addressbook.print();
cout << "\n\n";
cout << "*** Print using PrintVisitor\n";
PrintVisitor printVisitor;
addressbook.accept(printVisitor);
cout << "\n\n";
cout << "*** Find using Visitor\n";
FindVisitor pv("Fred");
addressbook.accept(pv);
for (const Entry *p : pv.getFindings()) {
p->print();
}
cout << "*** Print Entry counts using Visitor\n";
CountVisitor cv;
addressbook.accept(cv);
cv.printCounts();
cout << "*** Test complete\n";
return 0;
}