Need help with calling function correctly

My logic is off I know what I want to do but can't figure out how

Page 1 of 1

10 Replies - 1067 Views - Last Post: 13 November 2009 - 12:43 AM Rate Topic: -----

#1 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 258
  • Joined: 19-September 09

Need help with calling function correctly

Posted 12 November 2009 - 07:14 PM

I got everything correct until it has to fugure out what time zone and output the right time with time zone, any assistance is greatly appreciated , here is the code

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file



#pragma once

#ifndef _WIN32_WINNT			// Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600	 // Change this to the appropriate value to target other versions of Windows.
#endif


#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
using namespace std;

#include "time.h"
#include "extTime.h"

// TODO: reference additional headers your program requires here



#pragma once

#include "stdafx.h"
#include "time.h"

class extTime : public time

{
public:
	extTime();//default constructor
	extTime(int hr, int min, string tZone);//constructor with parameters
	~extTime(void);//destructor
	string getTimeZone();
	void printTime();//redefining the print member function of the base class
private:
	string tZone;//a new data member specific to the derived class
				  //this assumes time zone is denoted by one character
};



#include "stdafx.h"

extTime::extTime(void)
{
	if (tZone == "PST")
		cout << "The time is " << (getHour()-3) << ":" << getMinute() << endl;
	if (tZone == "MST")
		cout << "The time is " << (getHour()-2) << ":" << getMinute() << endl;
	if (tZone == "CST")
		cout << "The time is " << (getHour()-1) << ":" << getMinute() << endl;
	if (tZone == "EST")
		cout << "The time is " << getHour() << ":" << getMinute() << endl;
}
extTime::extTime(int hr, int min, string tZone)
{
	hour = hr;
	minute = min;
	timeZone = tZone;
}
extTime::~extTime(void)
{
}
string extTime::getTimeZone()
{
	cout << endl << "Please enter the time zone abbreviation: ";
	cin >> timeZone;
	return timeZone;
}
void extTime::printTime()
{
	extTime::extTime();//which will invoke the original printing function from the base class
	cout << ";Time Zone = ";
	cout << timeZone;
}



#pragma once

#include "stdafx.h"

class time
{
public:
	time();//the default constructor
	time(int hrs, int min, char tZone);// constructor with parameters
	~time(void);//deconstructor
	void setHour(int hrs);//sets the hour
	void setMinute(int mins);//sets the minute
	int getHour();//gets the hour and returns a value
	int getMinute();//gets the minute and returns a value	
	void incrementHrs();//increments the hour
	void incrementMin();//incrememts the minute
	void printTime();//prints the hour and the minute

protected:
	int hour;//declares the hour
	int minute;//declares the minute
	string timeZone;//declares the time zone
};



include "stdafx.h"

time::time()//implementation of the default constructor
{
	hour = 0;
	minute = 0;
}
time::time(int hrs, int mins, char tZone)//implementation of the constructor with parameters
{
	hour = hrs;
	minute = mins;
	timeZone = tZone;
}
time::~time(void)
{
}
void time::setHour(int hrs)
{
	hour = hrs;
}
void time::setMinute(int mins)
{
	minute = mins;
}
int time::getHour()
{
	return hour;	
}
int time::getMinute()
{
	return minute;
}
void time::incrementHrs()
{
	hour++;
		if (hour > 23)
			hour = 0;
}
void time::incrementMin()
{
	minute++;
	if (minute > 59)
		minute = 0;
}
void time::printTime()
{
	//note from the if statements that consideration
	//is taken whether the hours and minutes are 1 or 2 digits
	if (hour < 10)
		cout << "0";
	cout << hour << ":";
	if (minute < 10)
		cout << "0";
	cout << minute;
}



#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	time theTime;
	extTime timeZone;
	
 
	int hours;
	int minutes;


	cout << "Please set the hour of the time: ";
	cin >> hours;
	cout << "Thank you." << endl << "Now please set the minute of the time: ";
	cin >> minutes;
	cout << "Thank you." << endl;
	cout << endl;

	theTime.setHour(5);
	theTime.setMinute(30);//Set time for theTime
	
	cout << "The time of object [theTime] is: ";
	theTime.printTime(); //prints the time of theTime
	cout << endl;

	theTime.incrementMin(); //increments the mintues by one

	cout << "After incrementing theTime by one minute, theTime: ";
	theTime.printTime();  //print the time of theTime
	cout << endl;

	theTime.getHour();
	theTime.getMinute();//gets the values for hours and minutes


	

	theTime.incrementHrs();  //increments the hours by one

	cout << "After incrementing theTime by one hour, theTime: ";
	theTime.printTime();
	cout << endl;

	theTime.getHour();
	theTime.getMinute();//gets the values for hours and minutes	

  

	timeZone.getTimeZone(); //sets the timezone
	cout << endl;

	timeZone.printTime(); //prints the time and the timezone
	cout << endl;
	
	cout << "Thank you for using my time program, Goodbye." << endl;

	system("PAUSE");
	return 0;
} //end main



I'm pretty sure my error is calling the function correctly and having it in the right order for extTime

here is the output:

Please set the hour of the time: 5
Thank you.
Now please set the minute of the time: 30
Thank you.

The time of object [theTime] is: 05:30
After incrementing theTime by one minute, theTime: 05:31
After incrementing theTime by one hour, theTime: 06:31

Please enter the time zone abbreviation: est

;Time Zone = est
Thank you for using my time program, Goodbye.
Press any key to continue . . .
Press any key to continue . . .







for the out put needs to be more like this

Please set the hour of the time: 5
Thank you.
Now please set the minute of the time: 30
Thank you.

The time of object [theTime] is: 05:30
After incrementing theTime by one minute, theTime: 05:31
After incrementing theTime by one hour, theTime: 06:31

Please enter the time zone abbreviation: est

05:30;Time Zone = est
Thank you for using my time program, Goodbye.
Press any key to continue . . .
Press any key to continue . . .








or if I would have put in a different time zone abbreviation it would display the time for that time zone when it is 05:30 est

This post has been edited by Gmoney93079: 12 November 2009 - 07:15 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with calling function correctly

#2 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 601
  • Joined: 20-July 09

Re: Need help with calling function correctly

Posted 12 November 2009 - 07:23 PM

What is this?
int _tmain(int argc, _TCHAR* argv[])


Was This Post Helpful? 0
  • +
  • -

#3 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 258
  • Joined: 19-September 09

Re: Need help with calling function correctly

Posted 12 November 2009 - 07:59 PM

Its whats needs to be there when main is made by VS what it does I have never understood, but I've been using it for the last 3 weeks now. I don't think thats anything that is causing the question I am asking.
Was This Post Helpful? 0
  • +
  • -

#4 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 258
  • Joined: 19-September 09

Re: Need help with calling function correctly

Posted 12 November 2009 - 08:45 PM

anyone got an answer for me?
Was This Post Helpful? 0
  • +
  • -

#5 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 258
  • Joined: 19-September 09

Re: Need help with calling function correctly

Posted 12 November 2009 - 09:29 PM

I know it deals with calling the function correctly for the extTime but I can't figure it out, you have to understand I have been at it with this code now for like 24 hrs, so any help is appreciated.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_c.user*


Reputation:

Re: Need help with calling function correctly

Posted 12 November 2009 - 10:18 PM

05:30;Time Zone = est
you do not save the old time before the incrementing
if you will print even while the theTime.printTime(); it will print the new time
Was This Post Helpful? 0

#7 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 258
  • Joined: 19-September 09

Re: Need help with calling function correctly

Posted 12 November 2009 - 10:22 PM

sorry not sure what you meant by that, I think what your trying to say is the variable is not being saved and thats why the time is not printing, am I correct on that?
Was This Post Helpful? 0
  • +
  • -

#8 Guest_c.user*


Reputation:

Re: Need help with calling function correctly

Posted 12 November 2009 - 10:48 PM

you don't print the time, but if you even will print it, it will not be printed as 05:30 (because you have changed it by the incremention methods)
Was This Post Helpful? 0

#9 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 258
  • Joined: 19-September 09

Re: Need help with calling function correctly

Posted 12 November 2009 - 11:04 PM

I now see what you mean so how can I fix that?
Was This Post Helpful? 0
  • +
  • -

#10 Guest_c.user*


Reputation:

Re: Need help with calling function correctly

Posted 13 November 2009 - 12:25 AM

	time theTime;



it is from the main function (_tmain)

make changes
	time theTime, oldTime;

...

	hours = 5;
	minutes = 30;

	theTime.setHour(hours);
	theTime.setMinute(minutes);
	oldTime.setHour(hours);
	oldTime.setMinute(minutes);

...

	timeZone.getTimeZone();
	cout << endl;

	oldTime.printTime();
	cout << ";";
	timeZone.printTime();
	cout << endl;

...



Was This Post Helpful? 1

#11 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 258
  • Joined: 19-September 09

Re: Need help with calling function correctly

Posted 13 November 2009 - 12:43 AM

thanks I think that did it, thanks so much I'm going to go get some sleep;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1