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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#include <iostream>
#include <cmath>
using namespace std;
class Pair {
private:
double left;
double right;
public:
Pair() {left = 0; right = 0;}
Pair(double l, double r) {left = l; right = r;}
void set_left(double n) {left = n;}
void set_right(double n) {right = n;}
double get_left() const {return left;}
double get_right() const {return right;}
virtual void print() const {
cout << "(" << get_left() << "," << get_right() << ")" << endl;}
};
class Point: public Pair {
public:
Point():Pair() {};
Point(double x, double y):Pair(x,y) {};
void set_abc(int x) {set_left(x);}
void set_ord(int y) {set_right(y);}
double get_abc() {return get_left();}
double get_ord() {return get_right();}
virtual void print() const {
cout << "(" << get_left() << "," << get_right() << ")" << endl;}
};
template <class C, int I>
class Pille
{
private:
typedef struct pille_node
{
C * elem;
struct pille_node * next;
} Pille_node, * Pille_node_ptr;
Pille_node_ptr pille;
public:
Pille() {pille = NULL;}
int count;
virtual C pop(){
if (pille == NULL) {cout << " Pille vide " << endl;}
else {Pille_node_ptr aux = pille;
pille = pille -> next;
delete aux;
}
};
void push(C& i)
{
Pille_node_ptr aux = new Pille_node;
aux -> elem = &i;
aux -> next = pille;
pille = aux;
}
virtual void printpille() const
{
Pille_node_ptr aux = pille;
while (aux != NULL)
{aux -> elem -> print();
aux = aux -> next;}
}
};
int main()
{
int j = 1;
int k = 1;
int l = 1;
int a, b;
int x, y;
int count = 1;
Pille<Pair, 10> pp;
while (j != 0) {
cout << " Voulez-vous insérer ou éliminer un object da pille? " << endl;
cout << " 1. Insérer " << endl;
cout << " 2. Éliminer " << endl;
cout << " 0. Sortie " << endl;
cin >> j;
if (j == 1) {
cout << " Chosis l'object que vous voulez insérer: " <<endl; cout << " 1. Object de la class Pair " << endl;
cout << " 2. Object de la class Point " << endl;
cout << " 0. Sortie" << endl;
cin >> k;
switch(k) {
case 1: {cout << " Introduit l'élément gauche: ";
cin >> a;
cout << " Introduit ´l'élément droite: ";
cin >> b;
Pair p(a,b);
pp.push(p);
count = count++;
pp.printpille();
cout << "Pour continuer presse dans une touche númerique ";
cin >> l;
break;}
case 2: {cout << " Introduit l'abcisse du point: ";
cin >> x;
cout << " Introduit l'ordénné du point: ";
cin >> y;
Point p(x,y);
pp.push(p);Pour continuer presse dans une touche númerique ";
count = count++;
pp.printpille();
cout << "
cin >> l;
break;}
j=0;
}}
if (j == 2) {pp.pop(); pp.printpille(); count=count--;break;j=0;}
if (j == 0) {cout << "Merci" << endl;}
}
}; |
Partager