1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
//passing values from set to another one
# include <iostream.h>
# include <conio.h>
class DataType {
//create list
private:
int list;
public:
// constructor
DataType(){list=NULL;}
DataType(int z){list=z;}
int GetValue(){return list;}
};
class SetType {
private:
DataType list[3];
int index;
public:
void create(){index=-1;}
//add elements
void AddElement(DataType e){
if(index<3) list[++index]=e;}
//display elements
void display() {
for(int i=0; i<=index;i++)
cout<<list[i].GetValue()<<endl;}
//transport data from set to another
void assign(SetType e,SetType c){
for(int i=0; i<=index; i++) {
e.list[i]=c;}
}
};
void main() {
DataType e1(10), e2(20), e3(30);
SetType group1, group2;
group1.create();
group2.create();
group1.AddElement(e1);
group1.AddElement(e2);
group1.AddElement(e3);
group1.display();
group1.assign(group1,group2);
cout<<"----------------"<<endl;
group2.display();
getch();
} |
Partager