diff --git a/oef/Makefile b/oef/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5ccb5b8f9ed5fd39b50516eb293cd89a06c21fec --- /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 0000000000000000000000000000000000000000..3663d8d9569ca04ac3969a05bdbb36df9c704b84 --- /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 0000000000000000000000000000000000000000..a29f666fd51acf1bed7848f1d778f007cc6e38c0 --- /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 0000000000000000000000000000000000000000..8c79f1b03af862b9446e99689eea11113a2f0c67 --- /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 4eec177a57256b1570da196e67e4da693ba96fb6..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..9a9105e0407a1014fe1ef42bc39532a77f91c80c --- /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 0000000000000000000000000000000000000000..6d42c80d46467bfec3e898e209495b0466a4dfad --- /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 0000000000000000000000000000000000000000..3fc83b7903597b8fe8d02422c6c9e09e9808b05f --- /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 cb0d8c855352cfe92b4c3460e7b7dae77d8c5e99..14942a8ad10b935948b346d051402ba0a4216aa5 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 0000000000000000000000000000000000000000..be80bf445ceeacdc62d26aec09c00402c6ab56d2 --- /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 0000000000000000000000000000000000000000..d6b960603aab458a80ddeacc8420151ef4d45b05 --- /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 0000000000000000000000000000000000000000..51cf67bd8ee41314bbf0432f030377bc47a50e5c --- /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 0000000000000000000000000000000000000000..770df1d380d8925617666c59c546ee3e7302774d --- /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 0000000000000000000000000000000000000000..36d920e599670301cc23e9743611c729d786b54b --- /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; +}