first time learning c++. Making a date class were we use integers to represent month, day, and year. We need to have a member function to increment the date to the next day, and free functions to display the date in number and word format. My header file compiles but when I compiled my Date.cpp file in emacs I got these errors:
Date.cpp: In member function âDate Date::operator++()â:
Date.cpp:38: warning: suggest parentheses around â&&â within â||â
Date.cpp:46: error: â(((Date*)this)->Date::yyear ++)â cannot be used as a function
Date.cpp:50: error: conversion from âintâ to non-scalar type âDateâ requested
Date.cpp:51: error: conversion from âintâ to non-scalar type âDateâ requested
Date.cpp:52: error: conversion from âintâ to non-scalar type âDateâ requested
Date.cpp: At global scope:
Date.cpp:58: error: ISO C++ forbids declaration of âdisplay1â with no type
Date.cpp:58: error: no âint Date::display1()â member function declared in class âDateâ
Date.cpp:65: error: ISO C++ forbids declaration of âdisplay2â with no type
Date.cpp:65: error: no âint Date::display2()â member function declared in class âDateâ
The code for my Date.cpp is shown here:
#include "Date.h"
#include <iostream>
#include <cassert>
Date::Date(int month, int day, int year)
{
mmonth = month;
dday = day;
yyear = year;
}
int Date::get_mmonth()const
{
return mmonth;
}
//postcondition: month has been returned
int Date::get_dday()const
{
return dday;
}
//postcondition: day has been returned
int Date::get_yyear()const
{
return yyear;
}
//year has been returned
//precondition: day will be incremented
Date operator ++()
{
dday++;
assert(dday >= 1 && dday <= 31);
mmonth++;
assert(mmonth >= 1 && mmonth <= 12);
yyear++;
if(mmonth == 2 && dday == 28 || dday == 29)
{
if(yyear % 4 || yyear % 400)
{
std::cout<<"Thats a Leap Year"<<std::endl;
mmonth++;
dday++;
yyear++
assert(dday >= 1 && dday <= 31);
assert(mmonth >= 1 && mmonth <= 12);
}
}
return mmonth;
return dday;
return yyear;
}
//post condition: date has been incremented
//precondition: Date will be displayed in number format
Date::display1()
{
std::cout<<mmonth<<'/'<<dday<<'/'<<yyear<<std::endl;
}
//postcondition: Date is displayed in number format
//precondition: Date will be displayed in word format
Date::display2()
{
switch(mmonth)
{
case 1:
std::cout<<"Januar"<<std::endl;
break;
case 2:
std::cout<<"February"std::endl;
break;
case 3:
std::cout<<"March"<<std::endl;
break;
case 4:
std::cout<<"April"<<std::endl;
break;
case 5:
std::cout<<"May"<<std::endl;
break;
case 6:
std::cout<<"June"<<std::endl;
break;
case 7:
std::cout<<"July"<<std::endl;
break;
case 8:
std::cout<<"August"<<std::endl;
break;
case 9:
std::cout<<"September"<<std::endl;
break;
case 10:
std::cout<<"October"<<std::endl;
break;
case 11:
std::cout<<"November"<<std::endl;
break;
case 12:
std::cout<<"December"<<std::endl;
break;
default;
}
std::cout<<mmonth<<'/'<<dday<<'/'<<yyear<<std::endl;
//post condition: Date will be displayed in word format
}
Why am I getting these errors??