Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write pseudocode in english language for this C program. No code needed, just cl

ID: 3717109 • Letter: W

Question

Write pseudocode in english language for this C program. No code needed, just clear pseudocode . Thank you

You're tasked with writing a program for the security team at a high-profile art gallery. The police will

regularly notify the gallery of the names of art thieves. Your job is to keep track of the last 10 patrons to

enter the gallery and when they entered (as an integer "unix time"), as well as to keep a list of the last

50 art thief names the police have given you.

Most of the code has been written by your coworkers. Your colleagues even recommended using this

struct for your part of the program:

struct patron_entry {

char * patron;

int time;

}

Your part is to write the following functions as well as any necessary global variables:

void add_patron_to_list(char * patron, int time);

int add_thief_to_list(char * thief);

SOLUTION :

struct patron_entry people[10];

int head = 0;

int tail = 0;

int count = 0;

void add_patron_to_list(char * patron, int time) {

struct patron_entry person;

int i;

person.patron = (char *) malloc(strlen(patron));

for (i = 0; patron[i]; i++)

person.patron[i] = patron[i];

person.patron[i] = '';

person.time = time;

if (head == tail && count == 10)

free(people[tail].patron);

people[tail] = person;

if (head == tail && count == 10) {

head = (head + 1) % 10;

tail = (tail + 1) % 10;

} else {

tail = (tail + 1) % 10;

count++;

} }

char *thieves[50];

int thiefcount = 0;

int add_thief_to_list(char * thief) {

if (thiefcount == 50)

return THIEF_FAILURE;

thieves[thiefcount++] == (char *) malloc(strlen(thief));

for (i = 0; thief[i]; i++)

thieves[thiefcount][i] = thief[i];

thieves[thiefcount][i] = '';

return THIEF_SUCCESS;

}

Code is already given , just clear pseudocode for add_patron_to_list and add_theif_to_list . Please write pseudcode in clear and understandable form thank you !

Explanation / Answer

/*

1. maintain 50 ponters to store 50 theives

2. initialize count to 0

int add_thief_to_list(char * thief)

3. Check if the list is 50 or not

a.If true return failure

4. allocate required memory to store name

5.save the name and append NULL

6.increment the index and return success

*/

/*Maintain global variables head,tail,count to keep track if structure array is full or not */

/*

add_patron_to_list(char * patron, int time) ::

1.Maintain a global array of structure of 10 to always keep track of 10 patrons

2.create a temporary variable named person to store new patron for every function call.

3.As person.patron is pointer and does not have memory, allocate the memory using malloc()

4.now using a loop save the char * patron argument into the person.patron and at the end append NULL

5.save function argument time into person.time.

6.Check if the structure array is already full or not

a.If true then clear the memory allocation of tail i.e end

7. assign the person structure value to tail

8. Care has to been taken to increment head,tail after every addition of patron and if

they exceeds 10 then they must be brought back to index 1

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote