Macro parameters can be converted to strings inside the macro, a process called stringizing. Use that to modify the ASSERT macro so that it prints the assertion which failed. #ifndef MYASSERT_H...



Macro parameters can be converted to strings inside the macro, a process called stringizing. Use that to modify the ASSERT macro so that it prints the assertion which failed.


#ifndef MYASSERT_H
#define MYASSERT_H


#include
#define ASSERT(CONDITION, MSG) \
if (!(CONDITION)) std::cerr < "assert="" failed:="">< msg="">< std::endl;="">
else std::cerr < "assert="" passed"=""><>


#endif


Tester.cpp


#include #include #include #include using namespace std; #include "myassert.h" int main() { double n = 1 / 4; ASSERT(n == .25, "Invalid division"); cout < "expected:="" assert="" failed:="" n="=" .25:="" invalid="" division"="">< endl;="" double="" x="12" %="" 5;="" assert(x="=" 2.0,="" "invalid="" remainder");="" cout="">< "expected:="" assert="" passed:="" x="=" 2.0"="">< endl;="">




Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here