Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

1. Write CppUnitLite tests to verify correct behavior for all the exercises. Using C++ 2. Please show all outputs. Write functions to add one day,

1. Write CppUnitLite tests to verify correct behavior for all the exercises. Using C++

2. Please show all outputs.

Write functions to add one day, another function to add one month, and yet another function to add one year to a Date struct.

struct Date { int year; int month; int day; }; 

Pass Dates by reference when appropriate (i.e., Date& or const Date&). For example, the following function returns by value a new Date instance with one day added to the passed in date.

Date addOneDay(const Date& date); 

Create a C++ header file named write.h which contains function prototypes for three functions named write. Write the implementations for each write function in a file named write.cpp. Each write function takes two arguments. The first argument is always std::ostream& os. The second arguments are an int, a float, and a std::string respectively. Each write function should stream its second argument to the passed in std::ostream. Write cppunitlite unit tests that pass a std::stringstream as the first argument to each function and verify its operation. Write non unit test code that calls each write function and passes std::cout as the first argument (the cout tests are written outside the unit test framework because verification can't easily be automated). Here's the prototype for the first write overload:

void write(std::ostream& os, int value);

Notice that both std::stringstream and std::cout may be passed as the first argument. Both inherit from std::ostream and thus may be used where ever a std::ostream& is used. This is our first use of inheritance in C++. We'll do much more with inheritance as the course progresses.

Write a lambda function which makes the following TEST pass:

TEST(lambdaTestProblem, lambdas) { auto values = { 2, 4, 6, 8, 10, 12 }; auto sum = 0; std::for_each(values.begin(), values.end(), /*define lambda function here*/); CHECK_EQUAL(42, sum); } 

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_2

Step: 3

blur-text-image_3

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students explore these related Databases questions

Question

what is a peer Group? Importance?

Answered: 3 weeks ago