Solved

Time class Addition

Posted on 2004-04-06
3
301 Views
Last Modified: 2010-04-01
Need help in the correction of this code for addition Time class.  When I try to compile, compiler states Time, time1, time2, sumTime undeclared.  Line 8-10 on add_time_3.cpp.  Looking for corrected working code.  Please advise.  Del

#ifndef TIME3_H
#define TIME3_H

class Time {

public:

   Time();
   void inputTime();
   void normTime();
   Time addTime(const Time &);
   void printTime();

private:

   int week;
   int day;
   int hour;
   int minute;

};

#endif

// time3.cpp

#include <iostream>

using namespace std;

#include "time3.h"

void Time::inputTime() {

                char temp[15];
            cout << "Enter time value: " << endl;
                cin >> week >> temp >> day >> temp >> hour >>temp >> minute >> temp;

}

void Time::normTime() {

                while(minute >= 60) {
                           hour ++;
               minute = minute - 60;

               }

                while(hour >= 24) {
                           day ++;
                hour = hour - 24;

                }

                while(day >= 7) {
                          week ++;
                day = day - 7;

                }

}

Time Time::addTime(const Time &time) {
            
            Time result;
                result.week = week + time.week;
                result.day = day + time.day;
                result.hour = hour + time.hour;
                result.minute = minute + time.minute;

            return result;

}

void Time::printTime() {

                cout << week << " Weeks " << day << " Days " << hour << " Hours " << minute
                       << " Minutes" << endl;

} // end of time3.cpp

// add_time_3.cpp

#include "time3.h"

int main()
{
      Time.time1, time2, sumTime;
      time1.inputTime();
      //time1.normTime();
      //time1.printTime();

      time2.inputTime();
      //time2.normTime();
      //time2.printTime();
      
      sumTime = time1.addTime(time2);
      sumTime.normTime();
      sumTime.printTime();
      
      return 0;

} // end of main

#endif






















































0
Comment
Question by:edelossantos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 500 total points
ID: 10770498
>Time.time1, time2, sumTime;

Removed the . between Time and time1 like

Time time1, time2, sumTime;
0
 

Author Comment

by:edelossantos
ID: 10770708
I Removed the . between Time and time1 like

Time time1, time2, sumTime;

Now I am getting a user bin unresolved, Time::Time(void)
0
 
LVL 23

Expert Comment

by:chensu
ID: 10770805
You need to define the constructor in time3.cpp as follows.

Time::Time()
{
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question