Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2 Console outputs that you are required to write your code to exactly match them are written at the very end of the paper.

image text in transcribedimage text in transcribed

Question 2

Console outputs that you are required to write your code to exactly match them are written at the very end of the paper. Q4, Q5 and Q6 looks dependent in the code below. However, they will be evaluated on their own with their own input. That means, if you cannot solve Q4, Q5 will be tested with its intended input coming from a correct Q4 solution. The same situation applies to Q6 as well. Q6 will be tested with its intended input coming from a correct Q5 solution. Remember that we'll test your code with different inputs! Copy the code below to your editor and create midterm2.cpp" file and start solving it. // StudentID: xxxxxxxx, Name: AAA BBB CCC #include #include #include #include 1/ CAREFUL! + Do not use "using namespace std;". Always write std:: explicitly in your solutions if you want to use standard lib. // + std::string also has a begin().end(), size() methods. std::string is actually a container of chars. 1 + transform algorithm required in this exam is slightly more generic it can not only change container's values but can also change the type to a new type i.e. std::vector int>(10) may be transformed to std::vector<:string> "11") 1/ (if the supplied lambda was: increment by one, convert to a string and return it) 1 + It is enough for this exam to support only std::vector as container. W + You can also capture lambdas with "const auto lambda" instead of "auto lambda". It won't be a problem for this exam. 1 + Exam starts below. Provided code CANNOT be changed. Just fill in the necessary gaps to produce the wanted outcome (output). 1/ + Type aliases and traits for easy usage of std classes are declared for you as shown below. using String = std::string; template using Vector = std::vector; template using Tuple - std::tuple; template struct is tuple 1 static const bool value = false; }; template struct is_tuple<:tuple>> statie const bool value = true; }; Il custom user literal s is declared for easy std::string constant usage such as "hello"_s auto operator"" s (const chart 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) IL 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) 0);); struct Surname : String { using String:: String: Surname (const Stringa s) : String(s) 0); struct BirthYear : Integer { using Integer:: Integer; }; struct DeathYear : Integer | using Integer::Integer; !: using Scientist Tuple; using Scientists - Vector Scientist>; // A simple struet 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) it; struct Url : String { using String:: String; Url(const Strings s) : String(s) (); }; using Link - Tuple; using Links - Vector; // Declare necessary concepts, operator overloads, algorithms, their higher order versions, etc. 11 for to make below code execute and produce the wanted output exactly as described. 1/ WRITE YOUR CODE HERE, DO NOT CHANGE ANY OTHER PLACE // Below are written for you and shall not be changed. int main(int,char* 11) 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 Midterm begins:" si printer(); print("Q1 - Print scientists' and 'links' containers"); '' "); scientists printer ("Scientists"); links printer ("Links"); *scientists.begin() Ieval_namesurname() | printer ("Q2 - Write a lambda that returns 'Name' and 'Surname' concatenated with a space"); scientists transform(eval_namesurname()) printer("03 - Transform tuples with a new one with 'Name Surname concatenated"); cartesian (scientists, links) I printer ("04 - Cartesian Product of two containers") where[=] (const autos tpl) { return eval_namesurname() (tpl) == get(tpi): ) I printer (25 - Filter the elements where evaluated name surname is equal to the full name") select Url, FullName, BirthYear, Death Year) printer ("Q6 - Select Url, FullName, BirthYear, DeathYear fields in that order"); , ; scientists where (get() equal to ("Adas)) printer ("07 - Filter the elements where Name field is equal to 'Ada); return 0; 1 CS321 Midterm 2 begins: 2 Q1 - Print scientists' and 'links' containers Scientists (Charles) (Babbage) (1791) (1871) (Ada) (Lovelace) (1815) (1852) (Alan) (Turing) (1912) (1954) Links (Ada Lovelace) (https://en.wikipedia.org/wiki/Ada Lovelace) (Alan Turing) (https://en.wikipedia.org/wiki/Alan Turing) Q2 - Write a lambda that returns 'Name' and 'Surname concatenated with a space Charles Babbage 03 - Transform tuples with a new one with 'Name Surname' concatenated Charles Babbage Ada Lovelace Alan Turing 04 - Cartesian Product of two containers (Charles) (Babbage) (1791) (1871) (Ada Lovelace) (https://en.wikipedia.org/wiki/Ada_Lovelace) (Charles) (Babbage) (1791) (1871) (Alan Turing) https://en.wikipedia.org/wiki/Alan Turing) (Ada) (Lovelace) (1815) (1852) (Ada Lovelace) (https://en.wikipedia.org/wiki/Ada Lovelace) (Ada) (Lovelace) (1815) (1852) (Alan Turing) (https://en.wikipedia.org/wiki/Alan Turing) (Alan) (Turing) (1912) (1954) (Ada Lovelace) (https://en.wikipedia.org/wiki/Ada Lovelace) (Alan) (Turing) (1912) (1954) (Alan Turing) (https://en.wikipedia.org/wiki/Alan Turing) Q5 Filter the elements where evaluated name surname is equal to the full name (Ada) (Lovelace) (1815) (1852) (Ada Lovelace) (https://en.wikipedia.org/wiki/Ada Lovelace) (Alan) (Turing) (1912) (1954) (Alan Turing) (https://en.wikipedia.org/wiki/Alan Turing) 06 Select Url, FullName, BirthYear, DeathYear fields in that order (https://en.wikipedia.org/wiki/Ada Lovelace) (Ada Lovelace) (1815) (1852) (https://en.wikipedia.org/wiki/Alan Turing) (Alan Turing) (1912) (1954) 07 - Filter the elements where Name field is equal to 'Ada (Ada) (Lovelace) (1815) (1852) Console outputs that you are required to write your code to exactly match them are written at the very end of the paper. Q4, Q5 and Q6 looks dependent in the code below. However, they will be evaluated on their own with their own input. That means, if you cannot solve Q4, Q5 will be tested with its intended input coming from a correct Q4 solution. The same situation applies to Q6 as well. Q6 will be tested with its intended input coming from a correct Q5 solution. Remember that we'll test your code with different inputs! Copy the code below to your editor and create midterm2.cpp" file and start solving it. // StudentID: xxxxxxxx, Name: AAA BBB CCC #include #include #include #include 1/ CAREFUL! + Do not use "using namespace std;". Always write std:: explicitly in your solutions if you want to use standard lib. // + std::string also has a begin().end(), size() methods. std::string is actually a container of chars. 1 + transform algorithm required in this exam is slightly more generic it can not only change container's values but can also change the type to a new type i.e. std::vector int>(10) may be transformed to std::vector<:string> "11") 1/ (if the supplied lambda was: increment by one, convert to a string and return it) 1 + It is enough for this exam to support only std::vector as container. W + You can also capture lambdas with "const auto lambda" instead of "auto lambda". It won't be a problem for this exam. 1 + Exam starts below. Provided code CANNOT be changed. Just fill in the necessary gaps to produce the wanted outcome (output). 1/ + Type aliases and traits for easy usage of std classes are declared for you as shown below. using String = std::string; template using Vector = std::vector; template using Tuple - std::tuple; template struct is tuple 1 static const bool value = false; }; template struct is_tuple<:tuple>> statie const bool value = true; }; Il custom user literal s is declared for easy std::string constant usage such as "hello"_s auto operator"" s (const chart 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) IL 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) 0);); struct Surname : String { using String:: String: Surname (const Stringa s) : String(s) 0); struct BirthYear : Integer { using Integer:: Integer; }; struct DeathYear : Integer | using Integer::Integer; !: using Scientist Tuple; using Scientists - Vector Scientist>; // A simple struet 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) it; struct Url : String { using String:: String; Url(const Strings s) : String(s) (); }; using Link - Tuple; using Links - Vector; // Declare necessary concepts, operator overloads, algorithms, their higher order versions, etc. 11 for to make below code execute and produce the wanted output exactly as described. 1/ WRITE YOUR CODE HERE, DO NOT CHANGE ANY OTHER PLACE // Below are written for you and shall not be changed. int main(int,char* 11) 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 Midterm begins:" si printer(); print("Q1 - Print scientists' and 'links' containers"); '' "); scientists printer ("Scientists"); links printer ("Links"); *scientists.begin() Ieval_namesurname() | printer ("Q2 - Write a lambda that returns 'Name' and 'Surname' concatenated with a space"); scientists transform(eval_namesurname()) printer("03 - Transform tuples with a new one with 'Name Surname concatenated"); cartesian (scientists, links) I printer ("04 - Cartesian Product of two containers") where[=] (const autos tpl) { return eval_namesurname() (tpl) == get(tpi): ) I printer (25 - Filter the elements where evaluated name surname is equal to the full name") select Url, FullName, BirthYear, Death Year) printer ("Q6 - Select Url, FullName, BirthYear, DeathYear fields in that order"); , ; scientists where (get() equal to ("Adas)) printer ("07 - Filter the elements where Name field is equal to 'Ada); return 0; 1 CS321 Midterm 2 begins: 2 Q1 - Print scientists' and 'links' containers Scientists (Charles) (Babbage) (1791) (1871) (Ada) (Lovelace) (1815) (1852) (Alan) (Turing) (1912) (1954) Links (Ada Lovelace) (https://en.wikipedia.org/wiki/Ada Lovelace) (Alan Turing) (https://en.wikipedia.org/wiki/Alan Turing) Q2 - Write a lambda that returns 'Name' and 'Surname concatenated with a space Charles Babbage 03 - Transform tuples with a new one with 'Name Surname' concatenated Charles Babbage Ada Lovelace Alan Turing 04 - Cartesian Product of two containers (Charles) (Babbage) (1791) (1871) (Ada Lovelace) (https://en.wikipedia.org/wiki/Ada_Lovelace) (Charles) (Babbage) (1791) (1871) (Alan Turing) https://en.wikipedia.org/wiki/Alan Turing) (Ada) (Lovelace) (1815) (1852) (Ada Lovelace) (https://en.wikipedia.org/wiki/Ada Lovelace) (Ada) (Lovelace) (1815) (1852) (Alan Turing) (https://en.wikipedia.org/wiki/Alan Turing) (Alan) (Turing) (1912) (1954) (Ada Lovelace) (https://en.wikipedia.org/wiki/Ada Lovelace) (Alan) (Turing) (1912) (1954) (Alan Turing) (https://en.wikipedia.org/wiki/Alan Turing) Q5 Filter the elements where evaluated name surname is equal to the full name (Ada) (Lovelace) (1815) (1852) (Ada Lovelace) (https://en.wikipedia.org/wiki/Ada Lovelace) (Alan) (Turing) (1912) (1954) (Alan Turing) (https://en.wikipedia.org/wiki/Alan Turing) 06 Select Url, FullName, BirthYear, DeathYear fields in that order (https://en.wikipedia.org/wiki/Ada Lovelace) (Ada Lovelace) (1815) (1852) (https://en.wikipedia.org/wiki/Alan Turing) (Alan Turing) (1912) (1954) 07 - Filter the elements where Name field is equal to 'Ada (Ada) (Lovelace) (1815) (1852)

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

=+11.3. Show that Theorem 11.4(ii) can fail if u(B) =00.

Answered: 1 week ago

Question

18tionariar toryte 18tionariar toryte

Answered: 1 week ago

Question

9. Describe the characteristics of power.

Answered: 1 week ago

Question

3. Identify and describe nine cultural value orientations.

Answered: 1 week ago