Good Afternoon,

I need help on this assignment from school, I'm getting this error C2660: 'clockType::setTime' : function does not take 4 arguments. I need to make the class functional by the client program testClockClass.cpp. Below are the code that I have so far:

testClockClass.ccp

#include <iostream>
#include "extClockType.h"

using namespace std;

int main()
{
	extClockType time1(5,10,34,CST);
	extClockType time2;  

	cout<<"Time 1: ";
	time1.printTime();
	cout<<endl;

	time2.setTime(12,45,59,PST);

	cout<<"Time 2: ";
	time2.printTime();
	cout<<endl;

	time2.incrementSeconds();

	cout<<"After incrementing time2 by one second, Time 2: ";
	time2.printTime();
	cout<<endl;


	return 0;
}//end main

extClockTypeImp.cpp
#include <iostream>
#include <string>
#include "extClockType.h"

using namespace std;

//Write the implementation of setTime, printTime and constructors
//for extClockType class here

void extClockType::setTimeZone(int TimeZone)
{
	if (region<= 12 && region >= -12)
		region = TimeZone;
	else
		region = 0;
}

void extClockType::getTimeZone(int& TimeZone)
{
	TimeZone = region;

}

void extClockType::printTime() const
{
	clockType::printTime();
	cout << " timezone is: ";
	if (region >= 0)
		cout << "GMT+" << region;
	else
		cout << "GMT" << region;
}

extClockType::extClockType(int hours, int minutes, int seconds, int TimeZone): clockType(hours, minutes, seconds)
{
	if (region <= 12 && region >= -12)
		region = TimeZone;
	else

		region = 0;
}

extClockType::extClockType()
{
	region = 0;
}


extClockType.h
#ifndef H_ExtClockType
#define H_ExtClockType

#include "clockType.h"

enum zoneType{EST, CST, MST, PST, EDT, CDT, MDT, PDT};

class extClockType: public clockType
{

//define the class members here
public:
	void getTimeZone(int& TimeZone);
	void setTimeZone(int TimeZone);
	void printTime() const;
	extClockType();
	extClockType(int hours, int minutes, int seconds, int TimeZone);

private:
	int region;

};

#endif

clockTypeImp.cpp
#include <iostream>
#include "clockType.h"

using namespace std;

void clockType::setTime(int hours, int minutes, int seconds)
{
	if(0 <= hours && hours < 24)
		hr = hours;
	else 
		hr = 0;

	if(0 <= minutes && minutes < 60)
		min = minutes;
	else 
		min = 0;

	if(0 <= seconds && seconds < 60)
		sec = seconds;
	else 
		sec = 0;
}

void clockType::getTime(int& hours, int& minutes, int& seconds)
{
	hours = hr;
	minutes = min;
	seconds = sec;
}

void clockType::printTime() const
{
 	if(hr < 10)
	   cout<<"0";
	cout<<hr<<":";

	if(min < 10)
	   cout<<"0";
	cout<<min<<":";

	if(sec < 10)
	   cout<<"0";
	cout<<sec;
}

void clockType::incrementHours()
{
	hr++;
	if(hr > 23)
 	  hr = 0;
}

void clockType::incrementMinutes()
{
	min++;
	if(min > 59)
	{
	   min = 0;
	   incrementHours(); //increment hours
	}
}

void clockType::incrementSeconds()
{
    sec++;
	if(sec > 59)
	{
	   sec = 0;
	   incrementMinutes(); //increment minutes
	}
}

bool clockType::equalTime(const clockType& otherClock) const
{
   return(hr == otherClock.hr 
 	    && min == otherClock.min 
          && sec == otherClock.sec);
}

clockType::clockType(int hours, int minutes, int seconds)
{
	setTime(hours, minutes, seconds);
}

clockType::clockType()  //default constructor
{
	setTime(0, 0, 0);
}

clockType.h
#ifndef H_clock
#define H_Clock

class clockType
{
public:
    void setTime(int hours, int minutes, int seconds);
		//Function to set the time
		//The time is set according to the parameters
		//Postcondition: hr = hours; min = minutes; sec = seconds
 		//  The function checks whether the values of hours, minutes, 
 		//  and seconds are valid. If a value is invalid, the default 
 		//  value 0 is assigned.

    void getTime(int& hours, int& minutes, int& seconds);
		//Function to return the time
		//Postcondition: hours = hr; minutes = min;
		//	           seconds = sec

    void printTime() const;
		//Function to print the time
 		//Postconditions: Time is printed in the form hh:mm:ss

    void incrementSeconds();
		//Function to increment the time by one second
		//Postcondition: The time is incremented by one second
		//  If the before-increment time is 23:59:59, the time
 		//  is reset to 00:00:00

    void incrementMinutes();
		//Function to increment the time by one minute
		//Postcondition: The time is incremented by one minute 
		//  If the before-increment time is 23:59:53, the time
  		//  is reset to 00:00:53

    void incrementHours();
		//Function to increment the time by one hour
		//Postcondition: The time is incremented by one hour 
		//  If the before-increment time is 23:45:53, the time 
		//  is reset to 00:45:53

	bool equalTime(const clockType& otherClock) const;
		//Function to compare the two times
		//Postcondition: Returns true if this time is equal to
		//               otherClock; otherwise, returns false

    clockType(int hours, int minutes, int seconds);
		//Constructor with parameters 
		//The time is set according to the parameters
		//Postconditions: hr = hours; min = minutes; sec = seconds
 		//  The constructor checks whether the values of hours, 
 		//  minutes, and seconds are valid. If a value is invalid, 
 		//  the default value 0 is assigned.

    clockType();
		//Default constructor with parameters 
 		//The time is set to 00:00:00
		//Postcondition: hr = 0; min = 0; sec = 0

private:
    int hr;  //store hours
    int min; //store minutes
    int sec; //store seconds
};

#endif

I would really appreciate it if someone could help me.

Your compiler is correct -- look at the parameters to SetTime() and then look at the number of parameters main() is trying to pass to it. They ain't the same.

You don't have an implementation of setTime or getTime in the extClockType. The compiler assumes that the call refers to the setTime function in the base class ClockType and doesn't find a version of it with 4 parameters. Just implement a version of the setTime in the extClockType with the 4 parameters and it should work.

**Please use code tags in future posts**

You don't have an implementation of setTime or getTime in the extClockType. The compiler assumes that the call refers to the setTime function in the base class ClockType and doesn't find a version of it with 4 parameters. Just implement a version of the setTime in the extClockType with the 4 parameters and it should work.

**Please use code tags in future posts**

Hi,

if declare this on extClockType.cpp

void extClockType::setTime(int hours, int minutes, int seconds, enum zoneType)
{
if(0 <= hours && hours < 24)
		hr = hours;
	else 
		hr = 0;

	if(0 <= minutes && minutes < 60)
		min = minutes;
	else 
		min = 0;

	if(0 <= seconds && seconds < 60)
		sec = seconds;
	else 
		sec = 0;
}

would this make the program run, I'm new to C++, this is my first class that I'm taking. Please help me.

>>would this make the program run

Don't know -- why don't you compile it yourself and find out if it works or not?

it didn't work

it didn't work

Not helpful. How didn't it work?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.