1 / 24

CSE 2341 - Honors Principles of Computer Science I

CSE 2341 - Honors Principles of Computer Science I. Spring 2008 Mark Fontenot mfonten@engr.smu.edu. Note Set 3. Take Note!!!. Next Tuesday, January 22, 2008 Follows a Monday Schedule!!!. Quick Look. Activity Diagrams and the UML Use default and overloaded constructors

cree
Télécharger la présentation

CSE 2341 - Honors Principles of Computer Science I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 2341 - HonorsPrinciples of Computer Science I Spring 2008 Mark Fontenot mfonten@engr.smu.edu Note Set 3

  2. Take Note!!! Next Tuesday, January 22, 2008 Follows a Monday Schedule!!!

  3. Quick Look Activity Diagrams and the UML Use default and overloaded constructors Declare and work with an array of objects Validate user input from within a class

  4. UML® * Siegel, Jon. Introduction to OMG's Unified Modeling Language™ (UML®), http://www.omg.org/gettingstarted/what_is_uml.htm. July 2005 “helps you specify, visualize, and document models of software systems, including their structure and design”* Used heavily in industry to design software (and other things as well) Can be used to explore a current code base by reverse engineering to UML models UML specifies 13 different diagrammatic tools to use in design of system architecture

  5. Our First UML Diagram – Activity Diagram Sample Activity Diagram • Activity Diagram • models logic • can be used at various levels of detail (30,000 foot view or microscopic view of) • Somewhat similar to flowcharting

  6. Main Activity Diagram Artifacts Initial Node – indicates starting point of logic Final Node – indicates stopping point of logic Activity – rounded rectangle – represents the activities that are taking place Flow - arrow indicating flow of logic Decision – Diamond with one flow entering and two or more exiting Ambler, Scott. UML 2 Activity Diagrams, August 20 2006. http://www.agilemodeling.com/artifacts/activityDiagram.htm

  7. Main Activity Diagram Artifacts (2) Merge – Diamond – two or more flows entering and one exiting Condition – text in square brackets indicated a condition that must be satisfied to traverse its flow. [credentials valid] [credentials not valid] Ambler, Scott. UML 2 Activity Diagrams, August 20 2006. http://www.agilemodeling.com/artifacts/activityDiagram.htm

  8. Examples with pseudocode If x is greater than 60 print “YOU PASSED”

  9. Examples with pseudocode Initialize value to – 3Loop while value is less than 10 value = value + 2

  10. Overloaded Constructors InventoryItem.h #ifndef INVENTORYITEM_H #define INVENTORYITEM_H #include <cstring> using namespace std; class InventoryItem { private: char *description; int units; public: InventoryItem() { description = new char[51]; } InventoryItem(char *desc) { description = new char[strlen(desc)+1]; strcpy(description, desc); }

  11. Overloaded Constructors InventoryItem.h InventoryItem(char *desc, int u) { description = new char [strlen(desc) + 1]; strcpy(description,desc); units = u; } ~InventoryItem() { delete[] description; } void setDescription(char *d) { strcpy(description, d); } void setUnits (int u) { units = u; } char *getDescription() { return description; } int getUnits() { return units; } }; #endif

  12. Declaring Objects InventoryItem ii; InventoryItem ii2(“Wrench”); InventoryItem ii3(“Hammer”, 10); Because of the overloaded constructors, can instantiate in different ways

  13. Constructors and Destructors A class can only have one default constructor A class can have any number of overloaded constructors A class can have only one destructor

  14. Objects and Arrays InventoryItem store[10]; • Possible to declare arrays of objects • Default constructor would be called for each element in the array.

  15. Objects and Arrays • Square tres[3] = {5, 6, 10}; • InventoryItem store[3] = { “Wrench”, “Hammer”, “Pliers” }; • May use initialization lists to call overloaded constructors

  16. Objects and Arrays First Element InventoryItem inventory[3] = { “Hammer”, InventoryItem(“Wrench”,17), } Second Element Third Element- Which constructor???? Need more complex initialization list if number of args to constructor is greater than 1

  17. Objects and Arrays InventoryItem inventory[3] = { InventoryItem(“Hammer”, 12), InventoryItem(“wrench”, 17), InventoryItem(“pliers”, 10) }; for (int i =0; i < 3; i++) { cout << inventory[i].getDescription(); cout << inventory[i].getUnits(); }

  18. Design Time • Design an array class. The class should • create an array of integers of any size at runtime • perform bounds checking • allows setting of a particular element of an array • retrieves a particular element from the array

  19. Intlist #ifndef INTLIST_H#define INTLIST_H class IntList { private: int *list; int numElements; bool isValid(int); public: IntList(int); ~IntList(); bool set(int, int); bool get(int, int &);};#endif Intlist.h

  20. Intlist #include “IntList.h” IntList::IntList (int size){ list = new int[size]; numElements = size; for (int ndx =0; ndx < size; ndx++) list[ndx] = 0;} IntList::~IntList(){ delete [] list; } Intlist.cpp

  21. Intlist bool IntList::isValid(int element){ if (element < 0 || element >= numElements) return false; else return true;}bool IntList::set(int element, int value){ if (isValid(element)) { list[element] = value; return true; } else return false;} Intlist.cpp

  22. Intlist bool IntList::get(int element, int &value){ if (isValid(element)) { value = list[element]; return true; } else return false; } Intlist.cpp

  23. Take Note!!! Next Tuesday, January 22, 2008 Follows a Monday Schedule!!!

  24. ?

More Related