SlideShare a Scribd company logo
Answer
****************************************main.cpp******************************
****************************
#include
#include
#include
#include "Month.h"
int main()
{
//testing the constructors here
Month myMonth1;
Month myMonth12(12);
Month myMonth3("March");
string newMonth = "May";
int newNum = 4;
//testing the get and set functions
cout << " ---------------------------------------------" << endl;
cout << "Testing Constructors, Set() and Get()" << endl;
cout << "---------------------------------------------" << endl;
cout << "myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
cout << "myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl;
cout << "myMonth1.getMonthName() gives: " << myMonth12.getMonthName() << endl;
cout << "myMonth12.getMonthNumber() gives: " << myMonth12.getMonthNumber() <<
endl;
cout << "myMonth3.getMonthName() gives: " << myMonth3.getMonthName() << endl;
cout << "myMonth3.getMonthNumber() gives: " << myMonth3.getMonthNumber() << endl;
cout << endl << "Setting number to " << newNum << endl;
myMonth1.setMonthNumber(newNum);
cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() <<
endl;
cout << endl << "Setting number to 13 (invalid) " << endl;
myMonth1.setMonthNumber(13);
cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() <<
endl;
cout << endl << "Setting name to " << newMonth << endl;
myMonth1.setMonthName(newMonth);
cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() <<
endl;
cout << endl << "Setting name to XYZ (invalid) "<< endl;
myMonth1.setMonthName("XYZ");
cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() <<
endl;
//testing inputs, outputs, increments and decrements
cout << " ---------------------------------------------" << endl;
cout << "Testing cin, cout, increments and decrements" << endl;
cout << "---------------------------------------------" << endl;
cout << "myMonth12 is " << myMonth12<< endl;
cout << "myMonth12++ gives "<< myMonth12++ << endl;
cout << "But myMonth12 is now " << myMonth12 << endl;
cout << "++myMonth12 gives "<< ++myMonth12 << endl;
cout << "myMonth12-- gives "<< myMonth12-- << endl;
cout << "But myMonth2 is now " << myMonth12 << endl;
cout << "--myMonth12 gives "<< --myMonth12 << endl;
Month myMonth5;
cin >> myMonth5;
cout << "myMonth5 is set to "<< myMonth5 << endl;
cout << "Press Enter to quit." << endl;
cin.ignore();
cin.get();
return 0;
}
***********************************************month.h************************
****************************
#ifndef MONTH_H
#define MONTH_H
#include
#include
#include
#include "MyString.h"
class Month
{
private:
MyString monthName;
int monthNumber; // monthNumber will accept from 1 to 12
public:
Month() { monthName = "January"; monthNumber = 1; }
Month(const char *name) { setMonthName(name); }
Month(const int num) { setMonthNumber(num); }
MyString getMonthName() { return monthName; }
int getMonthNumber() const {return monthNumber; }
void setMonthName(const string name);
void setMonthNumber(const int num);
Month operator++();
Month operator++(int);
Month operator--();
Month operator--(int);
friend ostream &operator<<(ostream &strm, const Month &obj);
friend istream &operator >> (istream &strm, Month &monthObj);
};
#endif /* end of MONTH_H */
**************************************************month.cpp*******************
******************************
#include
#include
#include
#include "MyString.h"
#include "Month.h"
void Month::setMonthName(const string name)
{
if (name == "January" || name == "Jan") setMonthNumber(1);
else if (name == "February" || name == "Feb")
{
setMonthNumber(2);
}
else if (name == "March" || name == "Mar")
{
setMonthNumber(3);
}
else if (name == "April" || name == "Apr")
{
setMonthNumber(4);
}
else if (name == "May")
{
setMonthNumber(5);
}
else if (name == "June" || name == "Jun")
{
setMonthNumber(6);
}
else if (name == "July" || name == "Jul")
{
setMonthNumber(7);
}
else if (name == "August" || name == "Aug")
{
setMonthNumber(8);
}
else if (name == "September"|| name == "Sept")
{
setMonthNumber(9);
}
else if (name == "October" || name == "Oct")
{
setMonthNumber(10);
}
else if (name == "November" || name == "Nov")
{
setMonthNumber(11);
}
else if (name == "December" || name == "Dec")
{
setMonthNumber(12);
}
else
{
setMonthNumber(1);
}
}
void Month::setMonthNumber(const int num)
{
if (num < 1 || num > 12)
monthNumber = 1;
else
monthNumber = num;
if(monthNumber == 1)
monthName = "January";
else if(monthNumber == 2)
monthName = "February";
else if(monthNumber == 3)
monthName = "March";
else if(monthNumber == 4)
monthName = "April";
else if(monthNumber == 5)
monthName = "May";
else if(monthNumber == 6)
monthName = "June";
else if(monthNumber == 7)
monthName = "July";
else if(monthNumber == 8)
monthName = "August";
else if(monthNumber == 9)
monthName = "September";
else if(monthNumber == 10)
monthName = "October";
else if(monthNumber == 11)
monthName = "November";
else
monthName = "December";
}
Month Month::operator++()
{
if (monthNumber == 12)
monthNumber = 1;
else
++monthNumber;
setMonthNumber(monthNumber);
return *this;
}
Month Month::operator++(int)
{
Month temp(monthNumber);
setMonthNumber(++monthNumber);
return temp;
}
Month Month::operator--()
{
if (monthNumber == 1) monthNumber = 12;
else --monthNumber;
setMonthNumber(monthNumber);
return *this;
}
Month Month::operator--(int)
{
Month temp(monthNumber);
setMonthNumber(--monthNumber);
return temp;
}
ostream &operator << (ostream &strm, const Month &obj)
{
return strm << obj.monthName << "(" << obj.monthNumber << ")";
}
istream &operator >> (istream &strm, Month &monthObj)
{
string m_Name;
cout << endl << "Please enter the month name: " << endl;
strm >> m_Name;
monthObj.setMonthName(m_Name);
return strm;
}
*******************************************mystring.h**************************
***********
// header file for the MyString class
#ifndef MYSTRING_H
#define MYSTRING_H
#include
#include
class MyString;
// declaration of forward operators.
ostream &operator<<(ostream &, const MyString &);
istream &operator>>(istream &, MyString &);
// MyString is a class. This is an abstract data type for handling strings.
class MyString
{
private:
char *str;
int len;
public:
// this is a default constructor
MyString()
{
str = NULL; len = 0;
}
// this is a copy constructor
MyString(MyString &right)
{
str = new char[right.length() + 1];
strcpy(str, right.getValue());
len = right.length();
}
// The following constructor initializes the
// MyString object with a C-string
MyString(char *sptr)
{
len = strlen(sptr);
str = new char[len + 1];
strcpy(str, sptr);
}
// this is a destructor
~MyString()
{
if (len != 0)
delete [] str;
}
// Here is the length function which returns the string length.
int length() const
{
return len;
}
// The getValue function which returns the string.
const char *getValue() const
{
return str;
};
// here are overloaded operators
const MyString operator+=(MyString &);
const char *operator+=(const char *);
const MyString operator=(MyString &);
const char *operator=(const char *);
int operator==(MyString &);
int operator==(const char *);
int operator!=(MyString &);
int operator!=(const char *);
bool operator>(MyString &);
bool operator>(const char *);
bool operator<(MyString &);
bool operator<(const char *);
bool operator>=(MyString &);
bool operator>=(const char*);
bool operator<=(MyString &);
bool operator<=(const char *);
// Friends functions
friend ostream &operator<<(ostream &, const MyString &);
friend istream &operator>>(istream &, MyString &);
};
#endif /* end of MYSTRING_H */
**************************************************mystring.cpp*****************
***********************
// This is an implementation file for the MyString class
#include // include this for string library functions
#include "MyString.h"
const MyString MyString::operator=(MyString &right)
{
if (len != 0)
delete [] str;
str = new char[right.length() + 1];
strcpy(str, right.getValue());
len = right.length();
return *this;
}
const char *MyString::operator=(const char *right)
{
if (len != 0)
delete [] str;
len = strlen(right);
str = new char[len + 1];
strcpy(str, right);
return str;
}
const MyString MyString::operator+=(MyString &right)
{
char *temp = str;
str = new char[strlen(str) + right.length() + 1];
strcpy(str, temp);
strcat(str, right.getValue());
if (len != 0)
delete [] temp;
len = strlen(str);
return *this;
}
const char *MyString::operator+=(const char *right)
{
char *temp = str;
str = new char[strlen(str) + strlen(right) + 1];
strcpy(str, temp);
strcat(str, right);
if (len != 0)
delete [] temp;
return str;
}
int MyString::operator==(MyString &right)
{
return !strcmp(str, right.getValue());
}
int MyString::operator==(const char *right)
{
return !strcmp(str, right);
}
int MyString::operator!=(MyString &right)
{
return strcmp(str, right.getValue());
}
int MyString::operator!=(const char *right)
{
return strcmp(str, right);
}
bool MyString::operator>(MyString &right)
{
bool status;
if (strcmp(str, right.getValue()) > 0)
status = true;
else status = false;
return status;
}
bool MyString::operator>(const char *right)
{
bool status;
if (strcmp(str, right) > 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator<(MyString &right)
{
bool status;
if (strcmp(str, right.getValue()) < 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator<(const char *right)
{
bool status;
if (strcmp(str, right) < 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator>=(MyString &right)
{
bool status;
if (strcmp(str, right.getValue()) >= 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator>=(const char *right)
{
bool status;
if (strcmp(str, right) >= 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator<=(MyString &right)
{
bool status;
if (strcmp(str, right.getValue()) <= 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator<=(const char *right)
{
bool status;
if (strcmp(str, right) <= 0)
status = true;
else
status = false;
return status;
}
ostream &operator<<(ostream &strm, const MyString &obj)
{
strm << obj.str;
return strm;
}
istream &operator>>(istream &strm, MyString &obj)
{
strm.getline(obj.str, obj.len);
strm.ignore();
return strm;
}
Solution
Answer
****************************************main.cpp******************************
****************************
#include
#include
#include
#include "Month.h"
int main()
{
//testing the constructors here
Month myMonth1;
Month myMonth12(12);
Month myMonth3("March");
string newMonth = "May";
int newNum = 4;
//testing the get and set functions
cout << " ---------------------------------------------" << endl;
cout << "Testing Constructors, Set() and Get()" << endl;
cout << "---------------------------------------------" << endl;
cout << "myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
cout << "myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl;
cout << "myMonth1.getMonthName() gives: " << myMonth12.getMonthName() << endl;
cout << "myMonth12.getMonthNumber() gives: " << myMonth12.getMonthNumber() <<
endl;
cout << "myMonth3.getMonthName() gives: " << myMonth3.getMonthName() << endl;
cout << "myMonth3.getMonthNumber() gives: " << myMonth3.getMonthNumber() << endl;
cout << endl << "Setting number to " << newNum << endl;
myMonth1.setMonthNumber(newNum);
cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() <<
endl;
cout << endl << "Setting number to 13 (invalid) " << endl;
myMonth1.setMonthNumber(13);
cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() <<
endl;
cout << endl << "Setting name to " << newMonth << endl;
myMonth1.setMonthName(newMonth);
cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() <<
endl;
cout << endl << "Setting name to XYZ (invalid) "<< endl;
myMonth1.setMonthName("XYZ");
cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() <<
endl;
//testing inputs, outputs, increments and decrements
cout << " ---------------------------------------------" << endl;
cout << "Testing cin, cout, increments and decrements" << endl;
cout << "---------------------------------------------" << endl;
cout << "myMonth12 is " << myMonth12<< endl;
cout << "myMonth12++ gives "<< myMonth12++ << endl;
cout << "But myMonth12 is now " << myMonth12 << endl;
cout << "++myMonth12 gives "<< ++myMonth12 << endl;
cout << "myMonth12-- gives "<< myMonth12-- << endl;
cout << "But myMonth2 is now " << myMonth12 << endl;
cout << "--myMonth12 gives "<< --myMonth12 << endl;
Month myMonth5;
cin >> myMonth5;
cout << "myMonth5 is set to "<< myMonth5 << endl;
cout << "Press Enter to quit." << endl;
cin.ignore();
cin.get();
return 0;
}
***********************************************month.h************************
****************************
#ifndef MONTH_H
#define MONTH_H
#include
#include
#include
#include "MyString.h"
class Month
{
private:
MyString monthName;
int monthNumber; // monthNumber will accept from 1 to 12
public:
Month() { monthName = "January"; monthNumber = 1; }
Month(const char *name) { setMonthName(name); }
Month(const int num) { setMonthNumber(num); }
MyString getMonthName() { return monthName; }
int getMonthNumber() const {return monthNumber; }
void setMonthName(const string name);
void setMonthNumber(const int num);
Month operator++();
Month operator++(int);
Month operator--();
Month operator--(int);
friend ostream &operator<<(ostream &strm, const Month &obj);
friend istream &operator >> (istream &strm, Month &monthObj);
};
#endif /* end of MONTH_H */
**************************************************month.cpp*******************
******************************
#include
#include
#include
#include "MyString.h"
#include "Month.h"
void Month::setMonthName(const string name)
{
if (name == "January" || name == "Jan") setMonthNumber(1);
else if (name == "February" || name == "Feb")
{
setMonthNumber(2);
}
else if (name == "March" || name == "Mar")
{
setMonthNumber(3);
}
else if (name == "April" || name == "Apr")
{
setMonthNumber(4);
}
else if (name == "May")
{
setMonthNumber(5);
}
else if (name == "June" || name == "Jun")
{
setMonthNumber(6);
}
else if (name == "July" || name == "Jul")
{
setMonthNumber(7);
}
else if (name == "August" || name == "Aug")
{
setMonthNumber(8);
}
else if (name == "September"|| name == "Sept")
{
setMonthNumber(9);
}
else if (name == "October" || name == "Oct")
{
setMonthNumber(10);
}
else if (name == "November" || name == "Nov")
{
setMonthNumber(11);
}
else if (name == "December" || name == "Dec")
{
setMonthNumber(12);
}
else
{
setMonthNumber(1);
}
}
void Month::setMonthNumber(const int num)
{
if (num < 1 || num > 12)
monthNumber = 1;
else
monthNumber = num;
if(monthNumber == 1)
monthName = "January";
else if(monthNumber == 2)
monthName = "February";
else if(monthNumber == 3)
monthName = "March";
else if(monthNumber == 4)
monthName = "April";
else if(monthNumber == 5)
monthName = "May";
else if(monthNumber == 6)
monthName = "June";
else if(monthNumber == 7)
monthName = "July";
else if(monthNumber == 8)
monthName = "August";
else if(monthNumber == 9)
monthName = "September";
else if(monthNumber == 10)
monthName = "October";
else if(monthNumber == 11)
monthName = "November";
else
monthName = "December";
}
Month Month::operator++()
{
if (monthNumber == 12)
monthNumber = 1;
else
++monthNumber;
setMonthNumber(monthNumber);
return *this;
}
Month Month::operator++(int)
{
Month temp(monthNumber);
setMonthNumber(++monthNumber);
return temp;
}
Month Month::operator--()
{
if (monthNumber == 1) monthNumber = 12;
else --monthNumber;
setMonthNumber(monthNumber);
return *this;
}
Month Month::operator--(int)
{
Month temp(monthNumber);
setMonthNumber(--monthNumber);
return temp;
}
ostream &operator << (ostream &strm, const Month &obj)
{
return strm << obj.monthName << "(" << obj.monthNumber << ")";
}
istream &operator >> (istream &strm, Month &monthObj)
{
string m_Name;
cout << endl << "Please enter the month name: " << endl;
strm >> m_Name;
monthObj.setMonthName(m_Name);
return strm;
}
*******************************************mystring.h**************************
***********
// header file for the MyString class
#ifndef MYSTRING_H
#define MYSTRING_H
#include
#include
class MyString;
// declaration of forward operators.
ostream &operator<<(ostream &, const MyString &);
istream &operator>>(istream &, MyString &);
// MyString is a class. This is an abstract data type for handling strings.
class MyString
{
private:
char *str;
int len;
public:
// this is a default constructor
MyString()
{
str = NULL; len = 0;
}
// this is a copy constructor
MyString(MyString &right)
{
str = new char[right.length() + 1];
strcpy(str, right.getValue());
len = right.length();
}
// The following constructor initializes the
// MyString object with a C-string
MyString(char *sptr)
{
len = strlen(sptr);
str = new char[len + 1];
strcpy(str, sptr);
}
// this is a destructor
~MyString()
{
if (len != 0)
delete [] str;
}
// Here is the length function which returns the string length.
int length() const
{
return len;
}
// The getValue function which returns the string.
const char *getValue() const
{
return str;
};
// here are overloaded operators
const MyString operator+=(MyString &);
const char *operator+=(const char *);
const MyString operator=(MyString &);
const char *operator=(const char *);
int operator==(MyString &);
int operator==(const char *);
int operator!=(MyString &);
int operator!=(const char *);
bool operator>(MyString &);
bool operator>(const char *);
bool operator<(MyString &);
bool operator<(const char *);
bool operator>=(MyString &);
bool operator>=(const char*);
bool operator<=(MyString &);
bool operator<=(const char *);
// Friends functions
friend ostream &operator<<(ostream &, const MyString &);
friend istream &operator>>(istream &, MyString &);
};
#endif /* end of MYSTRING_H */
**************************************************mystring.cpp*****************
***********************
// This is an implementation file for the MyString class
#include // include this for string library functions
#include "MyString.h"
const MyString MyString::operator=(MyString &right)
{
if (len != 0)
delete [] str;
str = new char[right.length() + 1];
strcpy(str, right.getValue());
len = right.length();
return *this;
}
const char *MyString::operator=(const char *right)
{
if (len != 0)
delete [] str;
len = strlen(right);
str = new char[len + 1];
strcpy(str, right);
return str;
}
const MyString MyString::operator+=(MyString &right)
{
char *temp = str;
str = new char[strlen(str) + right.length() + 1];
strcpy(str, temp);
strcat(str, right.getValue());
if (len != 0)
delete [] temp;
len = strlen(str);
return *this;
}
const char *MyString::operator+=(const char *right)
{
char *temp = str;
str = new char[strlen(str) + strlen(right) + 1];
strcpy(str, temp);
strcat(str, right);
if (len != 0)
delete [] temp;
return str;
}
int MyString::operator==(MyString &right)
{
return !strcmp(str, right.getValue());
}
int MyString::operator==(const char *right)
{
return !strcmp(str, right);
}
int MyString::operator!=(MyString &right)
{
return strcmp(str, right.getValue());
}
int MyString::operator!=(const char *right)
{
return strcmp(str, right);
}
bool MyString::operator>(MyString &right)
{
bool status;
if (strcmp(str, right.getValue()) > 0)
status = true;
else status = false;
return status;
}
bool MyString::operator>(const char *right)
{
bool status;
if (strcmp(str, right) > 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator<(MyString &right)
{
bool status;
if (strcmp(str, right.getValue()) < 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator<(const char *right)
{
bool status;
if (strcmp(str, right) < 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator>=(MyString &right)
{
bool status;
if (strcmp(str, right.getValue()) >= 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator>=(const char *right)
{
bool status;
if (strcmp(str, right) >= 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator<=(MyString &right)
{
bool status;
if (strcmp(str, right.getValue()) <= 0)
status = true;
else
status = false;
return status;
}
bool MyString::operator<=(const char *right)
{
bool status;
if (strcmp(str, right) <= 0)
status = true;
else
status = false;
return status;
}
ostream &operator<<(ostream &strm, const MyString &obj)
{
strm << obj.str;
return strm;
}
istream &operator>>(istream &strm, MyString &obj)
{
strm.getline(obj.str, obj.len);
strm.ignore();
return strm;
}

More Related Content

PDF
I keep on get a redefinition error and an undefined error.Customer.pdf
PDF
Hey, looking to do the following with this programFill in the multip.pdf
DOCX
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
PDF
Problem DefinitionBuild a Date class and a main function to test i.pdf
DOCX
#include Status.hnamespace sdds{StatusStatus(c
DOCX
#include Status.hnamespace sdds{StatusStatus(c
PDF
sodapdf-converted into ppt presentation(1).pdf
PDF
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
I keep on get a redefinition error and an undefined error.Customer.pdf
Hey, looking to do the following with this programFill in the multip.pdf
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
Problem DefinitionBuild a Date class and a main function to test i.pdf
#include Status.hnamespace sdds{StatusStatus(c
#include Status.hnamespace sdds{StatusStatus(c
sodapdf-converted into ppt presentation(1).pdf
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf

Similar to Answer main.cpp.pdf (20)

PDF
I have written the code but cannot complete the assignment please help.pdf
DOCX
@author Jane Programmer @cwid 123 45 678 @class.docx
DOCX
Lab Assignment #6, part 3 Time ConversionProgram Name lab.docx
PDF
C# Assignmet Help
PDF
Bangun datar dan bangun ruang
DOCX
C++ project on police station software
PPT
Dynamically Evolving Systems: Cluster Analysis Using Time
PPT
c++ Lecture 2
PDF
ECMAScript 6 Review
PDF
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
PPTX
Lec 2.pptx programing errors \basic of programing
PDF
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
PPT
Falcon初印象
PDF
Method::Signatures
DOCX
Include
PPTX
Mysql:Operators
PPTX
MySQL Operators
PDF
Linear queue
DOCX
Tugas praktikukm pemrograman c++
PDF
Circular queue
I have written the code but cannot complete the assignment please help.pdf
@author Jane Programmer @cwid 123 45 678 @class.docx
Lab Assignment #6, part 3 Time ConversionProgram Name lab.docx
C# Assignmet Help
Bangun datar dan bangun ruang
C++ project on police station software
Dynamically Evolving Systems: Cluster Analysis Using Time
c++ Lecture 2
ECMAScript 6 Review
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
Lec 2.pptx programing errors \basic of programing
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
Falcon初印象
Method::Signatures
Include
Mysql:Operators
MySQL Operators
Linear queue
Tugas praktikukm pemrograman c++
Circular queue

More from vichu19891 (20)

PDF
1. Copper is above silver in the activity series. Thus Cu metal will.pdf
PDF
using recursive method .pdf
PDF
a. Population - families in the state of Florida b. Variable .pdf
PDF
there is no reaction between HNO3 and KCl. S.pdf
PDF
The thickness of non-saturated zone and physico-c.pdf
PDF
The folding process of proteins is hierarchical, .pdf
PDF
Step1 ppt of PbCl2 are soluble in hot water. Ste.pdf
PDF
Should take off H from SH group, forming RS-Na+ s.pdf
PDF
Rest are okay but B) I think should be vanderwall.pdf
PDF
pH =4.217 pH = - log(concentration of H+) = -log .pdf
PDF
Liquids may change to a vapor at temperatures bel.pdf
PDF
intra extra equilibrium potential mEqL mEqL 1.pdf
PDF
Which of the following forms of DES is considered the most vulnerabl.pdf
PDF
This is actually pretty simple, so Ill help explain. Take a gi.pdf
PDF
There are many test IPv6 networks deployed across the world. For act.pdf
PDF
The three ways of presenting the changes in the balance of the Compr.pdf
PDF
The RASopathies are a group of genetic syndromes caused by germline .pdf
PDF
ThanksSolutionThanks.pdf
PDF
Step1 In O2 ; we have 2 unpaired electrons which occupy pi 2p Anti.pdf
PDF
Quartzite is sandstone that has been converted to a solid quartz roc.pdf
1. Copper is above silver in the activity series. Thus Cu metal will.pdf
using recursive method .pdf
a. Population - families in the state of Florida b. Variable .pdf
there is no reaction between HNO3 and KCl. S.pdf
The thickness of non-saturated zone and physico-c.pdf
The folding process of proteins is hierarchical, .pdf
Step1 ppt of PbCl2 are soluble in hot water. Ste.pdf
Should take off H from SH group, forming RS-Na+ s.pdf
Rest are okay but B) I think should be vanderwall.pdf
pH =4.217 pH = - log(concentration of H+) = -log .pdf
Liquids may change to a vapor at temperatures bel.pdf
intra extra equilibrium potential mEqL mEqL 1.pdf
Which of the following forms of DES is considered the most vulnerabl.pdf
This is actually pretty simple, so Ill help explain. Take a gi.pdf
There are many test IPv6 networks deployed across the world. For act.pdf
The three ways of presenting the changes in the balance of the Compr.pdf
The RASopathies are a group of genetic syndromes caused by germline .pdf
ThanksSolutionThanks.pdf
Step1 In O2 ; we have 2 unpaired electrons which occupy pi 2p Anti.pdf
Quartzite is sandstone that has been converted to a solid quartz roc.pdf

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Pre independence Education in Inndia.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Types and Its function , kingdom of life
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Classroom Observation Tools for Teachers
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Institutional Correction lecture only . . .
PDF
Insiders guide to clinical Medicine.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Anesthesia in Laparoscopic Surgery in India
PPH.pptx obstetrics and gynecology in nursing
Pre independence Education in Inndia.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Supply Chain Operations Speaking Notes -ICLT Program
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Types and Its function , kingdom of life
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Renaissance Architecture: A Journey from Faith to Humanism
O5-L3 Freight Transport Ops (International) V1.pdf
01-Introduction-to-Information-Management.pdf
Final Presentation General Medicine 03-08-2024.pptx
Computing-Curriculum for Schools in Ghana
VCE English Exam - Section C Student Revision Booklet
Classroom Observation Tools for Teachers
human mycosis Human fungal infections are called human mycosis..pptx
Institutional Correction lecture only . . .
Insiders guide to clinical Medicine.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

Answer main.cpp.pdf

  • 1. Answer ****************************************main.cpp****************************** **************************** #include #include #include #include "Month.h" int main() { //testing the constructors here Month myMonth1; Month myMonth12(12); Month myMonth3("March"); string newMonth = "May"; int newNum = 4; //testing the get and set functions cout << " ---------------------------------------------" << endl; cout << "Testing Constructors, Set() and Get()" << endl; cout << "---------------------------------------------" << endl; cout << "myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl; cout << "myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl; cout << "myMonth1.getMonthName() gives: " << myMonth12.getMonthName() << endl; cout << "myMonth12.getMonthNumber() gives: " << myMonth12.getMonthNumber() << endl; cout << "myMonth3.getMonthName() gives: " << myMonth3.getMonthName() << endl; cout << "myMonth3.getMonthNumber() gives: " << myMonth3.getMonthNumber() << endl; cout << endl << "Setting number to " << newNum << endl; myMonth1.setMonthNumber(newNum); cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl; cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl; cout << endl << "Setting number to 13 (invalid) " << endl; myMonth1.setMonthNumber(13); cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl;
  • 2. cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl; cout << endl << "Setting name to " << newMonth << endl; myMonth1.setMonthName(newMonth); cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl; cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl; cout << endl << "Setting name to XYZ (invalid) "<< endl; myMonth1.setMonthName("XYZ"); cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl; cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl; //testing inputs, outputs, increments and decrements cout << " ---------------------------------------------" << endl; cout << "Testing cin, cout, increments and decrements" << endl; cout << "---------------------------------------------" << endl; cout << "myMonth12 is " << myMonth12<< endl; cout << "myMonth12++ gives "<< myMonth12++ << endl; cout << "But myMonth12 is now " << myMonth12 << endl; cout << "++myMonth12 gives "<< ++myMonth12 << endl; cout << "myMonth12-- gives "<< myMonth12-- << endl; cout << "But myMonth2 is now " << myMonth12 << endl; cout << "--myMonth12 gives "<< --myMonth12 << endl; Month myMonth5; cin >> myMonth5; cout << "myMonth5 is set to "<< myMonth5 << endl; cout << "Press Enter to quit." << endl; cin.ignore(); cin.get(); return 0; } ***********************************************month.h************************ **************************** #ifndef MONTH_H #define MONTH_H #include
  • 3. #include #include #include "MyString.h" class Month { private: MyString monthName; int monthNumber; // monthNumber will accept from 1 to 12 public: Month() { monthName = "January"; monthNumber = 1; } Month(const char *name) { setMonthName(name); } Month(const int num) { setMonthNumber(num); } MyString getMonthName() { return monthName; } int getMonthNumber() const {return monthNumber; } void setMonthName(const string name); void setMonthNumber(const int num); Month operator++(); Month operator++(int); Month operator--(); Month operator--(int); friend ostream &operator<<(ostream &strm, const Month &obj); friend istream &operator >> (istream &strm, Month &monthObj); }; #endif /* end of MONTH_H */ **************************************************month.cpp******************* ****************************** #include #include #include #include "MyString.h" #include "Month.h" void Month::setMonthName(const string name) { if (name == "January" || name == "Jan") setMonthNumber(1); else if (name == "February" || name == "Feb")
  • 4. { setMonthNumber(2); } else if (name == "March" || name == "Mar") { setMonthNumber(3); } else if (name == "April" || name == "Apr") { setMonthNumber(4); } else if (name == "May") { setMonthNumber(5); } else if (name == "June" || name == "Jun") { setMonthNumber(6); } else if (name == "July" || name == "Jul") { setMonthNumber(7); } else if (name == "August" || name == "Aug") { setMonthNumber(8); } else if (name == "September"|| name == "Sept") { setMonthNumber(9); } else if (name == "October" || name == "Oct") { setMonthNumber(10); } else if (name == "November" || name == "Nov")
  • 5. { setMonthNumber(11); } else if (name == "December" || name == "Dec") { setMonthNumber(12); } else { setMonthNumber(1); } } void Month::setMonthNumber(const int num) { if (num < 1 || num > 12) monthNumber = 1; else monthNumber = num; if(monthNumber == 1) monthName = "January"; else if(monthNumber == 2) monthName = "February"; else if(monthNumber == 3) monthName = "March"; else if(monthNumber == 4) monthName = "April"; else if(monthNumber == 5) monthName = "May"; else if(monthNumber == 6) monthName = "June"; else if(monthNumber == 7) monthName = "July"; else if(monthNumber == 8) monthName = "August"; else if(monthNumber == 9) monthName = "September";
  • 6. else if(monthNumber == 10) monthName = "October"; else if(monthNumber == 11) monthName = "November"; else monthName = "December"; } Month Month::operator++() { if (monthNumber == 12) monthNumber = 1; else ++monthNumber; setMonthNumber(monthNumber); return *this; } Month Month::operator++(int) { Month temp(monthNumber); setMonthNumber(++monthNumber); return temp; } Month Month::operator--() { if (monthNumber == 1) monthNumber = 12; else --monthNumber; setMonthNumber(monthNumber); return *this; } Month Month::operator--(int) { Month temp(monthNumber); setMonthNumber(--monthNumber); return temp; } ostream &operator << (ostream &strm, const Month &obj)
  • 7. { return strm << obj.monthName << "(" << obj.monthNumber << ")"; } istream &operator >> (istream &strm, Month &monthObj) { string m_Name; cout << endl << "Please enter the month name: " << endl; strm >> m_Name; monthObj.setMonthName(m_Name); return strm; } *******************************************mystring.h************************** *********** // header file for the MyString class #ifndef MYSTRING_H #define MYSTRING_H #include #include class MyString; // declaration of forward operators. ostream &operator<<(ostream &, const MyString &); istream &operator>>(istream &, MyString &); // MyString is a class. This is an abstract data type for handling strings. class MyString { private: char *str; int len; public: // this is a default constructor MyString() { str = NULL; len = 0; } // this is a copy constructor MyString(MyString &right)
  • 8. { str = new char[right.length() + 1]; strcpy(str, right.getValue()); len = right.length(); } // The following constructor initializes the // MyString object with a C-string MyString(char *sptr) { len = strlen(sptr); str = new char[len + 1]; strcpy(str, sptr); } // this is a destructor ~MyString() { if (len != 0) delete [] str; } // Here is the length function which returns the string length. int length() const { return len; } // The getValue function which returns the string. const char *getValue() const { return str; }; // here are overloaded operators const MyString operator+=(MyString &); const char *operator+=(const char *); const MyString operator=(MyString &); const char *operator=(const char *); int operator==(MyString &); int operator==(const char *);
  • 9. int operator!=(MyString &); int operator!=(const char *); bool operator>(MyString &); bool operator>(const char *); bool operator<(MyString &); bool operator<(const char *); bool operator>=(MyString &); bool operator>=(const char*); bool operator<=(MyString &); bool operator<=(const char *); // Friends functions friend ostream &operator<<(ostream &, const MyString &); friend istream &operator>>(istream &, MyString &); }; #endif /* end of MYSTRING_H */ **************************************************mystring.cpp***************** *********************** // This is an implementation file for the MyString class #include // include this for string library functions #include "MyString.h" const MyString MyString::operator=(MyString &right) { if (len != 0) delete [] str; str = new char[right.length() + 1]; strcpy(str, right.getValue()); len = right.length(); return *this; } const char *MyString::operator=(const char *right) { if (len != 0) delete [] str; len = strlen(right); str = new char[len + 1];
  • 10. strcpy(str, right); return str; } const MyString MyString::operator+=(MyString &right) { char *temp = str; str = new char[strlen(str) + right.length() + 1]; strcpy(str, temp); strcat(str, right.getValue()); if (len != 0) delete [] temp; len = strlen(str); return *this; } const char *MyString::operator+=(const char *right) { char *temp = str; str = new char[strlen(str) + strlen(right) + 1]; strcpy(str, temp); strcat(str, right); if (len != 0) delete [] temp; return str; } int MyString::operator==(MyString &right) { return !strcmp(str, right.getValue()); } int MyString::operator==(const char *right) { return !strcmp(str, right); } int MyString::operator!=(MyString &right) {
  • 11. return strcmp(str, right.getValue()); } int MyString::operator!=(const char *right) { return strcmp(str, right); } bool MyString::operator>(MyString &right) { bool status; if (strcmp(str, right.getValue()) > 0) status = true; else status = false; return status; } bool MyString::operator>(const char *right) { bool status; if (strcmp(str, right) > 0) status = true; else status = false; return status; } bool MyString::operator<(MyString &right) { bool status; if (strcmp(str, right.getValue()) < 0) status = true; else status = false; return status; } bool MyString::operator<(const char *right) { bool status;
  • 12. if (strcmp(str, right) < 0) status = true; else status = false; return status; } bool MyString::operator>=(MyString &right) { bool status; if (strcmp(str, right.getValue()) >= 0) status = true; else status = false; return status; } bool MyString::operator>=(const char *right) { bool status; if (strcmp(str, right) >= 0) status = true; else status = false; return status; } bool MyString::operator<=(MyString &right) { bool status; if (strcmp(str, right.getValue()) <= 0) status = true; else status = false; return status; } bool MyString::operator<=(const char *right) { bool status;
  • 13. if (strcmp(str, right) <= 0) status = true; else status = false; return status; } ostream &operator<<(ostream &strm, const MyString &obj) { strm << obj.str; return strm; } istream &operator>>(istream &strm, MyString &obj) { strm.getline(obj.str, obj.len); strm.ignore(); return strm; } Solution Answer ****************************************main.cpp****************************** **************************** #include #include #include #include "Month.h" int main() { //testing the constructors here Month myMonth1; Month myMonth12(12); Month myMonth3("March"); string newMonth = "May"; int newNum = 4;
  • 14. //testing the get and set functions cout << " ---------------------------------------------" << endl; cout << "Testing Constructors, Set() and Get()" << endl; cout << "---------------------------------------------" << endl; cout << "myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl; cout << "myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl; cout << "myMonth1.getMonthName() gives: " << myMonth12.getMonthName() << endl; cout << "myMonth12.getMonthNumber() gives: " << myMonth12.getMonthNumber() << endl; cout << "myMonth3.getMonthName() gives: " << myMonth3.getMonthName() << endl; cout << "myMonth3.getMonthNumber() gives: " << myMonth3.getMonthNumber() << endl; cout << endl << "Setting number to " << newNum << endl; myMonth1.setMonthNumber(newNum); cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl; cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl; cout << endl << "Setting number to 13 (invalid) " << endl; myMonth1.setMonthNumber(13); cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl; cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl; cout << endl << "Setting name to " << newMonth << endl; myMonth1.setMonthName(newMonth); cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl; cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl; cout << endl << "Setting name to XYZ (invalid) "<< endl; myMonth1.setMonthName("XYZ"); cout << "Now myMonth1.getMonthName() gives: " << myMonth1.getMonthName() << endl; cout << "And myMonth1.getMonthNumber() gives: " << myMonth1.getMonthNumber() << endl; //testing inputs, outputs, increments and decrements cout << " ---------------------------------------------" << endl; cout << "Testing cin, cout, increments and decrements" << endl; cout << "---------------------------------------------" << endl; cout << "myMonth12 is " << myMonth12<< endl;
  • 15. cout << "myMonth12++ gives "<< myMonth12++ << endl; cout << "But myMonth12 is now " << myMonth12 << endl; cout << "++myMonth12 gives "<< ++myMonth12 << endl; cout << "myMonth12-- gives "<< myMonth12-- << endl; cout << "But myMonth2 is now " << myMonth12 << endl; cout << "--myMonth12 gives "<< --myMonth12 << endl; Month myMonth5; cin >> myMonth5; cout << "myMonth5 is set to "<< myMonth5 << endl; cout << "Press Enter to quit." << endl; cin.ignore(); cin.get(); return 0; } ***********************************************month.h************************ **************************** #ifndef MONTH_H #define MONTH_H #include #include #include #include "MyString.h" class Month { private: MyString monthName; int monthNumber; // monthNumber will accept from 1 to 12 public: Month() { monthName = "January"; monthNumber = 1; } Month(const char *name) { setMonthName(name); } Month(const int num) { setMonthNumber(num); } MyString getMonthName() { return monthName; } int getMonthNumber() const {return monthNumber; } void setMonthName(const string name); void setMonthNumber(const int num);
  • 16. Month operator++(); Month operator++(int); Month operator--(); Month operator--(int); friend ostream &operator<<(ostream &strm, const Month &obj); friend istream &operator >> (istream &strm, Month &monthObj); }; #endif /* end of MONTH_H */ **************************************************month.cpp******************* ****************************** #include #include #include #include "MyString.h" #include "Month.h" void Month::setMonthName(const string name) { if (name == "January" || name == "Jan") setMonthNumber(1); else if (name == "February" || name == "Feb") { setMonthNumber(2); } else if (name == "March" || name == "Mar") { setMonthNumber(3); } else if (name == "April" || name == "Apr") { setMonthNumber(4); } else if (name == "May") { setMonthNumber(5); } else if (name == "June" || name == "Jun") {
  • 17. setMonthNumber(6); } else if (name == "July" || name == "Jul") { setMonthNumber(7); } else if (name == "August" || name == "Aug") { setMonthNumber(8); } else if (name == "September"|| name == "Sept") { setMonthNumber(9); } else if (name == "October" || name == "Oct") { setMonthNumber(10); } else if (name == "November" || name == "Nov") { setMonthNumber(11); } else if (name == "December" || name == "Dec") { setMonthNumber(12); } else { setMonthNumber(1); } } void Month::setMonthNumber(const int num) { if (num < 1 || num > 12) monthNumber = 1; else
  • 18. monthNumber = num; if(monthNumber == 1) monthName = "January"; else if(monthNumber == 2) monthName = "February"; else if(monthNumber == 3) monthName = "March"; else if(monthNumber == 4) monthName = "April"; else if(monthNumber == 5) monthName = "May"; else if(monthNumber == 6) monthName = "June"; else if(monthNumber == 7) monthName = "July"; else if(monthNumber == 8) monthName = "August"; else if(monthNumber == 9) monthName = "September"; else if(monthNumber == 10) monthName = "October"; else if(monthNumber == 11) monthName = "November"; else monthName = "December"; } Month Month::operator++() { if (monthNumber == 12) monthNumber = 1; else ++monthNumber; setMonthNumber(monthNumber); return *this; } Month Month::operator++(int)
  • 19. { Month temp(monthNumber); setMonthNumber(++monthNumber); return temp; } Month Month::operator--() { if (monthNumber == 1) monthNumber = 12; else --monthNumber; setMonthNumber(monthNumber); return *this; } Month Month::operator--(int) { Month temp(monthNumber); setMonthNumber(--monthNumber); return temp; } ostream &operator << (ostream &strm, const Month &obj) { return strm << obj.monthName << "(" << obj.monthNumber << ")"; } istream &operator >> (istream &strm, Month &monthObj) { string m_Name; cout << endl << "Please enter the month name: " << endl; strm >> m_Name; monthObj.setMonthName(m_Name); return strm; } *******************************************mystring.h************************** *********** // header file for the MyString class #ifndef MYSTRING_H #define MYSTRING_H #include
  • 20. #include class MyString; // declaration of forward operators. ostream &operator<<(ostream &, const MyString &); istream &operator>>(istream &, MyString &); // MyString is a class. This is an abstract data type for handling strings. class MyString { private: char *str; int len; public: // this is a default constructor MyString() { str = NULL; len = 0; } // this is a copy constructor MyString(MyString &right) { str = new char[right.length() + 1]; strcpy(str, right.getValue()); len = right.length(); } // The following constructor initializes the // MyString object with a C-string MyString(char *sptr) { len = strlen(sptr); str = new char[len + 1]; strcpy(str, sptr); } // this is a destructor ~MyString() { if (len != 0)
  • 21. delete [] str; } // Here is the length function which returns the string length. int length() const { return len; } // The getValue function which returns the string. const char *getValue() const { return str; }; // here are overloaded operators const MyString operator+=(MyString &); const char *operator+=(const char *); const MyString operator=(MyString &); const char *operator=(const char *); int operator==(MyString &); int operator==(const char *); int operator!=(MyString &); int operator!=(const char *); bool operator>(MyString &); bool operator>(const char *); bool operator<(MyString &); bool operator<(const char *); bool operator>=(MyString &); bool operator>=(const char*); bool operator<=(MyString &); bool operator<=(const char *); // Friends functions friend ostream &operator<<(ostream &, const MyString &); friend istream &operator>>(istream &, MyString &); }; #endif /* end of MYSTRING_H */ **************************************************mystring.cpp***************** ***********************
  • 22. // This is an implementation file for the MyString class #include // include this for string library functions #include "MyString.h" const MyString MyString::operator=(MyString &right) { if (len != 0) delete [] str; str = new char[right.length() + 1]; strcpy(str, right.getValue()); len = right.length(); return *this; } const char *MyString::operator=(const char *right) { if (len != 0) delete [] str; len = strlen(right); str = new char[len + 1]; strcpy(str, right); return str; } const MyString MyString::operator+=(MyString &right) { char *temp = str; str = new char[strlen(str) + right.length() + 1]; strcpy(str, temp); strcat(str, right.getValue()); if (len != 0) delete [] temp; len = strlen(str); return *this; } const char *MyString::operator+=(const char *right) {
  • 23. char *temp = str; str = new char[strlen(str) + strlen(right) + 1]; strcpy(str, temp); strcat(str, right); if (len != 0) delete [] temp; return str; } int MyString::operator==(MyString &right) { return !strcmp(str, right.getValue()); } int MyString::operator==(const char *right) { return !strcmp(str, right); } int MyString::operator!=(MyString &right) { return strcmp(str, right.getValue()); } int MyString::operator!=(const char *right) { return strcmp(str, right); } bool MyString::operator>(MyString &right) { bool status; if (strcmp(str, right.getValue()) > 0) status = true; else status = false; return status; } bool MyString::operator>(const char *right) {
  • 24. bool status; if (strcmp(str, right) > 0) status = true; else status = false; return status; } bool MyString::operator<(MyString &right) { bool status; if (strcmp(str, right.getValue()) < 0) status = true; else status = false; return status; } bool MyString::operator<(const char *right) { bool status; if (strcmp(str, right) < 0) status = true; else status = false; return status; } bool MyString::operator>=(MyString &right) { bool status; if (strcmp(str, right.getValue()) >= 0) status = true; else status = false; return status; } bool MyString::operator>=(const char *right) {
  • 25. bool status; if (strcmp(str, right) >= 0) status = true; else status = false; return status; } bool MyString::operator<=(MyString &right) { bool status; if (strcmp(str, right.getValue()) <= 0) status = true; else status = false; return status; } bool MyString::operator<=(const char *right) { bool status; if (strcmp(str, right) <= 0) status = true; else status = false; return status; } ostream &operator<<(ostream &strm, const MyString &obj) { strm << obj.str; return strm; } istream &operator>>(istream &strm, MyString &obj) { strm.getline(obj.str, obj.len); strm.ignore(); return strm; }