SlideShare a Scribd company logo
Computer Science Class
Master SMA/STEU/GC/AMASONE
Lab and Homework 5
2015
General instruction for all lab
See resource Assignment in https://hippocampus.ec-nantes.fr ”Labs” section of M SMA PROLA
course for due date and delivery.
Your work is sources answering to exercises given below. They must be provided as individual
text files following naming convention of your subject. For each exercise a table, called ’requested
information table’ hereafter, sets precisely what is expected in terms of naming convention, precises
order of input data for the programs you create and output format of these programs results (see
chapter 4.4 for complete explanations). You are expected to upload an archive containing all your
work in resource Assignments of course ”Labs” section of Pedagogic server (no individual file will
be allowed)
An auto evaluation tool called auto eval.bash (see chapter 4.1, 4.2, and 4.3 for details) given
with this document, has to be used to generate this archive. It can also be used to auto evaluate
your archive before submission and check partially correctness of your work.
The same auto evaluation tool will be used by the teachers to evaluate your work.
Failure to return the sources archive on time on the server will result in a grade
of zero for this homework.
Uploading an archive with a wrong structure or name (i.e. archive not readable
or not named correctly) will result in a grade of zero for this homework.
Note : Some useful tricks are given in chapter 4.5.
1
1 Template function
In lab 1, the computation of π with a trapezoidal rule may be implemented using a rather general
function like it is proposed in the correction. It has been isolated in the given trapezoidal.cc and
trapezoidal.h files. In this implementation we see that trapez rule depends explicitly on unitCircle
(see the given trapezoidal.cc file). We want to expand trapez rule to make it compute the trapezoidal
rule of any user given function. For that you will use template programing.
1.1 Function object
A first simple solution is to add a 4th
argument to the initial function to pass a function object
(see course C6 slide 28). Follow the track :
1. Copy the given trapez rule in a trapTemplate.h (declaration), and trapTemplate imp.h (im-
plementation).
2. Change the name of the function to trapTemplate
3. Add a 4th
argument, that we can call func, to trapTemplate that will be a constant reference
to an object. This object func will be of generic type. You must transform trapTemplate into
a function template to have func generic.
4. This 4th
argument object will be considerer to have at least a
”double operator ()(const double &x)const”
method that take a ”double” as argument and return the result of the computation of f(x).
f is the function that this object represent. This is is the only requirement on generic type
of func. This kind of object are called ”function object”.
5. Use this func instance in the implementation in place of unitCircle calls. You will keep all
the algorithmic part from the original function unchanged.
6. To test the new trapTemplate template function you will first have to create in objFunc.cc
and declare in objFunc.h a set of object functions representing f corresponding to :
Name of the class/struct f(x) mathematical definition
unitCircleOF 4
√
1 − x2
lineOF x
trigoOF sin(15 × x) + cos(3 × x)
bilineOF
x ifx < 0.5
1 − x ifx 0.5
7. You must then test your work with the main program given in the file test trapTemplate.cc.
Whatever implementation you choose for these function and object functions, this program
should give the appropriate results without modification of test trapTemplate.cc source file.
Requested information
Files
trapTemplate.h, trapTemplate imp.h, objFunc.h, objFunc.cc
Input
Output
Scaling : 1/4
Here is the expected output :
2
Give number of interval
5
PI : 3.03705
ERRORPI : 0.0332773
LINE : 0.5
ERRORLINE : 0
TRIGO : 0.0580991
ERRORTRIGO : 0.646497
BILINE : 0.24
ERRORBILINE : 0.04
1.2 Generalisation to every arithmetic types
Imagine that we want to use another arithmetic or precision to compute the trapezoidal rule. Says
instead of ”double” real we want to use for example the Real type (from Lab 3). Generalization
of the initial trapez rule function is now not only related to the use of any f function but also to
the use of any arithmetic. Follow the track :
1. Copy the given trapez rule in a trapTemplateGeneral.h (declaration), and trapTemplateGen-
eral imp.h (implementation).
2. Change the name of the function to trapTemplateGeneral
3. Add a 4th
argument, that we can call func, to trapTemplateGeneral that will be a reference to
a function that takes one ”const double” reference as unique argument and returns a ”double”
(see course C3 slide 14 where you can replace pointers by references). The exact syntax is
the following :
”double (&func)(const double &)”
Use this func variable name (representing a function) in the implementation in place of
unitCircle calls. You will keep all the algorithmic part from the original function unchanged.
Note that this gives another solution than function objects and template functions to the
problem of treating any f user given function. You can do some partial tests. Normally if
you call this new function with unitCircle (and 0.,1.,n for first 3 arguments) you should get a
result approaching π.
4. Now continue the generalization by making trapTemplateGeneral a template function on the
arithmetic type used for the computation. Says your trapTemplateGeneral might be able
to integrate a function f dealing with int,float,double or . . . Modify all the implementation
according to this new template parameter representing generic arithmetic type.
5. To test the new trapTemplateGenaral function template you will first have to create in func.cc
and declare in func.h a set of function representing f corresponding to :
Name of the function f(x) mathematical definition Arithmetic
unitCircle (you can copy the version in trapezoidal.cc) 4
√
1 − x2 double
line x integer
trigo sin(15 × x) + cos(3 × x) double
biline
x ifx < 0.5
1 − x ifx 0.5
float
6. You must then test your work with the main program given in file test GtrapTemplate.cc.
Proceed step by step. First comment out all the tests and includes related to other arithmetics
than int, float and double. Test. If you are successful pass to the next step.
7. Starting from the given Starting Real1.h and Starting Real1.cc try now to compute the in-
tegral of a rline function in Real arithmetic. For that use now the full original version of
test GtrapTemplate.cc. Add a function rline to func.cc and func.h that does the same as
line but in Real arithmetic. Copy Starting Real1.h and Starting Real1.cc files in Real1.h and
Real1.cc respectively and try to compile. If it does not compile modify class Real so that
3
it fulfills trapTemplateGeneral,rline and ’test GtrapTemplate’ requirements. Whatever imple-
mentation you choose for trapTemplateGeneral function and testing functions, this program
should give the appropriate results without modification of test GtrapTemplate.cc source file.
Requested information
Files
trapTemplateGeneral.h, trapTemplateGeneral imp.h, func.h, func.cc,
Real1.cc, Real1.h
Input
Output
Scaling : 1/4
Here is the expected output :
Give number of interval
5
LINE : 0
BILINE : 0.24
ERRORBILINE : 0.04
PI : 3.03705
ERRORPI : 0.0332773
TRIGO : 0.0580991
ERRORTRIGO : 0.646497
RLINE : 0.5E40
ERRORRLINE : -0.41633363423443E-15
2 Template Class
For this exercise, you will come back to Matrix class created during the previous lab. A new
implementation design, based on the use of three member variables is now mandatory for this ex-
ercise (this is somehow a kind of mixing of Vector class into Matrix class). Those three members
define your matrix dimension(n), structure(index) and entries(rows). To avoid losing time on this
specific reshaping task a header file (Matrix.h) and an implementation file (Matrix.cc) give you
the corresponding implementation. In this version the use of Vector class has been completely
removed. The data members described above are now pointers to a standard array. Multiplication
matrix by a vector method is now rather artificial as it takes a pointer to ”double” for right hand
side argument. This doesn’t give a way to check the dimension consistency between matrix and
vector but simplifies the exercise (it is assumed that they are consistent). Compare to the previous
lab the friend ”<<” operator is also replaced by a display function to simplify the exercise. All the
other methods keep the same interface as the previous lab.
You must expand this class to make it a template class on the arithmetic your matrix works
on. Up to now you could only compute matrices with entries represented as ”double”. Change the
Matrix class so that it becomes a template class, in order to compute matrices with entries of any
number type. The objective is to test the new version of Matrix class with a class Complex that
you will have to reimplement (using files Starting Complex.cc and Starting Complex.h),
and with the class Real already defined in previous work.
Follow the track :
1. Implement your template version of Matrix class. You must start from the Matrix class de-
fined in Matrix.h, keeping all the interface functionalities unchanged and the number of mem-
bers unchanged. Store your declaration in MatrixTemplate.h. Then starting from Matrix.cc
4
do the appropriate modifications and put your implementation in MatrixTemplate imp.h.
Again you must not change the algorithms of Matrix.cc but only the necessary source part
to make Matrix class template.
2. Before any attempt to use special types as template parameter, test ”double” type template
parameter and verify that the results (computed values, output format) are the same as those
given by non template class. For that use test MatrixTemplate D.cc and test Matrix D.cc
to create programs to test the template and non template version respectively. Try your
programs with the same input. Using the following given data, you should get :
Double arithmetic
Input dimension of Matrix A :
3
Input total number of terms of row skyline storage for upper triangle part
of A (diagonal included) :
6
Input row of A
Input number of term of 0 row :
3
Input 0 term of 0 row :
1.
Input 1 term of 0 row :
2.
Input 2 term of 0 row :
3.
Input number of term of 1 row :
2
Input 0 term of 1 row :
4.
Input 1 term of 1 row :
5.
Input number of term of 2 row :
1
Input 0 term of 2 row :
6.
i j 0 1
DAij : 2
DAji : 2
Test copy constructor.
DCopyConstructor : [ [1, 2, 3], [4, 5], [6] ]
i j 0 1
DCij : 2
DCji : 2
Input total number of terms of row skyline storage for upper triangle part
of B (diagonal included) :
4
Input row of B
Input number of term of 0 row :
1
Input 0 term of 0 row :
4.
Input number of term of 1 row :
2
Input 0 term of 1 row :
7.
Input 1 term of 1 row :
5
-5.
Input number of term of 2 row :
1
Input 0 term of 2 row :
9.
Test addition.
DAddition : [ [5, 2, 3], [11], [15] ]
Input terms of V
Input term of 0 row :
1.
Input term of 1 row :
2.
Input term of 2 row :
3.
Test matrix vector.
DMultiplication : [14, 25, 31]
3. Then try Real class type with test MatrixTemplate R.cc. Start from the version you want
but put your work in the files Real2.cc and Real2.h. Normally, independently on how you
transform Matrix class, you should not be able to compile the program. Figure out what are
the problems, and avoid them by modifing Real class so that function member of template
class Matrix “works” without algorithmic modifications. If you don’t modify Real class and
you pass the compilation stage successfully, it means that you changed too much the initial
Matrix class. It certainly won’t do things the way the initial template free class Matrix did.
Please revert to the initial class and start again from this point.
Using test MatrixTemplate R.cc with the given data, you should get the following output :
Real arithmetic
Input dimension of Matrix A :
3
Input total number of terms of row skyline storage for upper triangle part
of A (diagonal included) :
6
Input row of A
Input number of term of 0 row :
3
Input 0 term of 0 row :
1.e+300
Input 1 term of 0 row :
2.e+300
Input 2 term of 0 row :
3.e+300
Input number of term of 1 row :
2
Input 0 term of 1 row :
4.e+300
Input 1 term of 1 row :
5.e+300
Input number of term of 2 row :
1
Input 0 term of 2 row :
6.e+300
i j 0 1
RAij : 0.2E301
RAji : 0.2E301
Test copy constructor.
6
RCopyConstructor : [ [0.1E301, 0.2E301, 0.3E301], [0.4E301, 0.5E301], [0.6E301] ]
i j 0 1
RCij : 0.2E301
RCji : 0.2E301
Input total number of terms of row skyline storage for upper triangle part
of B (diagonal included) :
4
Input row of B
Input number of term of 0 row :
1
Input 0 term of 0 row :
4.e+300
Input number of term of 1 row :
2
Input 0 term of 1 row :
7.e+300
Input 1 term of 1 row :
-5.e+300
Input number of term of 2 row :
1
Input 0 term of 2 row :
9.e+300
Test addition.
RAddition : [ [0.5E301, 0.2E301, 0.3E301], [0.11E302], [0.15E302] ]
Input terms of V
Input term of 0 row :
1.e+300
Input term of 1 row :
2.e+300
Input term of 2 row :
3.e+300
Test matrix vector.
RMultiplication : [0.14E602, 0.25E602, 0.31E602]
4. Finally, try Complex class type with test MatrixTemplate C.cc. Start by renaming Start-
ing Complex.cc and Starting Complex.h in Complex.cc and Complex.h respectively. You will
then have to analyze, and modify this proposed Complex class to make it work with your
template Matrix class.
Note that ”>>” input operator is not implemented in given files. You will have to implement
it by saying that an input of a Complex instance corresponds to two inputs of two real ”double
”.
Using test MatixTemplate C.cc with the given data, you should get the following output :
Complex arithmetic
Input dimension of Matrix A :
3
Input total number of terms of row skyline storage for upper triangle part
of A (diagonal included) :
6
Input row of A
Input number of term of 0 row :
3
Input 0 term of 0 row :
1. 0.
Input 1 term of 0 row :
7
2. 1.
Input 2 term of 0 row :
3. 2.
Input number of term of 1 row :
2
Input 0 term of 1 row :
4. 3.
Input 1 term of 1 row :
5. 4.
Input number of term of 2 row :
1
Input 0 term of 2 row :
6. 5.
i j 0 1
CAij : (2,1i)
CAji : (2,1i)
Test copy constructor.
CCopyConstructor : [ [(1,0i), (2,1i), (3,2i)], [(4,3i), (5,4i)], [(6,5i)] ]
i j 0 1
CCij : (2,1i)
CCji : (2,1i)
Input total number of terms of row skyline storage for upper triangle part
of B (diagonal included) :
4
Input row of B
Input number of term of 0 row :
1
Input 0 term of 0 row :
4. 1.
Input number of term of 1 row :
2
Input 0 term of 1 row :
7. 2.
Input 1 term of 1 row :
-5. -4.
Input number of term of 2 row :
1
Input 0 term of 2 row :
9. 8.
Test addition.
CAddition : [ [(5,1i), (2,1i), (3,2i)], [(11,5i)], [(15,13i)] ]
Input terms of V
Input term of 0 row :
1. -1.
Input term of 1 row :
2. -2.
Input term of 2 row :
3. -3.
Test matrix vector.
CMultiplication : [(22,-6i), (44,-6i), (56,-6i)]
At the end, with MatrixTemplate.h, and MatrixTemplate imp.h files (where respectively you
declare and implement template version of the class Matrix), whatever implementation you chose,
’test MatrixTemplate D’, ’test MatrixTemplate R’ and ’test MatrixTemplate C’ programs should
give the appropriate results without modification of test MatrixTemplate D.cc, test MatrixTemplate R.cc
and test MatrixTemplate C.cc source files.
8
Requested information
Files
MatrixTemplate.h, MatrixTemplate imp.h, Complex.h, Complex.cc,
Real2.h, Real2.cc
Input
Output
Scaling : 2/5
3 STL
Based on the previous exercise, and the implementation of class Matrix given in MatrixSTL.cc
and MatrixSTL.h, create a new template version of class Matrix, with appropriate combination
of STL containers as your unique member data for matrix entries (of any kind) in skyline storage.
Starting from MatrixSTL.h, only generate the interface (i.e. the declaration in MatrixTem-
plateSTL.h header) that looks the more logical to you. To simplify the correction use T for the
template parameter name and stick to MatrixSTL.h declaration for unchanged instruction.
Requested information
Files
MatrixTemplateSTL.h
Input
Output
Scaling : 1/10
Optional :
For those who wish to verify their choice, do the implementation part in MatrixTemplat-
eSTL imp.h. Then by just including MatrixTemplateSTL.h in place of MatrixTemplate.h in
test MatrixTemplate D.cc, test MatrixTemplate R.cc or test MatrixTemplate C.cc you can verify
that you get the same results as exercise 2 This illustrates the fact that only the public interface
counts for a user. The implementation is hidden and your main ”doesn’t care” that Matrix class
uses STL or anything else.
4 Annexe
4.1 Auto eval.bash limits
This tool is just a help to verify mainly that:
• Your program is located in correct source files having correct names
• No file is missing. If so you will be able to pass through all steps but your points for the
missing file will be lost.
• Exercises program at least compiles and runs correctly (to obtain the 2 points see 4.2 ).
• With the student parameter setting it gives correct results(to obtain the 6 points see 4.2 ).
• The archive given to teacher has the correct structure and name.
9
What this tool doesn’t verify is that:
• Your programs are correct in absolute. Be careful auto eval.bash is tuned to have exercises
running with a set of parameter but different setting will be used by the teacher to correct your
work. This means that your code may work with auto eval.bash and the student parameter
setting but not with the teacher parameter setting. It’s your responsibility to ensure that
your program is correct and work with any setting.
• Your programs are correct if you just generate an archive and didn’t pass through evaluation
step.
• You give your correct group identification number. If you generated archive following a wrong
group ID and upload it as is you will have grade of zero for this homework.
4.2 Evaluation rule
The auto evaluation tool auto eval.bash will be used by teachers (in a slightly modified version)
to evaluate your work with the following rule:
• For an exercise the mandatory program doesn’t compile => 0 Points for the exercise.
• For an exercise the mandatory program compiles but doesn’t execute correctly (i.e. crash,stop
in the middle ...) => 1 Points
• For an exercise the mandatory program compiles and executes without bug but doesn’t give
correct results => 2 Points
• For an exercise the mandatory program compiles, executes without bug and gives correct
results/behavior => 6 Points
Naturally when you are in position of having only 1 or 2 points, program will be inspected to see
if it is relevant (answering the question). If not (something that as nothing to do with the exercise
but compiles and runs correctly) => 0 points.
For every exercise an extra scaling is done. After each requested information table (see 4.4)
you will have the coefficient used for this scaling.
By using auto eval.bash you will be able to estimate how many source evaluation points you
will have for this lab without scaling.
4.3 Getting and using auto eval.bash
auto eval.bash like this pdf files come from self extracting file labX.bash that you download from
resource ”Lx subject” in https://hippocampus.ec-nantes.fr ”Labs” section of M SMA PROLA
course, where X correspond to current lab number.
Place auto eval.bash in the folder where you have all exercises source that have to be given to
teachers. Then in this folder just type:
· · ·> ./auto eval.bash
The first step is to input your group ID (letter A or B and a number):
Input your group letter and number
10
If you launch the script for the first time, you have to create an archive of your work. Select
”Prepare an archive of your work”.
Create archive
A .gz archive file is created, and ready to be uploaded on the pedagogic server. If you want, at
this point you can stop the program (Type ”q”). Note that theses two steps at least are mandatory
to create the archive of your work that you will upload on the server. You can create this archive
by yourself (for instance using the tar command), but if there is any kind of problem when we
try to uncompress it, your grade may be affected with no protestation possible (the most stupid
problem would be that your archive doesn’t have the correct name which leads to ... zero for the
wall lab evaluation) .
Otherwise, you can use this tool to get an auto-evaluation of your work. Now that your archive
is created, you can notice that a new command appeared, ”evaluate archive already generated”.
Type ”b”.
Auto-evaluate your work
Some information are displayed on the screen, saying that the auto-evaluation worked through
well (or not). The most interesting information for you are the ones on the next screen-shot.
11
Results of your auto-evaluation
Here you can see:
• Which ones of your source codes compile correctly
• Which ones of your programs run correctly
• Which ones of your programs give the expected results
This way you can have an estimation of your grade according to the rules detailed in section
4.2. However keep in mind that the grade estimated using this tool may not be your definitive
grade (see section 4.1).Note that you can use this command only if you have generated an archive
first.
You could see that in the previous example, one of the results given by program ”ex1” is
incorrect. To display the difference between your results and the expected one, select the new
command ”display difference from solution of last generated archive” by typing ”c”.
12
Compare obtained results and expected results
Now you can:
• Generate a new archive of your work, if you modified some of your source files
• Auto-evaluate the current archive
• Compare the results obtained with your program and the solution
• Stop using the program
In the last case, if you decide to quit the program, you will be asked whether you want to clean
or save a certain temporary folder. This temporary folder was generated during the auto-evaluation
step, and can eventually be used for debugging even if the script is not launched. The ones of you
who are the most at ease with programming may want to use it, otherwise you can just delete it.
Stop the auto-evaluation program
13
4.4 Requested information
Table given at the end of each exercise untitled ’Requested information’ contains the following
items:
• Files: This is the list of files which must be present in your archive uploaded in the server.
auto eval.bash harvest this files to generate the mandatory archive.
• Input: This describes for each program the precise order in which informations must be
entered.
• Output: This describes for each program the output format of results. Results (that
teacher want to check easily) must be presented by your program in a rather
rigid format described by followings:
– A result is present on one single line. No other things may be written on that line.
– A result is first identified by a token which starts the line.
– After the token a ’:’ must separate token from result value.
– After ’:’ result value must be written (it could be anything).
– token, ’:’ and result value must be separated at least by one blank character.
In this section you have the list of mandatory results given by token names and in parentheses
by result name coming from subject.
Here is an example of a ’Lame’ program made of one file lame.cc. It is generating 2 output
results called λ and µ in the subject. From subject this program should ask for 2 input values call
E and ν to compute results. The requested informations table would look like
Requested information
Files
lam.cc
Input
ν then E
Output
MU(µ), LAMBDA(λ)
Scaling : 1/8
’Lame’ program execution would look like with E = 2500., ν = 0.28 and computed µ = 976.5625
and λ = 1242.8977 :
blablabla
please enter nu :
0.28
blabla
please enter E :
2500.
LAMBDA : 1242.8977
blabla
MU : 976.5625
blabla
Notice in this example that ν is asked before E as mandatory by ”Input” directive. And λ and
µ appears in undefined order but with mandatory format (i.e token LAMBDA and MU).
Very important. You should avoid at any cost the use of token for anything else than the
result it corresponds. Consequences may result in a zero grade just because you messed up the
tools with false information.
In example above if in any ’blabla’ you write MU or LAMBDA you will get a zero for associated
results.
Last but not least when you enter information and output first a question message
14
you must always add a new line to your question if it precedes a result. Let’s take
the example of ’Lame’ above which output token ’LAMBDA’ right after asking to input E. If
you don’t follow this last recommendation you may ask for E without inserting new line after the
question as you can see in the example below:
Your executable is Lame and on terminal you type:
· · ·> ./Lame
And obtain the following bunch of output:
blabla
please enter E : 2500.
LAMBDA : 1242.8977
blabla
This works well on the terminal by typing on the keyboard 2500. and ’enter’. But auto eval.bash
works differently. It uses what is called redirection mechanisms. And in fact this leads
auto eval.bash to miss recognize your results.
In this example you must add a ’end of line’ after the question to obtain:
· · ·> ./Lame
blabla
please enter E :
2500.
LAMBDA : 1242.8977
blabla
and auto eval.bash will work correctly in this case.
4.5 Useful
During Labs you will have questions where testing program ask for many inputs. During debugging
stage you may then be obliged to re enter those inputs manually many times. That may be error
prone and time consuming. To simplify your work use redirection.
For example lets take a ’prg’ program which run the following :
· · ·> prg
Enter number :
23
Enter number :
13
Enter number :
-1
Mean value :
18
Here for illustration we just limit inputs to three entries. Put all those inputs in a file, with one
input per line. Lets call this file ”ip.txt”. Its contain for this example will be :
23
13
-1
Now if you type the following command you get the same execution of ’prg’ without typing
anything :
· · ·> prg < ip.txt
Enter number :
Enter number :
Enter number :
Mean value :
18
Note that inputs just vanish from terminal display.
15

More Related Content

PPT
Lecture 4
PDF
Oct.22nd.Presentation.Final
PPTX
Matlab m files and scripts
PPTX
C language presentation
PPTX
PPTX
MATLAB Scripts - Examples
Lecture 4
Oct.22nd.Presentation.Final
Matlab m files and scripts
C language presentation
MATLAB Scripts - Examples

What's hot (20)

DOCX
Top MNC'S Interview questions and answers
PPTX
Amit user defined functions xi (2)
PPTX
Functions in c language
PPTX
Computer programming 2 Lesson 10
PPT
Ch4 functions
PDF
Functional programming java
PPT
Kelompok 8 Pbw
PPT
Kelompok 8 Pbw
PPT
Savitch ch 04
PPTX
Function in C program
PPT
RECURSION IN C
PPTX
User Defined Functions in MATLAB part 2
DOC
Matlab tut2
PPTX
Looping Statements and Control Statements in Python
PDF
BPstudy sklearn 20180925
PDF
Functional programming 101
PPTX
Control Structures in C
PDF
08 -functions
PPT
Recursion in c
Top MNC'S Interview questions and answers
Amit user defined functions xi (2)
Functions in c language
Computer programming 2 Lesson 10
Ch4 functions
Functional programming java
Kelompok 8 Pbw
Kelompok 8 Pbw
Savitch ch 04
Function in C program
RECURSION IN C
User Defined Functions in MATLAB part 2
Matlab tut2
Looping Statements and Control Statements in Python
BPstudy sklearn 20180925
Functional programming 101
Control Structures in C
08 -functions
Recursion in c
Ad

Viewers also liked (15)

PPTX
KINGS Main task hand drawn drafts
PDF
Leman E- Brochure 2017
PDF
OSV atelier bus mob-bi
PPTX
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
PPTX
Dealing with medico legal cases
PPTX
Regulatorni rizik u razvoju investicijskih projekata u Hrvatskoj Case Study ...
PDF
«Бренд вне конкуренции: построение, продвижение, коммуникации», Елена Золина...
PDF
Russia residential Real Estate 2017 – InterTech presentation
PDF
The Role of Health Coaches in the Future of Medical Care
PPTX
Mi presentación
PPTX
यशाची ८ रहस्ये.
PPTX
отчет прессцентра
PPTX
General aptitude amul
PDF
WSO2Con USA 2017: Implementing a Modern API Management Solution that Benefits...
PDF
BVBA kunstschilder Michaël Borremans boekt superwinst
KINGS Main task hand drawn drafts
Leman E- Brochure 2017
OSV atelier bus mob-bi
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
Dealing with medico legal cases
Regulatorni rizik u razvoju investicijskih projekata u Hrvatskoj Case Study ...
«Бренд вне конкуренции: построение, продвижение, коммуникации», Елена Золина...
Russia residential Real Estate 2017 – InterTech presentation
The Role of Health Coaches in the Future of Medical Care
Mi presentación
यशाची ८ रहस्ये.
отчет прессцентра
General aptitude amul
WSO2Con USA 2017: Implementing a Modern API Management Solution that Benefits...
BVBA kunstschilder Michaël Borremans boekt superwinst
Ad

Similar to Lab5 (20)

PPTX
Computer Science Assignment Help
PPTX
C Programming Homework Help
PPTX
C++ Homework Help
PDF
DeVry GSP 115 All Assignments latest
PDF
Catastrophic Cancellation
PDF
Chpater 6
PPTX
CPP Homework Help
PDF
Acm aleppo cpc training fifth session
PDF
02 Jo P Feb 07
PDF
Numerical analysis
PPT
PPT
lecture 10 Recursive Function and Macros.ppt
PDF
Scilabisnotnaive
 
PDF
Scilab is not naive
PDF
C++ manual Report Full
PPTX
Numerical Linear Algebra in digital image processing
PPT
Functions12
PPT
Functions123
PPTX
CPP Programming Homework Help
PPT
functions
Computer Science Assignment Help
C Programming Homework Help
C++ Homework Help
DeVry GSP 115 All Assignments latest
Catastrophic Cancellation
Chpater 6
CPP Homework Help
Acm aleppo cpc training fifth session
02 Jo P Feb 07
Numerical analysis
lecture 10 Recursive Function and Macros.ppt
Scilabisnotnaive
 
Scilab is not naive
C++ manual Report Full
Numerical Linear Algebra in digital image processing
Functions12
Functions123
CPP Programming Homework Help
functions

Recently uploaded (20)

PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Information Storage and Retrieval Techniques Unit III
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PPT
Total quality management ppt for engineering students
PPTX
UNIT - 3 Total quality Management .pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Safety Seminar civil to be ensured for safe working.
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPTX
introduction to high performance computing
PDF
86236642-Electric-Loco-Shed.pdf jfkduklg
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Information Storage and Retrieval Techniques Unit III
Fundamentals of safety and accident prevention -final (1).pptx
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
UNIT 4 Total Quality Management .pptx
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Nature of X-rays, X- Ray Equipment, Fluoroscopy
Total quality management ppt for engineering students
UNIT - 3 Total quality Management .pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Safety Seminar civil to be ensured for safe working.
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
introduction to high performance computing
86236642-Electric-Loco-Shed.pdf jfkduklg

Lab5

  • 1. Computer Science Class Master SMA/STEU/GC/AMASONE Lab and Homework 5 2015
  • 2. General instruction for all lab See resource Assignment in https://hippocampus.ec-nantes.fr ”Labs” section of M SMA PROLA course for due date and delivery. Your work is sources answering to exercises given below. They must be provided as individual text files following naming convention of your subject. For each exercise a table, called ’requested information table’ hereafter, sets precisely what is expected in terms of naming convention, precises order of input data for the programs you create and output format of these programs results (see chapter 4.4 for complete explanations). You are expected to upload an archive containing all your work in resource Assignments of course ”Labs” section of Pedagogic server (no individual file will be allowed) An auto evaluation tool called auto eval.bash (see chapter 4.1, 4.2, and 4.3 for details) given with this document, has to be used to generate this archive. It can also be used to auto evaluate your archive before submission and check partially correctness of your work. The same auto evaluation tool will be used by the teachers to evaluate your work. Failure to return the sources archive on time on the server will result in a grade of zero for this homework. Uploading an archive with a wrong structure or name (i.e. archive not readable or not named correctly) will result in a grade of zero for this homework. Note : Some useful tricks are given in chapter 4.5. 1
  • 3. 1 Template function In lab 1, the computation of π with a trapezoidal rule may be implemented using a rather general function like it is proposed in the correction. It has been isolated in the given trapezoidal.cc and trapezoidal.h files. In this implementation we see that trapez rule depends explicitly on unitCircle (see the given trapezoidal.cc file). We want to expand trapez rule to make it compute the trapezoidal rule of any user given function. For that you will use template programing. 1.1 Function object A first simple solution is to add a 4th argument to the initial function to pass a function object (see course C6 slide 28). Follow the track : 1. Copy the given trapez rule in a trapTemplate.h (declaration), and trapTemplate imp.h (im- plementation). 2. Change the name of the function to trapTemplate 3. Add a 4th argument, that we can call func, to trapTemplate that will be a constant reference to an object. This object func will be of generic type. You must transform trapTemplate into a function template to have func generic. 4. This 4th argument object will be considerer to have at least a ”double operator ()(const double &x)const” method that take a ”double” as argument and return the result of the computation of f(x). f is the function that this object represent. This is is the only requirement on generic type of func. This kind of object are called ”function object”. 5. Use this func instance in the implementation in place of unitCircle calls. You will keep all the algorithmic part from the original function unchanged. 6. To test the new trapTemplate template function you will first have to create in objFunc.cc and declare in objFunc.h a set of object functions representing f corresponding to : Name of the class/struct f(x) mathematical definition unitCircleOF 4 √ 1 − x2 lineOF x trigoOF sin(15 × x) + cos(3 × x) bilineOF x ifx < 0.5 1 − x ifx 0.5 7. You must then test your work with the main program given in the file test trapTemplate.cc. Whatever implementation you choose for these function and object functions, this program should give the appropriate results without modification of test trapTemplate.cc source file. Requested information Files trapTemplate.h, trapTemplate imp.h, objFunc.h, objFunc.cc Input Output Scaling : 1/4 Here is the expected output : 2
  • 4. Give number of interval 5 PI : 3.03705 ERRORPI : 0.0332773 LINE : 0.5 ERRORLINE : 0 TRIGO : 0.0580991 ERRORTRIGO : 0.646497 BILINE : 0.24 ERRORBILINE : 0.04 1.2 Generalisation to every arithmetic types Imagine that we want to use another arithmetic or precision to compute the trapezoidal rule. Says instead of ”double” real we want to use for example the Real type (from Lab 3). Generalization of the initial trapez rule function is now not only related to the use of any f function but also to the use of any arithmetic. Follow the track : 1. Copy the given trapez rule in a trapTemplateGeneral.h (declaration), and trapTemplateGen- eral imp.h (implementation). 2. Change the name of the function to trapTemplateGeneral 3. Add a 4th argument, that we can call func, to trapTemplateGeneral that will be a reference to a function that takes one ”const double” reference as unique argument and returns a ”double” (see course C3 slide 14 where you can replace pointers by references). The exact syntax is the following : ”double (&func)(const double &)” Use this func variable name (representing a function) in the implementation in place of unitCircle calls. You will keep all the algorithmic part from the original function unchanged. Note that this gives another solution than function objects and template functions to the problem of treating any f user given function. You can do some partial tests. Normally if you call this new function with unitCircle (and 0.,1.,n for first 3 arguments) you should get a result approaching π. 4. Now continue the generalization by making trapTemplateGeneral a template function on the arithmetic type used for the computation. Says your trapTemplateGeneral might be able to integrate a function f dealing with int,float,double or . . . Modify all the implementation according to this new template parameter representing generic arithmetic type. 5. To test the new trapTemplateGenaral function template you will first have to create in func.cc and declare in func.h a set of function representing f corresponding to : Name of the function f(x) mathematical definition Arithmetic unitCircle (you can copy the version in trapezoidal.cc) 4 √ 1 − x2 double line x integer trigo sin(15 × x) + cos(3 × x) double biline x ifx < 0.5 1 − x ifx 0.5 float 6. You must then test your work with the main program given in file test GtrapTemplate.cc. Proceed step by step. First comment out all the tests and includes related to other arithmetics than int, float and double. Test. If you are successful pass to the next step. 7. Starting from the given Starting Real1.h and Starting Real1.cc try now to compute the in- tegral of a rline function in Real arithmetic. For that use now the full original version of test GtrapTemplate.cc. Add a function rline to func.cc and func.h that does the same as line but in Real arithmetic. Copy Starting Real1.h and Starting Real1.cc files in Real1.h and Real1.cc respectively and try to compile. If it does not compile modify class Real so that 3
  • 5. it fulfills trapTemplateGeneral,rline and ’test GtrapTemplate’ requirements. Whatever imple- mentation you choose for trapTemplateGeneral function and testing functions, this program should give the appropriate results without modification of test GtrapTemplate.cc source file. Requested information Files trapTemplateGeneral.h, trapTemplateGeneral imp.h, func.h, func.cc, Real1.cc, Real1.h Input Output Scaling : 1/4 Here is the expected output : Give number of interval 5 LINE : 0 BILINE : 0.24 ERRORBILINE : 0.04 PI : 3.03705 ERRORPI : 0.0332773 TRIGO : 0.0580991 ERRORTRIGO : 0.646497 RLINE : 0.5E40 ERRORRLINE : -0.41633363423443E-15 2 Template Class For this exercise, you will come back to Matrix class created during the previous lab. A new implementation design, based on the use of three member variables is now mandatory for this ex- ercise (this is somehow a kind of mixing of Vector class into Matrix class). Those three members define your matrix dimension(n), structure(index) and entries(rows). To avoid losing time on this specific reshaping task a header file (Matrix.h) and an implementation file (Matrix.cc) give you the corresponding implementation. In this version the use of Vector class has been completely removed. The data members described above are now pointers to a standard array. Multiplication matrix by a vector method is now rather artificial as it takes a pointer to ”double” for right hand side argument. This doesn’t give a way to check the dimension consistency between matrix and vector but simplifies the exercise (it is assumed that they are consistent). Compare to the previous lab the friend ”<<” operator is also replaced by a display function to simplify the exercise. All the other methods keep the same interface as the previous lab. You must expand this class to make it a template class on the arithmetic your matrix works on. Up to now you could only compute matrices with entries represented as ”double”. Change the Matrix class so that it becomes a template class, in order to compute matrices with entries of any number type. The objective is to test the new version of Matrix class with a class Complex that you will have to reimplement (using files Starting Complex.cc and Starting Complex.h), and with the class Real already defined in previous work. Follow the track : 1. Implement your template version of Matrix class. You must start from the Matrix class de- fined in Matrix.h, keeping all the interface functionalities unchanged and the number of mem- bers unchanged. Store your declaration in MatrixTemplate.h. Then starting from Matrix.cc 4
  • 6. do the appropriate modifications and put your implementation in MatrixTemplate imp.h. Again you must not change the algorithms of Matrix.cc but only the necessary source part to make Matrix class template. 2. Before any attempt to use special types as template parameter, test ”double” type template parameter and verify that the results (computed values, output format) are the same as those given by non template class. For that use test MatrixTemplate D.cc and test Matrix D.cc to create programs to test the template and non template version respectively. Try your programs with the same input. Using the following given data, you should get : Double arithmetic Input dimension of Matrix A : 3 Input total number of terms of row skyline storage for upper triangle part of A (diagonal included) : 6 Input row of A Input number of term of 0 row : 3 Input 0 term of 0 row : 1. Input 1 term of 0 row : 2. Input 2 term of 0 row : 3. Input number of term of 1 row : 2 Input 0 term of 1 row : 4. Input 1 term of 1 row : 5. Input number of term of 2 row : 1 Input 0 term of 2 row : 6. i j 0 1 DAij : 2 DAji : 2 Test copy constructor. DCopyConstructor : [ [1, 2, 3], [4, 5], [6] ] i j 0 1 DCij : 2 DCji : 2 Input total number of terms of row skyline storage for upper triangle part of B (diagonal included) : 4 Input row of B Input number of term of 0 row : 1 Input 0 term of 0 row : 4. Input number of term of 1 row : 2 Input 0 term of 1 row : 7. Input 1 term of 1 row : 5
  • 7. -5. Input number of term of 2 row : 1 Input 0 term of 2 row : 9. Test addition. DAddition : [ [5, 2, 3], [11], [15] ] Input terms of V Input term of 0 row : 1. Input term of 1 row : 2. Input term of 2 row : 3. Test matrix vector. DMultiplication : [14, 25, 31] 3. Then try Real class type with test MatrixTemplate R.cc. Start from the version you want but put your work in the files Real2.cc and Real2.h. Normally, independently on how you transform Matrix class, you should not be able to compile the program. Figure out what are the problems, and avoid them by modifing Real class so that function member of template class Matrix “works” without algorithmic modifications. If you don’t modify Real class and you pass the compilation stage successfully, it means that you changed too much the initial Matrix class. It certainly won’t do things the way the initial template free class Matrix did. Please revert to the initial class and start again from this point. Using test MatrixTemplate R.cc with the given data, you should get the following output : Real arithmetic Input dimension of Matrix A : 3 Input total number of terms of row skyline storage for upper triangle part of A (diagonal included) : 6 Input row of A Input number of term of 0 row : 3 Input 0 term of 0 row : 1.e+300 Input 1 term of 0 row : 2.e+300 Input 2 term of 0 row : 3.e+300 Input number of term of 1 row : 2 Input 0 term of 1 row : 4.e+300 Input 1 term of 1 row : 5.e+300 Input number of term of 2 row : 1 Input 0 term of 2 row : 6.e+300 i j 0 1 RAij : 0.2E301 RAji : 0.2E301 Test copy constructor. 6
  • 8. RCopyConstructor : [ [0.1E301, 0.2E301, 0.3E301], [0.4E301, 0.5E301], [0.6E301] ] i j 0 1 RCij : 0.2E301 RCji : 0.2E301 Input total number of terms of row skyline storage for upper triangle part of B (diagonal included) : 4 Input row of B Input number of term of 0 row : 1 Input 0 term of 0 row : 4.e+300 Input number of term of 1 row : 2 Input 0 term of 1 row : 7.e+300 Input 1 term of 1 row : -5.e+300 Input number of term of 2 row : 1 Input 0 term of 2 row : 9.e+300 Test addition. RAddition : [ [0.5E301, 0.2E301, 0.3E301], [0.11E302], [0.15E302] ] Input terms of V Input term of 0 row : 1.e+300 Input term of 1 row : 2.e+300 Input term of 2 row : 3.e+300 Test matrix vector. RMultiplication : [0.14E602, 0.25E602, 0.31E602] 4. Finally, try Complex class type with test MatrixTemplate C.cc. Start by renaming Start- ing Complex.cc and Starting Complex.h in Complex.cc and Complex.h respectively. You will then have to analyze, and modify this proposed Complex class to make it work with your template Matrix class. Note that ”>>” input operator is not implemented in given files. You will have to implement it by saying that an input of a Complex instance corresponds to two inputs of two real ”double ”. Using test MatixTemplate C.cc with the given data, you should get the following output : Complex arithmetic Input dimension of Matrix A : 3 Input total number of terms of row skyline storage for upper triangle part of A (diagonal included) : 6 Input row of A Input number of term of 0 row : 3 Input 0 term of 0 row : 1. 0. Input 1 term of 0 row : 7
  • 9. 2. 1. Input 2 term of 0 row : 3. 2. Input number of term of 1 row : 2 Input 0 term of 1 row : 4. 3. Input 1 term of 1 row : 5. 4. Input number of term of 2 row : 1 Input 0 term of 2 row : 6. 5. i j 0 1 CAij : (2,1i) CAji : (2,1i) Test copy constructor. CCopyConstructor : [ [(1,0i), (2,1i), (3,2i)], [(4,3i), (5,4i)], [(6,5i)] ] i j 0 1 CCij : (2,1i) CCji : (2,1i) Input total number of terms of row skyline storage for upper triangle part of B (diagonal included) : 4 Input row of B Input number of term of 0 row : 1 Input 0 term of 0 row : 4. 1. Input number of term of 1 row : 2 Input 0 term of 1 row : 7. 2. Input 1 term of 1 row : -5. -4. Input number of term of 2 row : 1 Input 0 term of 2 row : 9. 8. Test addition. CAddition : [ [(5,1i), (2,1i), (3,2i)], [(11,5i)], [(15,13i)] ] Input terms of V Input term of 0 row : 1. -1. Input term of 1 row : 2. -2. Input term of 2 row : 3. -3. Test matrix vector. CMultiplication : [(22,-6i), (44,-6i), (56,-6i)] At the end, with MatrixTemplate.h, and MatrixTemplate imp.h files (where respectively you declare and implement template version of the class Matrix), whatever implementation you chose, ’test MatrixTemplate D’, ’test MatrixTemplate R’ and ’test MatrixTemplate C’ programs should give the appropriate results without modification of test MatrixTemplate D.cc, test MatrixTemplate R.cc and test MatrixTemplate C.cc source files. 8
  • 10. Requested information Files MatrixTemplate.h, MatrixTemplate imp.h, Complex.h, Complex.cc, Real2.h, Real2.cc Input Output Scaling : 2/5 3 STL Based on the previous exercise, and the implementation of class Matrix given in MatrixSTL.cc and MatrixSTL.h, create a new template version of class Matrix, with appropriate combination of STL containers as your unique member data for matrix entries (of any kind) in skyline storage. Starting from MatrixSTL.h, only generate the interface (i.e. the declaration in MatrixTem- plateSTL.h header) that looks the more logical to you. To simplify the correction use T for the template parameter name and stick to MatrixSTL.h declaration for unchanged instruction. Requested information Files MatrixTemplateSTL.h Input Output Scaling : 1/10 Optional : For those who wish to verify their choice, do the implementation part in MatrixTemplat- eSTL imp.h. Then by just including MatrixTemplateSTL.h in place of MatrixTemplate.h in test MatrixTemplate D.cc, test MatrixTemplate R.cc or test MatrixTemplate C.cc you can verify that you get the same results as exercise 2 This illustrates the fact that only the public interface counts for a user. The implementation is hidden and your main ”doesn’t care” that Matrix class uses STL or anything else. 4 Annexe 4.1 Auto eval.bash limits This tool is just a help to verify mainly that: • Your program is located in correct source files having correct names • No file is missing. If so you will be able to pass through all steps but your points for the missing file will be lost. • Exercises program at least compiles and runs correctly (to obtain the 2 points see 4.2 ). • With the student parameter setting it gives correct results(to obtain the 6 points see 4.2 ). • The archive given to teacher has the correct structure and name. 9
  • 11. What this tool doesn’t verify is that: • Your programs are correct in absolute. Be careful auto eval.bash is tuned to have exercises running with a set of parameter but different setting will be used by the teacher to correct your work. This means that your code may work with auto eval.bash and the student parameter setting but not with the teacher parameter setting. It’s your responsibility to ensure that your program is correct and work with any setting. • Your programs are correct if you just generate an archive and didn’t pass through evaluation step. • You give your correct group identification number. If you generated archive following a wrong group ID and upload it as is you will have grade of zero for this homework. 4.2 Evaluation rule The auto evaluation tool auto eval.bash will be used by teachers (in a slightly modified version) to evaluate your work with the following rule: • For an exercise the mandatory program doesn’t compile => 0 Points for the exercise. • For an exercise the mandatory program compiles but doesn’t execute correctly (i.e. crash,stop in the middle ...) => 1 Points • For an exercise the mandatory program compiles and executes without bug but doesn’t give correct results => 2 Points • For an exercise the mandatory program compiles, executes without bug and gives correct results/behavior => 6 Points Naturally when you are in position of having only 1 or 2 points, program will be inspected to see if it is relevant (answering the question). If not (something that as nothing to do with the exercise but compiles and runs correctly) => 0 points. For every exercise an extra scaling is done. After each requested information table (see 4.4) you will have the coefficient used for this scaling. By using auto eval.bash you will be able to estimate how many source evaluation points you will have for this lab without scaling. 4.3 Getting and using auto eval.bash auto eval.bash like this pdf files come from self extracting file labX.bash that you download from resource ”Lx subject” in https://hippocampus.ec-nantes.fr ”Labs” section of M SMA PROLA course, where X correspond to current lab number. Place auto eval.bash in the folder where you have all exercises source that have to be given to teachers. Then in this folder just type: · · ·> ./auto eval.bash The first step is to input your group ID (letter A or B and a number): Input your group letter and number 10
  • 12. If you launch the script for the first time, you have to create an archive of your work. Select ”Prepare an archive of your work”. Create archive A .gz archive file is created, and ready to be uploaded on the pedagogic server. If you want, at this point you can stop the program (Type ”q”). Note that theses two steps at least are mandatory to create the archive of your work that you will upload on the server. You can create this archive by yourself (for instance using the tar command), but if there is any kind of problem when we try to uncompress it, your grade may be affected with no protestation possible (the most stupid problem would be that your archive doesn’t have the correct name which leads to ... zero for the wall lab evaluation) . Otherwise, you can use this tool to get an auto-evaluation of your work. Now that your archive is created, you can notice that a new command appeared, ”evaluate archive already generated”. Type ”b”. Auto-evaluate your work Some information are displayed on the screen, saying that the auto-evaluation worked through well (or not). The most interesting information for you are the ones on the next screen-shot. 11
  • 13. Results of your auto-evaluation Here you can see: • Which ones of your source codes compile correctly • Which ones of your programs run correctly • Which ones of your programs give the expected results This way you can have an estimation of your grade according to the rules detailed in section 4.2. However keep in mind that the grade estimated using this tool may not be your definitive grade (see section 4.1).Note that you can use this command only if you have generated an archive first. You could see that in the previous example, one of the results given by program ”ex1” is incorrect. To display the difference between your results and the expected one, select the new command ”display difference from solution of last generated archive” by typing ”c”. 12
  • 14. Compare obtained results and expected results Now you can: • Generate a new archive of your work, if you modified some of your source files • Auto-evaluate the current archive • Compare the results obtained with your program and the solution • Stop using the program In the last case, if you decide to quit the program, you will be asked whether you want to clean or save a certain temporary folder. This temporary folder was generated during the auto-evaluation step, and can eventually be used for debugging even if the script is not launched. The ones of you who are the most at ease with programming may want to use it, otherwise you can just delete it. Stop the auto-evaluation program 13
  • 15. 4.4 Requested information Table given at the end of each exercise untitled ’Requested information’ contains the following items: • Files: This is the list of files which must be present in your archive uploaded in the server. auto eval.bash harvest this files to generate the mandatory archive. • Input: This describes for each program the precise order in which informations must be entered. • Output: This describes for each program the output format of results. Results (that teacher want to check easily) must be presented by your program in a rather rigid format described by followings: – A result is present on one single line. No other things may be written on that line. – A result is first identified by a token which starts the line. – After the token a ’:’ must separate token from result value. – After ’:’ result value must be written (it could be anything). – token, ’:’ and result value must be separated at least by one blank character. In this section you have the list of mandatory results given by token names and in parentheses by result name coming from subject. Here is an example of a ’Lame’ program made of one file lame.cc. It is generating 2 output results called λ and µ in the subject. From subject this program should ask for 2 input values call E and ν to compute results. The requested informations table would look like Requested information Files lam.cc Input ν then E Output MU(µ), LAMBDA(λ) Scaling : 1/8 ’Lame’ program execution would look like with E = 2500., ν = 0.28 and computed µ = 976.5625 and λ = 1242.8977 : blablabla please enter nu : 0.28 blabla please enter E : 2500. LAMBDA : 1242.8977 blabla MU : 976.5625 blabla Notice in this example that ν is asked before E as mandatory by ”Input” directive. And λ and µ appears in undefined order but with mandatory format (i.e token LAMBDA and MU). Very important. You should avoid at any cost the use of token for anything else than the result it corresponds. Consequences may result in a zero grade just because you messed up the tools with false information. In example above if in any ’blabla’ you write MU or LAMBDA you will get a zero for associated results. Last but not least when you enter information and output first a question message 14
  • 16. you must always add a new line to your question if it precedes a result. Let’s take the example of ’Lame’ above which output token ’LAMBDA’ right after asking to input E. If you don’t follow this last recommendation you may ask for E without inserting new line after the question as you can see in the example below: Your executable is Lame and on terminal you type: · · ·> ./Lame And obtain the following bunch of output: blabla please enter E : 2500. LAMBDA : 1242.8977 blabla This works well on the terminal by typing on the keyboard 2500. and ’enter’. But auto eval.bash works differently. It uses what is called redirection mechanisms. And in fact this leads auto eval.bash to miss recognize your results. In this example you must add a ’end of line’ after the question to obtain: · · ·> ./Lame blabla please enter E : 2500. LAMBDA : 1242.8977 blabla and auto eval.bash will work correctly in this case. 4.5 Useful During Labs you will have questions where testing program ask for many inputs. During debugging stage you may then be obliged to re enter those inputs manually many times. That may be error prone and time consuming. To simplify your work use redirection. For example lets take a ’prg’ program which run the following : · · ·> prg Enter number : 23 Enter number : 13 Enter number : -1 Mean value : 18 Here for illustration we just limit inputs to three entries. Put all those inputs in a file, with one input per line. Lets call this file ”ip.txt”. Its contain for this example will be : 23 13 -1 Now if you type the following command you get the same execution of ’prg’ without typing anything : · · ·> prg < ip.txt Enter number : Enter number : Enter number : Mean value : 18 Note that inputs just vanish from terminal display. 15