Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created December 19, 2014 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightfold/901aafb7a7ae26e76396 to your computer and use it in GitHub Desktop.
Save rightfold/901aafb7a7ae26e76396 to your computer and use it in GitHub Desktop.

I have my homework and i don't know how i can solve that ... can you help me ? Here is the C program i need.

Specifications: Implement a system of distribution of packets in a city that operate according to the following specifications: ● NRC city is divided into districts. A neighborhood is a structure comprising: ○ id a whole ○ char * name ● A packet is represented through a structure that contains the following fields: ○ id a whole ○ address an array int [18] only the values 0 or 1 ○ idCartier a whole ○ a whole street ○ a whole number ○ priority value from the set {1,2,3,4,5}; 5 = highest priority, 1 = lowest priority ○ float weight ○ post a short message accompanying the package (~ a sentence) char *. The message may contain only: letters, numbers, spaces and punctuation (.,!? :) ○ message encoding an entire package task distribution calculated I. Each packet has an address represented by a vector of 18 positions that retains only the values 0 or 1, with the following meaning: the first 5 digits represent id neighborhood next 5 represents street and The following 8 is the number. Note! For fields of type char * name and district must assign space message exactly as needed, no more! ● Each postman will have a coinciding with id id district is responsible, it must distribute packages in that neighborhood. The structure is defined by the postman contains the following fields: ○ id int in the range [0, 31], 32 the maximum number of postmen ○ nrPachete int in the range [0, 49], 50 the maximum number of packets distributed. ○ vector with packages that have distributed

There is a chief postman who initially receives all packets and is responsible for distributing postmen (simple) packages in each district. Once you have received from the chief packages that were distributed, postmen will:

  1. order packets that are responsible according to priority and weight. First distributes packets higher priority. If two packages have the same priority, then the postman will deliver heavier package.
  2. Each recipient postman gives you a code calculated based on the message that you receive with the package (message field) following algorithm:

i. reverses the order of words in the sentence, removing punctuation. Example: If the original message was: "Ana has more than 3 apples." After reversal message should be: "apples3thanmorehasAna"

ii. Calculate a code that is the sum of the products of the ASCII code of each character and position it inside the string after or processing carried out earlier. (Numbering starts at character position 0). iii. The final code is code-sharing above the rest of the product of the house and street number package. Postman chief will check each received code is correct, because some postmen used to modify messages in certain packages. Using his Verification code does the same algorithm that recipients lau used to generate code for each package.

Task I:

  1. Implement a function that reads the keyboard following: NRC number of neighborhoods and postmen following lines NRC receives the name of each quarter; NRP total packages 4 * NRP on the following lines will each receive package (four lines / package): ◆ address package (18 values 0 or 1) ◆ priority ◆ weight ◆ This message is 100 characters maximum length. Both ID's neighborhoods and the packages will be filled automatically from 0. Do not read from the keyboard!

  2. Implement a function that, for a given package, extract the address neighborhood, street and that number by completing the appropriate fields in the packet structure.

  3. Implement a function that distributes packets postmen.

  4. Write a function that receives an array of structures of type package, packages of vector to order by priority (high to low), and if more packets have priority Wherefore, be ordered by weight (still low), if in this case there are packages with the same weight and the same priority, then the packages to be left in the natural order.

  5. Write the message encoding functions to calculate: a. function that reverses the order of words and text dintrun remove punctuation. b. function that receives as parameter and calculates a packet message code as specified above.

Task II:

  1. Write a function that receives Id postman to alter only the codes were last digit equal to the id postman. Example: mailman with Idul 6, it will alter the code 246, but will not alter the code 261 (for the first ending in June, and second, no), and if the mailman has Idul 13, it will alter the code 4913, but will not alter the code 403 as the last 2 digits are 13 in said second case. Use an auxiliary function to alter (change) code of a message using the following algorithm: a. Calculate the prime factors of Id postman. These factors will represent bit positions receive .Dacă Id bit positions is 0, then we will consider only the value 0 as a "divider". In the case of one, the only one divisor will be considered. b. Each bit before heading described in the previous step will be "reversed" (1 becomes 0, 0 becomes 1). Bits will change only once, even if power factor occurs at> 1. If there are factors larger than 31, then those factors will be ignored during the algorithm. Bit numbering starts at 0 and is from right to left. The function receives as parameters id code and a mailman.
  2. Write a function to assign a score to each postman, the score equal to the number of packets distributed correctly / total number of packets distributed. A package is considered correct if properly distributed to the appropriate code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment