C++

i want to thses .cpp files and .h header file put in one .cpp file without using separate file only one main.cpp

for the example i want to put all these file in one .cpp file how to do it and is it possible ?

#include "sort.cpp"
#include "sequence.cpp"
#include <iostream>
#include <time.h>
#include <iomanip>

using namespace std;


void test (Sequence & sequence, int repeat, int order, bool average);


int getN (int row);


void printTableInt (int table [][5], int repeat);
void printTableFloat (float table [][5], int repeat);


int printW = 12;


int main () {
Sequence sequence;

/////////////////////////////////////////////

#include "sequence.h"
#include <cstdlib>
#include <ctime>

Sequence::Sequence () {}

Sequence::~Sequence () {

if (initialized) {
delete [] arr;
}
}

void Sequence::initialize (int n) {


if (!initialized) {

initialized = true;

} else {
// Delete the previous one.
delete [] arr;
}
#include "sequence.h"
#include <cstdlib>
#include <ctime>

Sequence::Sequence () {}

Sequence::~Sequence () {

if (initialized) {
delete [] arr;
}
}

void Sequence::initialize (int n) {


if (!initialized) {

initialized = true;

} else {
// Delete the previous one.
delete [] arr;
}
/////////////////////////////

#ifndef _SEQUENCE
#define _SEQUENCE

class Sequence {
public:
Sequence ();
~Sequence ();
void initialize (int length = 100);
void ascend ();
void descend ();
void random ();
int * getArray ();
int getLength () const;
private:
int * arr;
int length;
bool initialized;
};
///////////////////////////////////////

#include "sort.h"

Sort::Sort () {}
Sort::~Sort () {}

void Sort::insertion (int * arr, int length, int & steps) const {

int j, temp;


steps += 1;

for (int i = 0; i < length; i++)
/////////////////////////////////////////////////

#ifndef _SORT
#define _SORT

class Sort {
public:
Sort ();
~Sort ();
void insertion (int * arr, int length, int & steps) const;
void selection (int * arr, int length, int & steps) const;
void bubble (int * arr, int length, int & steps) const;
void merge (int * arr, int length, int & steps);
void quick (int * arr, int start, int length, int & steps);
void mergeStep (int * arr, int n1, int n2, int & steps);
int partitionStep (int * arr, int start, int length, int & steps);
void swap (int* val1, int* val2);
private:
};

#endif

Last edited on
You need to edit your post and repaste your code in code tags to preserve indentation: http://www.cplusplus.com/forum/articles/16853/
Is it possible? Yes. You'll have
definitions and declarations
implementations


Note: Your code contains
1
2
#include "sort.cpp"
#include "sequence.cpp" 

Which is most likely a logical error. Each cpp-file is supposed to be compiled separately; not included.


The bigger question is: Why do you want?
Transition from one-file into multi-file code organization requires some learning. If you already master the latter, then why do you want to use the former?
Topic archived. No new replies allowed.