Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// StudentID: xxxxxxxx, Name: AAA BBB CCC #include #include #include #include using String = std::string; template using Vector = std::vector ; template using Tuple =

// StudentID: xxxxxxxx, Name: AAA BBB CCC #include #include #include #include

using String = std::string; template using Vector = std::vector; template using Tuple = std::tuple;

template struct is_tuple { static const bool value = false; };

template struct is_tuple> { static const bool value = true; };

// custom user literal _s is declared for easy std::string constant usage such as "hello"_s auto operator"" _s(const char* str, size_t) { return std::string(str); }

// Distinct new classes are derived from already available base classes for you struct Integer { int value; Integer(int value) : value(value) { } };

// A simple struct and its container is declared in a generic way that has 4 dimensions struct Name : String { using String::String; Name(const String& s) : String(s) {};}; struct Surname : String { using String::String; Surname(const String& s) : String(s) {};}; struct BirthYear : Integer { using Integer::Integer; }; struct DeathYear : Integer { using Integer::Integer; }; using Scientist = Tuple; using Scientists = Vector;

// A simple struct and its container is declared in a generic way that has 2 dimensions struct FullName : String { using String::String; FullName(const String& s) : String(s) {}; }; struct Url : String { using String::String; Url(const String& s) : String(s) {}; }; using Link = Tuple; using Links = Vector;

// Declare necessary concepts, operator overloads, algorithms, their higher order versions, etc. // for to make below code execute and produce the wanted output exactly as described. // WRITE YOUR CODE HERE, DO NOT CHANGE ANY OTHER PLACE

// Below are written for you and shall not be changed. int main(int, char* []) {

auto scientists = Scientists{ {"Charles", "Babbage", 1791, 1871}, {"Ada", "Lovelace", 1815, 1852}, {"Alan", "Turing", 1912, 1954}, }; auto links = Links{ {"Ada Lovelace", "https://en.wikipedia.org/wiki/Ada_Lovelace"}, {"Alan Turing", "https://en.wikipedia.org/wiki/Alan_Turing"}, }; "CS321 Homework:"_s | printer(); print("Q1 - Print 'scientists' and 'links' containers"); scientists | printer("Scientists"); links | printer("Links"); *scientists.begin() | eval_namesurname() | printer("Q2 - Write a lambda that returns 'Name' and 'Surname' concatenated with a space"); scientists | transform(eval_namesurname()) | printer("Q3 - Transform tuples with a new one with 'Name Surname' concatenated"); cartesian(scientists, links) | printer("Q4 - Cartesian Product of two containers") | where([=](const auto& tpl) { return eval_namesurname()(tpl) == get(tpl); }) | printer("Q5 - Filter the elements where evaluated name surname is equal to the full name") | select() | printer("Q6 - Select Url, FullName, BirthYear, DeathYear fields in that order"); scientists | where(get() | equal_to("Ada"_s)) | printer("Q7 - Filter the elements where Name field is equal to 'Ada'"); return 0; }

I want to print 'scientists' and 'links' containers as written in the below:

Scientists (Charles) (Babbage) (1791) (1871) (Ada) (Lovelace) (1815) (1852) (Alan) (Turing) (1912) (1954)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

then (d) If In which case W (2)

Answered: 1 week ago