Programmation Liste 1
LA PROGRAMMATION
Elle consiste à expliquer en détails à l'ordinateur ce qu'il doit faire dans un langage qu'il comprend.
Ces exercices viennent en complément au cours d'initiation à la programmation. ils s'adressent aux élèves de la 2eC de l'ISCA.
Le langage utilisé s'appelle : SMALL BASIC. On peut télécharger gratuitement le logiciel sur le Net. Pour les élèves de l'Isca, il est déjà téléchargé dans les ordinateurs de la salle informatique. Il y aura plusieurs listes.
Attention ! il ne faut pas taper les titres : Programe 1, Programme 2, etc., ni les tirets qui séparent les codes. Bonne Pratique !
PROGRAMME N°1
'Programme qui affiche BONJOUR 10 fois
For i = 1 To 10
TextWindow.WriteLine("BONJOUR ")
EndFor
---------------------------------------------------
PROGRAMME N°2
'--Programme qui compte de 1 à 20 sur une ligne
For i = 1 To 20
TextWindow.Write(i)
EndFor
----------------------------------------------------
PROGRAMME N°3
'--Programme qui compte de 1 à 20 avec une virgule qui sépare
For i = 1 To 20
TextWindow.Write(i +", ")
EndFor
----------------------------------------------------
PROGRAMME N°4
'--Programme comptant de 1 à 20 en colonne
For i = 1 To 20
TextWindow.WriteLine(i)
EndFor
----------------------------------------------------
PROGRAMME N°5
'--Programme comptant de 1 à 5
For i = 1 To 5
TextWindow.WriteLine("Ligne "+i)
For j = 1 To 10
TextWindow.Write(j + " ")
EndFor
TextWindow.WriteLine(" ")
EndFor
----------------------------------------------------
PROGRAMME N°6
'--Programme comptant de 1 à 10 cinq fois
For i = 1 To 5
TextWindow.WriteLine("Ligne "+i)
For j = 1 To 10
TextWindow.Write(j + " ")
EndFor
TextWindow.WriteLine("") 'On saute deux lignes à l'écran
TextWindow.WriteLine("")
EndFor
--------------------------------------------------------
PROGRAMME N°7
'--Programme : Table de multiplication par 7
For i = 1 To 10
TextWindow.WriteLine(7 + " X "+ i + " = "+ i*7)
EndFor
----------------------------------------------------------
PROGRAMME N°8
'--Programme Portant sur les dimensions d'un champ rectangulaire
TextWindow.Write("Le Nom du Propriétaire du champ: ")
NomProp =TextWindow.Read()
TextWindow.Write("Longueur du champ : ")
LongCh = TextWindow.ReadNumber()
TextWindow.Write("Largeur du champ : ")
LargCh = TextWindow.ReadNumber()
DemiPéri = LongCh + LargCh
Périm = DemiPéri * 2
Surf = LongCh * LargCh
TextWindow.WriteLine("Le Démi-Périmètre est : " + DemiPéri)
TextWindow.WriteLine("Le Périmètre est : " + Périm)
TextWindow.WriteLine("La surface du champ : " + Surf)
TextWindow.WriteLine("Nom du Propriétaire : " + NomProp)
----------------------------------------------------------------
PROGRAMME N°9
'-Programme qui calcule la surface d'un rectangle
'saisie des données
TextWindow.WriteLine("CALCUL DE LA SURFACE D'UN RECTANGLE ")
TextWindow.Write("Quelle est la longueur du rectangle ? : ")
Longueur = TextWindow.ReadNumber()
TextWindow.Write("Quelle est la largeur du rectangle ? : ")
Largeur = TextWindow.ReadNumber()
'Calcul
Surface = Longueur * Largeur
'Affichage des résultats
TextWindow.WriteLine("La surface du rectangle est : "+ Surface)
'Fin du programme
------------------------------------------------------------------
PROGRAMME N°10
'-Programme qui calcule la surface d'un rectangle
'--------------------------------------------------------------
'Auteur : Frère ZADI Roger, Dir., Isca
Début:
TextWindow.Clear() 'Efface l'écran
'saisie des données
TextWindow.WriteLine("CALCUL DE LA SURFACE D'UN RECTANGLE ")
TextWindow.Write("Quelle est la longueur du rectangle ? : ")
Longueur = TextWindow.ReadNumber()
TextWindow.Write("Quelle est la largeur du rectangle ? : ")
Largeur = TextWindow.ReadNumber()
'Contrôle des données
If Largeur>=Longueur Then
TextWindow.Writeline("Erreur ! la longueur doit être supérieure !")
TextWindow.Pause() 'Arrêt momentané
Goto Début
Else
Surface = Longueur * Largeur
EndIf
'Affichage des résultats
TextWindow.WriteLine("La surface du rectangle est : "+ Surface)
'Nouvelles données
TextWindow.Write("Voulez-Vous continuer ? (1 = OUI ou 0 = NON) : ")
Continuer = TextWindow.ReadNumber()
If Continuer = 1 Then
Goto Début
Else
TextWindow.Writeline("Au revoir... et à bientôt ! ")
EndIf
'Fin du programme
---------------------------------------------------------------------
PROGRAMME N°11
'-Programme qui calcule la surface d'un rectangle
'--------------------------------------------------------------
'Auteur : Frère ZADI Roger, Dir., Isca
Début:
TextWindow.Clear() 'Efface l'écran
'saisie des données
TextWindow.backgroundColor = "DarkBlue" 'Couleur de fond en bleu foncé
TextWindow.WriteLine("CALCUL DE LA SURFACE D'UN RECTANGLE ")
TextWindow.Write("Quelle est la longueur du rectangle ? : ")
Longueur = TextWindow.ReadNumber()
TextWindow.Write("Quelle est la largeur du rectangle ? : ")
Largeur = TextWindow.ReadNumber()
'Contrôle des données
If Largeur>=Longueur Then
TextWindow.ForegroundColor="yellow"
TextWindow.Writeline("Erreur ! la longueur doit être supérieure !")
TextWindow.Pause() 'Arrêt momentané
Goto Début
Else
Surface = Longueur * Largeur
EndIf
'Affichage des résultats
textWindow.ForegroundColor="yellow"
TextWindow.WriteLine("La surface du rectangle est : "+ Surface)
'Nouvelles données
'extWindow.ForegroundColor="Red" 'Couleur texte en rouge
TextWindow.Write("Voulez-Vous continuer ? (1 = OUI ou 0 = NON) : ")
Continuer = TextWindow.ReadNumber()
If Continuer = 1 Then
Goto Début
Else
textWindow.ForegroundColor="yellow"
TextWindow.Writeline("Au revoir... et à bientôt ! ")
EndIf
--------------------------------------------------------------------
PROGRAMME N°12
'-- Programme: Calcul de Moyenne dans une matière
'Saisie des données au clavier
TextWindow.Write("Quelle Matière ?: ")
NomMat = TextWindow.Read()
TextWindow.Write("Note 1 : ")
N1 = TextWindow.ReadNumber()
TextWindow.Write("Note 2 :")
N2 = TextWindow.ReadNumber()
TextWindow.Write("Note 3 : ")
N3 = TextWindow.ReadNumber()
TextWindow.Write("Note 4 : ")
N4 = TextWindow.ReadNumber()
TextWindow.Write("Note 5 :")
N5 = TextWindow.ReadNumber()
'Calcul des données saisies au clavier
TotalN = N1 + N2 + N3 + N4 + N5
MoyMat = TotalN/5
TextWindow.Clear() 'On efface l'écran
'Affichage à l'écran des résultats
TextWindow.Writeline("Nom de la Matière: " + NomMat)
TextWindow.WriteLine("Le Total des 5 notes est : " + TotalN)
TextWindow.WriteLine("La Moyenne est : " + MoyMat)
'-- Fin du programme
------------------------------------------------------------------
PROGRAMME N°13
'--Programme Passage en classe supérieure
'Auteur: fr. Zadi Roger, Dir., Isca
'Saisie de l'identité de l'élève
TextWindow.Write("Nom de l'Elève : ")
NomEl = textwindow.Read()
TextWindow.Write("Prénom de l'Elève : ")
PrénomEl = textwindow.Read()
TextWindow.Write("Classe : ")
Clas = TextWindow.Read()
TextWindow.Write("Moyenne Générale Annuelle : ")
MGA = TextWindow.ReadNumber()
'Test pour une décision
If MGA >= 10.0 Then
Résultat = "Admis sur coup "
ElseIf MGA >=9.50 then
Résultat = "Repêché"
Elseif MGA >= 8.50 then
Résultat = "Redouble"
else
Résultat = "Renvoyé"
EndIf
'Affichage des données
TextWindow.Clear() 'On efface l'écran
TextWindow.WriteLine("IDENTITE DU CANDIDAT")
TextWindow.WriteLine("--------------------")
TextWindow.WriteLine("") 'on saute une ligne à l'écran
TextWindow.Writeline("Nom et Prénoms : " + NomEl+" "+PrénomEl)
TextWindow.WriteLine("Classe : "+ Clas)
TextWindow.WriteLine("MGA : " + MGA)
TextWindow.WriteLine("Décision : " + Résultat)
--------------------------------------------------------------------------
PROGRAMME N°14
'--Programme Passage en classe supérieure
'Auteur: fr. Zadi Roger, Dir., Isca
'Appel du Sous-Programme TrouveCode
TrouveCode()
If CodeTrouvé ="Faux" then
Goto Erreur
endif
Début:
TextWindow.Clear() 'On efface l'écran
'Saisie de l'identité de l'élève
TextWindow.Write("Nom de l'Elève : ")
NomEl = textwindow.Read()
TextWindow.Write("Prénom de l'Elève : ")
PrénomEl = textwindow.Read()
TextWindow.Write("Classe : ")
Clas = TextWindow.Read()
TextWindow.Write("Moyenne Générale Annuelle : ")
MGA = TextWindow.ReadNumber()
'Appel du Sous-Programme Décision
Décision()
'Affichage des données
TextWindow.Clear() 'On efface l'écran
TextWindow.WriteLine("IDENTITE DU CANDIDAT")
TextWindow.WriteLine("--------------------")
TextWindow.WriteLine("") 'on saute une ligne à l'écran
TextWindow.Writeline("Nom et Prénoms : " + NomEl+" "+PrénomEl)
TextWindow.WriteLine("Classe : "+ Clas)
TextWindow.WriteLine("MGA : " + MGA)
TextWindow.WriteLine("Décision : " + Résultat)
'Relancer le programme
TextWindow.Write("Voulez-Vous continuer ? (1 ou 0) : ")
Continuer = TextWindow.ReadNumber()
If Continuer = 1 Then
Goto Début
Else
Goto Fin
EndIf
Sub TrouveCode
TextWindow.Write("CODE : ")
Code = TextWindow.Read()
If Code <> "SEMPER" Then
CodeTrouvé ="Faux"
endif
EndSub
Sub Décision
'Test pour une décision
If MGA >= 10.0 Then
Résultat = "Admis sur coup "
ElseIf MGA >=9.50 then
Résultat = "Repêché"
Elseif MGA >= 8.50 then
Résultat = "Redouble"
else
Résultat = "Renvoyé"
EndIf
EndSub
Erreur:
TextWindow.ForegroundColor="yellow"
TextWindow.WriteLine("Code erroné !")
TextWindow.WriteLine("Le Programme sera fermé !")
TextWindow.ForegroundColor="white"
TextWindow.Pause()
Goto Fin
Fin:
TextWindow.WriteLine("") ' On saute une ligne
TextWindow.ForegroundColor="red"
TextWindow.WriteLine("Aurevoir .... et à bientôt !")
TextWindow.ForegroundColor="white"
-----------------------------------------------------------------------
PROGRAMME N°15
'Programme Couleurs
TextWindow.ForegroundColor="d0arkred"
TextWindow.WriteLine("Bonjour Frère")
-----------------------------------------------------------------------
PROGRAMME N°16
--Programme Enregistrer une liste de 5 noms
'Enregistrement
For i = 1 To 5
TextWindow.Write("Nom "+ i+ " :")
Nom[i]=TextWindow.Read()
EndFor
'Affichage des 5 noms
TextWindow.WriteLine("")
TextWindow.WriteLine("AFFICHAGE DE LA LISTE DES CINQ NOMS")
For i = 1 To 5
TextWindow.Writeline(nom[i])
EndFor
--------------------------------------------------------------------------
PROGRAMME N°17
'Programme : Calcul de la moyenne de 5 notes
'Saisie des notes
TextWindow.WriteLine("SAISIE DES NOTES")
For i = 1 To 5
Reprise : 'Reprendre ici en cas d'erreur
TextWindow.Write("Note " + i + ": ")
Note[i] = TextWindow.ReadNumber()
if Note[i]<0 or Note[i]>20 Then
TextWindow.WriteLine("Erreur de saisie !")
TextWindow.WriteLine("Tape une note entre 0 et 20")
TextWindow.WriteLine("")
Goto Reprise
Endif
EndFor
'Calcul des notes
For i = 1 To 5
Total = Total + Note[i] 'Total des 5 notes saisies
EndFor
Moy = total/5 'Moyenne des 5 notes
'Affichage des données
TextWindow.WriteLine("")
TextWindow.WriteLine("RESULTATS OBTENUS")
TextWindow.WriteLine("Total : " + Total)
textWindow.WriteLine("Moyenne : " + Moy)
------------------------------------------------------------------------------
PROGRAMME N°18
'Programme : Calcul de la moyenne de 5 notes
'Saisie des notes
TextWindow.WriteLine("SAISIE DES NOTES")
For i = 1 To 5
Reprise : 'Reprendre ici en cas d'erreur
TextWindow.Write("Note " + i + ": ")
Note[i] = TextWindow.ReadNumber()
if Note[i]<0 or Note[i]>20 Then
TextWindow.WriteLine("Erreur de saisie !")
TextWindow.WriteLine("Tape une note entre 0 et 20")
TextWindow.WriteLine("")
Goto Reprise
Endif
EndFor
'Calcul des notes
For i = 1 To 5
Total = Total + Note[i] 'Total des 5 notes saisies
EndFor
Moy = total/5 'Moyenne des 5 notes
'Affichage des données
TextWindow.WriteLine("")
TextWindow.WriteLine("RESULTATS OBTENUS")
TextWindow.WriteLine("Total : " + Total)
textWindow.WriteLine("Moyenne : " + Moy)
--------------------------------------------------------------------------------
PROGRAMME N°19
'--Programme : Table de multiplication de 1 à 5
For i = 1 To 5
For j = 1 To 10
TextWindow.WriteLine(i + " X "+ j + " = "+ i*j)
EndFor
TextWindow.WriteLine(" ")
TextWindow.WriteLine(" ")
endfor
---------------------------------------------------------------------------------
PROGRAMME N°20
'--Programme commercial
TextWindow.Write("Quel est ton nom ?: ")
MonNom = TextWindow.Read()
TextWindow.Write("Quel estle prix Hors Taxte de l'article ? : ")
PrixHT = TextWindow.ReadNumber()
TextWindow.WriteLine("Ton nom est : " + MonNom)
TextWindow.WriteLine("Le prix hors taxe est : " + PrixHT)
---------------------------------------------------------------------------------
PROGRAMME N°21
'--Programme Dire bonjour 10 fois
Tour = 10
While Tour > 0
TextWindow.WriteLine("Bonjour, amis iscadiens ! ")
Tour = Tour - 1 'il faut réduire la variable à chaque fois
EndWhile
TextWindow.WriteLine("")
TextWindow.WriteLine("Après avoir compté, je suis en dehors de la boucle.")
---------------------------------------------------------------------------------
PROGRAMME N°22
'--Programme EnregistrerClients
Nom="P"
While Nom <> ""
TextWindow.WriteLine("Tape un nom vide pour quitter la boucle.")
TextWindow.Write("Nom : ")
Nom = TextWindow.Read()
TextWindow.Write("Prénom : ")
Prénom = TextWindow.Read()
TextWindow.WriteLine("") 'on saute une ligne à l'écran
EndWhile
TextWindow.WriteLine("AUREVOIR MON AMI ! ET A BIENTOT...")
------------------------------------------------------------------------------
PROGRAMME N°23
'--Programme Trouver le nombre magique
TextWindow.Clear()
Réponse = "Z"
While Réponse <>""
NombreMagic = Math.GetRandomNumber(100) ' Entre 1 et 100
For i = 1 To 10
Tour = Tour +1 'Compter le nombre de tours
TextWindow.Write("Quel est le nombre magique ?: ")
NombreSaisi = TextWindow.ReadNumber()
' On compare le nombre saisi au nombre aléatoire dit magique
If NombreSaisi > NombreMagic Then
TextWindow.WriteLine("Le Nombre magique est plus petit")
ElseIf NombreSaisi < NombreMagic then
TextWindow.WriteLine("Le Nombre magique est plus grand")
Else
TextWindow.WriteLine("") 'On saute une ligne à l'écran
TextWindow.ForegroundColor="Yellow"
TextWindow.WriteLine("BRAVO ! Tu as gagné en " + Tour +" Tours")
Goto Suite 'On sort de la boucle For en cas de réponse juste
EndIf
EndFor 'Fin de la boucle For
'Après 10 tours, le jeu peut reprendre
Suite :
TextWindow.Write("Continuez ? (O = oui / Enter pour quitter : ")
Réponse = TextWindow.Read()
TextWindow.Clear()
EndWhile 'Fin de la boucle While
TextWindow.WriteLine("AU REVOIR, MON AMI ! ")
--------------------------------------------------------------------------------