From 2ea7aa9fbafc4d56944f64c75aeb4c9e999b0ddc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolas=20M=2E=20Thi=C3=A9ry?= <nthiery@users.sf.net>
Date: Mon, 29 Sep 2014 01:26:05 +0200
Subject: [PATCH] WIMS: exercice avec plusieurs programmes, et logique
 implantee en local; WIMS recoit un unique gros fichier main.oef

---
 oef/Makefile                                  |  3 +
 oef/TODO                                      |  6 ++
 oef/footer.oef                                | 11 ++++
 oef/header.oef                                |  7 +++
 oef/main.oef                                  | 57 -------------------
 oef/programs/guess-output/Makefile            | 29 ++++++++++
 .../guess-output/function-factorial.cpp       | 17 ++++++
 oef/programs/guess-output/function-max.cpp    | 17 ++++++
 oef/programs/guess-output/if-semicolon.cpp    |  2 +-
 .../guess-output/loops-do-while-factorial.cpp | 18 ++++++
 .../guess-output/loops-for-factorial.cpp      | 17 ++++++
 .../guess-output/loops-while-factorial.cpp    | 18 ++++++
 .../guess-output/variables-assign.cpp         | 24 ++++++++
 .../guess-output/variables-factorial7.cpp     | 17 ++++++
 14 files changed, 185 insertions(+), 58 deletions(-)
 create mode 100644 oef/Makefile
 create mode 100644 oef/TODO
 create mode 100644 oef/footer.oef
 create mode 100644 oef/header.oef
 delete mode 100644 oef/main.oef
 create mode 100644 oef/programs/guess-output/Makefile
 create mode 100644 oef/programs/guess-output/function-factorial.cpp
 create mode 100644 oef/programs/guess-output/function-max.cpp
 create mode 100644 oef/programs/guess-output/loops-do-while-factorial.cpp
 create mode 100644 oef/programs/guess-output/loops-for-factorial.cpp
 create mode 100644 oef/programs/guess-output/loops-while-factorial.cpp
 create mode 100644 oef/programs/guess-output/variables-assign.cpp
 create mode 100644 oef/programs/guess-output/variables-factorial7.cpp

diff --git a/oef/Makefile b/oef/Makefile
new file mode 100644
index 0000000..5ccb5b8
--- /dev/null
+++ b/oef/Makefile
@@ -0,0 +1,3 @@
+main.oef: header.oef programs/guess-output/*.cpp footer.oef Makefile
+	cd programs/guess-output; make all.oef
+	cat header.oef programs/guess-output/all.oef footer.oef > main.oef
diff --git a/oef/TODO b/oef/TODO
new file mode 100644
index 0000000..3663d8d
--- /dev/null
+++ b/oef/TODO
@@ -0,0 +1,6 @@
+Randomization
+Implement all the logic in WIMS
+Onsite compilation and production of the output
+Support for various programming languages, based on file extension
+Selection of theme based on file prefix
+CSS style sheet for colored syntax highlighting
diff --git a/oef/footer.oef b/oef/footer.oef
new file mode 100644
index 0000000..a29f666
--- /dev/null
+++ b/oef/footer.oef
@@ -0,0 +1,11 @@
+\statement{
+<p>
+
+Quel affichage produit le programme C++ suivant? On donnera le
+résultat sur une seule ligne, les éléments étant séparés par des
+espaces.
+
+\special{expandlines \code}
+}
+
+\answer{}{\output}{type=text}
diff --git a/oef/header.oef b/oef/header.oef
new file mode 100644
index 0000000..8c79f1b
--- /dev/null
+++ b/oef/header.oef
@@ -0,0 +1,7 @@
+\title{Deviner l'affichage d'un programme C++}
+\description{Deviner l'affichage d'un programme C++}
+\language{fr}
+\niveau{U1}
+\author{Nicolas M. Thiéry}
+\email{Nicolas.Thiery@u-psud.fr}
+\format{html}
diff --git a/oef/main.oef b/oef/main.oef
deleted file mode 100644
index 4eec177..0000000
--- a/oef/main.oef
+++ /dev/null
@@ -1,57 +0,0 @@
-\title{Affichage d'un programme C++}
-\language{fr}
-\author{Nicolas M. Thiéry}
-\email{Nicolas.Thiery@u-psud.fr}
-\format{html}
-
-\text{programName=random(if-semicolon.cpp, function-max.cpp)}
-
-\text{code= \programName issametext if-semicolon.cpp ?
-#include <iostream>
-using namespace std;
-
-int main() {
-    int x = 1+2;
-    if ( x == 3 ); {
-        cout << "Bonjour!" << endl;
-    }
-    cout << "Au revoir." << endl;
-    return 0;
-}
-}
-
-\text{code= \programName issametext function-max.cpp ?
-#include <iostream>
-using namespace std;
-
-float max(float a, float b) {
-    if ( a >= b ) {
-        return a;
-    } else {
-        return b;
-    }
-}
-
-int main() {
-    cout << max(1.0, 3.0) << endl;
-    cout << max(5.0, 2.0) << endl;
-    cout << max(2.0, 2.0) << endl;
-    return 0;
-}
-}
-
-\text{output=
-42
-}
-
-\statement{
-<p>
-On considère le programme C++ suivant:
-<hr>
-<pre>
-\special{expandlines \code}
-</pre>
-<hr>
-}
-
-\answer{Qu'affiche-t'il?}{\output}{type=text}
diff --git a/oef/programs/guess-output/Makefile b/oef/programs/guess-output/Makefile
new file mode 100644
index 0000000..9a9105e
--- /dev/null
+++ b/oef/programs/guess-output/Makefile
@@ -0,0 +1,29 @@
+PROGRAMS=$(wildcard *.cpp)
+HTML=$(PROGRAMS:%.cpp=%.html)
+OUTPUT=$(PROGRAMS:%.cpp=%.output)
+BASENAMES=$(PROGRAMS:%.cpp=%)
+
+all: $(OUTPUT) $(HTML) filelist
+
+%.output: %.bin
+	./$< > $@
+
+%.bin: %.cpp
+	g++ $< -o $@
+
+%.html: %.cpp
+	pygmentize -o $@ -O style=colorful $<  # ,linenos=1
+
+clean:
+	rm *.bin *.output *.html all.oef
+
+all.oef: Makefile $(OUTPUT) $(HTML)
+	echo "\\\\text{programName=random("`ls -m *.cpp`")}" > $@
+	for basename in $(BASENAMES); do \
+	    echo "\\\\text{code=\\programName issametext $$basename.cpp ?"; \
+	    cat $$basename.html; \
+	    echo "}"; \
+	    echo "\\\\text{output=\\programName issametext $$basename.cpp ?"; \
+	    cat $$basename.output; \
+	    echo "}"; \
+	done >> $@
diff --git a/oef/programs/guess-output/function-factorial.cpp b/oef/programs/guess-output/function-factorial.cpp
new file mode 100644
index 0000000..6d42c80
--- /dev/null
+++ b/oef/programs/guess-output/function-factorial.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+using namespace std;
+
+int factorielle(int n) {
+    int resultat = 1;
+    for ( int k = 1; k <= n; k++ ) {
+        resultat = resultat * k;
+    }
+    return resultat;
+}
+
+int main() {
+    int n;
+    n = 4;
+    cout << n << "! = " << factorielle(n) << endl;
+    return 0;
+}
diff --git a/oef/programs/guess-output/function-max.cpp b/oef/programs/guess-output/function-max.cpp
new file mode 100644
index 0000000..3fc83b7
--- /dev/null
+++ b/oef/programs/guess-output/function-max.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+using namespace std;
+
+float max(float a, float b) {
+    if ( a >= b ) {
+        return a;
+    } else {
+        return b;
+    }
+}
+
+int main() {
+    cout << max(1.0, 3.0) << endl;
+    cout << max(5.0, 2.0) << endl;
+    cout << max(2.0, 2.0) << endl;
+    return 0;
+}
diff --git a/oef/programs/guess-output/if-semicolon.cpp b/oef/programs/guess-output/if-semicolon.cpp
index cb0d8c8..14942a8 100644
--- a/oef/programs/guess-output/if-semicolon.cpp
+++ b/oef/programs/guess-output/if-semicolon.cpp
@@ -4,7 +4,7 @@ using namespace std;
 int main() {
     int x = 1+2;
     if ( x == 3 ); {
-	cout << "Bonjour!" << endl;
+        cout << "Bonjour!" << endl;
     }
     cout << "Au revoir." << endl;
     return 0;
diff --git a/oef/programs/guess-output/loops-do-while-factorial.cpp b/oef/programs/guess-output/loops-do-while-factorial.cpp
new file mode 100644
index 0000000..be80bf4
--- /dev/null
+++ b/oef/programs/guess-output/loops-do-while-factorial.cpp
@@ -0,0 +1,18 @@
+#include <iostream>
+using namespace std;
+
+int main() {
+    int n, resultat;
+
+    n = 4;
+    resultat = 1;
+
+    do {
+        resultat = resultat * n;
+        n = n - 1;
+    } while (n > 0);
+
+    cout << resultat << endl;
+
+    return 0;
+}
diff --git a/oef/programs/guess-output/loops-for-factorial.cpp b/oef/programs/guess-output/loops-for-factorial.cpp
new file mode 100644
index 0000000..d6b9606
--- /dev/null
+++ b/oef/programs/guess-output/loops-for-factorial.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+using namespace std;
+
+int main() {
+    int n, resultat;
+
+    n=5;
+    resultat = 1;
+
+    for ( int k = 1; k <= n; k++ ) {
+        resultat = resultat * k;
+    }
+
+    cout << resultat << endl;
+
+    return 0;
+}
diff --git a/oef/programs/guess-output/loops-while-factorial.cpp b/oef/programs/guess-output/loops-while-factorial.cpp
new file mode 100644
index 0000000..51cf67b
--- /dev/null
+++ b/oef/programs/guess-output/loops-while-factorial.cpp
@@ -0,0 +1,18 @@
+#include <iostream>
+using namespace std;
+
+int main() {
+    int n, resultat;
+
+    n = 3;
+    resultat = 1;
+
+    while (n > 0) {
+        resultat = resultat * n;
+        n = n - 1;
+    }
+
+    cout << resultat << endl;
+
+    return 0;
+}
diff --git a/oef/programs/guess-output/variables-assign.cpp b/oef/programs/guess-output/variables-assign.cpp
new file mode 100644
index 0000000..770df1d
--- /dev/null
+++ b/oef/programs/guess-output/variables-assign.cpp
@@ -0,0 +1,24 @@
+#include <iostream>
+using namespace std;
+
+int main() {
+    int a, b, c, d;
+    a = 0;
+    b = 0;
+    c = 0;
+    d = 0;
+
+    cout << a << " " << b << " " << c << " " << d << endl;
+    a = 1;
+    cout << a << " " << b << " " << c << " " << d << endl;
+    b = 3;
+    cout << a << " " << b << " " << c << " " << d << endl;
+    a + b;
+    cout << a << " " << b << " " << c << " " << d << endl;
+    a - b;
+    cout << a << " " << b << " " << c << " " << d << endl;
+    a = a + 2 * b;
+    cout << a << " " << b << " " << c << " " << d << endl;
+    c + b;
+    cout << a << " " << b << " " << c << " " << d << endl;
+}
diff --git a/oef/programs/guess-output/variables-factorial7.cpp b/oef/programs/guess-output/variables-factorial7.cpp
new file mode 100644
index 0000000..36d920e
--- /dev/null
+++ b/oef/programs/guess-output/variables-factorial7.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+using namespace std;
+
+int main() {
+    int resultat = 1;
+
+    resultat = resultat * 2;
+    resultat = resultat * 3;
+    resultat = resultat * 4;
+    resultat = resultat * 5;
+    resultat = resultat * 6;
+    resultat = resultat * 7;
+
+    cout << "Factorielle 7 vaut " << resultat << endl;
+
+    return 0;
+}
-- 
GitLab