#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>

using namespace std;

class letter{
	private:
	    int genre;
	    int price;
	    string adress;
	public:
		letter();
		~letter();
	};

class parcel{
	private:
		int genre;
		int price;
		string adress;
	public:
		parcel();
		~parcel();
	};
	
class post{
	private:
		letter** LETTERS;
		parcel** PARCELS;
		int number_of_letters;
		int number_of_parcels;
		int sort_parcels();
		int sort_letters();
	public:
		post();
		~post();
	};
	
//In the constructor of letter it gets genre-price-adress
//In the constructor of parcel it gets genre-price-adress

int post::sort_parcels(){
	//how do i use sort here?
}
int post::sort_letters(){
	//how do i use sort here?
}
post::post(){
    number_of_letters=rand()%50;
	number_of_parcels=rand()%50;
	LETTERS=new letter*[number_of_letters];
	for(int i=0;i<number_of_letters;i++){
		LETTERS[i]=new letter;}
	PARCELS=new parcel*[number_of_parcels];
	for(int i=0;i<number_of_parcels;i++){
		PARCELS[i]=new parcel;}
	//Here i want to sort LETTERS and PARCELS regarding their adress
	//Would it be easier if i used vectors of parcel-letter instead of pointer-to-pointer ?

Can u answer to my questions marked as // in the code segment?
I am a newbie and i dont know well how while we are in a class we get sth from the other class.
Thx in advance....

To access member variables of a class from another class, you can either:
1-Use the friend keyword or
2-inheritance

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>

using namespace std;

class letter{
	private:
	    int genre;
	    int price;
	    string adress;
	public:
		letter();
		~letter();
	};

class parcel{
	private:
		int genre;
		int price;
		string adress;
	public:
		parcel();
		~parcel();
	};
	
class post{
	private:
		letter** pLetters;
		parcel** pParcels;
		int number_of_letters;
		int number_of_parcels;
		int sort_parcels();
		int sort_letters();
	public:
		post();
		~post();
	};
	
//In the constructor of letter it gets genre-price-adress
//In the constructor of parcel it gets genre-price-adress

int post::sort_parcels(){
	//how do i use sort here?
}
int post::sort_letters(){
	//how do i use sort here?
}
post::post(){
    number_of_letters=rand()%50;
	number_of_parcels=rand()%50;
	pLetters=new letter*[number_of_letters];
	for(int i=0;i<number_of_letters;i++){
		pLetters[i]=new letter;}
	pParcels=new parcel*[number_of_parcels];
	for(int i=0;i<number_of_parcels;i++){
		pParcels[i]=new parcel;}
	//Here i want to sort LETTERS and PARCELS regarding their adress
	//Would it be easier if i used vectors of parcel-letter instead of pointer-to-pointer ?
//--------------------------------------------------------------------------------------------------------------------
//In post::post, Shouldn't you have used srand() first ?

You said you want to use sort() int sort_parcels() and sort_letters().... Under what criteria do you want to sort? is is alphabetically, or accoding to date
dropped or somehting else?
In general, you need to throw MORE light on this question before I can help you!!

I want to sort them according to adress.

Edited 7 Years Ago by kavourdoukos: n/a

This article has been dead for over six months. Start a new discussion instead.