Need help on this not for sure what I am missing I get a couple of errors!In included both the .h and .cpp information.

// Make sure the header file it not added more than once

#pragma once
#ifndef MYTIME_H
#define MYTIME_H

#include <iostream>
using std::ostream;
using std::istream

class MyTime
{
      private:
              // day 1
              int day;
              // hours 0-23
              int hour;
              // minutes 0-59
              int min;
              // seconds 0-59
              int sec;
            
      public:
             // Default
             MyTime ()
             
             // copy
             MyTime(const MyTime & origMyTime)
             
             // pram
             MyTime(int day, int hour, int min, int sec)
             
             // destructor
            
             ~MyTime()
             // access
             // day, hour, min, sec
             int SetDay()
             int SetHour()
             int SetMinute() 
             int SetSecond() 
             
             // get functions
             // day, hour, min, sec
             int GetDay() const
             int GetHour()const
             int GetMinute()const
             int GetSeconds()const
             
             // print functions
             void setDay()
             void setHour()
             void setMinute()
             void setSecond()
             
             // add 
             void IncrDay(int addDay)
             void IncrHour(int addHour)
             void IncrMinute(int addMinute)
             void IncrSecond(int addSecond)
             
             // subtract
             void DecDay(int subtractDay)
             void DecHour(int subtractHour)
             void DecMinute(int subtractMinute)
             void DecSecond(int subtractSecond)
 
// <<, >> insertion and extraction  
friend ostream & operator<< (ostream & os, const MyTime & aMyTime )    // Output
friend istream & operator>> (istream & is, const MyTime & aMyTime )           // Input
             
//(boolean test operators)
bool operator==(const MyTime & aMyTime)    // Compare ==
bool operator!=(const MyTime & aMyTime)    // Compare !=
bool operator< (const MyTime & aMyTime)    // Compare <
bool operator<=(const MyTime & aMyTime)    // Compare <=
bool operator> (const MyTime & aMyTime)    // Compare >
bool operator>=(const MyTime & aMyTime)    // Compare >=

}#endif
//MyTime.cpp
#include "MyTime.h" // time class definition
#include <ctime>

using std::ostream


  MyTime::MyTime()

              // day 1
              int day = 0;
              // hours 0-23
              int hour = 0;
              // minutes 0-59
              int min = 0;
              // seconds 0-59
              int sec = 0;
         
  MyTime::MyTime(const MyTime &origMyTime)
  
  MyTime::~MyTime()
      
  MyTime::SetDay()
 
  MyTime::SetHour()
 
  MyTime::SetMinute()
 
  MyTime::SetSecond()
 
 
 // Methods
 
  int MyTime::GetDay()
 
  int MyTime::GetHour()
 
  int MyTime::GetMinute()
 
  int MyTime::GetSecond()
 
 
 // print
 
 void MyTime::setDay
 
 void MyTime::setHour

 void MyTime::setMinute
      
 void MyTime::setSecond   
 
 // add time
   
 void MyTime::IncrDay
      
 void MyTime::IncrHour     

 void MyTime::IncrMinute
      
 void MyTime::IncrSecond  
      
 // subtract time
 
 void MyTime::DecDay
      
 void MyTime::DecHour
      
 void MyTime::DecMinute
      
 void MyTime::DecSecond  
 
bool MyTime::Equals(const MyTime & aMyTime) const                      

ostream & operator<< (ostream & os, const MyTime & aMyTime)

istream & operator>> (istream & is, MyTime & aMyTime) 

// >, <, >=, <=, ==, != (boolean relational test operators)
bool MyTime::operator> (const MyTime & aMyTime) const 

        if (this->Compare(aMyTime) > 0)
                return true;
        else 
                return false;



bool MyTime::operator< (const MyTime & aMyTime) const 

if (this->Compare(aMyTime) < 0)
                return true;
        else 
                return false;


bool MyTime::operator>= (const MyTime & aMyTime) const 

if (this->Compare(aMyTime) >= 0)
                return true;
        else 
                return false;


bool MyTime::operator<= (const MyTime & aMyTime) const

if (this->Compare(aMyTime) <= 0)
                return true;
        else 
                return false;


bool MyTime::operator== (const MyTime & aMyTime) const

        if (this->Equals(aMyTime) == true)
                return true;
        else 
                return false;


bool MyTime::operator!= (const MyTime & aMyTime) const 

        if (this->Equals(aMyTime) == false)
                return true;
        else 
                return false;



        return is;
}

Recommended Answers

All 4 Replies

Need help on this not for sure what I am missing I get a couple of errors!In included both the .h and .cpp information.

A couple of errors? Must be something wrong then. But since we aren't psychic, you might want to be less vague.

It looks like you are missing a bunch of semi-colons ( ; ) and curly braces ( {} ), and the #endif preprocessor directive should be on its own line. Are those missing in your code, or did they not get copied over somehow? If they weren't copied, please repost your code and, like WaltP said, give us some more information.

Need help on this not for sure what I am missing I get a couple of errors!In included both the .h and .cpp information.

// Make sure the header file it not added more than once

#pragma once
#ifndef MYTIME_H
#define MYTIME_H

#include <iostream>
using std::ostream;
using std::istream

class MyTime
{
      private:
              // day 1
              int day;
              // hours 0-23
              int hour;
              // minutes 0-59
              int min;
              // seconds 0-59
              int sec;
            
      public:
             // Default
             MyTime ()
             
             // copy
             MyTime(const MyTime & origMyTime)
             
             // pram
             MyTime(int day, int hour, int min, int sec)
             
             // destructor
            
             ~MyTime()
             // access
             // day, hour, min, sec
             int SetDay()
             int SetHour()
             int SetMinute() 
             int SetSecond() 
             
             // get functions
             // day, hour, min, sec
             int GetDay() const
             int GetHour()const
             int GetMinute()const
             int GetSeconds()const
             
             // print functions
             void setDay()
             void setHour()
             void setMinute()
             void setSecond()
             
             // add 
             void IncrDay(int addDay)
             void IncrHour(int addHour)
             void IncrMinute(int addMinute)
             void IncrSecond(int addSecond)
             
             // subtract
             void DecDay(int subtractDay)
             void DecHour(int subtractHour)
             void DecMinute(int subtractMinute)
             void DecSecond(int subtractSecond)
 
// <<, >> insertion and extraction  
friend ostream & operator<< (ostream & os, const MyTime & aMyTime )    // Output
friend istream & operator>> (istream & is, const MyTime & aMyTime )           // Input
             
//(boolean test operators)
bool operator==(const MyTime & aMyTime)    // Compare ==
bool operator!=(const MyTime & aMyTime)    // Compare !=
bool operator< (const MyTime & aMyTime)    // Compare <
bool operator<=(const MyTime & aMyTime)    // Compare <=
bool operator> (const MyTime & aMyTime)    // Compare >
bool operator>=(const MyTime & aMyTime)    // Compare >=

}#endif
//MyTime.cpp
#include "MyTime.h" // time class definition
#include <ctime>

using std::ostream


  MyTime::MyTime()

              // day 1
              int day = 0;
              // hours 0-23
              int hour = 0;
              // minutes 0-59
              int min = 0;
              // seconds 0-59
              int sec = 0;
         
  MyTime::MyTime(const MyTime &origMyTime)
  
  MyTime::~MyTime()
      
  MyTime::SetDay()
 
  MyTime::SetHour()
 
  MyTime::SetMinute()
 
  MyTime::SetSecond()
 
 
 // Methods
 
  int MyTime::GetDay()
 
  int MyTime::GetHour()
 
  int MyTime::GetMinute()
 
  int MyTime::GetSecond()
 
 
 // print
 
 void MyTime::setDay
 
 void MyTime::setHour

 void MyTime::setMinute
      
 void MyTime::setSecond   
 
 // add time
   
 void MyTime::IncrDay
      
 void MyTime::IncrHour     

 void MyTime::IncrMinute
      
 void MyTime::IncrSecond  
      
 // subtract time
 
 void MyTime::DecDay
      
 void MyTime::DecHour
      
 void MyTime::DecMinute
      
 void MyTime::DecSecond  
 
bool MyTime::Equals(const MyTime & aMyTime) const                      

ostream & operator<< (ostream & os, const MyTime & aMyTime)

istream & operator>> (istream & is, MyTime & aMyTime) 

// >, <, >=, <=, ==, != (boolean relational test operators)
bool MyTime::operator> (const MyTime & aMyTime) const 

        if (this->Compare(aMyTime) > 0)
                return true;
        else 
                return false;



bool MyTime::operator< (const MyTime & aMyTime) const 

if (this->Compare(aMyTime) < 0)
                return true;
        else 
                return false;


bool MyTime::operator>= (const MyTime & aMyTime) const 

if (this->Compare(aMyTime) >= 0)
                return true;
        else 
                return false;


bool MyTime::operator<= (const MyTime & aMyTime) const

if (this->Compare(aMyTime) <= 0)
                return true;
        else 
                return false;


bool MyTime::operator== (const MyTime & aMyTime) const

        if (this->Equals(aMyTime) == true)
                return true;
        else 
                return false;


bool MyTime::operator!= (const MyTime & aMyTime) const 

        if (this->Equals(aMyTime) == false)
                return true;
        else 
                return false;



        return is;
}

2 C:\Documents and Settings\west\Desktop\MyTime.cpp In file included from C:\Documents and Settings\west\Desktop\MyTime.cpp
11 C:\Documents and Settings\west\Desktop\MyTime.h expected `;' before "class"
28 C:\Documents and Settings\west\Desktop\MyTime.h expected `;' before "MyTime"
13 C:\Documents and Settings\west\Desktop\MyTime.cpp ISO C++ forbids initialization of member `hour'
13 C:\Documents and Settings\west\Desktop\MyTime.cpp making `hour' static
13 C:\Documents and Settings\west\Desktop\MyTime.cpp ISO C++ forbids in-class initialization of non-const static member `hour'
13 C:\Documents and Settings\west\Desktop\MyTime.cpp declaration of `int MyTime::hour'
17 C:\Documents and Settings\west\Desktop\MyTime.h conflicts with previous declaration `int MyTime::hour'
15 C:\Documents and Settings\west\Desktop\MyTime.cpp ISO C++ forbids initialization of member `min'
15 C:\Documents and Settings\west\Desktop\MyTime.cpp making `min' static
15 C:\Documents and Settings\west\Desktop\MyTime.cpp ISO C++ forbids in-class initialization of non-const static member `min'
15 C:\Documents and Settings\west\Desktop\MyTime.cpp declaration of `int MyTime::min'
19 C:\Documents and Settings\west\Desktop\MyTime.h conflicts with previous declaration `int MyTime::min'
17 C:\Documents and Settings\west\Desktop\MyTime.cpp ISO C++ forbids initialization of member `sec'
17 C:\Documents and Settings\west\Desktop\MyTime.cpp making `sec' static
17 C:\Documents and Settings\west\Desktop\MyTime.cpp ISO C++ forbids in-class initialization of non-const static member `sec'
17 C:\Documents and Settings\west\Desktop\MyTime.cpp declaration of `int MyTime::sec'
21 C:\Documents and Settings\west\Desktop\MyTime.h conflicts with previous declaration `int MyTime::sec'
21 C:\Documents and Settings\west\Desktop\MyTime.cpp expected `;' before "MyTime"
84 C:\Documents and Settings\west\Desktop\MyTime.cpp expected unqualified-id before "else"
91 C:\Documents and Settings\west\Desktop\MyTime.cpp expected `;' before "if"
93 C:\Documents and Settings\west\Desktop\MyTime.cpp expected unqualified-id before "else"
99 C:\Documents and Settings\west\Desktop\MyTime.cpp expected `;' before "if"
101 C:\Documents and Settings\west\Desktop\MyTime.cpp expected unqualified-id before "else"
107 C:\Documents and Settings\west\Desktop\MyTime.cpp expected `;' before "if"
109 C:\Documents and Settings\west\Desktop\MyTime.cpp expected unqualified-id before "else"
115 C:\Documents and Settings\west\Desktop\MyTime.cpp expected `;' before "if"
117 C:\Documents and Settings\west\Desktop\MyTime.cpp expected unqualified-id before "else"
123 C:\Documents and Settings\west\Desktop\MyTime.cpp expected `;' before "if"
125 C:\Documents and Settings\west\Desktop\MyTime.cpp expected unqualified-id before "else"
130 C:\Documents and Settings\west\Desktop\MyTime.cpp expected unqualified-id before "return"
130 C:\Documents and Settings\west\Desktop\MyTime.cpp expected `,' or `;' before "return"

These are the errors that I get when I run the program I have tried to add ; in different areas!

your codes in MyTime.cpp aren't complete. let's say your default constructor

instead of:

MyTime::MyTime()
//code

It should be:

MyTime::MyTime()
{
//code
}

do keep in mind that functions have to have () at the back of their name such as void Mytime::IncrDay() which you typed as void MyTime::IncrDay. try fixing your code again and see what other errors come up.

Oh, and I almost missed this, you lack a ; before #endif

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.