I'm an undergrad taking my first C++ class. So I'm new with C++.
I have a homework assignment to create my own class, with a header file for that class, a cpp file for the member functions, and a cpp file with a main function to drive it.
I haven't started on the assignment yet. I've just copied an example out of the text book to get comfortable linking all of the files.
I'm using Dev C++, and my textbook mentions nothing about projects. so I'm kinda just throwing darts with project, but I think they all linked properly. Idon't see anything wrong with the code, but when I try to compile it I get a huge list of errors. I think it might have something to do with where these files are located.
If anyone could please help me figure out why this isn't working on my machine I would really appreciate it.
Here is the header file:
Here is my cpp file containing the member functions:
and here is my main driver:
I didn't type out the entire example of the main driver out of the text book, but both Time.cpp and Time.h are exactly from the text.
I have a separate homework directory on my computer for coding for school, but when I tried it in that I got even more errors than in it's current location, the Dev C++ program file.
Here is my compile log: (It says there are 15 total errors)
If anyone could help that would be great
I have a homework assignment to create my own class, with a header file for that class, a cpp file for the member functions, and a cpp file with a main function to drive it.
I haven't started on the assignment yet. I've just copied an example out of the text book to get comfortable linking all of the files.
I'm using Dev C++, and my textbook mentions nothing about projects. so I'm kinda just throwing darts with project, but I think they all linked properly. Idon't see anything wrong with the code, but when I try to compile it I get a huge list of errors. I think it might have something to do with where these files are located.
If anyone could please help me figure out why this isn't working on my machine I would really appreciate it.
Here is the header file:
Code:
#ifndef TIME_H
#define TIME_H
class Time
{
public:
Time();
void setTime(int, int, int);
void printUniversal();
void printStandard();
Private:
int hour;
int minute;
int second;
};
#endif
Here is my cpp file containing the member functions:
Code:
#include <iostream>
#include <iomanip>
#include "Time.h"
using namespace std;
Time::Time()
{
hour = minute = second = 0;
}
void Time::setTime(int h, int m, int s)
{
hour = (h>= 0 && < 24)) ? h:0;
minute = (m>= 0 && < 60)) ? m:0;
second = (s>= 0 && < 60)) ? s:0;
}
void Time::printUniversal()
{
cout << setfill('0') << setw(2) << hour << ":"
<< setw(2) << minute << ":" << setw(2) << second;
}
void Time::printStandard()
{
cout << ((hour == 0 || hour == 12) ? 12:hour % 12) << ":"
<< setfill('0') << setw(2) << minute << ":" << setw(2)
<< second << (hour<12? " AM":" PM");
}
and here is my main driver:
Code:
#include <iostream>
#include "Time.h"
using namespace std;
int main()
{
Time t;
t.printUniversal();
t.printStandard();
t.setTime(5,22,35);
t.printUniversal();
t.printStandard();
system("PAUSE");
}
I didn't type out the entire example of the main driver out of the text book, but both Time.cpp and Time.h are exactly from the text.
I have a separate homework directory on my computer for coding for school, but when I tried it in that I got even more errors than in it's current location, the Dev C++ program file.
Here is my compile log: (It says there are 15 total errors)
Code:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c Time.cpp -o Time.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
In file included from C:/Dev-Cpp/include/c++/3.4.2/ctime:51,
from C:/Dev-Cpp/include/c++/3.4.2/cwchar:51,
from C:/Dev-Cpp/include/c++/3.4.2/bits/postypes.h:46,
from C:/Dev-Cpp/include/c++/3.4.2/iosfwd:50,
from C:/Dev-Cpp/include/c++/3.4.2/ios:44,
from C:/Dev-Cpp/include/c++/3.4.2/ostream:45,
from C:/Dev-Cpp/include/c++/3.4.2/iostream:45,
from Time.cpp:1:
C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include/time.h:12: error: expected primary-expression before "int"
C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include/time.h:12: error: expected `;' before "int"
In file included from C:/Dev-Cpp/include/c++/3.4.2/cwchar:51,
from C:/Dev-Cpp/include/c++/3.4.2/bits/postypes.h:46,
from C:/Dev-Cpp/include/c++/3.4.2/iosfwd:50,
from C:/Dev-Cpp/include/c++/3.4.2/ios:44,
from C:/Dev-Cpp/include/c++/3.4.2/ostream:45,
from C:/Dev-Cpp/include/c++/3.4.2/iostream:45,
from Time.cpp:1:
C:/Dev-Cpp/include/c++/3.4.2/ctime:64: error: expected unqualified-id before "namespace"
C:/Dev-Cpp/include/c++/3.4.2/ctime:64: error: expected `,' or `;' before "namespace"
Time.cpp: In constructor `Time::Time()':
Time.cpp:9: error: `hour' undeclared (first use this function)
Time.cpp:9: error: (Each undeclared identifier is reported only once for each function it appears in.)
Time.cpp: In member function `void Time::setTime(int, int, int)':
Time.cpp:14: error: `hour' undeclared (first use this function)
Time.cpp:14: error: expected primary-expression before '<' token
Time.cpp:14: error: expected `;' before ')' token
Time.cpp:15: error: expected primary-expression before '<' token
Time.cpp:15: error: expected `;' before ')' token
Time.cpp:16: error: expected primary-expression before '<' token
Time.cpp:16: error: expected `;' before ')' token
Time.cpp: In member function `void Time::printUniversal()':
Time.cpp:21: error: `hour' undeclared (first use this function)
Time.cpp: In member function `void Time::printStandard()':
Time.cpp:27: error: `hour' undeclared (first use this function)
make.exe: *** [Time.o] Error 1
Execution terminated
If anyone could help that would be great
Last edited: