0

hey guys/gals im havin a problem in my test.cpp file in line 65 where i have cout << date.print();

the compiler says:
test.cpp: In member function âvoid Test::print() constâ:
test.cpp:67: error: no match for âoperator<<â in âstd::cout << ((const Test*)this)->Test::date.Date::print()â

where am i making a mistake because i have <iostream> and using namespace std; where i need it? any suggestions?

Attachments
//class member functions
#include "date.h"

Date::Date()//default constructor
{
	month = 1;
	day = 1;
	year = 2010;
};

void Date::setDate()
{
	cout << "What date was this test performed(mm/dd/yyyy): ";
	cin >> setw(2) >> month;
	cin.ignore(1);
	cin >> setw(2) >> day;
	cin.ignore(1);
	cin >> setw(4) >> year;
	
	month = checkMonth(month);
	day = checkDay(day);
	year = checkYear(year);
}

int Date::checkMonth(int testMonth)
{
	if(testMonth < 0 || testMonth > 12)
	{
		cout << "Invalaid month(" << testMonth << ") set to 1.\n";
		return 1;
	}else
		return testMonth;
}

int Date::checkDay(int testDay)
{
	int daysPerMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

	if(testDay > 0 && testDay <= daysPerMonth[month])
	{
		return testDay;
	}else if(month == 2 && testDay == 29 && (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)))
	{
		return testDay;
	}else
	{
		cout << "Invalid day(" << testDay << ") set to 1.\n";
		return 1;
	}
}

int Date::checkYear(int testYear)
{
	if(testYear > 2010 || testYear < 1990)
	{
		cout << "Invalid year (" << testYear << ") set to 2010.\n";
		return 2010;
	}else
		return testYear;
}

void Date::print()const
{
	cout << month << '/' << day << '/' << year;
}
//header file
#ifndef DATE_H
#define DATE_H

#include <iostream>
#include <iomanip>
using namespace std;

class Date
{
public:
	Date();
	void setDate();
	void print()const;//int checkDate(Date &); //int = 1, int = 1, int = 1900);
private:
	int month;
	int day;
	int year;
	int checkMonth(int);
	int checkDay(int);
	int checkYear(int);
};

#endif
//main
#include "test.h"
#include "date.h"

int main()
{
	/*Date d1;
	d1.setDate();
	d1.print();*/

	Test t1;
	t1.print();

	return 0;
}
//header file
//header file
#ifndef TEST_H
#define TEST_H

#include "date.h"
#include <iostream>
#include <iomanip>
using namespace std;

class Test
{
public:
	Test();
	void setTester();
	void setPosResponse();
	void setNegResponse();
	void setIndResponse();
	void getTestInfo();
	int getTester()const;
	int getPosResponse()const;
	int getNegResponse()const;
	int getIndResponse()const;
	void print()const;	
private:
	Date date;//the data the test was executed
	int posResponse;//Number of positive responses logged 
	int negResponse;//Number of negative responses logged
	int indResponse;//Number of indeterminate responses logged
	int tester;//person who gathered the information
};

#endif
//class member functions
#include "test.h"

Test::Test()
{
	posResponse = negResponse = indResponse = 0;
}

void Test::setTester()
{
	date.setDate();
	cout << "Who performed the test?";
	cin >> tester;
}

void Test::setPosResponse()
{
	cout << "How many positive responses were logged?";
	cin >> posResponse;
}

void Test::setNegResponse()
{
	cout << "How many negative responses were logged?";
	cin >> negResponse;
}

void Test::setIndResponse()
{
	cout << "How many indifferent responses were logged?";
	cin >> indResponse;
}

void Test::getTestInfo()
{
	setTester();
	setPosResponse();
	setNegResponse();
	setIndResponse();
}

int Test::getTester()const
{
	return tester;
}

int Test::getPosResponse()const
{
	return posResponse;
}

int Test::getNegResponse()const
{
	return negResponse;
}

int Test::getIndResponse()const
{
	return indResponse;
}

void Test::print()const
{
	cout << "Date" << setw(15) << "Tester" << setw(15) << "Data" << setw(15) << "pos" << setw(15) << "neg" << setw(15) << "ind";
	cout << date.print();
	cout << setw(15) << getTester();
	cout << setw(15) << "Data here";
	cout << setw(15) << getPosResponse();
	cout << setw(15) << getNegResponse();
	cout << setw(15) << getIndResponse();
}
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by corby
0

In order to print something using a cout statement your function must return something (a string, int, double, etc). Your print() method is void. Just call your print method on its own without sending it into cout.

Edited by jonsca: n/a

0

In order to print something using a cout statement your function must return something (a string, int, double, etc). Your print() method is void. Just call your print method on its own without sending it into cout.

ok thx

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.