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 135 136
| #include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#include <string> // => strcpy
#include "Dossier1.h"
void EffEcran(void);
void Pause(void);
int message::cpt_id_message = 0;
message::message (void)
{
num_id_message = 0;
adresse_expediteur = NULL;
adresse_destinataire = NULL;
urgent = false;
mess_lu = false;
sujet = NULL;
texte = NULL;
tmpCheckFormat = NULL;
}
message::message(int num, char *ad_exp, char *ad_dest, bool urg, bool msg_lu, char *sjt, char *txt, char *tmpCF)
{
int i=0;
num_id_message = num;
adresse_expediteur = new char [strlen(ad_exp)+1];
strcpy(adresse_expediteur,ad_exp);
adresse_destinataire = new char [strlen(ad_dest)+1];
strcpy(adresse_destinataire,ad_dest);
urgent = urg;
mess_lu = msg_lu;
sujet= new char [strlen(sjt)+1];
strcpy(sujet,sjt);
texte = new char [strlen(txt)+1];
strcpy(texte,txt);
tmpCheckFormat = new char [strlen(tmpCF)+1];
strcpy(tmpCheckFormat,tmpCF);
}
void message::affMessage (void)
{
int i=0;
EffEcran();
cout << "||================================================||" << endl;
cout << "||---------- Affiche un message ----------||" << endl;
cout << "||================================================||" << endl;
cout << "||* ID Message : " << num_id_message << endl;
cout << "||* Expediteur : " << adresse_expediteur << endl;
cout << "||* Destinataire : " << adresse_destinataire << endl;
cout << "||* Urgent : " << urgent << endl;
cout << "||* Lu : " << mess_lu << endl;
cout << "||* Sujet : " << sujet << endl;
cout << "||* Texte : " << texte << endl;
cout << "||================================================||" << endl;
}
void message::encMessage (void)
{
EffEcran();
int rep, i=0;
char choix1,choix2;
num_id_message=++cpt_id_message;
cout << "||================================================||" << endl;
cout << "||---------- Ecrire un message ----------||" << endl;
cout << "||================================================||" << endl;
cout << "||* Entrer l adresse expediteur : ";
fflush(stdin); cin >> tmpCheckFormat;
checkFormatMsg(); strcpy(adresse_expediteur,tmpCheckFormat);
cout << "||* Entrer l adresse destinataire : ";
fflush(stdin); cin >> tmpCheckFormat;
checkFormatMsg(); strcpy(adresse_destinataire,tmpCheckFormat);
cout << "||* Urgent : (1/0)";
cin >> rep; urgent=(rep == 1)?true:false;
cout << "|| Souhaitez-vous utiliser un message de type predefini ? (O/N)" << endl;
cout << "||=> "; cin >> choix1;
switch(choix1)
{
case 'O' : cout << "|| Souhaitez-vous envoyer un message d'(A)bsence ou de (F)elicitation ?"; cin >> choix2;
switch(choix2)
{
case 'A' :
strcpy(texte,"Je serai absent car : ");
strcpy(sujet,"ABSENCE pendant ");
/* Définition du TEXTE */
cout << "||* Quelle en est la raison ?\n||=> "; fflush(stdin); cin.getline(tmpCheckFormat,1000);
strcat(texte,tmpCheckFormat); // Réutilisation de la variable tmpCheckFormat comme variable temporaire pour la concaténation
strcat(texte," pour une duree de : ");
cout << "||* Pendant combien de temps ?\n||=> "; fflush(stdin); cin.getline(tmpCheckFormat,1000);
strcat(texte,tmpCheckFormat);
strcat(sujet,tmpCheckFormat);
break;
case 'F' :
strcpy(texte,"Sincere felicitation pour : ");
strcpy(sujet,"OCCASION pour ");
/* Définition du TEXTE */
cout << "|| Quelle est l'occasion ?\n||=> "; fflush(stdin); cin.getline(tmpCheckFormat,1000);
strcat(texte,tmpCheckFormat);
strcat(sujet,tmpCheckFormat);
cout << "|| Formule de politesse :\n||=> "; fflush(stdin); cin.getline(tmpCheckFormat,1000);
strcat(texte,tmpCheckFormat);
break;
}
break;
case 'N' : cout << "||* Sujet (max 100) : ";
fflush(stdin); cin.getline(sujet,100);
cout << "||* Texte (max 1000) : ";
fflush(stdin); cin.getline(texte,1000);
break;
}
cout << "||================================================||" << endl;
}
void message::checkFormatMsg (void)
{
int verif = 0;
char *result_cmp, arobat='@';
result_cmp = strchr(tmpCheckFormat,arobat);
while(result_cmp == NULL)
{
cout << "\n|| !!! L'adresse doit comporter un @ ! Recommencez !\n||=> ";
cin >> tmpCheckFormat;
result_cmp=strchr(tmpCheckFormat,arobat);
}
}
void EffEcran(void)
{
#ifdef _WIN32
system("CLS");
#else
printf("\033[2J");
#endif
} |
Partager