Implement in C++ language. Run it and show the screenshot. Write comments to understand the functionality. Also, make the program simple.
Create a class representing anything you like.
· Separate the header and implementation files.
· Include a few member variables, including at least one composite type (such as std::string or std::vector)
· Create a default constructo
· Create a constructor that requires only one paramete
· Use member initialization lists for both constructors
· Overload the + operator for your class
· Overload the
operator for your class as a non-member function and make the function a friend within your class.
· Create a method for your class that is const qualified.
Create main.cpp to demonstrate use of your class.
· Create an instance of your class using the default constructor. Add a comment to the statement that says "Calling the default constructor".
· Create three more instances of your class using functional form, assignment initialization, and uniform initialization.
· Use the overloaded + operator to add two instances of your class together.
· Use the overloaded
operator to print an instance of your class to the console
· Note: Just make a one simple class separate the header file and test your class in the main. Follow the above requirement .
· a) create one class that has member data vecto
int> v, and member data int sizeOfVector,
· b) Create a default constructor and Use member initialization lists
· c) Create a constructor that requires only one parameter(int size) and Use member initialization lists
· d) write a method that use overloaded + operator to add two instances of your class together.
Like: obj1 values of vector [0] = 12
obj2 values of vector [0] = obj1 value + obj2 value
Sample:
Date Date::operator+(const Date &otherDate) {
Date sumDate { this->m_year + otherDate.m_year,
(*this).m_month + otherDate.m_month,
this->m_day + otherDate.m_day };
eturn sumDate;
}
· e) write a method that print vector value. for obj1
· f) write a method that Use the overloaded
operator to print an instance of your class to the console.
for obj2
sample:
Date d1(1,3,5);
Date d2(3, 4, 5);
Date d5= d1+d2;
std::cout
d5
std::endl;
operato
(std::cout, d5);
· friend std::ostream& operato
(std::ostream&, const Date& d);
· std::ostream& operato
(std::ostream& os, const Date& d) {
os
d.m_year
"/"
d.m_month
"/"
d.m_day;
eturn os;
}
· g) Create a method for your class that is const qualified.
· like:
· int Date::getMonth() const {
eturn m_month;
}