SlideShare a Scribd company logo
C# Assignmet Help
Operator overloading implementation in CPP
This program is using the Date function in a formatimplementing
operator overloading functionalities.
#include <iostream>
#include <iomanip>
#include "DateTime.h"
usingstd::cout;
usingstd::endl;
/*********************************************************************
*******
**********************************************************************
******
**
**
**
**
**
**
** class Date implementation code
**
**
**
**
**
**
**
**********************************************************************
******
**********************************************************************
******/
// default constructor
Date::Date(int year, int month, int day)
{
this->yyyy = year;
this->mm = month;
this->dd = day;
}
//copy constructor
Date::Date(const Date& d)
{
this->yyyy = d.yyyy;
this->mm = d.mm;
this->dd = d.dd;
}
int Date::getDay()
{
return this->dd;
}
int Date::getMonth()
{
return this->mm;
}
int Date::getYear()
{
return this->yyyy;
}
void Date::setDate(int year, int month, int day)
{
this->yyyy = year;
this->mm = month;
this->dd = day;
}
void Date::setDate(const Date& d)
{
this->yyyy = d.yyyy;
this->mm = d.mm;
this->dd = d.dd;
}
// Date class stream extraction operator
std::istream& operator>>(std::istream&in, Date &d)
{
charch;
in>>d.yyyy; //extract the year and store them in data member yyyy
in>>ch; //extract and discard the dilimiting character
in>> d.mm; //extract the month and store them in data member mm
in>>ch; //extract and discard the dilimiting character
in>> d.dd; ///extract the day and store them in data member dd
return in;
} //END overloaded stream extraction operator for Date class
/*********************************************************************
*******
* Date class stream insertion operator
*
**********************************************************************
******/
std::ostream& operator<<(std::ostream&os, const Date &d)
{
os<<std::setfill('0');
os<<std::setw(4) <<d.yyyy<< "/";
os<<std::setw(2) << d.mm << "/";
os<<std::setw(2) << d.dd;
os<<std::setfill(' ');
returnos;
} //END overloaded stream insertion operator for Date class
bool Date::operator==(const Date& d) const
{
return (this->yyyy == d.yyyy&& this->mm == d.mm && this->dd ==
d.dd);
}
bool Date::operator!=(const Date& d) const
{
return !(this->yyyy == d.yyyy&& this->mm == d.mm && this->dd ==
d.dd);
}
bool Date::operator<(const Date& d) const
{
if (this->yyyy<d.yyyy)
{
return true;
}
else if (this->mm < d.mm)
{
return true;
}
else if (this->dd< d.dd)
{
return true;
}
}
bool Date::operator<=(const Date& d) const
{
if (this->yyyy<= d.yyyy)
{
return true;
}
else if (this->mm <= d.mm)
{
return true;
}
else if (this->dd<= d.dd)
{
return true;
}
}
bool Date::operator>(const Date& d) const
{
if (this->yyyy>d.yyyy)
{
return true;
}
else if (this->mm > d.mm)
{
return true;
}
else if (this->dd> d.dd)
{
return true;
}
}
bool Date::operator>=(const Date& d) const
{
if (this->yyyy>= d.yyyy)
{
return true;
}
else if (this->mm >= d.mm)
{
return true;
}
else if (this->dd>= d.dd)
{
return true;
}
}
Date Date::operator =(const Date& d)
{
if (this != &d)
{
//not a self assignment, OK to proceed
yyyy = d.yyyy;
mm = d.mm;
dd = d.dd;
}
return d;
}
/*********************************************************************
*******
**********************************************************************
******
**
**
** class Time implementation code
**
**
**
** This code is provided to students
**
** in COSC 052 Spring 2016 to use in
**
** part or in total for class projects.
**
** Students may use this code as their
**
** own, without any attribution.
**
**
**
**********************************************************************
******
**********************************************************************
******/
/*********************************************************************
*******
* Time class default constructor
*
**********************************************************************
******/
Time::Time(int hour, int minute)
{
#ifdef DEBUG_DATE
std::cout<< "Entered constructor Time::Time(int, int, int)"
<<std::endl;
#endif
setTime(hour, minute);
#ifdef DEBUG_DATE
std::cout<< "Exiting constructor Time::Time(int, int)"
<<std::endl;
#endif
} //END constructor with parameters for Time class
/*********************************************************************
*******
* Time class member function setTime
*
**********************************************************************
******/
void Time::setTime(int hour, int minute)
{
hh = hour;
mm = minute;
} //END member function Time::setTime
/*********************************************************************
*******
* Time class stream extraction operator
*
**********************************************************************
******/
std::istream& operator>>(std::istream&in, Time &t)
{
charch;
in>>t.hh; //extract the hours and store them in data member hh
in>>ch; //extract and discard the dilimiting character
in>> t.mm; //extract the minutes and store them in data member mm
return in;
} //END overloaded stream extraction operator for Time class
/*********************************************************************
*******
* Time class stream insertion operator
*
**********************************************************************
******/
std::ostream& operator<<(std::ostream&os, const Time &t)
{
os<<std::setfill('0');
os<<std::setw(2) <<t.hh<< ":";
os<<std::setw(2) << t.mm;
os<<std::setfill(' ');
returnos;
} //END overloaded stream insertion operator for Time class
/*********************************************************************
*******
* Time class assignment operator
*
**********************************************************************
******/
Time Time::operator=(const Time &rhsObj)
{
if (this != &rhsObj)
{
//not a self assignment, OK to proceed
hh = rhsObj.hh;
mm = rhsObj.mm;
}
returnrhsObj;
} //END overloaded assignment operator for Time class
C# Assignmet Help

More Related Content

PDF
Optimal three stage flow shop scheduling in which processing time, set up tim...
PDF
11.optimal three stage flow shop scheduling in which processing time, set up ...
PDF
Bicriteria in n x 2 flow shop scheduling problem under specified rental polic...
PDF
11.bicriteria in n x 0002www.iiste.org call for paper flow shop scheduling pr...
PDF
Sujet bac info 2013 g1, g2 et g3 avec correction
PDF
Сalculation of the сentral node
PPTX
PPT
C++ Function
Optimal three stage flow shop scheduling in which processing time, set up tim...
11.optimal three stage flow shop scheduling in which processing time, set up ...
Bicriteria in n x 2 flow shop scheduling problem under specified rental polic...
11.bicriteria in n x 0002www.iiste.org call for paper flow shop scheduling pr...
Sujet bac info 2013 g1, g2 et g3 avec correction
Сalculation of the сentral node
C++ Function

Similar to C# Assignmet Help (20)

PDF
Modify the Time classattached to be able to work with Date.pdf
PDF
Modify the Date class that was covered in the lecture which overload.pdf
DOCX
#include Status.hnamespace sdds{StatusStatus(c
DOCX
#include Status.hnamespace sdds{StatusStatus(c
PDF
C++ Please I am posting the fifth time and hoping to get th.pdf
PDF
Please I am posting the fifth time and hoping to get this r.pdf
PPTX
Synapse india dotnet development overloading operater part 4
PDF
Please make a comment for all the codesOr explain this pro.pdf
PDF
Problem DefinitionBuild a Date class and a main function to test i.pdf
PPT
lecture12.ppt
PPT
Operator overloading in c++ is the most required.
PPT
OOP OOOOOverloading Concept lecture12.ppt
PPT
operator overloading concept in oops lecture12.ppt
PPT
Operator overloading
DOCX
#include iostream #include iomanip needed for formatting .docx
PDF
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
PPT
Synapse india complain sharing info on chapter 8 operator overloading
PPT
Overloading
PPT
Object oriented programming; operator overloading array
PPT
Operator overloading Object Oriented Programming
Modify the Time classattached to be able to work with Date.pdf
Modify the Date class that was covered in the lecture which overload.pdf
#include Status.hnamespace sdds{StatusStatus(c
#include Status.hnamespace sdds{StatusStatus(c
C++ Please I am posting the fifth time and hoping to get th.pdf
Please I am posting the fifth time and hoping to get this r.pdf
Synapse india dotnet development overloading operater part 4
Please make a comment for all the codesOr explain this pro.pdf
Problem DefinitionBuild a Date class and a main function to test i.pdf
lecture12.ppt
Operator overloading in c++ is the most required.
OOP OOOOOverloading Concept lecture12.ppt
operator overloading concept in oops lecture12.ppt
Operator overloading
#include iostream #include iomanip needed for formatting .docx
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
Synapse india complain sharing info on chapter 8 operator overloading
Overloading
Object oriented programming; operator overloading array
Operator overloading Object Oriented Programming
Ad

More from Programming Homework Help (8)

PDF
Java Assignment Help
PDF
C# Assignmet Help
PDF
Family tree in java
PDF
Binary tree in java
PDF
Bank account in java
PDF
Mouse and Cat Game In C++
PDF
Word games in c
PDF
Card Games in C++
Java Assignment Help
C# Assignmet Help
Family tree in java
Binary tree in java
Bank account in java
Mouse and Cat Game In C++
Word games in c
Card Games in C++
Ad

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Types and Its function , kingdom of life
PDF
Insiders guide to clinical Medicine.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
master seminar digital applications in india
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Computing-Curriculum for Schools in Ghana
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Classroom Observation Tools for Teachers
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Final Presentation General Medicine 03-08-2024.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Types and Its function , kingdom of life
Insiders guide to clinical Medicine.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
GDM (1) (1).pptx small presentation for students
master seminar digital applications in india
VCE English Exam - Section C Student Revision Booklet
Computing-Curriculum for Schools in Ghana
human mycosis Human fungal infections are called human mycosis..pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Classroom Observation Tools for Teachers

C# Assignmet Help

  • 2. Operator overloading implementation in CPP This program is using the Date function in a formatimplementing operator overloading functionalities. #include <iostream> #include <iomanip> #include "DateTime.h" usingstd::cout; usingstd::endl; /********************************************************************* ******* ********************************************************************** ****** ** ** ** ** ** ** ** class Date implementation code ** ** ** ** ** ** ** ********************************************************************** ****** ********************************************************************** ******/ // default constructor Date::Date(int year, int month, int day) { this->yyyy = year; this->mm = month; this->dd = day; } //copy constructor Date::Date(const Date& d) { this->yyyy = d.yyyy; this->mm = d.mm;
  • 3. this->dd = d.dd; } int Date::getDay() { return this->dd; } int Date::getMonth() { return this->mm; } int Date::getYear() { return this->yyyy; } void Date::setDate(int year, int month, int day) { this->yyyy = year; this->mm = month; this->dd = day; } void Date::setDate(const Date& d) { this->yyyy = d.yyyy; this->mm = d.mm; this->dd = d.dd; } // Date class stream extraction operator std::istream& operator>>(std::istream&in, Date &d) { charch; in>>d.yyyy; //extract the year and store them in data member yyyy in>>ch; //extract and discard the dilimiting character in>> d.mm; //extract the month and store them in data member mm in>>ch; //extract and discard the dilimiting character in>> d.dd; ///extract the day and store them in data member dd return in; } //END overloaded stream extraction operator for Date class
  • 4. /********************************************************************* ******* * Date class stream insertion operator * ********************************************************************** ******/ std::ostream& operator<<(std::ostream&os, const Date &d) { os<<std::setfill('0'); os<<std::setw(4) <<d.yyyy<< "/"; os<<std::setw(2) << d.mm << "/"; os<<std::setw(2) << d.dd; os<<std::setfill(' '); returnos; } //END overloaded stream insertion operator for Date class bool Date::operator==(const Date& d) const { return (this->yyyy == d.yyyy&& this->mm == d.mm && this->dd == d.dd); } bool Date::operator!=(const Date& d) const { return !(this->yyyy == d.yyyy&& this->mm == d.mm && this->dd == d.dd); } bool Date::operator<(const Date& d) const { if (this->yyyy<d.yyyy) { return true; } else if (this->mm < d.mm) { return true; } else if (this->dd< d.dd) { return true; } } bool Date::operator<=(const Date& d) const { if (this->yyyy<= d.yyyy)
  • 5. { return true; } else if (this->mm <= d.mm) { return true; } else if (this->dd<= d.dd) { return true; } } bool Date::operator>(const Date& d) const { if (this->yyyy>d.yyyy) { return true; } else if (this->mm > d.mm) { return true; } else if (this->dd> d.dd) { return true; } } bool Date::operator>=(const Date& d) const { if (this->yyyy>= d.yyyy) { return true; } else if (this->mm >= d.mm) { return true; } else if (this->dd>= d.dd) { return true; } } Date Date::operator =(const Date& d) { if (this != &d) { //not a self assignment, OK to proceed yyyy = d.yyyy; mm = d.mm;
  • 6. dd = d.dd; } return d; } /********************************************************************* ******* ********************************************************************** ****** ** ** ** class Time implementation code ** ** ** ** This code is provided to students ** ** in COSC 052 Spring 2016 to use in ** ** part or in total for class projects. ** ** Students may use this code as their ** ** own, without any attribution. ** ** ** ********************************************************************** ****** ********************************************************************** ******/ /********************************************************************* ******* * Time class default constructor * ********************************************************************** ******/ Time::Time(int hour, int minute) { #ifdef DEBUG_DATE
  • 7. std::cout<< "Entered constructor Time::Time(int, int, int)" <<std::endl; #endif setTime(hour, minute); #ifdef DEBUG_DATE std::cout<< "Exiting constructor Time::Time(int, int)" <<std::endl; #endif } //END constructor with parameters for Time class /********************************************************************* ******* * Time class member function setTime * ********************************************************************** ******/ void Time::setTime(int hour, int minute) { hh = hour; mm = minute; } //END member function Time::setTime /********************************************************************* ******* * Time class stream extraction operator * ********************************************************************** ******/ std::istream& operator>>(std::istream&in, Time &t) { charch; in>>t.hh; //extract the hours and store them in data member hh in>>ch; //extract and discard the dilimiting character in>> t.mm; //extract the minutes and store them in data member mm return in; } //END overloaded stream extraction operator for Time class
  • 8. /********************************************************************* ******* * Time class stream insertion operator * ********************************************************************** ******/ std::ostream& operator<<(std::ostream&os, const Time &t) { os<<std::setfill('0'); os<<std::setw(2) <<t.hh<< ":"; os<<std::setw(2) << t.mm; os<<std::setfill(' '); returnos; } //END overloaded stream insertion operator for Time class /********************************************************************* ******* * Time class assignment operator * ********************************************************************** ******/ Time Time::operator=(const Time &rhsObj) { if (this != &rhsObj) { //not a self assignment, OK to proceed hh = rhsObj.hh; mm = rhsObj.mm; } returnrhsObj; } //END overloaded assignment operator for Time class