Parent directory
acceder au document
/*******************************************************************************
author: Pierre-Emmanuel Périllon
date: 30/05/2007
encoding: utf8
level: beginner+
langage: C++ (without class), comments in french
licence: Creative common by+nc+sa. see http://creativecommons.org/
website: http://tutorat.univ-lyon1.fr/
build: g++ -Wall if3_2004_janvier2.cpp -o out
********************************************************************************

PARTIE 2************************************************************************

Q1
*/

#include <iostream>
#include <string>

using namespace std;

typedef struct
{
float note;
float coef;
} Notation;

/**
* Q2 affectation & initialisation
*/
/*
Notation test;
test.note = 5.0f;
test.coef = 2.0f;
*/
/**
* Q3, on fixe la taille du tableau à 100
*/
Notation echantillon[100];

/**
* Q4,
*/

void setNotation(Notation tab[],
const int tailleTableau,
const int rang,
const float note,
const float coef )
{
int indice = rang -1;
if ( indice < 0 )
{
cout << "précondition sur rang echoue (min)." << endl;
}
else if ( indice >= tailleTableau )
{
cout << "précondition sur rang échoue (max)." << endl;
}
else
{
tab[indice].note = note;
tab[indice].coef = coef;
}
}

// setNotation( n , 100 , 3, 18.25 , 1.5 );

/*
* Q6, utilisation d'un passage par reference
*/

void saisieNotation( Notation & a )
{
cout << "note?" ;
cin >> a.note;
cout << "coef?";
cin >> a.coef;
cout << endl;
}


void saisieTableauNotation( Notation tab[], const int tailleTableau )
{
int i;
for ( i = 0 ; i < tailleTableau ; i++ )
{
cout << "(" << i + 1 << "/" << tailleTableau << ")" << endl;
saisieNotation( tab[i] );
}
}


/*
* Q7, toutes les notes sont sur la même échelle (toutes sur 20 ou 10)
*/

float moyennePonderee( Notation notes[], const int tailleTableau )
{
int i;
float cumulSomme = 0.0f;
float cumulCoef = 0.0f;

for ( i = 0 ; i < tailleTableau ; i++ )
{
cumulSomme += notes[i].coef * notes[i].note;
cumulCoef = cumulCoef + notes[i].coef;
}
return cumulSomme/cumulCoef;
}

/*
* Q8
*/
int main(){
Notation n[5];
saisieTableauNotation( n , 5 );

cout << "moyenne: " << moyennePonderee( n , 5 ) << endl << endl;
return 0;
}
acceder au document