Files: Header, Implementation, Test

  • Thread starter Jammin_James
  • Start date
  • Tags
    files Test
In summary: But for more complicated programs, you might have multiple files that contain the definitions. And you would include them in the order that they are listed in the source files.
  • #1
Jammin_James
49
0
Hey all!

I've been reading through my book trying to figure all this out for my Data Structures class and I'm typing this out while I take a break from reading the book.

I'm looking over the examples from class and my teacher has header, implementation and test files. There is no input from a user that I can see in these programs, which is where these test files come in. Also, I think I understand why people use header and imp files, but I'm having troubles understanding how aurguments are passed between them. I'm also having trouble with the declarations in header and implementation files.

IN HEADER:

class Date
{
Date(arguments)
}

IN IMPLEMENTATION FILE:

Date::Date(arguments)

Is my teacher making the function declaration twice?

I could link the code if you'd like because I really doubt any of this made sense, haha.
 
Technology news on Phys.org
  • #2
Jammin_James said:
Hey all!

I've been reading through my book trying to figure all this out for my Data Structures class and I'm typing this out while I take a break from reading the book.

I'm looking over the examples from class and my teacher has header, implementation and test files. There is no input from a user that I can see in these programs, which is where these test files come in. Also, I think I understand why people use header and imp files, but I'm having troubles understanding how aurguments are passed between them. I'm also having trouble with the declarations in header and implementation files.

IN HEADER:

class Date
{
Date(arguments)
}

IN IMPLEMENTATION FILE:

Date::Date(arguments)

Is my teacher making the function declaration twice?

I could link the code if you'd like because I really doubt any of this made sense, haha.

Yeah putting the actual code is better than things out of context.


But you are missing the basics with this one.


The declaration is

class Date
{
Date(args);
myMethod(args);
}

That is the declaration. And the fact that the function and the class share the same name, means it is a special type of method: a constructor


Now you still need to define the function ( you can do it in the declaration, but let's keep it like your code ).

so in a cpp file you need to define it.

the syntax

Date::Date(args)
{
//some code
}

is the definition.

Data::myMethod(args)
{
// some code
}

and that defines my new method
 
  • #3
Now let me explain your other issue.

If you are creating a simple program and you want to define a few classes for your program. You can do it with one file.

But the reason for header files is so you can create the declarations so that you can implement code in modules.

You build classes, such as your date class. And all you have to do is include the header file any source file, and that source file will see the definition of the Date class.

And when you build your program, you just need to make sure you have the definition source file, ( or object or library file.. ) and you have a Date class that can be reused over and over again.

That is how the standard libraries work. You get the header files and include them, and somewhere in library files are the definitions.
 

What is a header file?

A header file is a file that contains declarations of functions, variables, and data structures that are used in a program. It is typically included at the beginning of a source code file and provides information to the compiler about how to interpret the code.

What is an implementation file?

An implementation file is a file that contains the actual code for the functions and variables declared in the header file. It is typically compiled separately from the header file and then linked together to create the final executable program.

What is a test file?

A test file is a file that contains code that is used to test the functionality of a program or specific functions. It typically includes different scenarios and inputs to ensure that the program is working correctly.

Why are header, implementation, and test files separated?

Separating header, implementation, and test files allows for better organization and modularity in a program. It also allows for easier debugging and maintenance as changes can be made to specific files without affecting the entire program.

How do header, implementation, and test files work together?

The header file provides the declarations for functions and variables, the implementation file contains the code for those functions and variables, and the test file is used to test the functionality of the code. Together, these files create a well-organized and functional program.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
2
Views
377
  • Programming and Computer Science
3
Replies
81
Views
5K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
21
Views
531
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
5
Views
816
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
7
Views
3K
Back
Top