Question: Assignment #8 Introduction to C Programming COP 3223 Objectives 1. To learn how to design and implement functions for program development 2. To reinforce how
Assignment #8 Introduction to C Programming COP 3223 Objectives 1. To learn how to design and implement functions for program development 2. To reinforce how to use pass by value and pass by reference variables 3. To learn how to use structures
Introduction: Ninja Academy Ninjas are awesome! Your friend has not stopped talking about how cool ninjas and how they would like to become a ninja. To amuse your friend, you have decided to create a series of programs about ninjas.
Problem: Forming an Alliance (ninjateam.c) Congratulations! You have graduated from the Ninja Academy! Now its time to form your own alliance of ninjas with yourself and fellow graduates. You will be able to tackle the toughest ninja jobs and bring home the best rewards. You want to make sure your team is balanced, so as you add members you will track their name and their strongest skillset.
You will need to be able to do the following: 1) Add a ninja to your team 2) Remove a ninja from your team 3) Search for a particular ninja by name 4) List all of the ninjas with a particular skillset
To make the testing of the program easier, your program will read in all of its input from a file called ninjas.txt. Your alliance of ninjas cannot exceed 1000 members.
Input Specification (ninjas.txt) The first line of the file will contain a single positive integer representing the number of updates to the ninja alliance. (Note: We assume that at the beginning of the program, the team has no ninjas on it.) Each following line will have directions for a single update to the team. The formats for these lines are as follows:
The very first value on each of these lines will be a string from the following subset: {ADD, REMOVE, SEARCH, LIST}. This string indicates which operation (corresponding to the list in the problem statement) is being designated.
If the operation is to add a ninja (ADD), then the line will contain the following information after ADD, separated by spaces: NAME SKILL
The name and skill of the ninja will be strings that contain only alphabetic letters and underscores. None of these strings will exceed 39 characters. No ninja will share a name with another ninja, though there may be multiple ninjas with the same special skillset.
If the operation is to remove a ninja (REMOVE), then the line will only contain the exact name of the ninja after REMOVE.
If the operation is to search for a ninja (SEARCH), then the line will only contain the exact name of the ninja that is being searched for.
If the operation is to list all of the ninjas by a particular skill (LIST), then the line will only contain the desired skill after LIST.
Output Specification All output should go to the screen. Separate the output for each command with one blank line. Here is the format for output for each command:
For adding a ninja, simply write out a statement of the form: X has joined the alliance! Their special skill is Y.
For removing a ninja, simply write out a statement of the form: X has left the alliance.
For both of these, X represents the name of the ninja and Y represents his or her special skillset. You may assume that remove operations in the input file will always be valid. Thus, if a remove is ever requested, the ninja in question is guaranteed to be on the team.
For searching for a ninja, output one of two statements, depending on whether or not the designated ninja was found on the team: X is currently in the alliance. X is NOT currently in the alliance.
For searching for all the ninjas with a particular skill, output a single line of the form: Members with Y skill: Y represents the skill requested. Each following line should list the name of one ninja with that skill in the alliance. List each ninja exactly once.
Implementation Restrictions You must use the following constants: #define MAX_LENGTH 40 #define MAX_TEAM 1000 You must use the following structures to store information: struct ninja { char name[MAX_LENGTH]; char skill[MAX_LENGTH]; };
struct alliance { struct ninja team[MAX_TEAM]; int num_ninjas; };
It is not sufficient to simply have the structures in your program, you must use them store information and process operations for the alliance. Though function prototypes will not be provided, it is expected that you follow good programming design and create several functions with well-specified tasks related to the solution of this problem. Make sure to pay very careful attention to parameter passing.
Hints Use pass by reference parameters for your functions. This will ensure that any change made to the ninja alliance in a function is reflected in main. Inside the function, remember to access the components using the -> syntax for structures. Use the prewritten string functions when dealing with strings:
use strcpy whenever you want to copy the contents of one string into another, instead of the equals sign. use strcmp to determine which operation is being requested.
Whenever you add a ninja to the team, make sure you add it to the first open slot on the team. Whenever you remove a ninja from the team, make sure you copy the ninja in the last spot on the team into the vacated spot.
For example, if the ninja to be removed is in index 3 and the number of ninjas on the team before removal is 7, then the ninja in index 6 (the last filled index) should be copied into the ninja spot in index 3. Subsequently, the number of ninjas on the team should be updated to 6.
Sample Input File (ninjas.txt) 12 ADD NAGATO SWORDS ADD SANDAYU STAVES SEARCH HANZO ADD HANZO STEALTH ADD CHIYOME DISGUISE ADD KOTARO STEALTH LIST STEALTH REMOVE KOTARO ADD HATTORI SWORDS LIST SWORDS LIST DISGUISE LIST STAVES
Sample Output (corresponding to input file) NAGATO has joined the alliance! Their special skill is SWORDS. SANDAYU has joined the alliance! Their special skill is STAVES. HANZO is NOT currently in the alliance. HANZO has joined the alliance! Their special skill is STEALTH. CHIYOME has joined the alliance! Their special skill is DISGUISE. KOTARO has joined the alliance! Their special skill is STEALTH. Members with STEALTH skill: HANZO KOTARO KOTARO has left the alliance. HATTORI has joined the alliance! Their special skill is SWORDS. Members with SWORDS skill: NAGATO HATTORI Members with DISGUISE skill: CHIYOME Members with STAVES skill: SANDAYU
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
