Presentation is loading. Please wait.

Presentation is loading. Please wait.

EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019

Similar presentations


Presentation on theme: "EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019"— Presentation transcript:

1 EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Lecture 15: Program 2 overview

2 Announcements/reminders
Program 2 due 3/21 Will implement dictionary Each entry contains word, part of speech, definition Load contents of dictionary from file or user input Implement string-based commands to interact Friday, 3/8: deadline for P1 resubmissions Exams to be returned Friday 6/8/2019 Data Structures: Lecture 15

3 Data Structures: Lecture 15
Today’s lecture Review Constructors & initialization lists Program 2 intro … … and that’s it, since I have a Faculty Senate meeting on South Campus that starts at 3:30 … 6/8/2019 Data Structures: Lecture 15

4 Review: Initialization lists
How would we write Rectangle constructor(s)? Could use Point set functions Ideally, we’d like to call Point constructor as well Create new Point every time we create Rectangle object Use an initialization list Explicitly calls constructors for member data Requires parameterized constructor to be defined Can be used for predefined types as well Example: Rectangle::Rectangle() : height(1), width(1), origin(0,0) {} 6/8/2019 Data Structures: Lecture 15

5 Data Structures: Lecture 15
Program 2 Model a dictionary using two classes DEntry: single word, part of speech, definition Dictionary: collection of DEntry objects Gives practice with Composition String objects 6/8/2019 Data Structures: Lecture 15

6 Data Structures: Lecture 15
Program 2: main program Main program handles commands add word: Add 1 word to dictionary add file: Add file contents to dictionary print all: Print all entries in dictionary print letter <L>: Print all entries containing words starting with letter <L> find <word>: Search dictionary for <word> exit: Exit the program 6/8/2019 Data Structures: Lecture 15

7 Data Structures: Lecture 15
Program 2: classes Class definitions provided in spec, on site (shortly) Spec also contains implementation notes Feel free to use completely, modify, or simply write your own As long as your program correctly implements commands, it’s a good solution! 6/8/2019 Data Structures: Lecture 15

8 Data Structures: Lecture 15
Program 2: DEntry class class DEntry { public: void writeEntry(string w, string p, string d); void printEntry(ostream &out); string getWord(); private: string word; // Word string part; // Part of speech string defn; // Definition }; 6/8/2019 Data Structures: Lecture 15

9 Program 2: Dictionary class
class Dictionary { public: Dictionary(); bool addWord(string w, string p, string d); bool addFile(string fname); bool find(DEntry &entry, string word); void printAll(ostream &out); void printLetter(ostream &out, char letter); private: DEntry entries[100]; // Array of dictionary entries unsigned size; // # entries actually in dictionary unsigned posn(string w); // Position in which word w // exists or should be placed }; 6/8/2019 Data Structures: Lecture 15

10 Data Structures: Lecture 15
Final notes Next time Return exams Reminders: Program 2 due 3/21 Friday, 3/8: deadline for P1 resubmissions 6/8/2019 Data Structures: Lecture 15


Download ppt "EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019"

Similar presentations


Ads by Google