Exercice langage C: Programme essai
Créez un programme contenant:
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
|
#include
using namespace std;
#include
#include "swindow.h"
int main(int argc, char ** argv)
{
const int longueur = 300;
const int hauteur = 200;
const int rayon_max = 50;
SimpleWindow window("cercles", longueur, hauteur);
window.map();
// Remplit la fenetre en blanc:
window.color(1, 1, 1);
window.fill();
// Dessine en noir:
window.color(0, 0, 0);
window.drawCircle(longueur / 2, hauteur / 2, rayon_max);
window.show();
// Attend que l'utilisateur appuie sur une touche:
getchar();
return 0;
}
|
Comment modifier ce programme pour qu'il affiche plusieurs cercles, dont le centre et le rayon seront tirés au hasard ?
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
|
#include
using namespace std;
#include
#include "swindow.h"
int main(int argc, char ** argv)
{
const int longueur = 300;
const int hauteur = 200;
const int rayon_max = 50;
const int nbr_cercles = 20;
// Initialise le generateur de nombres aleatoires
srand(time(0));
SimpleWindow window("cercles", longueur, hauteur);
window.map();
// Remplit la fenetre en blanc:
window.color(1, 1, 1);
window.fill();
// Dessine en noir:
window.color(0, 0, 0);
for (int i=0; inbr_cercles; i++) {
// Tire les coordonnees et le rayon du cercle aleatoirement
int x = rand() % longueur;
int y = rand() % hauteur;
int rayon = rand() % rayon_max;
// Dessine un cercle
window.drawCircle(x, y, rayon);
}
window.show();
getchar();
return 0;
}
|