You don't have 3 programs, you have 3 source files, AKA translation units, you can use to create one unified program.
As long as your main source file includes the header files, and the make commands used compiles and links your 3 source files you can call functions in the other source files.
BTW, you can use whatever extension you want; I prefer to use .hpp/.cpp for C++ header/source files, .h/.c for C files, etc. Makes it easy to see at a glance if a file is C or C++. Or another type source file such as assembly or Fortran or BASIC.
a.hpp
1 2 3 4 5 6
|
#ifndef A_HPP
#define A_HPP
void A();
#endif
|
a.cpp
1 2 3 4 5 6 7 8
|
#include <iostream>
#include "a.hpp"
void A()
{
std::cout << "I'm A!\n";
}
|
b.hpp
1 2 3 4 5 6
|
#ifndef B_HPP
#define B_HPP
void B();
#endif
|
b.cpp
1 2 3 4 5 6 7 8
|
#include <iostream>
#include "b.hpp"
void B()
{
std::cout << "This is B!\n";
}
|
main.cpp
1 2 3 4 5 6 7 8 9 10 11
|
#include <iostream>
#include "a.hpp"
#include "b.hpp"
int main()
{
A();
B();
}
|
Splitting code into separate translation units makes managing large amounts of code easier. You really want to deal with 10,000,000 lines of code in one file? I sure don't.
And having separate source code files lets you reuse code that works in another project so you don't have to rewrite code that already works. A library.