Hi, I'm newbie with C++ and I found an example which I need http://ideone.com/Eikbr4

But I've a question, how do I seperate this piece of code into .h and .cpp..

I tried to do something similar on my own but I'm having struggling with it after multiple try.. I've read many sort article on the but it's just not help..

missionplan.h

class MissionPlan
{
    private:
        int sizeofarray;
        int sizeofarray2;
        int xcordi;
        int ycordi;
        static float civnum;


    public:
        MissionPlan();
        MissionPlan(int, int, float);

        int getx();
        int gety();
        float getciv();

        void stats();
        void storedata(int, int, float);
        void test();
        void displayall();
        void compute();
        void topfives();

};

missionplan.cpp

#include "LocationData.h"
#include "PointTwoD.h"
#include "MissionPlan.h"


#include <iostream>
#include <string>
#include <algorithm> 
#include <vector>
#include <iterator>

using namespace std;

    vector <PointTwoD> point1;//set PointTwoD object as a vector array, name of array "point1"
    vector <PointTwoD> topfive;
    LocationData locationdata;
    PointTwoD pointtwoD;
    MissionPlan missionplan;

MissionPlan::MissionPlan()
{
    xcordi = 0;
    ycordi = 0;
    civnum = 0;
}

MissionPlan::MissionPlan(int x, int y, float civ)
{
    xcordi = x;
    ycordi = y;
    civnum = civ;
}   

int MissionPlan::getx()
{
    return pointtwoD.getxcord();
}

int MissionPlan::gety()
{
    return pointtwoD.getycord();
}

float MissionPlan::getciv()
{
    return locationdata.getCivIndex();
}

void MissionPlan::stats()
{
    string sunType;
    int earth;
    int moon;
    float particle;
    float plasma;
    int xcord;
    int ycord;

    cout<< "X axis: ";
    cin >> xcord;
    pointtwoD.setxcord(xcord);

    cout<< "y axis: ";
    cin >> ycord;
    pointtwoD.setycord(ycord);

    cout << "Suntype: ";
    cout.flush();//flush getline problem
    cin.ignore();
    getline(cin, sunType);
    locationdata.setsunType(sunType);

    cout << "No of Earth Like Planets: ";
    cin >> earth;
    locationdata.setnoOfEarthLikePlanets(earth);

    cout << "No of Earth Like Moons: ";
    cin >> moon;
    locationdata.setnoOfEarthLikeMoons(moon);

    cout << "Ave Particle Density: ";
    cin >> particle;
    locationdata.setaveParticulateDensity(particle);

    cout << "Ave Plasma Density: ";
    cin >> plasma;
    locationdata.setavePlasmaDensity(plasma);


    locationdata.computeCivIndex(sunType, earth, moon, particle, plasma);
    missionplan.test();
    missionplan.displayall();
}

void MissionPlan::test()
{

        int xcord = pointtwoD.getxcord();
        int ycord = pointtwoD.getycord();
        float civIndex = locationdata.getCivIndex();
        pointtwoD.setPointDetail(xcord, ycord, civIndex);
        point1.push_back(pointtwoD);//push/store new object into array

}



void MissionPlan::topfives()
{   
    bool sortByCiv(const PointTwoD &t1, const  PointTwoD  &t2);

    topfive.assign( point1.begin(), point1.end() ); 

    sort(topfive.begin(), topfive.end(), sortByCiv);

    for(int i=0; i < 5; i++)
    {
        topfive = point1.at(i);//display all data starting from the first index
        pointtwoD.displayPointdata();
    }

    bool sortByCiv(const  PointTwoD &t1, const  PointTwoD &t2)
    {
        return t1.getciv < t2.getciv;
    }
}

What part are you having trouble with? Just name the files accordingly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.