Introduction For this assignment, we are asking you to implement a mini Pokédex in C. The task is split into 5 sections; each section is not weighted the same. What is a Pokémon? What is a Pokédex?...

1 answer below »
need to do an introductory c programming assignment on linked list. In this case the linked list is a pokedex and each node in the linked list stores detail such as pokemon name, weight, height, type, etc. Instructions are in files. Only pokedex.c is to be edited and there are 20 functions to write for the pokedex. The other two files are reference files for instructions. This assignment is in C language only.



Introduction For this assignment, we are asking you to implement a mini Pokédex in C. The task is split into 5 sections; each section is not weighted the same. What is a Pokémon? What is a Pokédex? Hello there! Welcome to the world of Pokémon! My name is Oak! People call me the Pokémon Prof! This world is inhabited by creatures called Pokémon! For some people, Pokémon are pets. Others use them for fights. Myself ... I study Pokémon as a profession. — Professor Oak Pokémon are fictional creatures from the Pokémon franchise, most famously from the Pokémon games. The game revolves around the (questionably ethical) capturing of these creatures. Within the fiction of this universe, a device called the Pokédex is used to catalogue all the creatures a player finds and captures. Where can we learn more about Pokédexes? You can play the one of the original Pokémon games here. Quite early in the game you get introduced to the Pokédex. There's some more information on the Pokémon Wikia. In addition, Google will be a great resource, as the topic has been extensively written up about. Supplied Code This zip file contains the files that you need to get started with the assignment. It contains the following files: pokedex.h contains declarations for all functions you need to implement for this assignment. Don't change pokedex.h pokedex.c contains stubs for all the functions you need to implement for this assignment. Put all your Pokédex code in pokedex.c. pokemon.h contains declarations for all functions you must call to create and manipulate Pokémon. Don't change pokemon.h pokemon.c contains the functions you must call to create and manipulate Pokémon. Don't change pokemon.c main.c contains a main function and other functions that allow you to interactively test the functions you implement in pokedex.c Don't change main.c test_pokedex.c contains a main function and other functions which are your starting point for a test framework to automatically test the functions you implement in pokedex.c. As you implement functions in pokedex.c you should add tests to test_pokedex.c. Only put testing code in test_pokedex.c. Reference implementation A reference implementation 1511 pokedex_reference is available to help you understand the assignment. 1511 pokedex_reference ===========================[ Pokédex ]========================== Welcome to the Pokédex! How can I help? ================================================================ Enter command: ? a [pokemon_id] [name] [height] [weight] [type1] [type2] Add a Pokemon to the Pokedex p Print all of the Pokemon in the Pokedex (in the order they were added) d Display details of the currently selected Pokemon > Move the cursor to the next Pokemon in the Pokedex< move="" the="" cursor="" to="" the="" previous="" pokemon="" in="" the="" pokedex="" m="" [pokemon_id]="" move="" the="" cursor="" to="" the="" pokemon="" with="" the="" specified="" pokemon_id="" r="" remove="" the="" current="" pokemon="" from="" the="" pokedex="" x="" [seed]="" [factor]="" [how_many]="" go="" exploring="" for="" pokemon="" f="" set="" the="" current="" pokemon="" to="" be="" found="" c="" print="" out="" the="" count="" of="" pokemon="" who="" have="" been="" found="" t="" print="" out="" the="" total="" count="" of="" pokemon="" in="" the="" pokedex="" e="" [pokemon_a]="" [pokemon_b]="" add="" an="" evolution="" from="" pokemon="" a="" to="" pokemon="" b="" s="" show="" evolutions="" of="" the="" currently="" selected="" pokemon="" q="" quit="" show="" help="" enter="" command:="" a="" 1="" bulbasaur="" 0.7="" 6.9="" poison="" grass="" added="" bulbasaur="" to="" the="" pokedex!="" your="" pokedex.c="" (compiled="" with="" the="" supplied="" pokemon.c="" and="" main.c)="" should="" match="" the="" behaviour="" of="" the="" reference="" implementation.="" provision="" of="" a="" reference="" implementation="" is="" a="" common="" method="" to="" provide="" an="" operational="" specification,="" and="" it's="" something="" you="" will="" likely="" need="" to="" do="" outside="" unsw.="" if="" you="" discover="" what="" you="" believe="" to="" be="" a="" bug="" in="" the="" reference="" implementation,="" report="" it="" in="" the="" class="" forum.="" we="" may="" fix="" the="" bug="" or="" indicate="" that="" you="" do="" not="" need="" to="" match="" the="" reference="" implementation's="" behaviour="" in="" this="" case.="" stage="" 1:="" adding="" and="" printing="" when="" you="" compile="" and="" run="" the="" given="" code,="" you="" will="" get="" the="" following="" message="" if="" you="" try="" to="" add="" a="" pokemon:="" dcc="" -o="" pokedex="" main.c="" pokedex.c="" pokemon.c="" ./pokedex="==========================[" pokédex="" ]="=========================" welcome="" to="" the="" pokédex!="" how="" can="" i="" help?="===============================================================" enter="" command:="" a="" 1="" bulbasaur="" 0.7="" 6.9="" poison="" grass="" exiting="" because="" you="" have="" not="" implemented="" the="" add_pokemon="" function="" in="" pokedex.c="" when="" you="" run="" the="" a="" command,="" this="" function="" in="" pokedex.c="" is="" called:="" void="" add_pokemon(pokedex="" pokedex,="" pokemon="" pokemon)="" {="" fprintf(stderr,="" "exiting="" because="" you="" have="" not="" implemented="" the="" add_pokemon="" function="" in="" pokedex.c\n");="" exit(1);="" }="" your="" first="" task="" is="" to="" implement="" add_pokemon.="" all="" the="" functions="" you="" have="" to="" implement="" in="" pokedex.c="" have="" descriptions="" in="" pokedex.h:="" add="" a="" new="" pokemon="" to="" the="" pokedex.="" note:="" just="" adding="" the="" pokemon="" to="" the="" pokedex="" does="" not="" mean="" it="" has="" been="" 'found'.="" the="" new="" pokemon="" should="" be="" added="" to="" the="" end="" of="" the="" pokedex="" (i.e.="" directly="" after="" the="" pokemon="" that="" was="" added="" when="" add_pokemon="" was="" last="" called).="" when="" the="" first="" pokemon="" is="" added="" to="" the="" pokédex,="" the="" currently="" selected="" pokemon="" becomes="" this="" pokemon.="" the="" currently="" selected="" pokemon="" remains="" the="" first="" pokemon="" that="" was="" inserted="" into="" the="" pokedex,="" until="" the="" `change_current_pokemon`,="" `next_pokemon`,="" or="" `prev_pokemon`="" functions="" are="" called.="" if="" there="" is="" already="" a="" pokemon="" in="" the="" pokedex="" with="" the="" same="" pokemon_id="" as="" this="" pokemon,="" the="" function="" should="" print="" an="" appropriate="" error="" message="" and="" exit="" the="" program.="" pokedex="" order:="" --------------="" the="" pokemon="" in="" the="" pokedex="" are="" stored="" in="" the="" order="" in="" which="" they="" were="" added,="" i.e.="" the="" first="" pokemon="" in="" the="" pokedex="" will="" be="" the="" first="" pokemon="" that="" was="" added,="" the="" second="" pokemon="" in="" the="" pokedex="" will="" be="" the="" second="" pokemon="" that="" was="" added="" etc,="" and="" the="" last="" pokemon="" in="" the="" pokedex="" will="" be="" the="" pokemon="" that="" was="" added="" most="" recently.="" for="" example,="" if="" pikachu="" (#025)="" was="" added="" into="" an="" empty="" pokedex,="" the="" pokedex="" would="" now="" contain="" pikachu="" at="" the="" start="" of="" the="" list,="" and="" pikachu="" would="" be="" the="" currently="" selected="" pokemon.="" [start="" of="" pokedex]="" #025:="" pikachu=""><-- currently="" selected="" pokemon="" [end="" of="" pokedex]="" if="" squirtle="" (#007)="" was="" then="" added,="" it="" would="" be="" the="" second="" pokemon="" in="" the="" pokedex,="" after="" pikachu.="" the="" currently="" selected="" pokemon="" would="" remain="" pikachu.="" [start="" of="" pokedex]="" #025:="" pikachu=""><-- currently="" selected="" pokemon="" #003:="" squirtle="" [end="" of="" pokedex]="" if="" diglett="" (#050)="" was="" then="" added,="" it="" would="" be="" the="" third="" pokemon="" in="" the="" pokedex,="" after="" squirtle.="" [start="" of="" pokedex]="" #025:="" pikachu=""><-- currently selected pokemon // #003: squirtle // #050: diglett // [end of pokedex] void add_pokemon(pokedex pokedex, pokemon pokemon); you need to put code in the add_pokemon function to store the pokemon it is given into the pokedex it is given. you don't need to know any details about what the pokemon type is (i.e. the type of the pokemon pokemon argument passed to add_pokemon) to implement add_pokemon or any other function in pokedex.c. pokemon tip #0: pokemon ids in the pokemon game franchise, pokemon ids start at 1 and go up to 809 (at the time of writing this). the first pokemon is bulbasaur, who has a pokemon id of 1. this assignment, however, allows any pokemon id from 0 upwards (because programmers love counting from 0). throughout this spec we'll be making use of bulbasaur (as well as some of the other official pokemon) in our examples, but do note that you can make your own pokemon with any id from 0 to the maximum number that can be stored in an integer. hint: your code should also operate under the assumption that a pokemon_id of 0 is valid. if you look in pokedex.h you will discover this definition: typedef struct pokedex *pokedex in other words the type pokedex is the same as struct pokedex *. struct pokedex is defined at the top of pokedex.c. it already has one field: a pointer to struct pokenode which can be used to store a linked list. put in code in add_pokemon to add the pokemon it is given to the linked list whose head is in the pokedex it is given. hint: allocate a struct pokenode with malloc. when you run your code you should see this: dcc -o pokedex main.c pokedex.c pokemon.c ./pokedex ===========================[ pokédex ]========================== welcome to the pokédex! how can i help? ================================================================ enter command: a 1 bulbasaur 0.7 6.9 poison grass added bulbasaur to the pokedex! you'll need to implement 4 more functions to find out if add_pokemon really works: void detail_pokemon(pokedex pokedex); pokemon get_current_pokemon(pokedex pokedex); void find_current_pokemon(pokedex pokedex); void print_pokemon(pokedex pokedex); see pokedex.h for information on each function. detail_pokemon and print_pokemon need to call functions defined in pokemon.h to get the information about a pokemon they need to print. note the information detail_pokemon and print_pokemon print about a pokemon depends on whether it has been found. hint: add a field to struct pokenode to indicate if a pokemon has been found. pokemon tip #1: finding pokemon. your pokedex is like an encyclopedia that stores information about pokemon. but unlike a normal encyclopaedia, some of the information in your pokedex is hidden until you've discovered a pokemon of that kind. once you have "found" a certain kind of pokemon, its details will become visible to you in your pokedex. you will need to keep track of whether a pokemon has been found in your pokedex implementation. hint: add a field to struct pokenode to indicate if a pokemon has been found. pokemon tip #2: the currently selected pokemon. your pokedex allows you to scroll through the pokemon stored within, allowing you to see the details of a specific pokemon of your choice. this means that there will always be one pokemon that is currently selected by the pokedex. when you add the first pokemon to the pokedex, that pokemon becomes the currently selected pokemon. when you add additional pokemon, the currently selected pokemon does not change. in stage 2, you will implement functions to allow you to scroll back and forth between pokemon. but for now, you won't need to change the currently="" selected="" pokemon="" #003:="" squirtle="" #050:="" diglett="" [end="" of="" pokedex]="" void="" add_pokemon(pokedex="" pokedex,="" pokemon="" pokemon);="" you="" need="" to="" put="" code="" in="" the="" add_pokemon="" function="" to="" store="" the="" pokemon="" it="" is="" given="" into="" the="" pokedex="" it="" is="" given.="" you="" don't="" need="" to="" know="" any="" details="" about="" what="" the="" pokemon="" type="" is="" (i.e.="" the="" type="" of="" the="" pokemon="" pokemon="" argument="" passed="" to="" add_pokemon)="" to="" implement="" add_pokemon="" or="" any="" other="" function="" in="" pokedex.c.="" pokemon="" tip="" #0:="" pokemon="" ids="" in="" the="" pokemon="" game="" franchise,="" pokemon="" ids="" start="" at="" 1="" and="" go="" up="" to="" 809="" (at="" the="" time="" of="" writing="" this).="" the="" first="" pokemon="" is="" bulbasaur,="" who="" has="" a="" pokemon="" id="" of="" 1.="" this="" assignment,="" however,="" allows="" any="" pokemon="" id="" from="" 0="" upwards="" (because="" programmers="" love="" counting="" from="" 0).="" throughout="" this="" spec="" we'll="" be="" making="" use="" of="" bulbasaur="" (as="" well="" as="" some="" of="" the="" other="" official="" pokemon)="" in="" our="" examples,="" but="" do="" note="" that="" you="" can="" make="" your="" own="" pokemon="" with="" any="" id="" from="" 0="" to="" the="" maximum="" number="" that="" can="" be="" stored="" in="" an="" integer.="" hint:="" your="" code="" should="" also="" operate="" under="" the="" assumption="" that="" a="" pokemon_id="" of="" 0="" is="" valid.="" if="" you="" look="" in="" pokedex.h="" you="" will="" discover="" this="" definition:="" typedef="" struct="" pokedex="" *pokedex="" in="" other="" words="" the="" type="" pokedex="" is="" the="" same="" as="" struct="" pokedex="" *.="" struct="" pokedex="" is="" defined="" at="" the="" top="" of="" pokedex.c.="" it="" already="" has="" one="" field:="" a="" pointer="" to="" struct="" pokenode="" which="" can="" be="" used="" to="" store="" a="" linked="" list.="" put="" in="" code="" in="" add_pokemon="" to="" add="" the="" pokemon="" it="" is="" given="" to="" the="" linked="" list="" whose="" head="" is="" in="" the="" pokedex="" it="" is="" given.="" hint:="" allocate="" a="" struct="" pokenode="" with="" malloc.="" when="" you="" run="" your="" code="" you="" should="" see="" this:="" dcc="" -o="" pokedex="" main.c="" pokedex.c="" pokemon.c="" ./pokedex="==========================[" pokédex="" ]="=========================" welcome="" to="" the="" pokédex!="" how="" can="" i="" help?="===============================================================" enter="" command:="" a="" 1="" bulbasaur="" 0.7="" 6.9="" poison="" grass="" added="" bulbasaur="" to="" the="" pokedex!="" you'll="" need="" to="" implement="" 4="" more="" functions="" to="" find="" out="" if="" add_pokemon="" really="" works:="" void="" detail_pokemon(pokedex="" pokedex);="" pokemon="" get_current_pokemon(pokedex="" pokedex);="" void="" find_current_pokemon(pokedex="" pokedex);="" void="" print_pokemon(pokedex="" pokedex);="" see="" pokedex.h="" for="" information="" on="" each="" function.="" detail_pokemon="" and="" print_pokemon="" need="" to="" call="" functions="" defined="" in="" pokemon.h="" to="" get="" the="" information="" about="" a="" pokemon="" they="" need="" to="" print.="" note="" the="" information="" detail_pokemon="" and="" print_pokemon="" print="" about="" a="" pokemon="" depends="" on="" whether="" it="" has="" been="" found.="" hint:="" add="" a="" field="" to="" struct="" pokenode="" to="" indicate="" if="" a="" pokemon="" has="" been="" found.="" pokemon="" tip="" #1:="" finding="" pokemon.="" your="" pokedex="" is="" like="" an="" encyclopedia="" that="" stores="" information="" about="" pokemon.="" but="" unlike="" a="" normal="" encyclopaedia,="" some="" of="" the="" information="" in="" your="" pokedex="" is="" hidden="" until="" you've="" discovered="" a="" pokemon="" of="" that="" kind.="" once="" you="" have="" "found"="" a="" certain="" kind="" of="" pokemon,="" its="" details="" will="" become="" visible="" to="" you="" in="" your="" pokedex.="" you="" will="" need="" to="" keep="" track="" of="" whether="" a="" pokemon="" has="" been="" found="" in="" your="" pokedex="" implementation.="" hint:="" add="" a="" field="" to="" struct="" pokenode="" to="" indicate="" if="" a="" pokemon="" has="" been="" found.="" pokemon="" tip="" #2:="" the="" currently="" selected="" pokemon.="" your="" pokedex="" allows="" you="" to="" scroll="" through="" the="" pokemon="" stored="" within,="" allowing="" you="" to="" see="" the="" details="" of="" a="" specific="" pokemon="" of="" your="" choice.="" this="" means="" that="" there="" will="" always="" be="" one="" pokemon="" that="" is="" currently="" selected="" by="" the="" pokedex.="" when="" you="" add="" the="" first="" pokemon="" to="" the="" pokedex,="" that="" pokemon="" becomes="" the="" currently="" selected="" pokemon.="" when="" you="" add="" additional="" pokemon,="" the="" currently="" selected="" pokemon="" does="" not="" change.="" in="" stage="" 2,="" you="" will="" implement="" functions="" to="" allow="" you="" to="" scroll="" back="" and="" forth="" between="" pokemon.="" but="" for="" now,="" you="" won't="" need="" to="" change="">
Answered Same DayApr 30, 2021

Answer To: Introduction For this assignment, we are asking you to implement a mini Pokédex in C. The task is...

Aditi answered on May 01 2021
140 Votes
pokedex.c
// Version 1.0.0: Assignment released.
// Version 1.0.1: Minor clarifications about `struct pokenode`.
// Version 1.1.0: Moved destroy_pokedex function to correct location.
// Version 1.1.1: Renamed "pokemon_id" to "id" in change_current_pokemon.
#include
#include
#
include
// Add any extra #includes your code needs here.
//
// But note you are not permitted to use functions from string.h
// so do not #include
#include "pokedex.h"
#include
// Add your own #defines here.
// Note you are not permitted to use arrays in struct pokedex,
// you must use a linked list.
//
// You are also not permitted to use arrays in any of the functions
// below.
//
// The only exception is that char arrays are permitted for
// search_pokemon and functions it may call, as well as the string
// returned by pokemon_name (from pokemon.h).
//
// You will need to add fields to struct pokedex.
// You may change or delete the head field.
struct pokedex {
struct pokenode *head;
struct pokenode *tail;
struct pokenode *current;
};
// You don't have to use the provided struct pokenode, you are free to
// make your own struct instead.
// If you use the provided struct pokenode, you will need to add fields
// to it to store other information.
struct pokenode {
struct pokenode *next;
Pokemon pokemon;
bool found;
int evolveFrom;
int evolveTo;
};
// Add any other structs you define here.
// Add prototypes for any extra functions you create here.
struct pokenode* new_pokenode(Pokemon pokemon){
    struct pokenode* new_pokenode = (struct pokenode*)malloc(sizeof(struct pokenode));
    new_pokenode->pokemon = pokemon;
    new_pokenode->next = NULL;
    new_pokenode->found = false;
    new_pokenode->evolveFrom = -;
    new_pokenode->evolveTo = -1;
    return new_pokenode;
}
// You need to implement the following 20 functions.
// In other words, replace the lines calling fprintf & exit with your code.
// You can find descriptions of what each function should do in pokedex.h
Pokedex new_pokedex(void) {
Pokedex new_pokedex = (struct pokedex*)malloc(sizeof (struct pokedex));
assert(new_pokedex != NULL);

new_pokedex->current = NULL;
new_pokedex->tail = NULL;
new_pokedex->head = NULL;

return new_pokedex;
}
////////////////////////////////////////////////////////////////////////
// Stage 1 Functions //
////////////////////////////////////////////////////////////////////////
void add_pokemon(Pokedex pokedex, Pokemon pokemon) {
    
    struct pokenode* temp = new_pokenode(pokemon);
    
    if(pokedex->head == NULL){
        pokedex->head = temp;
        pokedex->tail = temp;
        pokedex->current = temp;
    }
    else{
        pokedex->tail->next = temp;
        pokedex->tail = pokedex->tail->next;
    }
}
void detail_pokemon(Pokedex pokedex) {
    Pokemon pokemon = pokedex->current->pokemon;
    
if(pokedex->found){
    printf("Id: %d",...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here