?
Solved

Time class Addition

Posted on 2004-04-06
3
Medium Priority
?
304 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 2000 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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

719 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