You are on page 1of 19

Computer Science Class

Master ENG/ENV/TECH

Lab and Homework 1

2017
General instruction for all lab

See resource Assignment in https://hippocampus.ec-nantes.fr Labs section of M SMA PROGR


course for due date and delivery.

Your work consists of sources answering exercises given below. They must be provided as indi-
vidual text files following the naming convention of your subject. For each exercise a table, called
requested information table hereafter, sets precisely what is expected in terms of naming conven-
tion, precises order of input data for the programs you create and output format of these programs
results (see chapter 8.4 for complete explanations). You are expected to upload an archive con-
taining 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 8.1, 8.2, and 8.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 the 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 8.5.

Specific instruction for this lab


The two unnumbered following chapters are not graded. They are just training exercises to start
practice.

Hexadecimal representation
In some exercises we will use hexadecimal representation of integers. Here is a table to recall you
the correspondence between decimal and hexadecimal notations:

decimal hexadecimal
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 A
11 B
12 C
13 D
14 E
15 F

1
To avoid confusion with decimal representation a hexadecimal number is always prepended by
a 0x or 0X.

Here are some little examples of arithmetic operations with hexadecimal notation:
0x32FF+0x0021=0x3320
0x329F+4=0x32A3
0x000A*2=0x0014
If you want you can translate in decimal and do the arithmetic operation and then translate
back to hexadecimal notation: 0x32FF+0x0021=13055+33=13088=0x3320

In this lab we will use 0x notation only and all letter will be in upper case. All
hexadecimal numbers will use 4 digits by prepending 0 if necessary.

Training - Getting familiar with the console and linux.


Below are some training exercises. Dont spend too much time on those little training
exercises. Their purpose is that you can start.
Do the following:

Open a terminal (browse menu to find this program). Then click inside this window. Thats
it, you are now interacting with Linux command interpreter!

In your home directory (where you arrive if you just type cd ) type:
> mkdir -p ComputerLab/lab1
then get into this new folder:
> cd ComputerLab/lab1

then type:
> gedit hello.cc (or any other editor than gedit that you want)
and pass to next training.

You can come back to the following later on:

Using the console create a directory named ComputerLab in your home directory. Inside this
directory create a directory named lab1. Edit a file (use for instance gedit) named test1.txt, put
whatever you want inside it. Using the console, try to change its name. Try to copy it in your
home directory. Modify this file on the home directory, copy it with the name test2.txt in the
ComputerLab/lab1.
Look at the rights you have on the file. Change your rights on the file to read only, try to
modify the file using an editor. You can use your one-sheet linux survival guide to help you do
that. Remember that you can get a complete description of each command using the command
man, or a short help by adding --help or -h at the end of the command.
There is much more that can be done within the command line. Even complicated scripts can
be written to help you do repetitive tasks. The command language usually used on Linux is the
bash (born again shell).
When you have time, you can learn more tricks with the console. For example, for shell script,
you can have a look here.

2
Training - First program.
Write a hello word program (a program that prints hello world on the screen), something similar
to the first C++ program that we have seen in class. Make sure you understand all the commands.
Compile it, correct it if needed. Execute it. Try to add errors in the program. Compile it. Try
to understand the error messages.
As it is just training, no source are requested for evaluation.

3
1 A simple program.
1.1 First basic Input/Output
Write a program basic io that asks for your age and then prints it on the screen.
You'll need to look at course C1 for basic i/o and possibly take a look on the Web to complete
it.
Modify your code so that it also asks for your height in meters, and then prints it out.

1.2 Input/Output string


Modify your program so that it also asks for your last name and then displays all those three
informations following requirements below.
You'll need to store your last name in a variable which is an array of char. Declare for that
char myname[10]; in your code. Which means that myname is an array of 10 characters.
See what happens if you reply something much longer than 10 characters. Try 11, 15 then a
very long sequence of characters.
Requested information
Files
basic io.cc
Input
age, height then myname
Output
NAME(myname) AGE(age) and HEIGHT(height)
Scaling : 1/19

2 Barycentric coordinates of a point in a given triangles


Write a bary triangle program (stored in bary triangle.cc) to compute barycentric coordinates of
any point given by the user taking a triangle (also given by the user) as barycentric coordinate
system.
Requested program input/output
Input
Plan Cartesian coordinates of 3 nodes describing a triangle, called
T hereafter.
Plan Cartesian coordinates of a node, called P hereafter.

Output
A message M telling if T is degenerate or not.
The barycentric coordinate of point P if T not degenerated.
Arbitrary fake barycentric coordinate 0. 0. 0. if T is degenerated

Having input information the program first checks that T is not degenerate, saying that its
points are not collinear nor at the same location. Dont start doing your own set of tests for that.
The way barycentric coordinates have to be computed following the mathematical definition given
below induces a natural degenerate triangle test. So if T is degenerate program must give message
M:
TRIANGLE : degenerated

4
and :

TRIANGLE : correct
otherwise.
Then the program computes and outputs P barycentric coordinates in given triangle system
according to the output rule given above.

You will start from the following definition:


x1 , y1 , x2 , y2 , x3 , y3 are the Cartesian coordinates of respectively first, second and third points
of triangle T.
x and y are the Cartesian coordinate of point P.

if 1 , 2 and 3 are the barycentric coordinates of point P in triangle T we have:


x = 1 .x1 + 2 .x2 + 3 .x3
y = 1 .y1 + 2 .y2 + 3 .y3
1 + 2 + 3 = 1

Requested information
Files
bary triangle.cc
Input
x1 , y1 , x2 , y2 , x3 , y3 , x then y
Output
lambda1(1 ), lambda2(2 ), lambda3(3 ) and TRIANGLE(M)
Scaling : 4/19

3 First functions implementation.


The purpose of this exercise is to get familiar with the way functions are declared and implemented
from a storage point of view (i.e. library concept, headers, implementation files . . . ). It is really
short. Dont search for algorithmic complication but be sure to correctly understand it because
library concept will be used in all following labs.

Write two functions, named maximum and minimum. maximum must return the maximum of
the two doubles given as inputs of the function. minimum must return the minimum of the two
doubles given as inputs of the function.
The two functions must be declared in a header file named mathfunction.h and implemented
in a separate mathfunction.cc file.

The mathfunction.cc can be compiled using the following command:


> g++ -c mathfunction.cc
This will produce a mathfunction.o file. Note that this file is not an executable. It is called an
object file. mathfunction.o file corresponds to a kind of file used in libraries. A library groups .o
files to form an archive. The compiler may then use it at the linking stage to finalize compilation
of a program using some implemented functions present in that library. Here (and in the next
labs) we will just use the .o files without generating the archive but think of this (these) file(s) as
a library.

5
To test your maximum and minimum functions, you need to create a main program test mathfunction
that calls them with two doubles a and b asked to the user and outputs the result of their compu-
tation on the terminal (following requirements below). You will write it in a test mathfunction.cc
file. When it's done you can compile it:
> g++ -c test mathfunction.cc
This will produce the file test mathfunction.o.

You can now produce an executable by linking test mathfunction.o and mathfunction.o:
> g++ mathfunction.o test mathfunction.o -o test mathfunction.exe

Requested information
Files
mathfunction.h,mathfunction.cc,test mathfunction.cc
Input
a then b
Output
MAXIMUM(max(a, b)) and MINIMUM(min(a, b))
Scaling : 1/19

Here test mathfunction.o may be of great interest only in large projects where you are compiling
not one, but hundreds of programs, or if compilation of the main itself is very very long. Then you
are happy when you do a modification in a shared library not to compile again all the programs but
just link their associated .o files with the new library. This saves compilation time.
In our case we may shorten the compilation step by using the following commands as test mathfunction.cc
is obviously very quick to compile:
> g++ -c mathfunction.cc
> g++ mathfunction.o test mathfunction.cc -o test mathfunction.exe
And again as in this case mathfunction.cc is also obviously very quick to compile, we may even
be shorter:
> g++ mathfunction.cc test mathfunction.cc -o test mathfunction.exe
But this alleviates all the advantages of the library concept which is here among many things
to avoid as much as possible re compilation of unchanged sources. In the following labs you will
quickly adopt this concept to avoid losing time waiting for the compilation to finish.

4 First loops
Your program in both cases must use one of the loop structures available in C++ and use double
type for real arithmetic.

4.1 First version


Write a program mean 1 (stored in mean 1.cc) that computes the mean m of 6 real values
xi , i [1, 6].
Requested program input/output
Input The program must ask six real values to the user.
Output The program outputs the mean once the 6 values are entered.
Just for your information one possible solution has a computational cost of 7 floating point
operations and uses 20 bytes of memory for variables (bytes are easily obtained by using 8 bytes
for a double and 4 bytes for a int; recall course 1 variable type table).

6
Requested information
Files
mean 1.cc
Input
x1 , x2 ,x3 ,x4 ,x5 then x6
Output
Mean(m)
Scaling : 1/19

4.2 Second version


Write a program mean 2 (stored in mean 2.cc) that computes the mean m of the real positive
values xi entered by the user.
Requested program input/output
Input The user enters positive value one by one. The program will stop asking
for new values if a negative or null number is entered.
Output It must then output the number N of values entered (negative or null
value not counted) and the mean m .
Just for your information one possible solution has a computational cost of N+1 floating point
operations and uses 20 bytes of memory.

Requested information
Files
mean 2.cc
Input
xi
Output
INPUT(N ), MEAN(m)
Scaling : 1/19

5 Pointers and functions


Write a function named mySort that has tree arguments, pa, pb and pc that are pointers to doubles.
This function must sort the pointed values in ascending order.

Requested program input/output


Input Three pointers pa, pb, pc to double
Output
The function must sort in ascending order the values pointers pa,
pb and pc point to. On exit the pointer pa points to the lowest
value, pb to the middle one and pc to the highest.
It must also return the pointer corresponding to the lowest value.

For example the following code:

double a=3., b=2., c= 4.;


mySort (&a, &b, &c);
cout << a << " " << b << " " << c <<endl;

should print 2 3 4 on the screen.

7
Declare mySort in a header file mySort.h, implement it in a mySort.cc file and test it with the
main program given by file test mySort.cc. Whatever implementation you chose for this function,
this program should give the appropriate results without modification of test mySort.cc source file.

Requested information
Files
mySort.cc, mySort.h
Input

Output

Scaling : 1/19
Note: This is the first example of a requested information table with empty Input/Output
directives. This is normal since you have to use the given teacher test .cc file (and you are not
expected to change anything in it) which does input/output. Auto evaluation tool is tuned to work
with this file and your evaluation will be done here only on the results that your functions give and
not also on the way you present results (as in previous exercises). In all the labs you will have
many exercises that work like that.

6 References and functions


Write a function mySort having the same functionality as mySort of exercise 5 but using as input
3 references instead of 3 pointers and returning a reference. As usual, declare mySort in a header
file refMySort.h, implement it in a refMySort.cc file and test it with the main program given by
file test refMySort.cc. Whatever implementation you chose for this function, this program should
give the appropriate results without modification of test refMySort.cc source file.

Requested information
Files
refMySort.cc, refMySort.h
Input

Output

Scaling : 1/19

7 Pointers and arrays


Operator ++ applied to a pointer moves the address it stores to the next address in memory for
a variable of the type the pointer points to. Operator - - does the reverse. Operator + applied
between a pointer and an integer i returns a pointer to the same address as the one obtained by
applying i time operator ++ on the pointer.

Consider the following example:

1 i n t a [ ] = {1 , 2 , 3 , 4 , 5};
2 i n t pa = &a [ 0 ] ;
3 c o u t << pa <<e n d l ;
4 c o u t << (++pa ) << e n d l ;
5 c o u t << ( pa+2) << e n d l ;

On line 2, the pointer pa points to the first element of array a. On line 3 pa is derefer-
enced and the value it points to is printed on screen. It therefore prints the value 1.

8
On line 4, pa is incremented using ++ (as pres operator, recall course 1 on operator and prece-
dence), and then dereferenced. When ++ is applied, pa points to the next integer in memory,
which is the same as the one stored in slot a [1] , which is 2. Line 4 therefore prints 2 on the screen.

Line 5 outputs the value 4 on the screen.

Note: On line 2, &a[0] is the address of the first element of a. Line 2 could have been
replaced by the following: int pa =a; which has the exact same meaning: the identifier of an
array variable is equivalent to a non-modifiable pointer that contains the address of the first element
of the array. By nature it then can be assigned to a pointer, and in this case pa is set to the
address of the first element of the a array.

7.1 Pointers training


The following training is to be done by typing by hand the answers in a file with an editor. All the
addresses must be written in hexadecimal notation (see page 1). Requested information table is
still used to give you the precise name of those hand made files. They also give the list of tokens to
use just like previous programs output, except that here you play the role of the program. Assume
the address of the blocks array is your group id translated as a hexadecimal with the following
rule:
2*group letter+3*group number= address (see appendix 8.6)

What will be printed when the following statements are executed?


1 i n t main ( )
2 {
3 int blocks [ 6 ] = {9 ,80 ,2 ,45 ,12 ,8};
4 i n t p t r = &b l o c k s [ 2 ] ;
5 cout<<R1 : <<ptr<<e n d l ;
6 i n t temp ;
7 temp = b l o c k s [ 3 ] ;
8 cout<<R2 : <<temp<<e n d l ;
9 temp = p t r ;
10 cout<<R3 : <<temp<<e n d l ;
11 temp = ( p t r + 3 ) ;
12 cout<<R4 : <<temp<<e n d l ;
13 temp = ( b l o c k s + 2 ) ;
14 cout<<R5 : <<temp<<e n d l ;
15 cout<<R6 : <<( b l o c k s +4)<<e n d l ;
16 ptr = blocks + 2;
17 cout<<R7 : <<ptr<<e n d l ;
18 temp = p t r [ 2 ] ;
19 cout<<R8 : <<temp<<e n d l ;
20 p t r = &b l o c k s [ 1 ] ;
21 temp = ++p t r ;
22 cout<<R9 : <<ptr<<e n d l ;
23 temp = p t r ++;
24 cout<<R10 : <<ptr<<e n d l ;
25 temp = p t r ;
26 cout<<R11 : <<temp<<e n d l ;
27 cout<<R12 : <<ptr<<e n d l ;
28 p t r=b l o c k s ;
29 p t r +=5;
30 cout<<R13 : <<ptr<<e n d l ;
31 temp = p t r ;
32 cout<<R14 : <<temp<<e n d l ;
33 temp = p t r [ 1 ] ;
34 p t r ;
35 cout<<R15 : <<temp<<e n d l ;
36 temp = ( b l o c k s + 3 ) ;

9
37 cout<<R16 : <<temp<<e n d l ;
38 ptr [1]=27;
39 p t r=b l o c k s + 3 ;
40 cout<<R17 : <<ptr<<e n d l ;
41 temp=ptrb l o c k s ;
42 cout<<R18 : <<temp<<e n d l ;
43 temp=( p t r +2) ;
44 cout<<R19 : <<temp<<e n d l ;
45 ptr =3;
46 cout<<R20 : <<ptr<<e n d l ;
47 return 0;
48 }

For the order of evaluation of the operator, you can refer to the table of course 1.
Requested information
Files
pointer array.txt
Input

Output
R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15,
R16, R17, R18, R19 and R20 following code above
Scaling : 4/19

7.2 Sort odd and even


For this question, use the pointer notation ONLY. Do NOT use the array index [ ] notation.
Write a function sortOdd (function signature will be: int sortOdd(inta, int size )) which re-
ceives an integer array and its size, and does the following:
pack at begin of the array all odd numbers and after put even numbers
sort both set in ascending order (using quick sort standard function)
return a pointer to the first even number in the array after sorting

Requested function input/output


Input
An array of integers a
Its size n

Output A pointer to the first even number in the array after sorting (or a pointer
to the location in memory past the end of the array a if no even number
is entered). a array is sorted fulfilling requirement above.

The aim of this exercise is to pack odd and even number into two sets in the array a.
Depending on your algorithm many values order are possible for both sets so we need to have a
common order to ease the correction of your work. Sorting those sets is then mandatory but it
is far behind the scope of this course. To simplify this sorting task you will use the qsort of the
standard library. Here an example on how to use it:
1 #i n c l u d e <i o s t r e a m >
2 // D e c l a r a t i o n o f q s o r t i s :
3 // v o i d q s o r t ( v o i d base , s i z e t nmemb, s i z e t s i z e ,
4 // i n t ( compar ) ( c o n s t v o i d , c o n s t v o i d ) ) ;
5 // i t i s g i v e n i n t h i s h e a d e r
6 #i n c l u d e <c s t d l i b >

10
7 u s i n g namespace s t d ;
8

10 // H e l p i n g Function f o r q s o r t ( a s c e n d i n g o r d e r )
11 i n t intCompare ( c o n s t v o i d i , c o n s t v o i d j )
12 {
13 i f ( ( ( i n t ) i ) < ( ( i n t ) j ) )
14 r e t u r n 1;
15 e l s e i f ( ( ( i n t ) i ) > ( ( i n t ) j ) )
16 return 1;
17 else
18 return 0;
19 }
20

21

22 // main
23 i n t main ( )
24 {
25 // an a r r a y t o s o r t
26 const int n = 7;
27 int some int [ n ] = {42 ,2 ,6 ,8 ,99 ,23 ,2};
28

29 // s o r t i n g a r r a y with q s o r t
30 q s o r t ( s o m e i n t , n , s i z e o f ( i n t ) , intCompare ) ;
31

32 // output
33 f o r ( i n t i = 0 ; i < n ; ++i ) cout<< <<s o m e i n t [ i ] ;
34 cout<<e n d l ;
35

36 return 0;
37 }

Use exactly the same way this qsort function (with intCompare function) to sort each set (odd and
even) in your sortOdd function (two calls to qsort must be present in the implementation
of your sortOdd function, no more, no less). You must not implement your own version of
sorting algorithm or worse implementing your own version of sorting and packing together algo-
rithm (if you are interested by the subject, and have time... Donald Knuth in The Art of Computer
Programming III dedicated more then 350 pages to it... ). Last but not least it is prohibited to
use any other function than intCompare with qsort. One may be lazy and change intCompare
so that it considers also an even number greater than an odd one... For those who are interested
it may be an exercise, apart from labs, to modify intCompare so that in one qsort call you get the
result expected by this subject.

Implement sortOdd function in an sortOdd.cc file and test it with the main program given by
file test sortOdd.cc which includes directly this file (your work is included in the test sortOdd.cc
source just as if you had typed this function in this file). This inclusion controls that you will
use the intCompare implemented in test sortOdd.cc and not yours. Whatever implementation you
chose for this function, this program should give the appropriate results without modification of
test sortOdd.cc source file. Here is an example:

Enter array size:


5
Enter array value:
124 11 2 7 1
0
PEVEN : 3
SORTODD : 1 7 11 2 124

11
Requested information
Files
sortOdd.cc
Input

Output

Scaling : 5/19

8 Appendix
8.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.
All programs, at least, compiles and runs correctly (to obtain the 2 points see 8.2).
With the student parameter setting, it gives correct results (to obtain the 6 points see 8.2).
The archive given to teacher has the correct structure and name.
What this tool doesnt verify is that:
Your programs are correct in absolute. Be careful auto eval.bash is tuned to have exercises
running with a set of parameters but a 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. Its your responsibility to
ensure that your program is correct and works with any setting.
Your programs are correct if you just generate an archive and didnt pass through evaluation
step.
You give your correct group identification number. If you generated an archive following a
wrong group ID and upload it as it is then you will have a grade of zero for this homework.

8.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 doesnt compile => 0 points for the exercise.
For an exercise the mandatory program compiles but doesnt execute correctly (i.e. crash,stop
in the middle ...) => 1 point.
For an exercise the mandatory program compiles and executes without bug but doesnt 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, the program will be inspected to
see if it is relevant (answering the question). If not (something that has 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 8.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.

12
8.3 Getting and using auto eval.bash
auto eval.bash like this pdf files comes from self extracting file labX.bash that you download from
resource Lx subject in https://hippocampus.ec-nantes.fr Labs section of M1 M-ENG PROGR
course, where X corresponds to current lab number.

Place auto eval.bash in the folder where you have all exercises sources 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, B or C and a number):

Input your group letter and number

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

13
problem would be that your archive doesnt have the correct name which leads to ... zero for the
whole 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.

Results of your auto-evaluation

Here you can see:


Which of your source codes compile correctly.

Which of your programs run correctly.


Which of your programs give the expected results.

14
This way you can have an estimation of your grade according to the rules detailed in section
8.2. However keep in mind that the grade estimated using this tool may not be your final grade
(see section 8.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.

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 possibly be used for debugging even if the script is not launched. Those of you who
are the most at ease with programming may want to use it, otherwise you can just delete it.

15
Stop the auto-evaluation program

8.4 Requested information


Tables given at the end of each exercise entitled 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 harvests these files to generate the mandatory archive.
Input: describes for each program the precise order in which information must be entered.
Output: describes for each program the output format of the results. Results (that teach-
ers want to check easily) must be presented by your program in a rather rigid
format described by the following:
A result is present on one single line. Nothing else may be written on that line.
A result is first identified by a token which starts the line.
After the token a : must separate the 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
called E and to compute results. The requested information 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:

16
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
appear 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 to. 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
you must always add a new line to your question if it precedes a result. Lets take the
example of Lame above which outputs token LAMBDA right after asking to input E. If you
dont follow this last recommendation you may ask for E without inserting a 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 outputs:

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.

8.5 Useful
During Labs you will have questions where testing program asks 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 runs the following:
> prg

Enter number :
23

17
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 contents 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.

8.6 Addresses in hexadecimal corresponding to group identification num-


ber
Group ID address Group ID address Group ID address
A 01 0x0017 B 01 0x0019 C 01 0x001B
A 02 0x001A B 02 0x001C C 02 0x001E
A 03 0x001D B 03 0x001F C 03 0x0021
A 04 0x0020 B 04 0x0022 C 04 0x0024
A 05 0x0023 B 05 0x0025 C 05 0x0027
A 06 0x0026 B 06 0x0028 C 06 0x002A
A 07 0x0029 B 07 0x002B C 07 0x002D
A 08 0x002C B 08 0x002E C 08 0x0030
A 09 0x002F B 09 0x0031 C 09 0x0033
A 10 0x0032 B 10 0x0034 C 10 0x0036
A 11 0x0035 B 11 0x0037 C 11 0x0039
A 12 0x0038 B 12 0x003A C 12 0x003C
A 13 0x003B B 13 0x003D C 13 0x003F
A 14 0x003E B 14 0x0040 C 14 0x0042
A 15 0x0041 B 15 0x0043 C 15 0x0045
A 16 0x0044 B 16 0x0046 C 16 0x0048
A 17 0x0047 B 17 0x0049 C 17 0x004B
A 18 0x004A B 18 0x004C C 18 0x004E
A 19 0x004D B 19 0x004F C 19 0x0051
A 20 0x0050 B 20 0x0052 C 20 0x0054

18

You might also like