I need help writing this code in C. It begins by making a struct that holds 2 other structs inside and allocates memory dynamically. Input will begin with a line containing 1 integer, N (1 ≤ N ≤ 100,000), representing the number of park sections. Each park section initially contains 0 cages. Following this line will be list of commands. The commands must be processed in the order they are given. Each command begins with a number and can be 1 of 4 types. The types are listed below ●1 S C ○This command changes the number of cages in some particular section. The section that is modified is the section numbered S (1-indexed). The resulting number of cages in section S is the number C. This could increase or decrease the number of cages. Any animal that was in a cage with ID after C (1-indexed) is sent back to the warehouse. If the section number is invalid, no changes should be made. ●2 S C A ○This command adds an animal to a cage. The section that is modified is the section numbered S (1-indexed). The resulting cage the animal is added to is C (1-indexed), if the cage is empty and the section and cage exists. If an animal is already present in cage C of section S or there is no section S or cage C of section S does not exist, then the animal is NOT added to the cage. The type of animal is A (a string of at most 1000 alphanumeric characters). ●3 S C ○This command requests the animal type of the animal in cage C (1-indexed) of section S. If no animal is present or the section or cage number is invalid, the phrase “No animal found.” (quotes for clarity) should be printed instead. ●4 ○This command requests that the program ends (I guess we finished organizing all the exhibits). Output should contain a line for each command of type 3. The line should either contain the animal type if the request was valid or the string “No animal found.”
I need help writing this code in C. It begins by making a struct that holds 2 other structs inside and allocates memory dynamically. Input will begin with a line containing 1 integer, N (1 ≤ N ≤ 100,000), representing the number of park sections. Each park section initially contains 0 cages. Following this line will be list of commands. The commands must be processed in the order they are given. Each command begins with a number and can be 1 of 4 types. The types are listed below ●1 S C ○This command changes the number of cages in some particular section. The section that is modified is the section numbered S (1-indexed). The resulting number of cages in section S is the number C. This could increase or decrease the number of cages. Any animal that was in a cage with ID after C (1-indexed) is sent back to the warehouse. If the section number is invalid, no changes should be made. ●2 S C A ○This command adds an animal to a cage. The section that is modified is the section numbered S (1-indexed). The resulting cage the animal is added to is C (1-indexed), if the cage is empty and the section and cage exists. If an animal is already present in cage C of section S or there is no section S or cage C of section S does not exist, then the animal is NOT added to the cage. The type of animal is A (a string of at most 1000 alphanumeric characters). ●3 S C ○This command requests the animal type of the animal in cage C (1-indexed) of section S. If no animal is present or the section or cage number is invalid, the phrase “No animal found.” (quotes for clarity) should be printed instead. ●4 ○This command requests that the program ends (I guess we finished organizing all the exhibits). Output should contain a line for each command of type 3. The line should either contain the animal type if the request was valid or the string “No animal found.”
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
I need help writing this code in C. It begins by making a struct that holds 2 other structs inside and allocates memory dynamically.
Input will begin with a line containing 1 integer, N (1 ≤ N ≤ 100,000), representing the number of park
sections. Each park section initially contains 0 cages.
sections. Each park section initially contains 0 cages.
Following this line will be list of commands. The commands must be processed in the order they are
given. Each command begins with a number and can be 1 of 4 types. The types are listed below
●1 S C
○This command changes the number of cages in some particular section. The section that
is modified is the section numbered S (1-indexed). The resulting number of cages in
section S is the number C. This could increase or decrease the number of cages. Any
animal that was in a cage with ID after C (1-indexed) is sent back to the warehouse. If the
section number is invalid, no changes should be made.
●2 S C A
○This command adds an animal to a cage. The section that is modified is the section
numbered S (1-indexed). The resulting cage the animal is added to is C (1-indexed), if the
cage is empty and the section and cage exists. If an animal is already present in cage C of
section S or there is no section S or cage C of section S does not exist, then the animal is
NOT added to the cage. The type of animal is A (a string of at most 1000 alphanumeric
characters).
●3 S C
○This command requests the animal type of the animal in cage C (1-indexed) of section S.
If no animal is present or the section or cage number is invalid, the phrase “No animal
found.” (quotes for clarity) should be printed instead.
●4
○This command requests that the program ends (I guess we finished organizing all the
exhibits).
Output should contain a line for each command of type 3. The line should either contain the animal type if
the request was valid or the string “No animal found.”
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education