SlideShare a Scribd company logo
1 of 86
#include "Status.h"
namespace sdds
{
Status::Status(char* str, int code)
{
if (str != NULL)
{
description = new char[strlen(str) + 1];
strcpy(description, str);
}
else
description = NULL;
status_code = code;
}
Status::Status(const Status& s)
{
if (!s)
{
description = new char[strlen(s.description) +
1];
strcpy(description, s.description);
}
else
description = NULL;
status_code = s.status_code;
}
Status& Status::operator=(const Status& s)
{
if (!s)
{
description = new char[strlen(s.description) +
1];
strcpy(description, s.description);
}
else
description = NULL;
status_code = s.status_code;
return *this;
}
Status::~Status()
{
delete(description);
}
Status& Status::operator=(const char* str)
{
description = new char[strlen(str) + 1];
strcpy(description, str);
return *this;
}
Status& Status::operator=(const int code)
{
status_code = code;
return *this;
}
Status::operator bool() const
{
if (description == NULL)
return true;
else
return false;
}
Status::operator int() const
{
return status_code;
}
Status::operator char* () const
{
return (char*)description;
}
ostream& operator<<(ostream& out, const Status& s)
{
if (!s)
{
if (s.status_code != 0)
out << "ERR#" << s.status_code << ": ";
out << s.description;
}
return out;
}
Status& Status::clear()
{
description = NULL;
status_code = 0;
return *this;
}
}
#include <iostream>
#include "Date.h"
#include "Utils.h"
#include "Status.h"
using namespace std;
using namespace sdds;
void statusTester();
void dateTester();
int main() {
cout << "Status Tester ---------------------------------------------
--------" << endl;
statusTester();
cout << "Date Tester ----------------------------------------------
---------" << endl;
dateTester();
}
// Copied from StatusTestr.cpp
const int c_min{ 0 };
const int c_max{ 100 };
class Container {
int m_val{};
sdds::Status m_state;
Container& set(int value) {
if (value < c_min) {
m_state = "value too low";
m_state = -1;
}
else if (value > c_max) {
m_state = "value too high";
m_state = 1;
}
else {
m_state.clear();
}
return *this;
}
public:
Container(int value = 0) {
set(value);
}
istream& read(istream& istr = cin) {
istr >> m_val;
m_state.clear();
if (istr) {
set(m_val);
}
else {
m_state = "Invalid Integer";
istr.clear();
}
istr.ignore(1000, 'n');
return istr;
}
ostream& write(ostream& ostr = cout)const {
if (m_state) {
ostr << m_val;
}
else {
ostr << m_state;
}
return ostr;
}
Container& value(int val) {
set(val);
return *this;
}
int value()const {
return m_val;
}
operator bool()const {
return m_state;
}
const sdds::Status& state()const {
return m_state;
}
};
ostream& operator<<(ostream& ostr, const Container& I) {
return I.write(ostr);
}
istream& operator>>(istream& istr, Container& I) {
return I.read(istr);
}
void prnContainer(Container C) {
cout << "Container: (" << C << ")" << endl;
if (!C) {
cout << "Error #: " << int(C.state()) << endl;
cout << "Problem: " << (const char*)(C.state()) << endl;
}
}
void statusTester() {
Container c;
cout << "Enter following values :nabcn123n-123n12" <<
endl;
for (int i = 0; i < 4; i++) {
cout << "> ";
cin >> c;
prnContainer(c);
}
}
// Copied from DateTester.cpp
void testDate() {
Date D;
cout << "> ";
cin >> D;
if (!cin) {
cin.clear();
cin.ignore(1000, 'n');
cout << D.state() << endl;
}
else {
cout << "Date enterd: " << D << endl;
}
}
void dateTester() {
cout << "Current Date: " << Date() << endl;
cout << "Test mode: " << endl;
ut.testMode();
Date C;
Date F(2022, 5, 25);
cout << "Current Date formatted (C): " << C << endl;
C.formatted(false);
cout << "Current Date unformatted (C): " << C << endl;
cout << "Future Date formatted (F): " << F << endl;
F.formatted(false);
cout << "Future Date unformatted (F): " << F << endl;
cout << "The current date is" << (C != F ? " NOT" : "") << "
the same as the future date" << endl;
cout << "The current date is" << (C == C ? "" : " NOT") << "
the same as the current date" << endl;
cout << "The current date is" << (C <= F ? " Less than or
equal to" : " greater than") << " the future date" << endl;;
cout << "The current date is" << (C <= C ? " Less than or
equal to" : " greater than") << " the current date" << endl;;
cout << "The current date is" << (C < F ? " Less than" : "
greater than or equal to") << " the future date" << endl;;
cout << "The future date is" << (F >= C ? " greater than or
equal to" : " Less than") << " the current date" << endl;;
cout << "The future date is" << (F >= F ? " greater than or
equal to" : " Less than") << " the future date" << endl;;
cout << "The future date is" << (F > C ? " greater than" : "
Less than or equal to") << " the current date" << endl;;
cout << "--------------nAssigning the Current date to the
future date!" << endl;
C = F;
if (C == F)
cout << "Now both of the dates are the same!" << endl;
else
cout << "The two dates are different after assignment!!! !!"
<< endl;
cout << "Enter the following:n1- abcn2- 12n3- 1212n4-
121212"
"n5- 221312n6- 220229n7- 220228" << endl;
for (int i = 0; i < 7; i++) {
testDate();
}
}
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <ctime>
#include "Utils.h"
using namespace std;
namespace sdds {
Utils ut;
void Utils::testMode(bool testmode) {
m_testMode = testmode;
}
void Utils::getSystemDate(int* year, int* mon, int* day) {
if (m_testMode) {
if (day) *day = sdds_testDay;
if (mon) *mon = sdds_testMon;
if (year) *year = sdds_testYear;
}
else {
time_t t = std::time(NULL);
tm lt = *localtime(&t);
if (day) *day = lt.tm_mday;
if (mon) *mon = lt.tm_mon + 1;
if (year) *year = lt.tm_year + 1900;
}
}
int Utils::daysOfMon(int month, int year)const {
int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
-1 };
int mon = (month >= 1 && month <= 12 ? month : 13) - 1;
return days[mon] + int((mon == 1) * ((year % 4 == 0) &&
(year % 100 != 0)) || (year % 400 == 0));
}
}
#include <iostream>
#include <cstring>
#include <ctime>
#include "Date.h"
namespace sdds {
int Date::currentYear() {
time_t current_time;
current_time = time(NULL);
int year = 1970 + current_time / 31537970;
return year;
}
int Date::currentMonth() {
std::time_t current_time;
current_time = std::time(NULL);
std::tm* now = std::localtime(&current_time);
int month = now->tm_mon + 1;
return month;
}
int Date::currentDay() {
std::time_t current_time;
current_time = std::time(NULL);
std::tm* now = std::localtime(&current_time);
int day = now->tm_mday;
return day;
}
int Date::numOfDays(int mon, int year) const {
int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
-1 };
int month = mon >= 1 && mon <= 12 ? mon : 13;
month--;
return days[month] + int((month == 1) * ((year % 4 == 0)
&& (year % 100 != 0)) || (year % 400 == 0));
}
bool Date::validate() {
bool isValid;
int min_year = currentYear();
if (m_year < min_year || m_year > max_year) {
State = "Invalid year in date";
State = 1;
isValid = false;
}
else if (m_month < 1 || m_month > 12) {
State = "Invalid month in date";
State = 2;
isValid = false;
}
else if (m_day < 1 || m_day > numOfDays(m_month,
m_year)) {
State = "Invalid day in date";
State = 3;
isValid = false;
}
else {
State.clear();
isValid = true;
}
return isValid;
}
Date::Date() {
m_year = currentYear();
m_month = currentMonth();
m_day = currentDay();
m_formatted = true;
}
Date::Date(int year, int month, int day) {
m_year = year;
m_month = month;
m_day = day;
m_formatted = true;
}
int Date::uniqueDateValue()const {
return m_year * 372 + m_month * 31 + m_day;
}
bool Date::operator==(const Date& data) const {
return (this->uniqueDateValue() ==
data.uniqueDateValue());
}
bool Date::operator!=(const Date& data) const {
return (this->uniqueDateValue() !=
data.uniqueDateValue());
}
bool Date::operator<(const Date& data) const {
return (this->uniqueDateValue() <
data.uniqueDateValue());
}
bool Date::operator>(const Date& data)const {
return (this->uniqueDateValue() >
data.uniqueDateValue());
}
bool Date::operator<=(const Date& data)const {
return (this->uniqueDateValue() <=
data.uniqueDateValue());
}
bool Date::operator>=(const Date& data)const {
return (this->uniqueDateValue() >=
data.uniqueDateValue());
}
const Status& Date::state() {
return State;
}
Date& Date::formatted(bool formatted) {
m_formatted = formatted;
return *this;
}
std::ostream& Date::write(std::ostream& ostr) const {
if (m_formatted == true) {
ostr << m_year << "/";
if (m_month < 10) {
ostr << "0" << m_month << "/";
}
else {
ostr << m_month << "/";
}
if (m_day < 10) {
ostr << "0" << m_day;
}
else {
ostr << m_day;
}
}
else if (m_formatted == false) {
ostr << m_year % 100;
if (m_month < 10) {
ostr << "0" << m_month;
}
else {
ostr << m_month;
}
if (m_day < 10) {
ostr << "0" << m_day;
}
else {
ostr << m_day;
}
}
return ostr;
}
std::istream& Date::read(std::istream& istr) {
int date, size;
int year, month, day;
string tmp;
istr >> date;
tmp = to_string(date);
size = tmp.size();
if (size == 2)
{
m_year = currentYear();
m_month = 0;
m_day = date;
}
else if (size == 4)
{
m_year = currentYear();
m_month = date / 100;
m_day = date % 100;
}
else if (size == 6)
{
m_year = 2000 + date / 10000;
m_month = (date / 100) % 100;
m_day = date % 100;
}
else
{
cout << "Invalid date value";
}
if (validate() == false)
istr.std::istream::setstate(ios::badbit);
return istr;
}
std::ostream& operator<<(std::ostream& ostr, Date const&
data) {
return data.write(ostr);
}
std::istream& operator>>(std::istream& istr, Date& data) {
return data.read(istr);
}
}
correct output
this is the correct output
Script started on Wed 02 Mar 2022 07:28:07 PM EST
==112027== Memcheck, a memory error detector
==112027== Copyright (C) 2002-2017, and GNU GPL'd, by
Julian Seward et al.
==112027== Using Valgrind-3.15.0 and LibVEX; rerun with -h
for copyright info
==112027== Command: ws
==112027==
Status Tester -----------------------------------------------------
Enter following values :
abc
123
-123
12
> abc
Container: (Invalid Integer)
Error #: 0
Problem: Invalid Integer
> 123
Container: (ERR#1: value too high)
Error #: 1
Problem: value too high
> -123
Container: (ERR#-1: value too low)
Error #: -1
Problem: value too low
> 12
Container: (12)
Date Tester -------------------------------------------------------
Current Date: 2022/03/02
Test mode:
Current Date formatted (C): 2022/03/31
Current Date unformatted (C): 220331
Future Date formatted (F): 2022/05/25
Future Date unformatted (F): 220525
The current date is NOT the same as the future date
The current date is the same as the current date
The current date is Less than or equal to the future date
The current date is Less than or equal to the current date
The current date is Less than the future date
The future date is greater than or equal to the current date
The future date is greater than or equal to the future date
The future date is greater than the current date
--------------
Assigning the Current date to the future date!
Now both of the dates are the same!
Enter the following:
1- abc
2- 12
3- 1212
4- 121212
5- 221312
6- 220229
7- 220228
> abc
Invalid date value
> 12
ERR#2: Invalid month in date
> 1212
Date enterd: 2022/12/12
> 121212
ERR#1: Invalid year in date
> 221312
ERR#2: Invalid month in date
> 220229
ERR#3: Invalid day in date
> 220228
Date enterd: 2022/02/28
==112027==
==112027== HEAP SUMMARY:
==112027== in use at exit: 0 bytes in 0 blocks
==112027== total heap usage: 20 allocs, 20 frees, 75,812
bytes allocated
==112027==
==112027== All heap blocks were freed -- no leaks are possible
==112027==
==112027== ERROR SUMMARY: 0 errors from 0 contexts
(suppressed: 0 from 0)
Script done on Wed 02 Mar 2022 07:29:34 PM EST
this is my output
cript started on Sat 19 Mar 2022 11:54:49 AM EDT
==67598== Memcheck, a memory error detector
==67598== Copyright (C) 2002-2017, and GNU GPL'd, by
Julian Seward et al.
==67598== Using Valgrind-3.15.0 and LibVEX; rerun with -h
for copyright info
==67598== Command: ms
==67598==
Status Tester -----------------------------------------------------
Enter following values :
abc
123
-123
12
> abc
Container: (Invalid Integer)
Error #: 0
Problem: Invalid Integer
==67598== Mismatched free() / delete / delete []
==67598== at 0x4C2B51D: operator delete(void*)
(vg_replace_malloc.c:586)
==67598== by 0x4025CE: sdds::Status::~Status()
(Status.cpp:45)
==67598== by 0x4019B5: Container::~Container()
(main_prof.cpp:34)
==67598== by 0x401056: statusTester() (main_prof.cpp:112)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598== Address 0x5afdcd0 is 0 bytes inside a block of size
16 alloc'd
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4024F5: sdds::Status::Status(sdds::Status
const&) (Status.cpp:22)
==67598== by 0x4019EE: Container::Container(Container
const&) (main_prof.cpp:34)
==67598== by 0x40103E: statusTester() (main_prof.cpp:112)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
> 12
Container: (12)
> 123
Container: (ERR#1: value too high)
Error #: 1
Problem: value too high
> -123
Container: (ERR#-1: value too low)
Error #: -1
Problem: value too low
==67598== Mismatched free() / delete / delete []
==67598== at 0x4C2B51D: operator delete(void*)
(vg_replace_malloc.c:586)
==67598== by 0x4025CE: sdds::Status::~Status()
(Status.cpp:45)
==67598== by 0x4019B5: Container::~Container()
(main_prof.cpp:34)
==67598== by 0x40106C: statusTester() (main_prof.cpp:113)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598== Address 0x5afddc0 is 0 bytes inside a block of size
14 alloc'd
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4025F9: sdds::Status::operator=(char
const*) (Status.cpp:50)
==67598== by 0x40177B: Container::set(int)
(main_prof.cpp:39)
==67598== by 0x4018B8: Container::read(std::istream&)
(main_prof.cpp:59)
==67598== by 0x400EF1: operator>>(std::istream&,
Container&) (main_prof.cpp:95)
==67598== by 0x40102B: statusTester() (main_prof.cpp:111)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
Date Tester -------------------------------------------------------
Currect Date: 2022/03/19
Test mode:
Current Date formatted (C): 2022/03/19
Current Date unformatted (C): 220319
Future Date formatted (F): 2022/05/25
Future Date unformatted (F): 220525
The current date is NOT the same as the future date
The current date is the same as the current date
The current date is Less than or equal to the future date
The current date is Less than or equal to the current date
The current date is Less than the future date
The future date is greater than or equal to the current date
The future date is greater than or equal to the future date
The future date is greater than the current date
--------------
Assigning the Current date to the future date!
Now both of the dates are the same!
Enter the following:
1- abc
2- 12
3- 1212
4- 121212
5- 221312
6- 220229
7- 220228
> abc
Invalid date value
> 12
Invalid date valueDate enterd: 2022/03/19
> 1212
Invalid date valueDate enterd: 2022/03/19
> 121212
Invalid date valueDate enterd: 2022/03/19
> 221312
Invalid date valueDate enterd: 2022/03/19
> 220229
Invalid date valueDate enterd: 2022/03/19
> 20220228
Invalid date valueDate enterd: 2022/03/19
==67598==
==67598== HEAP SUMMARY:
==67598== in use at exit: 31 bytes in 2 blocks
==67598== total heap usage: 32 allocs, 30 frees, 75,963 bytes
allocated
==67598==
==67598== 15 bytes in 1 blocks are definitely lost in loss
record 1 of 2
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4025F9: sdds::Status::operator=(char
const*) (Status.cpp:50)
==67598== by 0x4017AD: Container::set(int)
(main_prof.cpp:43)
==67598== by 0x4018B8: Container::read(std::istream&)
(main_prof.cpp:59)
==67598== by 0x400EF1: operator>>(std::istream&,
Container&) (main_prof.cpp:95)
==67598== by 0x40102B: statusTester() (main_prof.cpp:111)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
==67598== 16 bytes in 1 blocks are definitely lost in loss
record 2 of 2
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4025F9: sdds::Status::operator=(char
const*) (Status.cpp:50)
==67598== by 0x4018CF: Container::read(std::istream&)
(main_prof.cpp:62)
==67598== by 0x400EF1: operator>>(std::istream&,
Container&) (main_prof.cpp:95)
==67598== by 0x40102B: statusTester() (main_prof.cpp:111)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
==67598== LEAK SUMMARY:
==67598== definitely lost: 31 bytes in 2 blocks
==67598== indirectly lost: 0 bytes in 0 blocks
==67598== possibly lost: 0 bytes in 0 blocks
==67598== still reachable: 0 bytes in 0 blocks
==67598== suppressed: 0 bytes in 0 blocks
==67598==
==67598== ERROR SUMMARY: 6 errors from 4 contexts
(suppressed: 0 from 0)
==67598==
==67598== 1 errors in context 1 of 4:
==67598== Mismatched free() / delete / delete []
==67598== at 0x4C2B51D: operator delete(void*)
(vg_replace_malloc.c:586)
==67598== by 0x4025CE: sdds::Status::~Status()
(Status.cpp:45)
==67598== by 0x4019B5: Container::~Container()
(main_prof.cpp:34)
==67598== by 0x40106C: statusTester() (main_prof.cpp:113)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598== Address 0x5afddc0 is 0 bytes inside a block of size
14 alloc'd
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4025F9: sdds::Status::operator=(char
const*) (Status.cpp:50)
==67598== by 0x40177B: Container::set(int)
(main_prof.cpp:39)
==67598== by 0x4018B8: Container::read(std::istream&)
(main_prof.cpp:59)
==67598== by 0x400EF1: operator>>(std::istream&,
Container&) (main_prof.cpp:95)
==67598== by 0x40102B: statusTester() (main_prof.cpp:111)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
==67598==
==67598== 3 errors in context 2 of 4:
==67598== Mismatched free() / delete / delete []
==67598== at 0x4C2B51D: operator delete(void*)
(vg_replace_malloc.c:586)
==67598== by 0x4025CE: sdds::Status::~Status()
(Status.cpp:45)
==67598== by 0x4019B5: Container::~Container()
(main_prof.cpp:34)
==67598== by 0x401056: statusTester() (main_prof.cpp:112)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598== Address 0x5afdcd0 is 0 bytes inside a block of size
16 alloc'd
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4024F5: sdds::Status::Status(sdds::Status
const&) (Status.cpp:22)
==67598== by 0x4019EE: Container::Container(Container
const&) (main_prof.cpp:34)
==67598== by 0x40103E: statusTester() (main_prof.cpp:112)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
==67598== ERROR SUMMARY: 6 errors from 4 contexts
(suppressed: 0 from 0)
Script done on Sat 19 Mar 2022 11:56:32 AM EDT
date.cpp
#include <iostream>
#include <cstring>
#include <ctime>
#include "Date.h"
namespace sdds {
int Date::currentYear() {
time_t current_time;
current_time = time(NULL);
int year = 1970 + current_time / 31537970;
return year;
}
int Date::currentMonth() {
std::time_t current_time;
current_time = std::time(NULL);
std::tm* now = std::localtime(&current_time);
int month = now->tm_mon + 1;
return month;
}
int Date::currentDay() {
std::time_t current_time;
current_time = std::time(NULL);
std::tm* now = std::localtime(&current_time);
int day = now->tm_mday;
return day;
}
int Date::numOfDays(int mon, int year) const {
int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
-1 };
int month = mon >= 1 && mon <= 12 ? mon : 13;
month--;
return days[month] + int((month == 1) * ((year % 4 == 0)
&& (year % 100 != 0)) || (year % 400 == 0));
}
bool Date::validate() {
bool isValid;
int min_year = currentYear();
if (m_year < min_year || m_year > max_year) {
State = "Invalid year in date";
State = 1;
isValid = false;
}
else if (m_month < 1 || m_month > 12) {
State = "Invalid month in date";
State = 2;
isValid = false;
}
else if (m_day < 1 || m_day > numOfDays(m_month,
m_year)) {
State = "Invalid day in date";
State = 3;
isValid = false;
}
else {
State.clear();
isValid = true;
}
return isValid;
}
Date::Date() {
m_year = currentYear();
m_month = currentMonth();
m_day = currentDay();
m_formatted = true;
}
Date::Date(int year, int month, int day) {
m_year = year;
m_month = month;
m_day = day;
m_formatted = true;
}
int Date::uniqueDateValue()const {
return m_year * 372 + m_month * 31 + m_day;
}
bool Date::operator==(const Date& data) const {
return (this->uniqueDateValue() ==
data.uniqueDateValue());
}
bool Date::operator!=(const Date& data) const {
return (this->uniqueDateValue() !=
data.uniqueDateValue());
}
bool Date::operator<(const Date& data) const {
return (this->uniqueDateValue() <
data.uniqueDateValue());
}
bool Date::operator>(const Date& data)const {
return (this->uniqueDateValue() >
data.uniqueDateValue());
}
bool Date::operator<=(const Date& data)const {
return (this->uniqueDateValue() <=
data.uniqueDateValue());
}
bool Date::operator>=(const Date& data)const {
return (this->uniqueDateValue() >=
data.uniqueDateValue());
}
const Status& Date::state() {
return State;
}
Date& Date::formatted(bool formatted) {
m_formatted = formatted;
return *this;
}
std::ostream& Date::write(std::ostream& ostr) const {
if (m_formatted == true) {
ostr << m_year << "/";
if (m_month < 10) {
ostr << "0" << m_month << "/";
}
else {
ostr << m_month << "/";
}
if (m_day < 10) {
ostr << "0" << m_day;
}
else {
ostr << m_day;
}
}
else if (m_formatted == false) {
ostr << m_year % 100;
if (m_month < 10) {
ostr << "0" << m_month;
}
else {
ostr << m_month;
}
if (m_day < 10) {
ostr << "0" << m_day;
}
else {
ostr << m_day;
}
}
return ostr;
}
std::istream& Date::read(std::istream& istr) {
int date=0, size=0;
string tmp;
istr >> date;
size = tmp.size();
if (size == 2)
{
m_year = currentYear();
m_month = 0;
m_day = date;
}
else if (size == 4)
{
m_year = currentYear();
m_month = date / 100;
m_day = date % 100;
}
else if (size == 6)
{
m_year = 2000 + date / 10000;
m_month = (date / 100) % 100;
m_day = date % 100;
}
else
{
cout << "Invalid date value";
}
if (validate() == false)
istr.std::istream::setstate(ios::badbit);
return istr;
}
std::ostream& operator<<(std::ostream& ostr, Date const&
data) {
return data.write(ostr);
}
std::istream& operator>>(std::istream& istr, Date& data) {
return data.read(istr);
}
}
status.cpp
#include "Status.h"
namespace sdds
{
Status::Status(char* str, int code)
{
if (str != NULL)
{
description = new char[strlen(str) + 1];
strcpy(description, str);
}
else
description = NULL;
status_code = code;
}
Status::Status(const Status& s)
{
if (!s)
{
description = new char[strlen(s.description) + 1];
strcpy(description, s.description);
}
else
description = NULL;
status_code = s.status_code;
}
Status& Status::operator=(const Status& s)
{
if (!s)
{
description = new char[strlen(s.description) + 1];
strcpy(description, s.description);
}
else
description = NULL;
status_code = s.status_code;
return *this;
}
Status::~Status()
{
delete(description);
}
Status& Status::operator=(const char* str)
{
description = new char[strlen(str) + 1];
strcpy(description, str);
return *this;
}
Status& Status::operator=(const int code)
{
status_code = code;
return *this;
}
Status::operator bool() const
{
if (description == NULL)
return true;
else
return false;
}
Status::operator int() const
{
return status_code;
}
Status::operator char* () const
{
return (char*)description;
}
ostream& operator<<(ostream& out, const Status& s)
{
if (!s)
{
if (s.status_code != 0)
out << "ERR#" << s.status_code << ": ";
out << s.description;
}
return out;
}
Status& Status::clear()
{
description = NULL;
status_code = 0;
return *this;
}
}
utils.cpp
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <ctime>
#include "Utils.h"
using namespace std;
namespace sdds {
Utils ut;
void Utils::testMode(bool testmode) {
m_testMode = testmode;
}
void Utils::getSystemDate(int* year, int* mon, int* day) {
if (m_testMode) {
if (day) *day = sdds_testDay;
if (mon) *mon = sdds_testMon;
if (year) *year = sdds_testYear;
}
else {
time_t t = std::time(NULL);
tm lt = *localtime(&t);
if (day) *day = lt.tm_mday;
if (mon) *mon = lt.tm_mon + 1;
if (year) *year = lt.tm_year + 1900;
}
}
int Utils::daysOfMon(int month, int year)const {
int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
-1 };
int mon = (month >= 1 && month <= 12 ? month : 13) - 1;
return days[mon] + int((mon == 1) * ((year % 4 == 0) &&
(year % 100 != 0)) || (year % 400 == 0));
}
}
date.h
#ifndef SDDS_DATE_H
#define SDDS_DATE_H
#include <iostream>
#include "Status.h"
using namespace std;
namespace sdds {
const int max_year = 2030;
class Date {
private:
int m_year, m_month, m_day;
Status State;
int uniqueDateValue() const;
bool m_formatted;
bool validate();
public:
Date();
Date(int year, int month, int day);
int numOfDays(int month, int year) const;
int currentYear();
int currentMonth();
int currentDay();
bool operator==(const Date& data) const;
bool operator!=(const Date& data) const;
bool operator<(const Date& data) const;
bool operator>(const Date& data) const;
bool operator<=(const Date& data) const;
bool operator>=(const Date& data) const;
const Status& state();
Date& formatted(bool formatted);
std::istream& read(std::istream& istr);
std::ostream& write(std::ostream& ostr) const;
};
std::ostream& operator<<(std::ostream& ostr, Date const&
data);
std::istream& operator>>(std::istream& istr, Date& data);
}
#endif
status.h
#ifndef SDDS_STATUS_H
#define SDDS_STATUS_H
#include<iostream>
#include<cstring>
using namespace std;
namespace sdds
{
class Status
{
char* description;
int status_code;
public:
Status(char* str = NULL, int code = 0);
Status(const Status& s);
Status& operator=(const Status& s);
~Status();
Status& operator=(const char* str);
Status& operator=(const int code);
operator bool() const;
operator int() const;
operator char* () const;
friend ostream& operator<<(ostream& out, const Status&
s);
Status& clear();
};
}
#endif // !SDDS_STATUS_H
utils.h
#ifndef SDDS_UTILS_H
#define SDDS_UTILS_H
namespace sdds {
const int sdds_testYear = 2022;
const int sdds_testMon = 03;
const int sdds_testDay = 31;
class Utils {
bool m_testMode = false;
public:
void getSystemDate(int* year = nullptr, int* mon =
nullptr, int* day = nullptr);
int daysOfMon(int mon, int year)const;
void testMode(bool testmode = true);
};
extern Utils ut;
}
#endif // !SDDS_UTILS_H
main.cpp
#include <iostream>
#include "Date.h"
#include "Utils.h"
#include "Status.h"
using namespace std;
using namespace sdds;
void statusTester();
void dateTester();
int main() {
cout << "Status Tester ---------------------------------------------
--------" << endl;
statusTester();
cout << "Date Tester ----------------------------------------------
---------" << endl;
dateTester();
}
// Copied from StatusTestr.cpp
const int c_min{ 0 };
const int c_max{ 100 };
class Container {
int m_val{};
sdds::Status m_state;
Container& set(int value) {
if (value < c_min) {
m_state = "value too low";
m_state = -1;
}
else if (value > c_max) {
m_state = "value too high";
m_state = 1;
}
else {
m_state.clear();
}
return *this;
}
public:
Container(int value = 0) {
set(value);
}
istream& read(istream& istr = cin) {
istr >> m_val;
m_state.clear();
if (istr) {
set(m_val);
}
else {
m_state = "Invalid Integer";
istr.clear();
}
istr.ignore(1000, 'n');
return istr;
}
ostream& write(ostream& ostr = cout)const {
if (m_state) {
ostr << m_val;
}
else {
ostr << m_state;
}
return ostr;
}
Container& value(int val) {
set(val);
return *this;
}
int value()const {
return m_val;
}
operator bool()const {
return m_state;
}
const sdds::Status& state()const {
return m_state;
}
};
ostream& operator<<(ostream& ostr, const Container& I) {
return I.write(ostr);
}
istream& operator>>(istream& istr, Container& I) {
return I.read(istr);
}
void prnContainer(Container C) {
cout << "Container: (" << C << ")" << endl;
if (!C) {
cout << "Error #: " << int(C.state()) << endl;
cout << "Problem: " << (const char*)(C.state()) << endl;
}
}
void statusTester() {
Container c;
cout << "Enter following values :nabcn123n-123n12" <<
endl;
for (int i = 0; i < 4; i++) {
cout << "> ";
cin >> c;
prnContainer(c);
}
}
// Copied from DateTester.cpp
void testDate() {
Date D;
cout << "> ";
cin >> D;
if (!cin) {
cin.clear();
cin.ignore(1000, 'n');
cout << D.state() << endl;
}
else {
cout << "Date enterd: " << D << endl;
}
}
void dateTester() {
cout << "Current Date: " << Date() << endl;
cout << "Test mode: " << endl;
ut.testMode();
Date C;
Date F(2022, 5, 25);
cout << "Current Date formatted (C): " << C << endl;
C.formatted(false);
cout << "Current Date unformatted (C): " << C << endl;
cout << "Future Date formatted (F): " << F << endl;
F.formatted(false);
cout << "Future Date unformatted (F): " << F << endl;
cout << "The current date is" << (C != F ? " NOT" : "") << "
the same as the future date" << endl;
cout << "The current date is" << (C == C ? "" : " NOT") << "
the same as the current date" << endl;
cout << "The current date is" << (C <= F ? " Less than or
equal to" : " greater than") << " the future date" << endl;;
cout << "The current date is" << (C <= C ? " Less than or
equal to" : " greater than") << " the current date" << endl;;
cout << "The current date is" << (C < F ? " Less than" : "
greater than or equal to") << " the future date" << endl;;
cout << "The future date is" << (F >= C ? " greater than or
equal to" : " Less than") << " the current date" << endl;;
cout << "The future date is" << (F >= F ? " greater than or
equal to" : " Less than") << " the future date" << endl;;
cout << "The future date is" << (F > C ? " greater than" : "
Less than or equal to") << " the current date" << endl;;
cout << "--------------nAssigning the Current date to the
future date!" << endl;
C = F;
if (C == F)
cout << "Now both of the dates are the same!" << endl;
else
cout << "The two dates are different after assignment!!!!!"
<< endl;
cout << "Enter the following:n1- abcn2- 12n3- 1212n4-
121212"
"n5- 221312n6- 220229n7- 220228" << endl;
for (int i = 0; i < 7; i++) {
testDate();
}
Script started on Sat 19 Mar 2022 11:54:49 AM EDT
==67598== Memcheck, a memory error detector
==67598== Copyright (C) 2002-2017, and GNU GPL'd, by
Julian Seward et al.
==67598== Using Valgrind-3.15.0 and LibVEX; rerun with -h
for copyright info
==67598== Command: ms
==67598==
Status Tester -----------------------------------------------------
Enter following values :
abc
123
-123
12
> abc
Container: (Invalid Integer)
Error #: 0
Problem: Invalid Integer
==67598== Mismatched free() / delete / delete []
==67598== at 0x4C2B51D: operator delete(void*)
(vg_replace_malloc.c:586)
==67598== by 0x4025CE: sdds::Status::~Status()
(Status.cpp:45)
==67598== by 0x4019B5: Container::~Container()
(main_prof.cpp:34)
==67598== by 0x401056: statusTester() (main_prof.cpp:112)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598== Address 0x5afdcd0 is 0 bytes inside a block of size
16 alloc'd
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4024F5: sdds::Status::Status(sdds::Status
const&) (Status.cpp:22)
==67598== by 0x4019EE: Container::Container(Container
const&) (main_prof.cpp:34)
==67598== by 0x40103E: statusTester() (main_prof.cpp:112)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
> 12
Container: (12)
> 123
Container: (ERR#1: value too high)
Error #: 1
Problem: value too high
> -123
Container: (ERR#-1: value too low)
Error #: -1
Problem: value too low
==67598== Mismatched free() / delete / delete []
==67598== at 0x4C2B51D: operator delete(void*)
(vg_replace_malloc.c:586)
==67598== by 0x4025CE: sdds::Status::~Status()
(Status.cpp:45)
==67598== by 0x4019B5: Container::~Container()
(main_prof.cpp:34)
==67598== by 0x40106C: statusTester() (main_prof.cpp:113)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598== Address 0x5afddc0 is 0 bytes inside a block of size
14 alloc'd
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4025F9: sdds::Status::operator=(char
const*) (Status.cpp:50)
==67598== by 0x40177B: Container::set(int)
(main_prof.cpp:39)
==67598== by 0x4018B8: Container::read(std::istream&)
(main_prof.cpp:59)
==67598== by 0x400EF1: operator>>(std::istream&,
Container&) (main_prof.cpp:95)
==67598== by 0x40102B: statusTester() (main_prof.cpp:111)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
Date Tester -------------------------------------------------------
Currect Date: 2022/03/19
Test mode:
Current Date formatted (C): 2022/03/19
Current Date unformatted (C): 220319
Future Date formatted (F): 2022/05/25
Future Date unformatted (F): 220525
The current date is NOT the same as the future date
The current date is the same as the current date
The current date is Less than or equal to the future date
The current date is Less than or equal to the current date
The current date is Less than the future date
The future date is greater than or equal to the current date
The future date is greater than or equal to the future date
The future date is greater than the current date
--------------
Assigning the Current date to the future date!
Now both of the dates are the same!
Enter the following:
1- abc
2- 12
3- 1212
4- 121212
5- 221312
6- 220229
7- 220228
> abc
Invalid date value
> 12
Invalid date valueDate enterd: 2022/03/19
> 1212
Invalid date valueDate enterd: 2022/03/19
> 121212
Invalid date valueDate enterd: 2022/03/19
> 221312
Invalid date valueDate enterd: 2022/03/19
> 220229
Invalid date valueDate enterd: 2022/03/19
> 20220228
Invalid date valueDate enterd: 2022/03/19
==67598==
==67598== HEAP SUMMARY:
==67598== in use at exit: 31 bytes in 2 blocks
==67598== total heap usage: 32 allocs, 30 frees, 75,963 bytes
allocated
==67598==
==67598== 15 bytes in 1 blocks are definitely lost in loss
record 1 of 2
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4025F9: sdds::Status::operator=(char
const*) (Status.cpp:50)
==67598== by 0x4017AD: Container::set(int)
(main_prof.cpp:43)
==67598== by 0x4018B8: Container::read(std::istream&)
(main_prof.cpp:59)
==67598== by 0x400EF1: operator>>(std::istream&,
Container&) (main_prof.cpp:95)
==67598== by 0x40102B: statusTester() (main_prof.cpp:111)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
==67598== 16 bytes in 1 blocks are definitely lost in loss
record 2 of 2
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4025F9: sdds::Status::operator=(char
const*) (Status.cpp:50)
==67598== by 0x4018CF: Container::read(std::istream&)
(main_prof.cpp:62)
==67598== by 0x400EF1: operator>>(std::istream&,
Container&) (main_prof.cpp:95)
==67598== by 0x40102B: statusTester() (main_prof.cpp:111)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
==67598== LEAK SUMMARY:
==67598== definitely lost: 31 bytes in 2 blocks
==67598== indirectly lost: 0 bytes in 0 blocks
==67598== possibly lost: 0 bytes in 0 blocks
==67598== still reachable: 0 bytes in 0 blocks
==67598== suppressed: 0 bytes in 0 blocks
==67598==
==67598== ERROR SUMMARY: 6 errors from 4 contexts
(suppressed: 0 from 0)
==67598==
==67598== 1 errors in context 1 of 4:
==67598== Mismatched free() / delete / delete []
==67598== at 0x4C2B51D: operator delete(void*)
(vg_replace_malloc.c:586)
==67598== by 0x4025CE: sdds::Status::~Status()
(Status.cpp:45)
==67598== by 0x4019B5: Container::~Container()
(main_prof.cpp:34)
==67598== by 0x40106C: statusTester() (main_prof.cpp:113)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598== Address 0x5afddc0 is 0 bytes inside a block of size
14 alloc'd
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4025F9: sdds::Status::operator=(char
const*) (Status.cpp:50)
==67598== by 0x40177B: Container::set(int)
(main_prof.cpp:39)
==67598== by 0x4018B8: Container::read(std::istream&)
(main_prof.cpp:59)
==67598== by 0x400EF1: operator>>(std::istream&,
Container&) (main_prof.cpp:95)
==67598== by 0x40102B: statusTester() (main_prof.cpp:111)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
==67598==
==67598== 3 errors in context 2 of 4:
==67598== Mismatched free() / delete / delete []
==67598== at 0x4C2B51D: operator delete(void*)
(vg_replace_malloc.c:586)
==67598== by 0x4025CE: sdds::Status::~Status()
(Status.cpp:45)
==67598== by 0x4019B5: Container::~Container()
(main_prof.cpp:34)
==67598== by 0x401056: statusTester() (main_prof.cpp:112)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598== Address 0x5afdcd0 is 0 bytes inside a block of size
16 alloc'd
==67598== at 0x4C2AC38: operator new[](unsigned long)
(vg_replace_malloc.c:433)
==67598== by 0x4024F5: sdds::Status::Status(sdds::Status
const&) (Status.cpp:22)
==67598== by 0x4019EE: Container::Container(Container
const&) (main_prof.cpp:34)
==67598== by 0x40103E: statusTester() (main_prof.cpp:112)
==67598== by 0x400E81: main (main_prof.cpp:23)
==67598==
==67598== ERROR SUMMARY: 6 errors from 4 contexts
(suppressed: 0 from 0)
Script done on Sat 19 Mar 2022 11:56:32 AM EDT

More Related Content

Similar to #include Status.hnamespace sdds{StatusStatus(c

This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
kostikjaylonshaewe47
 
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docxQ2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
amrit47
 
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docxLISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
SHIVA101531
 
Complete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdfComplete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdf
access2future1
 
#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf
annucommunication1
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
aksachdevahosymills
 
Hey, looking to do the following with this programFill in the multip.pdf
Hey, looking to do the following with this programFill in the multip.pdfHey, looking to do the following with this programFill in the multip.pdf
Hey, looking to do the following with this programFill in the multip.pdf
rupeshmehta151
 
Hi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdfHi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdf
aryan9007
 
Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdfDate.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
angelfragranc
 

Similar to #include Status.hnamespace sdds{StatusStatus(c (20)

sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
 
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docxQ2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docxLISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
 
Complete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdfComplete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdf
 
#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf
 
Implementing string
Implementing stringImplementing string
Implementing string
 
Functional C++
Functional C++Functional C++
Functional C++
 
12
1212
12
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
C programs
C programsC programs
C programs
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
 
CPP Quiz
CPP QuizCPP Quiz
CPP Quiz
 
Hey, looking to do the following with this programFill in the multip.pdf
Hey, looking to do the following with this programFill in the multip.pdfHey, looking to do the following with this programFill in the multip.pdf
Hey, looking to do the following with this programFill in the multip.pdf
 
Hi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdfHi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdf
 
Libor Market Model
Libor Market ModelLibor Market Model
Libor Market Model
 
Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdfDate.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
Date.h#ifndef DateFormat#define DateFormat#includetime.h.pdf
 

More from MoseStaton39

(U) WHAT INSIGHTS ARE DERIVED FROM OPERATION ANACONDA IN REGARDS T
(U) WHAT INSIGHTS ARE DERIVED FROM OPERATION ANACONDA IN REGARDS T(U) WHAT INSIGHTS ARE DERIVED FROM OPERATION ANACONDA IN REGARDS T
(U) WHAT INSIGHTS ARE DERIVED FROM OPERATION ANACONDA IN REGARDS T
MoseStaton39
 
(Remarks)Please keep in mind that the assi
(Remarks)Please keep in mind that the assi(Remarks)Please keep in mind that the assi
(Remarks)Please keep in mind that the assi
MoseStaton39
 
(This is provided as an example of the paper layout and spac
(This is provided as an example of the paper layout and spac(This is provided as an example of the paper layout and spac
(This is provided as an example of the paper layout and spac
MoseStaton39
 
(Student Name)Date of EncounterPreceptorClinical SiteCl
(Student Name)Date of EncounterPreceptorClinical SiteCl(Student Name)Date of EncounterPreceptorClinical SiteCl
(Student Name)Date of EncounterPreceptorClinical SiteCl
MoseStaton39
 
(TITLE)Sung Woo ParkInternational American UniversityFIN
(TITLE)Sung Woo ParkInternational American UniversityFIN(TITLE)Sung Woo ParkInternational American UniversityFIN
(TITLE)Sung Woo ParkInternational American UniversityFIN
MoseStaton39
 
(Student Name) UniversityDate of EncounterPreceptorClini
(Student Name) UniversityDate of EncounterPreceptorClini(Student Name) UniversityDate of EncounterPreceptorClini
(Student Name) UniversityDate of EncounterPreceptorClini
MoseStaton39
 
(Student Name)Miami Regional UniversityDate of Encounter
(Student Name)Miami Regional UniversityDate of Encounter(Student Name)Miami Regional UniversityDate of Encounter
(Student Name)Miami Regional UniversityDate of Encounter
MoseStaton39
 
(Student Name)Miami Regional UniversityDate of EncounterP
(Student Name)Miami Regional UniversityDate of EncounterP(Student Name)Miami Regional UniversityDate of EncounterP
(Student Name)Miami Regional UniversityDate of EncounterP
MoseStaton39
 
(Monica)Gender rarely shapes individual experience in isolation bu
(Monica)Gender rarely shapes individual experience in isolation bu(Monica)Gender rarely shapes individual experience in isolation bu
(Monica)Gender rarely shapes individual experience in isolation bu
MoseStaton39
 
(Monica) A summary of my decision-making process starts with flipp
(Monica) A summary of my decision-making process starts with flipp(Monica) A summary of my decision-making process starts with flipp
(Monica) A summary of my decision-making process starts with flipp
MoseStaton39
 
(Note This case study is based on many actual cases. All the name
(Note This case study is based on many actual cases. All the name(Note This case study is based on many actual cases. All the name
(Note This case study is based on many actual cases. All the name
MoseStaton39
 
(Minimum 175 words)In your own words, explain class conflict the
(Minimum 175 words)In your own words, explain class conflict the(Minimum 175 words)In your own words, explain class conflict the
(Minimum 175 words)In your own words, explain class conflict the
MoseStaton39
 
(Individuals With Disabilities Act Transformation Over the Years)D
(Individuals With Disabilities Act Transformation Over the Years)D(Individuals With Disabilities Act Transformation Over the Years)D
(Individuals With Disabilities Act Transformation Over the Years)D
MoseStaton39
 
(Kaitlyn)To be very honest I know next to nothing about mythology,
(Kaitlyn)To be very honest I know next to nothing about mythology,(Kaitlyn)To be very honest I know next to nothing about mythology,
(Kaitlyn)To be very honest I know next to nothing about mythology,
MoseStaton39
 
(Harry)Dante’s Inferno is the first of the three-part epic poem, D
(Harry)Dante’s Inferno is the first of the three-part epic poem, D(Harry)Dante’s Inferno is the first of the three-part epic poem, D
(Harry)Dante’s Inferno is the first of the three-part epic poem, D
MoseStaton39
 
(Lucious)Many steps in the systems development process may cause a
(Lucious)Many steps in the systems development process may cause a(Lucious)Many steps in the systems development process may cause a
(Lucious)Many steps in the systems development process may cause a
MoseStaton39
 
(Eric)Technology always seems simple when it works and it is when
(Eric)Technology always seems simple when it works and it is when (Eric)Technology always seems simple when it works and it is when
(Eric)Technology always seems simple when it works and it is when
MoseStaton39
 
(ELI)At the time when I first had to take a sociology class in hig
(ELI)At the time when I first had to take a sociology class in hig(ELI)At the time when I first had to take a sociology class in hig
(ELI)At the time when I first had to take a sociology class in hig
MoseStaton39
 
(Click icon for citation) Theme Approaches to History
(Click icon for citation) Theme Approaches to History(Click icon for citation) Theme Approaches to History
(Click icon for citation) Theme Approaches to History
MoseStaton39
 
(Executive Summary)MedStar Health Inc, a leader in the healthc
(Executive Summary)MedStar Health Inc, a leader in the healthc(Executive Summary)MedStar Health Inc, a leader in the healthc
(Executive Summary)MedStar Health Inc, a leader in the healthc
MoseStaton39
 

More from MoseStaton39 (20)

(U) WHAT INSIGHTS ARE DERIVED FROM OPERATION ANACONDA IN REGARDS T
(U) WHAT INSIGHTS ARE DERIVED FROM OPERATION ANACONDA IN REGARDS T(U) WHAT INSIGHTS ARE DERIVED FROM OPERATION ANACONDA IN REGARDS T
(U) WHAT INSIGHTS ARE DERIVED FROM OPERATION ANACONDA IN REGARDS T
 
(Remarks)Please keep in mind that the assi
(Remarks)Please keep in mind that the assi(Remarks)Please keep in mind that the assi
(Remarks)Please keep in mind that the assi
 
(This is provided as an example of the paper layout and spac
(This is provided as an example of the paper layout and spac(This is provided as an example of the paper layout and spac
(This is provided as an example of the paper layout and spac
 
(Student Name)Date of EncounterPreceptorClinical SiteCl
(Student Name)Date of EncounterPreceptorClinical SiteCl(Student Name)Date of EncounterPreceptorClinical SiteCl
(Student Name)Date of EncounterPreceptorClinical SiteCl
 
(TITLE)Sung Woo ParkInternational American UniversityFIN
(TITLE)Sung Woo ParkInternational American UniversityFIN(TITLE)Sung Woo ParkInternational American UniversityFIN
(TITLE)Sung Woo ParkInternational American UniversityFIN
 
(Student Name) UniversityDate of EncounterPreceptorClini
(Student Name) UniversityDate of EncounterPreceptorClini(Student Name) UniversityDate of EncounterPreceptorClini
(Student Name) UniversityDate of EncounterPreceptorClini
 
(Student Name)Miami Regional UniversityDate of Encounter
(Student Name)Miami Regional UniversityDate of Encounter(Student Name)Miami Regional UniversityDate of Encounter
(Student Name)Miami Regional UniversityDate of Encounter
 
(Student Name)Miami Regional UniversityDate of EncounterP
(Student Name)Miami Regional UniversityDate of EncounterP(Student Name)Miami Regional UniversityDate of EncounterP
(Student Name)Miami Regional UniversityDate of EncounterP
 
(Monica)Gender rarely shapes individual experience in isolation bu
(Monica)Gender rarely shapes individual experience in isolation bu(Monica)Gender rarely shapes individual experience in isolation bu
(Monica)Gender rarely shapes individual experience in isolation bu
 
(Monica) A summary of my decision-making process starts with flipp
(Monica) A summary of my decision-making process starts with flipp(Monica) A summary of my decision-making process starts with flipp
(Monica) A summary of my decision-making process starts with flipp
 
(Note This case study is based on many actual cases. All the name
(Note This case study is based on many actual cases. All the name(Note This case study is based on many actual cases. All the name
(Note This case study is based on many actual cases. All the name
 
(Minimum 175 words)In your own words, explain class conflict the
(Minimum 175 words)In your own words, explain class conflict the(Minimum 175 words)In your own words, explain class conflict the
(Minimum 175 words)In your own words, explain class conflict the
 
(Individuals With Disabilities Act Transformation Over the Years)D
(Individuals With Disabilities Act Transformation Over the Years)D(Individuals With Disabilities Act Transformation Over the Years)D
(Individuals With Disabilities Act Transformation Over the Years)D
 
(Kaitlyn)To be very honest I know next to nothing about mythology,
(Kaitlyn)To be very honest I know next to nothing about mythology,(Kaitlyn)To be very honest I know next to nothing about mythology,
(Kaitlyn)To be very honest I know next to nothing about mythology,
 
(Harry)Dante’s Inferno is the first of the three-part epic poem, D
(Harry)Dante’s Inferno is the first of the three-part epic poem, D(Harry)Dante’s Inferno is the first of the three-part epic poem, D
(Harry)Dante’s Inferno is the first of the three-part epic poem, D
 
(Lucious)Many steps in the systems development process may cause a
(Lucious)Many steps in the systems development process may cause a(Lucious)Many steps in the systems development process may cause a
(Lucious)Many steps in the systems development process may cause a
 
(Eric)Technology always seems simple when it works and it is when
(Eric)Technology always seems simple when it works and it is when (Eric)Technology always seems simple when it works and it is when
(Eric)Technology always seems simple when it works and it is when
 
(ELI)At the time when I first had to take a sociology class in hig
(ELI)At the time when I first had to take a sociology class in hig(ELI)At the time when I first had to take a sociology class in hig
(ELI)At the time when I first had to take a sociology class in hig
 
(Click icon for citation) Theme Approaches to History
(Click icon for citation) Theme Approaches to History(Click icon for citation) Theme Approaches to History
(Click icon for citation) Theme Approaches to History
 
(Executive Summary)MedStar Health Inc, a leader in the healthc
(Executive Summary)MedStar Health Inc, a leader in the healthc(Executive Summary)MedStar Health Inc, a leader in the healthc
(Executive Summary)MedStar Health Inc, a leader in the healthc
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 

#include Status.hnamespace sdds{StatusStatus(c

  • 1. #include "Status.h" namespace sdds { Status::Status(char* str, int code) { if (str != NULL) { description = new char[strlen(str) + 1]; strcpy(description, str); } else description = NULL; status_code = code; }
  • 2. Status::Status(const Status& s) { if (!s) { description = new char[strlen(s.description) + 1]; strcpy(description, s.description); } else description = NULL; status_code = s.status_code; } Status& Status::operator=(const Status& s) { if (!s) { description = new char[strlen(s.description) + 1];
  • 3. strcpy(description, s.description); } else description = NULL; status_code = s.status_code; return *this; } Status::~Status() { delete(description); } Status& Status::operator=(const char* str) { description = new char[strlen(str) + 1]; strcpy(description, str); return *this;
  • 4. } Status& Status::operator=(const int code) { status_code = code; return *this; } Status::operator bool() const { if (description == NULL) return true; else return false; } Status::operator int() const {
  • 5. return status_code; } Status::operator char* () const { return (char*)description; } ostream& operator<<(ostream& out, const Status& s) { if (!s) { if (s.status_code != 0) out << "ERR#" << s.status_code << ": "; out << s.description; } return out; }
  • 6. Status& Status::clear() { description = NULL; status_code = 0; return *this; } } #include <iostream> #include "Date.h" #include "Utils.h" #include "Status.h" using namespace std; using namespace sdds; void statusTester(); void dateTester();
  • 7. int main() { cout << "Status Tester --------------------------------------------- --------" << endl; statusTester(); cout << "Date Tester ---------------------------------------------- ---------" << endl; dateTester(); } // Copied from StatusTestr.cpp const int c_min{ 0 }; const int c_max{ 100 }; class Container { int m_val{}; sdds::Status m_state;
  • 8. Container& set(int value) { if (value < c_min) { m_state = "value too low"; m_state = -1; } else if (value > c_max) { m_state = "value too high"; m_state = 1; } else { m_state.clear(); } return *this; } public: Container(int value = 0) { set(value); }
  • 9. istream& read(istream& istr = cin) { istr >> m_val; m_state.clear(); if (istr) { set(m_val); } else { m_state = "Invalid Integer"; istr.clear(); } istr.ignore(1000, 'n'); return istr; } ostream& write(ostream& ostr = cout)const { if (m_state) { ostr << m_val; } else {
  • 10. ostr << m_state; } return ostr; } Container& value(int val) { set(val); return *this; } int value()const { return m_val; } operator bool()const { return m_state; } const sdds::Status& state()const { return m_state; } };
  • 11. ostream& operator<<(ostream& ostr, const Container& I) { return I.write(ostr); } istream& operator>>(istream& istr, Container& I) { return I.read(istr); } void prnContainer(Container C) { cout << "Container: (" << C << ")" << endl; if (!C) { cout << "Error #: " << int(C.state()) << endl; cout << "Problem: " << (const char*)(C.state()) << endl; } } void statusTester() { Container c; cout << "Enter following values :nabcn123n-123n12" << endl;
  • 12. for (int i = 0; i < 4; i++) { cout << "> "; cin >> c; prnContainer(c); } } // Copied from DateTester.cpp void testDate() { Date D; cout << "> "; cin >> D; if (!cin) { cin.clear(); cin.ignore(1000, 'n'); cout << D.state() << endl; } else {
  • 13. cout << "Date enterd: " << D << endl; } } void dateTester() { cout << "Current Date: " << Date() << endl; cout << "Test mode: " << endl; ut.testMode(); Date C; Date F(2022, 5, 25); cout << "Current Date formatted (C): " << C << endl; C.formatted(false); cout << "Current Date unformatted (C): " << C << endl; cout << "Future Date formatted (F): " << F << endl; F.formatted(false); cout << "Future Date unformatted (F): " << F << endl; cout << "The current date is" << (C != F ? " NOT" : "") << " the same as the future date" << endl; cout << "The current date is" << (C == C ? "" : " NOT") << " the same as the current date" << endl;
  • 14. cout << "The current date is" << (C <= F ? " Less than or equal to" : " greater than") << " the future date" << endl;; cout << "The current date is" << (C <= C ? " Less than or equal to" : " greater than") << " the current date" << endl;; cout << "The current date is" << (C < F ? " Less than" : " greater than or equal to") << " the future date" << endl;; cout << "The future date is" << (F >= C ? " greater than or equal to" : " Less than") << " the current date" << endl;; cout << "The future date is" << (F >= F ? " greater than or equal to" : " Less than") << " the future date" << endl;; cout << "The future date is" << (F > C ? " greater than" : " Less than or equal to") << " the current date" << endl;; cout << "--------------nAssigning the Current date to the future date!" << endl; C = F; if (C == F) cout << "Now both of the dates are the same!" << endl; else cout << "The two dates are different after assignment!!! !!" << endl; cout << "Enter the following:n1- abcn2- 12n3- 1212n4- 121212"
  • 15. "n5- 221312n6- 220229n7- 220228" << endl; for (int i = 0; i < 7; i++) { testDate(); } } #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <ctime> #include "Utils.h" using namespace std; namespace sdds { Utils ut; void Utils::testMode(bool testmode) { m_testMode = testmode; } void Utils::getSystemDate(int* year, int* mon, int* day) { if (m_testMode) { if (day) *day = sdds_testDay;
  • 16. if (mon) *mon = sdds_testMon; if (year) *year = sdds_testYear; } else { time_t t = std::time(NULL); tm lt = *localtime(&t); if (day) *day = lt.tm_mday; if (mon) *mon = lt.tm_mon + 1; if (year) *year = lt.tm_year + 1900; } } int Utils::daysOfMon(int month, int year)const { int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, -1 }; int mon = (month >= 1 && month <= 12 ? month : 13) - 1; return days[mon] + int((mon == 1) * ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); }
  • 17. } #include <iostream> #include <cstring> #include <ctime> #include "Date.h" namespace sdds { int Date::currentYear() { time_t current_time; current_time = time(NULL); int year = 1970 + current_time / 31537970; return year; } int Date::currentMonth() { std::time_t current_time; current_time = std::time(NULL);
  • 18. std::tm* now = std::localtime(&current_time); int month = now->tm_mon + 1; return month; } int Date::currentDay() { std::time_t current_time; current_time = std::time(NULL); std::tm* now = std::localtime(&current_time); int day = now->tm_mday; return day; } int Date::numOfDays(int mon, int year) const { int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, -1 }; int month = mon >= 1 && mon <= 12 ? mon : 13; month--; return days[month] + int((month == 1) * ((year % 4 == 0)
  • 19. && (year % 100 != 0)) || (year % 400 == 0)); } bool Date::validate() { bool isValid; int min_year = currentYear(); if (m_year < min_year || m_year > max_year) { State = "Invalid year in date"; State = 1; isValid = false; } else if (m_month < 1 || m_month > 12) { State = "Invalid month in date"; State = 2; isValid = false; } else if (m_day < 1 || m_day > numOfDays(m_month, m_year)) { State = "Invalid day in date";
  • 20. State = 3; isValid = false; } else { State.clear(); isValid = true; } return isValid; } Date::Date() { m_year = currentYear(); m_month = currentMonth(); m_day = currentDay(); m_formatted = true; } Date::Date(int year, int month, int day) {
  • 21. m_year = year; m_month = month; m_day = day; m_formatted = true; } int Date::uniqueDateValue()const { return m_year * 372 + m_month * 31 + m_day; } bool Date::operator==(const Date& data) const { return (this->uniqueDateValue() == data.uniqueDateValue()); } bool Date::operator!=(const Date& data) const { return (this->uniqueDateValue() != data.uniqueDateValue()); }
  • 22. bool Date::operator<(const Date& data) const { return (this->uniqueDateValue() < data.uniqueDateValue()); } bool Date::operator>(const Date& data)const { return (this->uniqueDateValue() > data.uniqueDateValue()); } bool Date::operator<=(const Date& data)const { return (this->uniqueDateValue() <= data.uniqueDateValue()); } bool Date::operator>=(const Date& data)const { return (this->uniqueDateValue() >= data.uniqueDateValue()); }
  • 23. const Status& Date::state() { return State; } Date& Date::formatted(bool formatted) { m_formatted = formatted; return *this; } std::ostream& Date::write(std::ostream& ostr) const { if (m_formatted == true) { ostr << m_year << "/"; if (m_month < 10) { ostr << "0" << m_month << "/"; } else { ostr << m_month << "/";
  • 24. } if (m_day < 10) { ostr << "0" << m_day; } else { ostr << m_day; } } else if (m_formatted == false) { ostr << m_year % 100; if (m_month < 10) { ostr << "0" << m_month; } else { ostr << m_month; } if (m_day < 10) { ostr << "0" << m_day;
  • 25. } else { ostr << m_day; } } return ostr; } std::istream& Date::read(std::istream& istr) { int date, size; int year, month, day; string tmp; istr >> date; tmp = to_string(date); size = tmp.size();
  • 26. if (size == 2) { m_year = currentYear(); m_month = 0; m_day = date; } else if (size == 4) { m_year = currentYear(); m_month = date / 100; m_day = date % 100; } else if (size == 6) { m_year = 2000 + date / 10000; m_month = (date / 100) % 100; m_day = date % 100; }
  • 27. else { cout << "Invalid date value"; } if (validate() == false) istr.std::istream::setstate(ios::badbit); return istr; } std::ostream& operator<<(std::ostream& ostr, Date const& data) { return data.write(ostr); } std::istream& operator>>(std::istream& istr, Date& data) { return data.read(istr); }
  • 28. } correct output this is the correct output Script started on Wed 02 Mar 2022 07:28:07 PM EST ==112027== Memcheck, a memory error detector ==112027== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==112027== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==112027== Command: ws ==112027== Status Tester ----------------------------------------------------- Enter following values : abc 123 -123
  • 29. 12 > abc Container: (Invalid Integer) Error #: 0 Problem: Invalid Integer > 123 Container: (ERR#1: value too high) Error #: 1 Problem: value too high > -123 Container: (ERR#-1: value too low) Error #: -1 Problem: value too low > 12 Container: (12) Date Tester ------------------------------------------------------- Current Date: 2022/03/02 Test mode:
  • 30. Current Date formatted (C): 2022/03/31 Current Date unformatted (C): 220331 Future Date formatted (F): 2022/05/25 Future Date unformatted (F): 220525 The current date is NOT the same as the future date The current date is the same as the current date The current date is Less than or equal to the future date The current date is Less than or equal to the current date The current date is Less than the future date The future date is greater than or equal to the current date The future date is greater than or equal to the future date The future date is greater than the current date -------------- Assigning the Current date to the future date! Now both of the dates are the same! Enter the following: 1- abc 2- 12
  • 31. 3- 1212 4- 121212 5- 221312 6- 220229 7- 220228 > abc Invalid date value > 12 ERR#2: Invalid month in date > 1212 Date enterd: 2022/12/12 > 121212 ERR#1: Invalid year in date > 221312 ERR#2: Invalid month in date > 220229 ERR#3: Invalid day in date > 220228
  • 32. Date enterd: 2022/02/28 ==112027== ==112027== HEAP SUMMARY: ==112027== in use at exit: 0 bytes in 0 blocks ==112027== total heap usage: 20 allocs, 20 frees, 75,812 bytes allocated ==112027== ==112027== All heap blocks were freed -- no leaks are possible ==112027== ==112027== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) Script done on Wed 02 Mar 2022 07:29:34 PM EST this is my output cript started on Sat 19 Mar 2022 11:54:49 AM EDT
  • 33. ==67598== Memcheck, a memory error detector ==67598== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==67598== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==67598== Command: ms ==67598== Status Tester ----------------------------------------------------- Enter following values : abc 123 -123 12 > abc Container: (Invalid Integer) Error #: 0 Problem: Invalid Integer ==67598== Mismatched free() / delete / delete [] ==67598== at 0x4C2B51D: operator delete(void*) (vg_replace_malloc.c:586)
  • 34. ==67598== by 0x4025CE: sdds::Status::~Status() (Status.cpp:45) ==67598== by 0x4019B5: Container::~Container() (main_prof.cpp:34) ==67598== by 0x401056: statusTester() (main_prof.cpp:112) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== Address 0x5afdcd0 is 0 bytes inside a block of size 16 alloc'd ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4024F5: sdds::Status::Status(sdds::Status const&) (Status.cpp:22) ==67598== by 0x4019EE: Container::Container(Container const&) (main_prof.cpp:34) ==67598== by 0x40103E: statusTester() (main_prof.cpp:112) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== > 12 Container: (12) > 123 Container: (ERR#1: value too high)
  • 35. Error #: 1 Problem: value too high > -123 Container: (ERR#-1: value too low) Error #: -1 Problem: value too low ==67598== Mismatched free() / delete / delete [] ==67598== at 0x4C2B51D: operator delete(void*) (vg_replace_malloc.c:586) ==67598== by 0x4025CE: sdds::Status::~Status() (Status.cpp:45) ==67598== by 0x4019B5: Container::~Container() (main_prof.cpp:34) ==67598== by 0x40106C: statusTester() (main_prof.cpp:113) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== Address 0x5afddc0 is 0 bytes inside a block of size 14 alloc'd ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4025F9: sdds::Status::operator=(char const*) (Status.cpp:50)
  • 36. ==67598== by 0x40177B: Container::set(int) (main_prof.cpp:39) ==67598== by 0x4018B8: Container::read(std::istream&) (main_prof.cpp:59) ==67598== by 0x400EF1: operator>>(std::istream&, Container&) (main_prof.cpp:95) ==67598== by 0x40102B: statusTester() (main_prof.cpp:111) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== Date Tester ------------------------------------------------------- Currect Date: 2022/03/19 Test mode: Current Date formatted (C): 2022/03/19 Current Date unformatted (C): 220319 Future Date formatted (F): 2022/05/25 Future Date unformatted (F): 220525 The current date is NOT the same as the future date The current date is the same as the current date The current date is Less than or equal to the future date
  • 37. The current date is Less than or equal to the current date The current date is Less than the future date The future date is greater than or equal to the current date The future date is greater than or equal to the future date The future date is greater than the current date -------------- Assigning the Current date to the future date! Now both of the dates are the same! Enter the following: 1- abc 2- 12 3- 1212 4- 121212 5- 221312 6- 220229 7- 220228 > abc Invalid date value
  • 38. > 12 Invalid date valueDate enterd: 2022/03/19 > 1212 Invalid date valueDate enterd: 2022/03/19 > 121212 Invalid date valueDate enterd: 2022/03/19 > 221312 Invalid date valueDate enterd: 2022/03/19 > 220229 Invalid date valueDate enterd: 2022/03/19 > 20220228 Invalid date valueDate enterd: 2022/03/19 ==67598== ==67598== HEAP SUMMARY: ==67598== in use at exit: 31 bytes in 2 blocks ==67598== total heap usage: 32 allocs, 30 frees, 75,963 bytes allocated ==67598== ==67598== 15 bytes in 1 blocks are definitely lost in loss
  • 39. record 1 of 2 ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4025F9: sdds::Status::operator=(char const*) (Status.cpp:50) ==67598== by 0x4017AD: Container::set(int) (main_prof.cpp:43) ==67598== by 0x4018B8: Container::read(std::istream&) (main_prof.cpp:59) ==67598== by 0x400EF1: operator>>(std::istream&, Container&) (main_prof.cpp:95) ==67598== by 0x40102B: statusTester() (main_prof.cpp:111) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== ==67598== 16 bytes in 1 blocks are definitely lost in loss record 2 of 2 ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4025F9: sdds::Status::operator=(char const*) (Status.cpp:50) ==67598== by 0x4018CF: Container::read(std::istream&) (main_prof.cpp:62) ==67598== by 0x400EF1: operator>>(std::istream&,
  • 40. Container&) (main_prof.cpp:95) ==67598== by 0x40102B: statusTester() (main_prof.cpp:111) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== ==67598== LEAK SUMMARY: ==67598== definitely lost: 31 bytes in 2 blocks ==67598== indirectly lost: 0 bytes in 0 blocks ==67598== possibly lost: 0 bytes in 0 blocks ==67598== still reachable: 0 bytes in 0 blocks ==67598== suppressed: 0 bytes in 0 blocks ==67598== ==67598== ERROR SUMMARY: 6 errors from 4 contexts (suppressed: 0 from 0) ==67598== ==67598== 1 errors in context 1 of 4: ==67598== Mismatched free() / delete / delete [] ==67598== at 0x4C2B51D: operator delete(void*) (vg_replace_malloc.c:586) ==67598== by 0x4025CE: sdds::Status::~Status() (Status.cpp:45)
  • 41. ==67598== by 0x4019B5: Container::~Container() (main_prof.cpp:34) ==67598== by 0x40106C: statusTester() (main_prof.cpp:113) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== Address 0x5afddc0 is 0 bytes inside a block of size 14 alloc'd ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4025F9: sdds::Status::operator=(char const*) (Status.cpp:50) ==67598== by 0x40177B: Container::set(int) (main_prof.cpp:39) ==67598== by 0x4018B8: Container::read(std::istream&) (main_prof.cpp:59) ==67598== by 0x400EF1: operator>>(std::istream&, Container&) (main_prof.cpp:95) ==67598== by 0x40102B: statusTester() (main_prof.cpp:111) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== ==67598== ==67598== 3 errors in context 2 of 4:
  • 42. ==67598== Mismatched free() / delete / delete [] ==67598== at 0x4C2B51D: operator delete(void*) (vg_replace_malloc.c:586) ==67598== by 0x4025CE: sdds::Status::~Status() (Status.cpp:45) ==67598== by 0x4019B5: Container::~Container() (main_prof.cpp:34) ==67598== by 0x401056: statusTester() (main_prof.cpp:112) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== Address 0x5afdcd0 is 0 bytes inside a block of size 16 alloc'd ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4024F5: sdds::Status::Status(sdds::Status const&) (Status.cpp:22) ==67598== by 0x4019EE: Container::Container(Container const&) (main_prof.cpp:34) ==67598== by 0x40103E: statusTester() (main_prof.cpp:112) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== ==67598== ERROR SUMMARY: 6 errors from 4 contexts (suppressed: 0 from 0)
  • 43. Script done on Sat 19 Mar 2022 11:56:32 AM EDT date.cpp #include <iostream> #include <cstring> #include <ctime> #include "Date.h" namespace sdds { int Date::currentYear() { time_t current_time; current_time = time(NULL); int year = 1970 + current_time / 31537970;
  • 44. return year; } int Date::currentMonth() { std::time_t current_time; current_time = std::time(NULL); std::tm* now = std::localtime(&current_time); int month = now->tm_mon + 1; return month; } int Date::currentDay() { std::time_t current_time; current_time = std::time(NULL); std::tm* now = std::localtime(&current_time); int day = now->tm_mday; return day; }
  • 45. int Date::numOfDays(int mon, int year) const { int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, -1 }; int month = mon >= 1 && mon <= 12 ? mon : 13; month--; return days[month] + int((month == 1) * ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } bool Date::validate() { bool isValid; int min_year = currentYear(); if (m_year < min_year || m_year > max_year) { State = "Invalid year in date"; State = 1; isValid = false; } else if (m_month < 1 || m_month > 12) {
  • 46. State = "Invalid month in date"; State = 2; isValid = false; } else if (m_day < 1 || m_day > numOfDays(m_month, m_year)) { State = "Invalid day in date"; State = 3; isValid = false; } else { State.clear(); isValid = true; } return isValid; } Date::Date() { m_year = currentYear();
  • 47. m_month = currentMonth(); m_day = currentDay(); m_formatted = true; } Date::Date(int year, int month, int day) { m_year = year; m_month = month; m_day = day; m_formatted = true; } int Date::uniqueDateValue()const { return m_year * 372 + m_month * 31 + m_day; } bool Date::operator==(const Date& data) const { return (this->uniqueDateValue() ==
  • 48. data.uniqueDateValue()); } bool Date::operator!=(const Date& data) const { return (this->uniqueDateValue() != data.uniqueDateValue()); } bool Date::operator<(const Date& data) const { return (this->uniqueDateValue() < data.uniqueDateValue()); } bool Date::operator>(const Date& data)const { return (this->uniqueDateValue() > data.uniqueDateValue()); } bool Date::operator<=(const Date& data)const { return (this->uniqueDateValue() <=
  • 49. data.uniqueDateValue()); } bool Date::operator>=(const Date& data)const { return (this->uniqueDateValue() >= data.uniqueDateValue()); } const Status& Date::state() { return State; } Date& Date::formatted(bool formatted) { m_formatted = formatted; return *this; } std::ostream& Date::write(std::ostream& ostr) const { if (m_formatted == true) {
  • 50. ostr << m_year << "/"; if (m_month < 10) { ostr << "0" << m_month << "/"; } else { ostr << m_month << "/"; } if (m_day < 10) { ostr << "0" << m_day; } else { ostr << m_day; } } else if (m_formatted == false) { ostr << m_year % 100; if (m_month < 10) { ostr << "0" << m_month;
  • 51. } else { ostr << m_month; } if (m_day < 10) { ostr << "0" << m_day; } else { ostr << m_day; } } return ostr; } std::istream& Date::read(std::istream& istr) { int date=0, size=0; string tmp; istr >> date;
  • 52. size = tmp.size(); if (size == 2) { m_year = currentYear(); m_month = 0; m_day = date; } else if (size == 4) { m_year = currentYear(); m_month = date / 100; m_day = date % 100; } else if (size == 6) {
  • 53. m_year = 2000 + date / 10000; m_month = (date / 100) % 100; m_day = date % 100; } else { cout << "Invalid date value"; } if (validate() == false) istr.std::istream::setstate(ios::badbit); return istr; } std::ostream& operator<<(std::ostream& ostr, Date const& data) { return data.write(ostr); }
  • 54. std::istream& operator>>(std::istream& istr, Date& data) { return data.read(istr); } } status.cpp #include "Status.h" namespace sdds { Status::Status(char* str, int code) { if (str != NULL) {
  • 55. description = new char[strlen(str) + 1]; strcpy(description, str); } else description = NULL; status_code = code; } Status::Status(const Status& s) { if (!s) { description = new char[strlen(s.description) + 1]; strcpy(description, s.description); } else description = NULL; status_code = s.status_code;
  • 56. } Status& Status::operator=(const Status& s) { if (!s) { description = new char[strlen(s.description) + 1]; strcpy(description, s.description); } else description = NULL; status_code = s.status_code; return *this; } Status::~Status() { delete(description);
  • 57. } Status& Status::operator=(const char* str) { description = new char[strlen(str) + 1]; strcpy(description, str); return *this; } Status& Status::operator=(const int code) { status_code = code; return *this; } Status::operator bool() const { if (description == NULL)
  • 58. return true; else return false; } Status::operator int() const { return status_code; } Status::operator char* () const { return (char*)description; } ostream& operator<<(ostream& out, const Status& s) { if (!s)
  • 59. { if (s.status_code != 0) out << "ERR#" << s.status_code << ": "; out << s.description; } return out; } Status& Status::clear() { description = NULL; status_code = 0; return *this; } } utils.cpp
  • 60. #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <ctime> #include "Utils.h" using namespace std; namespace sdds { Utils ut; void Utils::testMode(bool testmode) { m_testMode = testmode; } void Utils::getSystemDate(int* year, int* mon, int* day) { if (m_testMode) { if (day) *day = sdds_testDay; if (mon) *mon = sdds_testMon; if (year) *year = sdds_testYear; } else {
  • 61. time_t t = std::time(NULL); tm lt = *localtime(&t); if (day) *day = lt.tm_mday; if (mon) *mon = lt.tm_mon + 1; if (year) *year = lt.tm_year + 1900; } } int Utils::daysOfMon(int month, int year)const { int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, -1 }; int mon = (month >= 1 && month <= 12 ? month : 13) - 1; return days[mon] + int((mon == 1) * ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } } date.h
  • 62. #ifndef SDDS_DATE_H #define SDDS_DATE_H #include <iostream> #include "Status.h" using namespace std; namespace sdds { const int max_year = 2030; class Date { private: int m_year, m_month, m_day; Status State; int uniqueDateValue() const; bool m_formatted; bool validate(); public: Date();
  • 63. Date(int year, int month, int day); int numOfDays(int month, int year) const; int currentYear(); int currentMonth(); int currentDay(); bool operator==(const Date& data) const; bool operator!=(const Date& data) const; bool operator<(const Date& data) const; bool operator>(const Date& data) const; bool operator<=(const Date& data) const; bool operator>=(const Date& data) const; const Status& state(); Date& formatted(bool formatted); std::istream& read(std::istream& istr); std::ostream& write(std::ostream& ostr) const; }; std::ostream& operator<<(std::ostream& ostr, Date const& data); std::istream& operator>>(std::istream& istr, Date& data);
  • 64. } #endif status.h #ifndef SDDS_STATUS_H #define SDDS_STATUS_H #include<iostream> #include<cstring> using namespace std; namespace sdds { class Status { char* description;
  • 65. int status_code; public: Status(char* str = NULL, int code = 0); Status(const Status& s); Status& operator=(const Status& s); ~Status(); Status& operator=(const char* str); Status& operator=(const int code); operator bool() const; operator int() const; operator char* () const; friend ostream& operator<<(ostream& out, const Status& s);
  • 66. Status& clear(); }; } #endif // !SDDS_STATUS_H utils.h #ifndef SDDS_UTILS_H #define SDDS_UTILS_H namespace sdds { const int sdds_testYear = 2022; const int sdds_testMon = 03; const int sdds_testDay = 31; class Utils { bool m_testMode = false; public:
  • 67. void getSystemDate(int* year = nullptr, int* mon = nullptr, int* day = nullptr); int daysOfMon(int mon, int year)const; void testMode(bool testmode = true); }; extern Utils ut; } #endif // !SDDS_UTILS_H main.cpp #include <iostream> #include "Date.h" #include "Utils.h" #include "Status.h" using namespace std; using namespace sdds;
  • 68. void statusTester(); void dateTester(); int main() { cout << "Status Tester --------------------------------------------- --------" << endl; statusTester(); cout << "Date Tester ---------------------------------------------- ---------" << endl; dateTester(); } // Copied from StatusTestr.cpp const int c_min{ 0 }; const int c_max{ 100 }; class Container { int m_val{}; sdds::Status m_state;
  • 69. Container& set(int value) { if (value < c_min) { m_state = "value too low"; m_state = -1; } else if (value > c_max) { m_state = "value too high"; m_state = 1; } else { m_state.clear(); } return *this; } public: Container(int value = 0) { set(value); }
  • 70. istream& read(istream& istr = cin) { istr >> m_val; m_state.clear(); if (istr) { set(m_val); } else { m_state = "Invalid Integer"; istr.clear(); } istr.ignore(1000, 'n'); return istr; } ostream& write(ostream& ostr = cout)const { if (m_state) { ostr << m_val; } else {
  • 71. ostr << m_state; } return ostr; } Container& value(int val) { set(val); return *this; } int value()const { return m_val; } operator bool()const { return m_state; } const sdds::Status& state()const { return m_state; } };
  • 72. ostream& operator<<(ostream& ostr, const Container& I) { return I.write(ostr); } istream& operator>>(istream& istr, Container& I) { return I.read(istr); } void prnContainer(Container C) { cout << "Container: (" << C << ")" << endl; if (!C) { cout << "Error #: " << int(C.state()) << endl; cout << "Problem: " << (const char*)(C.state()) << endl; } } void statusTester() { Container c; cout << "Enter following values :nabcn123n-123n12" <<
  • 73. endl; for (int i = 0; i < 4; i++) { cout << "> "; cin >> c; prnContainer(c); } } // Copied from DateTester.cpp void testDate() { Date D; cout << "> "; cin >> D; if (!cin) { cin.clear(); cin.ignore(1000, 'n'); cout << D.state() << endl; }
  • 74. else { cout << "Date enterd: " << D << endl; } } void dateTester() { cout << "Current Date: " << Date() << endl; cout << "Test mode: " << endl; ut.testMode(); Date C; Date F(2022, 5, 25); cout << "Current Date formatted (C): " << C << endl; C.formatted(false); cout << "Current Date unformatted (C): " << C << endl; cout << "Future Date formatted (F): " << F << endl; F.formatted(false); cout << "Future Date unformatted (F): " << F << endl; cout << "The current date is" << (C != F ? " NOT" : "") << " the same as the future date" << endl; cout << "The current date is" << (C == C ? "" : " NOT") << "
  • 75. the same as the current date" << endl; cout << "The current date is" << (C <= F ? " Less than or equal to" : " greater than") << " the future date" << endl;; cout << "The current date is" << (C <= C ? " Less than or equal to" : " greater than") << " the current date" << endl;; cout << "The current date is" << (C < F ? " Less than" : " greater than or equal to") << " the future date" << endl;; cout << "The future date is" << (F >= C ? " greater than or equal to" : " Less than") << " the current date" << endl;; cout << "The future date is" << (F >= F ? " greater than or equal to" : " Less than") << " the future date" << endl;; cout << "The future date is" << (F > C ? " greater than" : " Less than or equal to") << " the current date" << endl;; cout << "--------------nAssigning the Current date to the future date!" << endl; C = F; if (C == F) cout << "Now both of the dates are the same!" << endl; else cout << "The two dates are different after assignment!!!!!" << endl; cout << "Enter the following:n1- abcn2- 12n3- 1212n4- 121212"
  • 76. "n5- 221312n6- 220229n7- 220228" << endl; for (int i = 0; i < 7; i++) { testDate(); } Script started on Sat 19 Mar 2022 11:54:49 AM EDT ==67598== Memcheck, a memory error detector ==67598== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==67598== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==67598== Command: ms ==67598== Status Tester ----------------------------------------------------- Enter following values : abc 123 -123 12 > abc
  • 77. Container: (Invalid Integer) Error #: 0 Problem: Invalid Integer ==67598== Mismatched free() / delete / delete [] ==67598== at 0x4C2B51D: operator delete(void*) (vg_replace_malloc.c:586) ==67598== by 0x4025CE: sdds::Status::~Status() (Status.cpp:45) ==67598== by 0x4019B5: Container::~Container() (main_prof.cpp:34) ==67598== by 0x401056: statusTester() (main_prof.cpp:112) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== Address 0x5afdcd0 is 0 bytes inside a block of size 16 alloc'd ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4024F5: sdds::Status::Status(sdds::Status const&) (Status.cpp:22) ==67598== by 0x4019EE: Container::Container(Container const&) (main_prof.cpp:34) ==67598== by 0x40103E: statusTester() (main_prof.cpp:112)
  • 78. ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== > 12 Container: (12) > 123 Container: (ERR#1: value too high) Error #: 1 Problem: value too high > -123 Container: (ERR#-1: value too low) Error #: -1 Problem: value too low ==67598== Mismatched free() / delete / delete [] ==67598== at 0x4C2B51D: operator delete(void*) (vg_replace_malloc.c:586) ==67598== by 0x4025CE: sdds::Status::~Status() (Status.cpp:45) ==67598== by 0x4019B5: Container::~Container() (main_prof.cpp:34) ==67598== by 0x40106C: statusTester() (main_prof.cpp:113)
  • 79. ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== Address 0x5afddc0 is 0 bytes inside a block of size 14 alloc'd ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4025F9: sdds::Status::operator=(char const*) (Status.cpp:50) ==67598== by 0x40177B: Container::set(int) (main_prof.cpp:39) ==67598== by 0x4018B8: Container::read(std::istream&) (main_prof.cpp:59) ==67598== by 0x400EF1: operator>>(std::istream&, Container&) (main_prof.cpp:95) ==67598== by 0x40102B: statusTester() (main_prof.cpp:111) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== Date Tester ------------------------------------------------------- Currect Date: 2022/03/19 Test mode: Current Date formatted (C): 2022/03/19 Current Date unformatted (C): 220319
  • 80. Future Date formatted (F): 2022/05/25 Future Date unformatted (F): 220525 The current date is NOT the same as the future date The current date is the same as the current date The current date is Less than or equal to the future date The current date is Less than or equal to the current date The current date is Less than the future date The future date is greater than or equal to the current date The future date is greater than or equal to the future date The future date is greater than the current date -------------- Assigning the Current date to the future date! Now both of the dates are the same! Enter the following: 1- abc 2- 12 3- 1212 4- 121212
  • 81. 5- 221312 6- 220229 7- 220228 > abc Invalid date value > 12 Invalid date valueDate enterd: 2022/03/19 > 1212 Invalid date valueDate enterd: 2022/03/19 > 121212 Invalid date valueDate enterd: 2022/03/19 > 221312 Invalid date valueDate enterd: 2022/03/19 > 220229 Invalid date valueDate enterd: 2022/03/19 > 20220228 Invalid date valueDate enterd: 2022/03/19 ==67598==
  • 82. ==67598== HEAP SUMMARY: ==67598== in use at exit: 31 bytes in 2 blocks ==67598== total heap usage: 32 allocs, 30 frees, 75,963 bytes allocated ==67598== ==67598== 15 bytes in 1 blocks are definitely lost in loss record 1 of 2 ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4025F9: sdds::Status::operator=(char const*) (Status.cpp:50) ==67598== by 0x4017AD: Container::set(int) (main_prof.cpp:43) ==67598== by 0x4018B8: Container::read(std::istream&) (main_prof.cpp:59) ==67598== by 0x400EF1: operator>>(std::istream&, Container&) (main_prof.cpp:95) ==67598== by 0x40102B: statusTester() (main_prof.cpp:111) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== ==67598== 16 bytes in 1 blocks are definitely lost in loss record 2 of 2
  • 83. ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4025F9: sdds::Status::operator=(char const*) (Status.cpp:50) ==67598== by 0x4018CF: Container::read(std::istream&) (main_prof.cpp:62) ==67598== by 0x400EF1: operator>>(std::istream&, Container&) (main_prof.cpp:95) ==67598== by 0x40102B: statusTester() (main_prof.cpp:111) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== ==67598== LEAK SUMMARY: ==67598== definitely lost: 31 bytes in 2 blocks ==67598== indirectly lost: 0 bytes in 0 blocks ==67598== possibly lost: 0 bytes in 0 blocks ==67598== still reachable: 0 bytes in 0 blocks ==67598== suppressed: 0 bytes in 0 blocks ==67598== ==67598== ERROR SUMMARY: 6 errors from 4 contexts (suppressed: 0 from 0)
  • 84. ==67598== ==67598== 1 errors in context 1 of 4: ==67598== Mismatched free() / delete / delete [] ==67598== at 0x4C2B51D: operator delete(void*) (vg_replace_malloc.c:586) ==67598== by 0x4025CE: sdds::Status::~Status() (Status.cpp:45) ==67598== by 0x4019B5: Container::~Container() (main_prof.cpp:34) ==67598== by 0x40106C: statusTester() (main_prof.cpp:113) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== Address 0x5afddc0 is 0 bytes inside a block of size 14 alloc'd ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4025F9: sdds::Status::operator=(char const*) (Status.cpp:50) ==67598== by 0x40177B: Container::set(int) (main_prof.cpp:39) ==67598== by 0x4018B8: Container::read(std::istream&) (main_prof.cpp:59) ==67598== by 0x400EF1: operator>>(std::istream&, Container&) (main_prof.cpp:95)
  • 85. ==67598== by 0x40102B: statusTester() (main_prof.cpp:111) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== ==67598== ==67598== 3 errors in context 2 of 4: ==67598== Mismatched free() / delete / delete [] ==67598== at 0x4C2B51D: operator delete(void*) (vg_replace_malloc.c:586) ==67598== by 0x4025CE: sdds::Status::~Status() (Status.cpp:45) ==67598== by 0x4019B5: Container::~Container() (main_prof.cpp:34) ==67598== by 0x401056: statusTester() (main_prof.cpp:112) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== Address 0x5afdcd0 is 0 bytes inside a block of size 16 alloc'd ==67598== at 0x4C2AC38: operator new[](unsigned long) (vg_replace_malloc.c:433) ==67598== by 0x4024F5: sdds::Status::Status(sdds::Status const&) (Status.cpp:22) ==67598== by 0x4019EE: Container::Container(Container
  • 86. const&) (main_prof.cpp:34) ==67598== by 0x40103E: statusTester() (main_prof.cpp:112) ==67598== by 0x400E81: main (main_prof.cpp:23) ==67598== ==67598== ERROR SUMMARY: 6 errors from 4 contexts (suppressed: 0 from 0) Script done on Sat 19 Mar 2022 11:56:32 AM EDT