[General Topics] TheDarkLord098:
Need it in 24 hours, thanks.

Page 1

PRACTICAL WORK 3:

THE FAUCES OF LOSS

75.40 Algorithms and Programming I

Course: Méndez

November 5, 2017

1. Objective

That students can analyze a problem and develop a solution applying the concepts of

algorithm and programming related to file management.

That students demonstrate that they manage good programming practices.

2. History

Thanks to the incredible operational preparation of the warships and having performed thousands of simulations

In order to detect the best strategy, the Death Star was finally destroyed by the torpedo of a

simple ship tied with wire.

The space briefly lit up before such an explosion so that the dissipation of the temporary blindness revealed itself

something even worse: the Death Star was a distraction that gave time for another ship to join, and finish,

the battle, which received the name Maw of Perdition. This incredible ship had self-repairing faculties

and self-defensive, really meaning the destruction of the galaxy.

In the face of such a threat, the Rebel Alliance squads had to reorganize quickly. Inteli-

Gerencia detected that Fauces had several weak points that do not self-repair but that would obviously be

highly guarded.

The task of putting together a good strategy falls once again on us ... will we be able to accept it and win

once and for all?

3. Functional specifications

A library should be developed that makes available a series of functions that allow the development of

Battle with Maw of Doom using different binary and text files. Keep in mind that the

user is going to be another programmer that will consume our library, so it is important that our

implementation does not have any interaction with the user, neither by keyboard nor by screen.

Each of the required functions will not have preconditions since all the parameters must be

validated When receiving invalid parameters the functions must return false and in the opposite case

Proceed with the expected action of the functions and return true. In this sense, postconditions must

give an account of those cases, for example: The function returns false in cases X, Y and Z, otherwise it does

certain thing and returns true.

A general validation for all functions is that the files involved must be able to be opened, whether they are

for reading or writing as needed. In the case of not being able to perform this operation, the

execution of the function, that is to close all files that have been previously opened and return false,

without executing anything of the rest of the functionality.

Maw of the Bane has, for now, up to 7 vulnerabilities that each have a weakness to an element

different chemical. The vulnerabilities found are to the following elements: hydrogen, iodine, carbon,

nitrogen, oxygen, sulfur and phosphorus. Knowing that, the Rebel Alliance developed torpedoes whose component

1

Page 2

principal is any of these elements. Then he distributed the torpedoes of these elements to the different

drones, keeping in mind that all the ships of a squadron have the same element of attack.

To assemble the attack strategy, first the information corresponding to the squadrons and the

vulnerabilities, using functions provided for such purposes. Then the distribution of the squares will be

drones that will attack the vulnerabilities and with the file obtained from that function Intelligence will generate the

Strike of attack to know if in the end Fauces of the Bane will be destroyed or not.

4. File specifications

Squad Master: SQUADS.dat

Binary file where each record is a struct that contains: squadron code (char), amount of

squadron ships (int), attack element (char), attack power (int). It is not necessarily

ordered but it is known that at most there will be 26 records.

Vulnerability master: VULNERA.dat

Binary file where each record is a struct that contains: element to which it is weak (char, field

code), resistance (int), durability (int). It is sorted upwards by element code and

at the most it has 7 registers (since there are 7 known vulnerabilities so far).

Distribution of squads by vulnerability: (parameter)

Text file where each line contains: vulnerability code, squad codes separated by

scripts in the middle (For example: "ABC"). Both fields are separated by semicolons (;).

It is ordered ascending by vulnerability code and has as many lines as vulnerabilities

have been loaded in the master file.

2

Page 3

Attacks by vulnerability and squadron: (parameter)

Text file where each line contains: vulnerability code, squad code, casualties

squad (whole number). All fields are separated by semicolons (;). It is ordered

ascending by code of vulnerability and squad code but the amount of

lines it has.

Attack summary: (parameter)

Text file where each line contains: vulnerability code, number of attacks until the

resistance reached 0 (integer), number of attacks until the durability reached 0 (number

whole). All fields are separated by semicolons (;). It is ordered ascending

by vulnerability code and has as many lines as there are vulnerabilities.

3

Page 4

Note: The structure of each record / line of the files will always be valid, that is, each file will have the

number of fields indicated and the type of data indicated. No need to validate that there is less or more

fields that are not of a data type other than that specified in the statement.

5. Implementation specifications

The fauces library (.hy .c) must be developed and must have the following functions:

bool update squads (char code squadron, int quantity ships, char element attack,

int power attack)

To any validation it must be added that the squadron code must be a capital letter, the

number of ships and attack power must always be positive and that the element of their attacks

It has to be one of the pre-established ones.

If the squadron does not exist, it will be registered in the master file, but if it exists, the data will be updated

with the past by parameter.

bool update vulnerabilities (char * file updates)

The records will be registered with the vulnerabilities that do not exist in the master file, but the

that exist will be updated with the data of the registry of the file of updates having that in

note that this will be done in the only case that the update record is valid (that the points of

resistance and durability are positive and that the element that is weak is one of the pre-established).

In the latter case, if an update record is not valid it will simply be ignored and will continue

with the rest.

bool distribute squads (char * file distributions)

It will generate the file of distributions of squads by vulnerability. For each vulnerability in the

master will be obtained squads whose element of attack matches said weakness of said

vulnerability.

bool perform attacks (char * file attacks, char * summary file, bool * fauces destroyed)

The file of attacks has lots of records by vulnerability, and in turn in those lots there are sublots

that correspond to the attacking squadrons. At the beginning of a batch of attacks due to vulnerability,

recover your data (resistance and durability) from the master file of vulnerabilities; at the beginning of a

sublot of attacks per squadron you must recover your data (number of ships and attack power

of each ship).

The dynamics of this function is as follows: for each record the number of ships of the

current squadron for the attack power of the ships of said squadron and will be subtracted from the resistance

of the vulnerability until it is 0; When the resistance reaches 0 the process will be the same

but for the durability until it also reaches 0. After each attack you should go discounting the

number of ships of the squadron the ships eliminated. The objective is to try to destroy each one of the

vulnerabilities, that is to say that its durability reaches 0. This process must be repeated for each of the

vulnerabilities.

At the end of all attacks, the attack summary file should be generated. Keep in mind that if

4

Page 5

some of the attack quantities never reached 0 then that amount will be replaced by -1 for

indicate that it was not possible to reach 0 there.

In the variable fauces variable passed by reference, a true value will be saved if all could be destroyed.

the vulnerabilities, or false if it could not.

It must be taken into account that the master vulnerability file can be opened only once but the

Squad master can be opened as many times as necessary.

The characters that we are going to use to represent the elements of the attacks and weaknesses of the vulnerabilities

The chemical symbols of these elements are:

'H' for hydrogen.

'I' for iodine.

'C' for carbon.

'N' for nitrogen.

'O' for oxygen.

'S' for sulfur.

'P' for phosphorus.

6. Correction specifications

When there is 1 week left until the delivery date, the files prueba.c that Kwyjibo uses for co-

To correct the works. Until that moment they should write their own tests. To make the corresponding

5

Page 6

tests. The following command line must be compiled locally without errors:

gcc fauces.c tests.c -o tests -std = c99 -Wall -Wconversion -Werror

All the good programming practices seen so far must be applied, as we have already seen

they are as or more important than the correct functioning of the code.

Important: The works that do not compile will NOT be corrected and will go directly to redelivery. In case of no

perform the delivery of the work will also go to direct redelivery.

7. Delivery

You must upload a zip file (regardless of the name) that exclusively contains the files fauces.c and fauces.h

to Kwyjibo. You can make as many deliveries as you want, but the last and with limit will be taken into account

of rise the day Wednesday 22/11 at 23:59 hs.

In case of going to redelivery, the limit will be on Wednesday 06/12 at 23:59 hs.

In both cases, the note and return of the works will be sent by mail.

6