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

Program In C language. Please write a pseudocode and code in C . You\'re tasked

ID: 3716339 • Letter: P

Question

Program In C language.

Please write a pseudocode and code in C .

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);

Specifications for the whole part

1. Must keep track of two separate lists for patrons and thieves.

2. As more patrons arrive, the oldest parton is to be "forgotten" from the list (like the tail program)

3. Thieves should never be forgotten.

4. You may use any string and library functions we have discussed in class.

5. Work on one function at a time and spent your time wisely.

Specifications for add_patron_to_list, called when a patron enters the gallery.

1. patron variable is an input buffer that will be overwritten with the program's next line of input.

a. This function should allocate new memory for a copy of the patron's name.

2. When there have been more than 10 patrons, the program should deallocate (free) memory that

was allocated from previous patrons.

Specifications for add_thief_to_list, called when the police tip you off about a thief.

1. thief variable is an input buffer that will be overwritten with the program's next line of input.

a. This function should allocate new memory for a copy of the thief's name.

2. Function should return THIEF_SUCCESS when it successfully adds a thief to the list, and

THIEF_FAILURE when there are already 50 thieves in the list.

a. Assume that these are pre-defined symbolic constants with integer values

? please write PSEUDOCODE too !

Explanation / Answer

#include<stdio.h>

#include<stdlib.h>

#include<sys/time.h>

#include<string.h>

struct patron_entry

{

char *patron;

int time;

};

struct thieflist

{

char *thief;

};

int patroncount=0,thiefcount=0;

patron_entry *p[10];

thieflist *th[50];

void add_patron_to_list(char *pat,int time)

{

struct patron_entry* pt=(struct patron_entry*) malloc(sizeof(struct patron_entry));

pt->patron=(char*)malloc(50*(sizeof(char)));

pt->patron=pat;

pt->time=time;

patroncount++;

int i=(patroncount%10);

printf("%d ",i);

p[i]=(struct patron_entry*) malloc(sizeof(struct patron_entry));

p[i]->patron=(char*)malloc(50*(sizeof(char)));

strcpy(p[i]->patron,pt->patron);

p[i]->time=pt->time;

printf(" patron added");

free(pt);

}

void add_thief(char *str)

{

if(thiefcount>50)

{

printf(" THIEF_FAILURE");

}

else

{

thieflist *newth=(thieflist*)malloc(sizeof(thieflist));

newth->thief=str;

th[thiefcount]=(thieflist*)malloc(sizeof(thieflist));

strcpy(th[thiefcount]->thief,newth->thief);

thiefcount++;

printf("SUCCESS");

}

}

int main()

{

  

char name[50];

int i,tm;

while(1)

{

printf(" Enter the name of new person entered in art gallary : ");

  

scanf("%s",name);

  

printf(" Enter 1 for patron or 2 for theif as indetify by POLICE : ");

  

scanf("%d",&i);

  

if(i==1)

{

tm=(int)time(NULL);

add_patron_to_list(name,tm);

  

}

else if(i==2)

{

add_thief(name);

}

}

}

/*

pseucode ---->

patron_entry structure

{

char *patron

int time

}

struct theiflist

{

char *thief

}

add_patron_to_list(char *patron,int time)

if patron greate then 10

remove first come petron

add new patron to patron list

add_theif(char *theif)

if theifcount>100

print "FAILURE"

else

add thief to list

print "SUCCESS

end if   

input new perosn entered in gallary

identify by police

infinite loop

if new perosn entered is patron

tm=get system time

add_patron_to_list(name,tm)

else

add_thief(name)

end loop

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote