Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>;
- using namespace std;
- class Date {
- private:
- public:
- int day;
- int month;
- int year;
- Date();
- Date(int day, int month, int year);
- void Print(Date date);
- Date operator=(const string str);
- };
- this is the class cpp file:
- #include "Date.h"
- Date::Date() {};
- Date::Date(int day, int month, int year) :
- day(day),month(month), year(year){};
- void Date::Print(Date date) {
- cout << date.day << "/" << date.month << "/" << date.year;
- }
- Date Date::operator=(string str) {
- Date date;
- date.day = 0; date.month = 0; date.year = 0;
- int i = 0;
- while(str[i] != '/'){
- date.day = (10 * date.day) + (int)str[i++]- 48;
- }
- i++;
- while(str[i] != '/'){
- date.month = (10 * date.month) + (int)str[i++]- 48;
- }
- i++;
- while(i < str.size()){
- date.year = (10 * date.year) + (int)str[i]- 48;
- i++;
- }
- cout << date.day << '/' << date.month << '/' << date.year<< endl;
- return date;
- }
- #include <iostream>
- #include "Date.h"
- using namespace std;
- int main() {
- Date d,d2(15,7,18);
- string str = "15/7/18";
- d = str;
- cout << d.day<< endl;
- d.Print(d);
- return 0;
- }
Add Comment
Please, Sign In to add comment