Vous êtes sur la page 1sur 17

Compte Rendu TP1

Ex1:
Main.cpp:
#include <iostream>
#include "Notes.h"

using namespace std;

int main()
{
Notes N1(10, 12, 15, 11, 17, 9.5);
Notes N2(11.5, 13, 18, 10, 12.5);

float moyenne1 = N1.calculMoyenne();


float moyenne2 = N2.calculMoyenne();

if (moyenne1 > moyenne2) {


cout << "La moyenne la plus grande est la moyenne1 : " << moyenne1 << endl;
} else {
cout << "La moyenne la plus grande est la moyenne2 : " << moyenne2 << endl;
}

return 0;
}
Notes.h:
#ifndef NOTES_H
#define NOTES_H

class Notes {
private:
float test1;
float test2;
float DS;
float Examen;
float orale;
float TP;
bool avecTP;
float calculNCC();

public:
Notes();
Notes(float ,float ,float ,float ,float ,float );
Notes(float ,float ,float ,float ,float );
float calculMoyenne();

};

#endif
Notes.cpp:
#include <iostream>
#include "Notes.h"

using namespace std;


Notes::Notes() {
test1 = 0;
test2 = 0;
DS = 0;
Examen = 0;
orale = 0;
TP = 0;
avecTP = true;
}

Notes::Notes(float a,float b,float c,float d,float e,float f)


{
test1 = a;
test2 = b;
DS = c;
Examen = d;
orale = e;
TP = f;
avecTP = true;
}
Notes::Notes(float a,float b,float c,float d,float e)
{
test1 = a;
test2 = b;
DS = c;
Examen = d;
orale = e;
avecTP = false;
}
float Notes::calculNCC()
{
return (test1 + test2 + orale + 2 * DS) / 5;
}
float Notes::calculMoyenne()
{
float NCC = calculNCC();
if (avecTP) {
return 0.3 * NCC + 0.2 * TP + 0.4 * Examen;
} else {
return 0.4 * NCC + 0.6 * Examen;
}
}

Execution:

Ex2:
main.cpp:
#include <iostream>
#include "compte.h"

using namespace std;

int main()
{
Compte compte(6001, "BEN SALEH MOHAMED", 850.175);
compte.consulterSolde();
compte.deposerArgent(100);
compte.consulterSolde();
if (compte.retirerArgent(980))
{
compte.consulterSolde();
}
else
{
cout << "Le solde est insuffisant pour effectuer ce retrait." << endl;
}

return 0;
}
compte.h:
#ifndef COMPTE_H
#define COMPTE_H

#include <string>
using namespace std;

class Compte
{
private:
int numCompte;
string nomProprietaire;
double solde;
public:
Compte();
Compte(int numCompte,string nomProprietaire,double solde);
bool retirerArgent(double montant);
void deposerArgent(double montant);
void consulterSolde();

};

#endif
compte.cpp:
#include <iostream>
#include "compte.h"
using namespace std;

Compte::Compte()
{
numCompte = 0 ;
nomProprietaire = "" ;
solde = 0 ;
}
Compte::Compte(int numCompte,string nomProprietaire,double solde)
{
this->numCompte = numCompte ;
this->nomProprietaire = nomProprietaire ;
this->solde = solde ;
}
bool Compte::retirerArgent(double montant)
{
if(montant>solde){
return false;
}
else{solde -= montant; return true;}
}
void Compte::deposerArgent(double montant)
{
solde += montant;
}
void Compte::consulterSolde(){
cout << solde << endl;
}
Execution:
Ex3:
Main.cpp:
#include <iostream>
#include "Bouteille.h"
using namespace std;

int main()
{
Bouteille B1(200);
Bouteille B2(100);
Verre v(30);
cout<<v.getQuantite()<<endl;
B1.ouvrir();
B1.verser_dans(v,25);
B2.ouvrir();
B2.verser_dans(v,5);
cout<<v.getQuantite()<<endl;
v.boire(v.getQuantite());
cout<<v.getQuantite()<<endl;
return 0;
}
Verre.h:
#include <iostream>

class Verre
{
private:
int contenance;
int quantite;
public:
Verre(int contenance);
void remplir(int add);
void boire(int mince);
int getQuantite();

};
Verre.cpp:
#include "Verre.h"

// Verre::Verre(int contenance):quantite(0)
// {
// this->contenance = contenance;
// }
Verre::Verre(int contenance) : quantite(0) {
this->contenance = contenance;
}
void Verre::remplir(int add){
if (quantite + add <= contenance) {
quantite += add;
} else {
quantite = contenance;
}
}
void Verre::boire(int mince){
if(quantite>mince)
{
quantite-=mince;
}
else
{
quantite=0;
}
}

int Verre::getQuantite() {
return quantite;
}

Bouteille.h:
#include <iostream>
#include "Verre.h"

class Bouteille
{
private:
int quantite;
bool estOuverte;
public:
Bouteille (int quantite);
void ouvrir ();
void fermer ();
void verser_dans (Verre & verre, int q);
int getQuantite ();
bool Open ();
};
Bouteille.cpp:
#include "Bouteille.h"

Bouteille::Bouteille(int quantite):estOuverte(false)
{
this->quantite = quantite;
}
void Bouteille::ouvrir()
{
estOuverte = true;
}
void Bouteille::fermer()
{
estOuverte = false;
}

void Bouteille::verser_dans(Verre &verre, int q)


{
if(estOuverte && quantite - q >=0)
{
verre.remplir(q);
quantite -=q;
}
}

int Bouteille::getQuantite(){
return quantite;
}
bool Bouteille::Open() {
return estOuverte;
}
Execution:
Ex4:
Main.cpp:
#include <iostream>
#include "Etudiant.h"

using namespace std;

int main()
{
Etudiant e1,e2;
e1.saisir();
e1.afficher();
e2.saisir();
e2.afficher();
std::cout << "La moyenne de l'étudiant 1 est : " << e1.moyenne() << std::endl;
std::cout << "La moyenne de l'étudiant 2 est : " << e2.moyenne() << std::endl;
if (e1.admis())
{
std::cout << "L'étudiant 1 est admis." << std::endl;
}
else
{
std::cout << "L'étudiant n'est pas admis." <<std::endl;
}
if (e2.admis())
{
std::cout << "L'étudiant 2 est admis." << std::endl;
}
else
{
std::cout << "L'étudiant n'est pas admis." <<std::endl;
}
cout<<e1.exae_quo(e2)<<endl;;

return 0;
}
Etudiant.h:
#include <iostream>
#include <string>

using namespace std;


class Etudiant
{
private:
string nom;
string prenom;
float tab_notes[10];
public:
Etudiant();
Etudiant(string nom, string prenom);
void saisir();
void afficher();
float moyenne();
bool admis();
int exae_quo(Etudiant E);
};
Etudiant.cpp:
#include <iostream>
#include "Etudiant.h"
#include <string>

using namespace std;

Etudiant::Etudiant() {}
Etudiant::Etudiant(string nom, string prenom) {
this->nom = nom;
this->prenom = prenom;
for (int i = 0; i < 3; i++)
{
tab_notes[i] = 0;
}
}
void Etudiant::saisir()
{
cin>>nom;
cin>>prenom;
for (int i = 0; i < 3; i++)
{
cin>>tab_notes[i];
}
}
void Etudiant::afficher()
{
cout<<"nom:"<< nom<<"\n" <<endl;
cout<<"prenom:"<< prenom<<"\n" <<endl;
for (int i = 0; i < 3; i++)
{
cout<<tab_notes[i]<<"\t"<<endl;
}

}
float Etudiant::moyenne()
{
double som=0;
for (int i = 0; i < 3; i++)
{
som += tab_notes[i];
}
return som/3;
}

bool Etudiant::admis()
{
if(moyenne()>=10){return true;}
else return false;
}

int Etudiant::exae_quo(Etudiant E)
{
if(moyenne()>E.moyenne()){return -1;}
else if(moyenne()==E.moyenne()){return 0;}
else{return 1;}
}

Execution:

Vous aimerez peut-être aussi