// fig8_6.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include "date1.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Date d1, d2(12, 27, 1992), d3(0, 99, 8045);
cout << " d1 is " << d1 << endl
<< " d2 is " << d2 << endl
<< " d3 is " << d3 << endl << endl;
cout << " d2 += 7 is " << (d2 += 7) << endl << endl;
d3.setDate(2, 28, 1992);
cout << " d3 is " << d3 << endl;
cout << " ++d3 is " << ++d3 << endl << endl;
Date d4(3, 18, 1969);
cout << " Check to operations prefix increment: " << endl
<< " d4 is " << d4 << endl;
cout << " ++d4 is " << ++d4 << endl;
cout << " d4 is " << d4 << endl << endl;
cout << "Check to operations postfix inrement: " << endl
<< " d4 is " << d4 << endl;
cout << " d4++ is " << d4++ << endl;
cout << " d4 is " << d4 << endl << endl;
_getch();
return 0;
}
Помогите с ошибкой
Видает ошибки:
date1.h(5) : error C2143: syntax error : missing ';' before '&'
date1.h(5) : error C2433: 'ostream' : 'friend' not permitted on data declarations
date1.h(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
date1.h(5) : error C2061: syntax error : identifier 'ostream'
date1.h(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
date1.h(5) : error C2805: binary 'operator <<' has too few parameters
date1.cpp(62) : error C2143: syntax error : missing ';' before '&'
date1.cpp(62) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
date1.cpp(62) : error C2086: 'int ostream' : redefinition
date1.h(5) : see declaration of 'ostream'
date1.cpp(62) : error C2065: 'output' : undeclared identifier
date1.cpp(62) : error C2059: syntax error : 'const'
date1.cpp(63) : error C2143: syntax error : missing ';' before '{'
date1.cpp(63) : error C2447: '{' : missing function header (old-style formal list?)
Есть три файла:
Код:
Код:
//--------date1.cpp-------------//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include "date1.h"
int Date::days[] = {0,31,28,31,30,31,30,31,31,30,
31,30,31};
Date::Date(int m, int d, int y) { setDate(m, d, y); }
void Date::setDate(int mm, int dd, int yy)
{
month = (mm >= 1 && mm <= 12) ? mm : 1;
year = (yy >= 1900 && yy <= 2100) ? yy : 1900;
if(month == 2 && leapYear(year))
day = (dd >= 1 && dd <= 29) ? dd : 1;
else
day = (dd >= 1 && dd <= days[month]) ? dd : 1;
}
Date Date::operator ++()
{
helpIncrement();
return *this;
}
Date Date::operator ++(int)
{
Date temp = *this;
helpIncrement();
return temp;
}
const Date &Date::operator +=(int additionalDays)
{
for(int i = 1; i <= additionalDays; i++)
helpIncrement();
return *this;
}
int Date::leapYear(int y)
{
if(y % 400 == 0 || (y % 100 != 0 && y % 4 == 0))
return 1;
else
return 0;
}
int Date::endOfMonth(int d)
{
if(month == 2 && leapYear(year))
return d == 29;
else
return d == days[month];
}
void Date::helpIncrement()
{
if(endOfMonth(day) && month == 12) {
day = 1;
month = 1;
++year;
}
else if(endOfMonth(day)) {
day = 1;
++month;
}
else
++day;
}
ostream &operator << (ostream &output, const Date &d)
{
static char *monthName[13] = {"", "January",
"February", "March", "April", "May", "June",
"July", "August", "September", "October",
"November", "December"};
output << monthName[d.month] << ' '
<< d.day << ", " << d.year;
return output;
}
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include "date1.h"
int Date::days[] = {0,31,28,31,30,31,30,31,31,30,
31,30,31};
Date::Date(int m, int d, int y) { setDate(m, d, y); }
void Date::setDate(int mm, int dd, int yy)
{
month = (mm >= 1 && mm <= 12) ? mm : 1;
year = (yy >= 1900 && yy <= 2100) ? yy : 1900;
if(month == 2 && leapYear(year))
day = (dd >= 1 && dd <= 29) ? dd : 1;
else
day = (dd >= 1 && dd <= days[month]) ? dd : 1;
}
Date Date::operator ++()
{
helpIncrement();
return *this;
}
Date Date::operator ++(int)
{
Date temp = *this;
helpIncrement();
return temp;
}
const Date &Date::operator +=(int additionalDays)
{
for(int i = 1; i <= additionalDays; i++)
helpIncrement();
return *this;
}
int Date::leapYear(int y)
{
if(y % 400 == 0 || (y % 100 != 0 && y % 4 == 0))
return 1;
else
return 0;
}
int Date::endOfMonth(int d)
{
if(month == 2 && leapYear(year))
return d == 29;
else
return d == days[month];
}
void Date::helpIncrement()
{
if(endOfMonth(day) && month == 12) {
day = 1;
month = 1;
++year;
}
else if(endOfMonth(day)) {
day = 1;
++month;
}
else
++day;
}
ostream &operator << (ostream &output, const Date &d)
{
static char *monthName[13] = {"", "January",
"February", "March", "April", "May", "June",
"July", "August", "September", "October",
"November", "December"};
output << monthName[d.month] << ' '
<< d.day << ", " << d.year;
return output;
}
Код:
//------date1.h------------//
#ifndef DATE1_H
#define DATE1_H
#include <iostream>
class Date {
friend ostream &operator << (ostream &, const Date &);
public:
Date(int m = 1, int d = 1, int y = 1900);
void setDate(int, int, int);
Date operator++();
Date operator++(int);
const Date &operator+=(int);
int leapYear(int);
int endOfMonth(int);
private:
int month;
int day;
int year;
static int days[];
void helpIncrement();
};
#endif
#ifndef DATE1_H
#define DATE1_H
#include <iostream>
class Date {
friend ostream &operator << (ostream &, const Date &);
public:
Date(int m = 1, int d = 1, int y = 1900);
void setDate(int, int, int);
Date operator++();
Date operator++(int);
const Date &operator+=(int);
int leapYear(int);
int endOfMonth(int);
private:
int month;
int day;
int year;
static int days[];
void helpIncrement();
};
#endif
Код:
//------date1.h------------//
#ifndef DATE1_H
#define DATE1_H
#include <iostream>
using std::ostream;
class Date {
friend ostream &operator << (ostream &, const Date &);
public:
Date(int m = 1, int d = 1, int y = 1900);
void setDate(int, int, int);
Date operator++();
Date operator++(int);
const Date &operator+=(int);
int leapYear(int);
int endOfMonth(int);
private:
int month;
int day;
int year;
static int days[];
void helpIncrement();
};
#endif
#ifndef DATE1_H
#define DATE1_H
#include <iostream>
using std::ostream;
class Date {
friend ostream &operator << (ostream &, const Date &);
public:
Date(int m = 1, int d = 1, int y = 1900);
void setDate(int, int, int);
Date operator++();
Date operator++(int);
const Date &operator+=(int);
int leapYear(int);
int endOfMonth(int);
private:
int month;
int day;
int year;
static int days[];
void helpIncrement();
};
#endif
Цитата: Artem_3A
Код:
//------date1.h------------//
#ifndef DATE1_H
#define DATE1_H
#include <iostream>
using std::ostream;
class Date {
friend ostream &operator << (ostream &, const Date &);
public:
Date(int m = 1, int d = 1, int y = 1900);
void setDate(int, int, int);
Date operator++();
Date operator++(int);
const Date &operator+=(int);
int leapYear(int);
int endOfMonth(int);
private:
int month;
int day;
int year;
static int days[];
void helpIncrement();
};
#endif
#ifndef DATE1_H
#define DATE1_H
#include <iostream>
using std::ostream;
class Date {
friend ostream &operator << (ostream &, const Date &);
public:
Date(int m = 1, int d = 1, int y = 1900);
void setDate(int, int, int);
Date operator++();
Date operator++(int);
const Date &operator+=(int);
int leapYear(int);
int endOfMonth(int);
private:
int month;
int day;
int year;
static int days[];
void helpIncrement();
};
#endif
Большое спасибо!!!!!!!!
Главная ошибка в етом что я забил прописать обявление для
using std::ostream;
просто только надавно начал изучать С++ и всех ево хитростей пока не знаю