x.Hmhe errors shown once you scroll down. Also I am not sure if I am using the r
ID: 3618325 • Letter: X
Question
x.Hmhe errors shown once you scroll down. Also I am not sure if I am using the right headers.Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:userslexdocumentsisual studio 2008projectscoplexch14_08.cpp 76
Error 2 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:userslexdocumentsisual studio 2008projectscoplexch14_08.cpp 81
#include <iostream>
#include <string.h>
using namespace std;
class Date
{
private: int month,day,year;
int days[12];
public:
Date(int m, int d, int y)
{
month=m;
day=d;
year=y;
setdaysinmonth();
}
int Date::todoy()
{int dayss=0,i;
for (i=0;i<month-1;i++)
dayss+=days[i];
dayss+=day;
if(dayss>59) //feb 28 is day 59
dayss+=leap();
return dayss;
}
int Date::leap(int year)
{int leapcode=0;
if(year%4==0)
{if(year%100!=0)
leapcode=1;
else
if(year%400==0)
leapcode=1;
}
return leapcode;
}
int Date::leap()
{int leapcode=0;
if(year%4==0)
{if(year%100!=0)
leapcode=1;
else
if(year%400==0)
leapcode=1;
}
return leapcode;
}
void Date::setdaysinmonth()
{
days[0] = 31;
days[1] = 28;
days[2] = 31;
days[3] = 30;
days[4] = 31;
days[5] = 30;
days[6] = 31;
days[7] = 31;
days[8] = 30;
days[9] = 31;
days[10] = 30;
days[11] = 31;
}
void Date::printslash()
{int yearminus2000;
yearminus2000=year%100;
cout<<month<<"/"<<day<<"/";
if(yearminus2000<10)
cout<<"0"<<yearminus2000<<endl;
else
cout<<yearminus2000<<endl;
}
void Date::printday()
{string mth[]={"January","February","March","April","May","June","July","August",
"September","October","November","December"};
cout<<day<<" "<<mth[month-1]<<" "<<year<<endl; //ERROR
}
void Date::printmonth()
{string mth[]={"January","February","March","April","May","June","July","August",
"September","October","November","December"};
cout<<mth[month-1]<<" "<<day<<","<<year<<endl; //ERROR
}
Date Date::operator ++() // Prefix ++
{int tempday=0;
if(month==2)
tempday=leap(year);
if(day==days[month-1]+tempday)
{day=1;
month++;
month%=12;
if(month==1)
year++;
}
else
day++;
}
Date operator ++(int) // Postfix ++
{int tempday=0;
if(month==2)
tempday=leap();
if(day==days[month-1]+tempday)
{day=1;
month++;
month%=12;
if(month==1)
year++;
}
else
day++;
}
Date Date::operator --() // Prefix --
{day--;
if(day==0)
{month--;
if(month==0)
{month=12;
year--;
}
day=days[month-1];
if(month==2)
day+=leap();
}
}
Date Date::operator --(int) // Postfix --
{ day--;
if(day==0)
{month--;
if(month==0)
{month=12;
year--;
}
day=days[month-1];
if(month==2)
day+=leap();
}
}
friend ostream &operator <<(ostream &,Date &val) // <<
{val.printslash();
}
friend i
Explanation / Answer
please rate - thanks try changing #include to #include I'm not familiar with Visual C++ but you may also need #include "stdafx.h but I don't think soRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.