DRAFT: This module has unpublished changes.



Software Design Document

 

for

 

Programming Assignment #2

 

February 28th, 2014





Prepared by Sanjay Kapoor

skaroop2@gmail.com





Prepared For:

Dr. Rick Coleman, Instructor

CS 221, Data Structures in C++

Computer Science Department

University of Alabama in Huntsville




















1.0 System Overview………………………………………………………………..3

2.0 Referenced Documents………………………………………………………..3

3.0 Architectural Design…………………………………………………………….3

3.1 Concept of Execution…………………………………………………..3

3.2 Code Outline……………………………………………………………..3

4.0 Detailed Design………………………………………………………………….4

4.1 Source File: CharacterList.cpp

           4.2 Source File: CharacterList.h

           4.3 Modified Source File: Character.cpp

           4.4 Modified Source File: Character.h

           




































1.0 System Overview

The purpose of this program is to enumerate a CharacterList class which would store and manipulate instances of the Character class which we developed in Programming Assignment 1, both making changes to itself and letting the modifying function know if such changes had been properly made.



2.0 Referenced Documents

 

Programming Assignment 1 Statement of Work

Dale, Nell C++ Plus Data Structures (2011)

 

3.0 Architectural Design

 

3.1 Concept of Execution

The purpose of this program is to enumerate a CharacterList class which would store  

 and manipulate instances of the Character class which we developed in Programming

Assignment 1, both making changes to itself and letting the modifying function know if

such changes had been properly made.

 

This class will use the List abstract data type to manage all of the Characters, in which

node of the List will point to the next node, and using this next pointer we can iterate

through the list and perform various functions like find, delete, and add.

 

3.2 Code Outline

The program will consist of the following files:

Class: CharacterList.h and CharacterList.cpp

 

CharacterList() and ~CharacterList()--default constructor and destructor.

bool addCharacter(Character *newCharacter)--this function takes a single argument,

a pointer to a Character class object. It will then add this character to the linked list of character objects. The list shall be an ordered linked list sorted by the name of the character. It will return true if the player was successfully added to the list or false if it failed to add the player.

 

bool deleteCharacter(char *characterName)--this function takes a character name as it's only argument. It shall locate the character in the list of characters and delete this character from the linked list of Character objects. It will return true if the character was successfully deleted from the list or false if the character was not found in the list.

bool addItem(char *characterName, Item *newItem)--this function takes a player name, and a pointer to an Item structure. It will then locate this character in the list and add this item to the character's list of carried items. It will return true if the item was successfully added to the player's array of items or false if the player's array of items is full. In this implementation the item will merely be added to a temporary array.

 

Item *deleteItem(char *characterName, char *itemName)--this function takes a character name, and an Item name. It will then locate this character in the list and remove the item from the character's list of carried items if the item exists. It will return a pointer to the item or null if the item was not found in the player's list of items. In this implementation the item will merely be removed from a temporary array.

 

void printCharacters()--this function will call the print function in each of the Character objects in the list to print all data stored in the list.

 

Functions added to Character.h and Character.cpp:

 

bool addItem(Item *item) - Add an item to the player's list of carried items. Return true if this item was successfully added, or false if the player's array of items is full and the new item cannot be added.

 

Item *dropItem(char *itemName) - Locate the named item in the player's array of items, remove it from the player and return a pointer to the item or NULL if the item was not found.

 

Functions modified in Character.h and Character.cpp:

 

void printAll() - The printAll() function shall be modified so that it prints all information on the character as required in programming assignment 1 (Name, Class, Alignment, Hit points, all 6 character trait values) and the list of items carried with their weight and value.

 

char *getName(); - Returns a pointer to a char array containing the name of the Character

 

int getClass(); - Returns an integer value containing the character’s Class int.

 

int getAlignment(); - Returns an integer value containing the character’s Alignment int.

 

int getHitPoints(); - Returns an integer value containing the character’s Hit Points int.

 

int getStrength(); - Returns an integer value containing the character’s Strength int.

 

int getDexterity(); - Returns an integer value containing the character’s Dexterity int.

 

int getConstitution(); - Returns an integer value containing the character’s Constitution int.

 

int getIntelligence(); - Returns an integer value containing the character’s Intelligence int.

 

int getWisdom(); - Returns an integer value containing the character’s Wisdom int.

 

int getCharisma(); - Returns an integer value containing the character’s Charisma int.

 

     
     
     
     
     
     

4.1 Source File: CharacterList.cpp

  4.1.1 Function CharacterList()

      4.1.1.1 Purpose

      This function shall create a CharacterList instance with the pointer to a Character pointing

      to NULL, as it is a default constructor.

      4.1.1.2 Arguments

      None.

      4.1.1.3 Return value

      A pointer to a CharacterList instance.

      4.1.1.4 Function outline in pseudocode

      Initialize a CharacterList object, setting its Character pointer (private variable head) to

      NULL.

      4.1.1.5 Traceability

      This function satisfies requirement 2.1.2.1 in the SoW.

 

      4.1.2 Function ~CharacterList()

      4.1.2.1 Purpose

      This function will destruct a CharacterList instance.

      4.1.2.2 Arguments

      None.

      4.1.2.3 Return value

      None.

      4.1.2.4 Function outline in pseudocode

      Character * tempCur = head

      Character * tempNext

 

      while(tempCur != NULL)

      {

          tempNext = tempCur -> next

          delete tempCur

          tempCur = tempNext

      }

 

    

     

      4.1.2.5 Traceability

      This function satisfies requirement 2.1.2.1 in the SoW.

      4.1.3 Function bool addCharacter(Character *newCharacter)

      4.1.3.1 Purpose

      This function takes a single argument, a pointer to a Character class object. It will then add   

      this character to the linked list of character objects. The list shall be an ordered linked list

      sorted by the name of the character.

      4.1.3.2 Arguments

      Character *newCharacter

      4.1.3.3 Return value

      A boolean value, true if the Character was added into its proper place in the list and false

      if for some reason it could not be added into its proper place

      4.1.3.4 Function outline in pseudocode

      

        temp = head

        back = NULL

        

 

        //Iterates through the list until it finds the end or two keys that sandwich our

        //newCharacters’ name

        while(temp != NULL && strcmp(temp->getName(), newCharacter -> getName()) < 0)

        {

              back = temp

              temp = temp -> next

        }

        //if we’re inserting in before the head of the list

        if(back == NULL)

        {

              newCharacter -> next = head

              head = newCharacter

        }

        //inserting at middle or end of list

        else

        {

             back -> next = newCharacter

             newCharacter -> next = temp

        }

 

    

 

 

      4.1.3.5 Traceability

      This function satisfies requirement 2.1.2.2 in the SoW.

 

      4.1.5 Function bool deleteCharacter(char *characterName)

      4.1.5.1 Purpose

      This function takes a character name as it's only argument. It shall locate the character in

      the list of characters and delete this character from the linked list of Character objects.

      4.1.5.2 Arguments

      A pointer to a character, char *characterName.

      4.1.5.3 Return value

      true if the Character instance was deleted and false if it was not in the list

      4.1.5.4 Function outline in pseudocode

      back = NULL

      temp = head

   

      while(temp != NULL)

      {

      back = temp

temp = temp.next

      }

     //temp is NULL implies node was never matched

     if(temp == NULL)

return false

     //head matched, delete it

     else if(back == NULL)

     {

head = head.next

          delete temp

     }

     //delete node in middle or end of list

     //if we’re at end of list temp.next == NULL so we do want to set back.next to that

     else

     {

back.next = temp.next

           delete temp

     }

 

      4.1.5.5 Traceability

      This function satisfies requirement 2.1.2.3 in the SoW.



      4.1.6 Function bool addItem(char *characterName, Item *newItem)

      4.1.6.1 Purpose

      This function takes a player name, and a pointer to anItem structure. It will then locate this

      character in the list and add this item to the character's list of carried items. It will return true

      if the item was successfully added to the player's array of items or false if the player's array

      of items is full. In this implementation the item will merely be added to a temporary array.

      4.1.6.2 Arguments

      A pointer to a char array, characterName, and another pointer to a character array, newItem

      4.1.6.3 Return value

      true if the item is added in the list, false if either the Character wasn’t found or the item array

      within that Character was full.

      4.1.6.4 Function outline in pseudocode

      temp = head

      

      //stop incrementing when we match or hit the end of the list

      while(temp != NULL && strcmp(characterName, temp ->getName()) != 0)

temp = temp.next

 

      //handle the reach the end case

      if(temp == NULL)

return false

      //handle the other cases where you match

      else

  return (temp -> addItem())

      4.1.6.5 Traceability

      This function satisfies requirement 2.1.2.4 in the SoW.

 

      4.1.7 Function Item *deleteItem(char *characterName, char* itemName)

      4.1.7.1 Purpose

      This function takes a character name, and an Item name. It will then locate this character in

      the list and remove the item from the character's list of carried items if the item exists. It will

      return a pointer to the item or null if the item was not found in the player's list of items.

      4.1.7.2 Arguments

      A character array, characterName, and another character array, itemName

      4.1.7.3 Return value

      A pointer to the Item that was deleted from the Character’s array of items, or NULL

      if it was not found.

      4.1.7.4 Function outline in pseudocode

      temp = head

      

      //stop incrementing when we match or hit the end of the list

      while(temp != NULL && strcmp(characterName, temp ->getName()) != 0)

temp = temp.next

 

      //handle the reach the end case

      if(temp == NULL)

return NULL

      //handle the other cases where you match

      else

  return (temp -> dropItem(itemName))

      4.1.7.5 Traceability

      This function satisfies requirement 2.1.2.5 in the SoW.

 

      4.1.8 Function void printCharacters()

      4.1.8.1 Purpose

      This function will call the print function in each of the Character objects in the list to print all

      data stored in the list.

      4.1.8.2 Arguments

      None

      4.1.8.3 Return value

      None.

      4.1.8.4 Function outline in pseudocode

      temp = head

 

      while(temp != NULL)

     {

temp -> printAll()

           cout << endl

           temp = temp ->next

     }

 

      4.1.8.5 Traceability

      This function satisfies requirement 2.1.2.6 in the SoW.

      

    4.3 Source File: Character.cpp

 

      4.3.1 Function bool addItem(Item *item)

      4.3.1.1 Purpose

      Add an item to the player's list of carried items. Return true if this item was successfully

      added, or false if the player's array of items is full and the new item cannot be added.

      4.3.1.2 Arguments

      A pointer to an Item, item.

      4.3.1.3 Return value

      None.

      4.3.1.4 Function outline in pseudocode

      Use a for loop and and if statement in conjunction with the strcmp function to find out the first

      empty space in the array and add the item there, or if there’s not one at all, return false

      (return true if the Item was added)

 

      for(i = 0; i<10; i++)

      {

            if(strcmp(m_pItems[i], “---”) == 0)

            {

                  //found the empty spot

      m_pItems[i] = *item

                  return true

            }

      }

      //did not find the empty spot

      return false

     

      4.3.1.5 Traceability

      This function satisfies requirement 2.2.3.1 in the SoW.

 

      4.3.2 Function Item *dropItem(char *itemName)

      4.3.2.1 Purpose

      Locate the named item in the player's array of items, remove it from the player and return a

      pointer to the item or NULL if the item was not found.

      4.3.2.2 Arguments

      A character array, itemName

      4.3.2.3 Return value

      A pointer to an Item.

      4.3.2.4 Function outline in pseudocode

      for(int i = 0; i < 10; i++)

      {

           //if we find Item named itemName in Character’s array

           if(strcmp(m_pItem[i], itemName) == 0)

           {

                  //we need to dynamically allocate so that this data doesn’t get thrown away

                  Item *newItem = new Item()

                  *newItem = m_pItems[i]

                  //delete the item by making it’s name variable the empty string

                  strcpy(m_pItems[i].m_sItemName, “---”)

                  return newItem

           }

      }

      return NULL

      4.3.2.5 Traceability

      This function satisfies requirement 2.2.3.2 in the SoW.

 

      4.3.3 Function char * getName()

      4.3.3.1 Purpose

      This function will get the character array that represents the name of the Character

      instance, m_sName

      4.3.3.2 Arguments

      None.

      4.3.3.3 Return value

      A character array containing the Character’s name

      4.3.3.4 Function outline in pseudocode

      Return m_sName

      4.3.3.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

 

      4.3.4 Function int getClass()

      4.3.4.1 Purpose

      This function will return the int describing the class of the Character instance, m_iClass.

      4.3.4.2 Arguments

      None

      4.3.4.3 Return value

      An int, the class of the Character.

      4.3.4.4 Function outline in pseudocode

      return m_iClass

      4.3.4.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

 

      4.3.5 Function int getAlignment()

      4.3.5.1 Purpose

      This function will return the Alignment int of the Character instance, m_iAlignment.

      4.3.5.2 Arguments

      None.

      4.3.5.3 Return value

      An int containing the Alignment value of the Character instance.

      4.3.5.4 Function outline in pseudocode

      Return m_iAlignment

      4.3.5.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

 

      4.3.6 Function int getHitPoints()

      4.3.6.1 Purpose

      This function will return the Hit Points value of the Character, m_iHitPoints.

      4.3.6.2 Arguments

      None.

      4.3.6.3 Return value

      An int containing the Hit Points value of the Character.

      4.3.6.4 Function outline in pseudocode

      return m_iHitPoints

      4.3.6.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

 

      4.3.7 Function int getStrength()

      4.3.7.1 Purpose

      This function will return the Strength int from the m_iCharTraits array at index 0.

      4.3.7.2 Arguments

      None.

      4.3.7.3 Return value

      The Strength int from m_iCharTraits[0] from the Character instance.

      4.3.7.4 Function outline in pseudocode

      return m_iCharTraits[0]

      4.3.7.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

 

      4.3.8 Function int getDexterity()

      4.3.8.1 Purpose

      This function will return the value stored in m_iCharTraits[1], the dexterity of the Character

      instance.

      4.3.8.2 Arguments

      None.

      4.3.8.3 Return value

      An int containing the value of dexterity, located at m_iCharTraits[1]

      4.3.8.4 Function outline in pseudocode

      return m_iCharTraits[1]

      4.3.8.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

     

      4.3.9 Function int getConstitution()

      4.3.9.1 Purpose

      This function will return the int Constitution value stored in m_iCharTraits[2]

      4.3.9.2 Arguments

      None.

      4.3.9.3 Return value

      An int containing the value of the Constitution stored in m_iCharTraits[2]

      4.3.9.4 Function outline in pseudocode

      return m_iCharTraits[2]

      4.3.9.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

 

      4.3.10 Function int getIntelligence()

      4.3.10.1 Purpose

      This function returns the value of intelligence stored in the Character instance at

      m_iCharTraits[3].

      4.3.10.2 Arguments

      None.

      4.3.10.3 Return value

      An int containing the value of the Intelligence stored at m_iCharTraits[3].

      4.3.10.4 Function outline in pseudocode

      return m_iCharTraits[3]

      4.3.10.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

 

      4.3.11 Function int getWisdom()

      4.3.11.1 Purpose

      This function returns the value stored at m_iCharTraits[4], the Wisdom int of the Character

      instance.

      4.3.11.2 Arguments

      None.

      4.3.11.3 Return value

      An int containing the Wisdom of the Character instance, stored at m_iCharTraits[4]

      4.3.11.4 Function outline in pseudocode

      return m_iCharTraits[4]

      4.3.11.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

 

      4.3.12 Function int getCharisma()

      4.3.12.1 Purpose

      This function returns the Charisma int stored at m_iCharTraits[5]

      4.3.12.2 Arguments

      None.

      4.3.12.3 Return value

      The Charisma int stored at m_iCharTraits[5] of the Character instance.

      4.3.12.4 Function outline in pseudocode

      return m_iCharTraits[5]

      4.3.12.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

 

        4.3.3 Function Character()

      4.3.3.1 Purpose

      Make a change to this function so that it initializes the Item array to all 0’s for weight

      and value and all “---” ‘s for m_sName

      4.3.3.2 Arguments

      None.

      4.3.3.3 Return value

      A character array containing the Character’s name

      4.3.3.4 Function outline in pseudocode

      Use a for loop to go through the item array and initialize it

      4.3.3.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

 

       4.3.3 Function Character(args)

      4.3.3.1 Purpose

      Make a change to this function so that it initializes the Item array to all 0’s for weight

      and value and all “---” ‘s for m_sName

      4.3.3.2 Arguments

      None.

      4.3.3.3 Return value

      A character array containing the Character’s name

      4.3.3.4 Function outline in pseudocode

      Use a for loop to go through the item array and initialize it

      4.3.3.5 Traceability

      This function satisfies requirement 2.2.4 in the SoW.

DRAFT: This module has unpublished changes.