Implementation Files

Published on: April 1, 2011

Last time I showed you how to split your program into two different files, the header and the main cpp. In this tutorial, I show you how to split your program further using implementation files (or extra cpp files) for your functions in C++ with ease. This made the program much easier to read because it was more organized and the main program was much smaller. Using .h files along with implementation files will do the same by splitting up the program into three different files. A main.cpp file, an Implementation.cpp file and a header.h file.

This is also a great way for data hiding in C++. You can use many more header and cpp files for your programs and connect them all into one main program. In the future, I hope to show you a program that has many more files to it. This is a very short tutorial that only shows how to break the program up.

Below you will find three section of codes, one for each file. Please read the comments on top of each section to know what file it is from, they are marked as header.h, main.cpp, and implementation.cpp. If you have any questions about the program or anything in general relating to beginner C++ Programming, feel free to ask. I hope you enjoy the video and if you have any requests feel free to let me know.

Remember to checkout the Codesnip below to review the C++ code yourself! Feel free to copy the code, but I ask that you please provide credit if you leave the code unchanged when you use it.

Codesnip:

//Name:  Nazmus
//Program: Using Implementation Files
//Website: EasyProgramming.net
//header.h

#pragma once
#include <iostream>

#include <string>

using namespace std;

void prompt(string name[3], int grade[3]);

void init(int index[3]);
void sort(string name[3], int index[3]);

void output(string name[3], int grade[3], int index[3]);




//Name:  Nazmus
//Program: Using Implementation Files
//Website: EasyProgramming.net
//main.cpp

#include "header.h"

int main()
{

 string name[3];
 int grade[3];
 int index[3];

 prompt(name, grade);
 init(index);
 sort(name, index);

 output(name, grade, index);
}



Comments: