Question: ADT(Abstract Data Type) entry.h #include 2 #include 3 #include 4 5 6 //This journal supports a title and notes 7 //In the real world this

ADT(Abstract Data Type)

entry.h

#include

2 #include

3 #include

4

5

6 //This journal supports a title and notes

7 //In the real world this would contain a date,

8 //author, type of journal entry, and much more!

9 class journal_entry

10 {

11 public:

12 /* These functions have ALREADY been created */

13 journal_entry(void);

14 ~journal_entry(void);

15 int create_entry(char * title, char * notes);

16 int display(void);

17

18

19 //Step #7: Implement this function

20 //This function takes the argument and copies it into

21 //the journal's data members

22 int copy_entry(const journal_entry & copy_from);

23

24 //Step #8: Implement this function

25 //This function will return non-zero if the title sent

26 //in as an argument matches the data member. It supplies

27 //the matching journal back as an argument

28 int retrieve(char * matching_title, journal_entry & found);

29 private:

30 char * title;

31 char * notes;

32 };

33 bool again();

list.h

#include "entry.h"

5

6 struct node

7 {

8 journal_entry entry;

9 node * next;

10 };

11

12 class list

13 {

14 public:

15 //These functions have ALREADY been implemented:

16 list(void);

17 ~list(void);

18

19 //Implement these three functions

20 int add(journal_entry & to_add);

21 int find(char matching_title[], journal_entry & found);

22 int display(void);

23

24 //Append one list onto the end of another

25 //Takes the argument and copies the source and places

26 //it at the end of the current list

27 int append(list & source);

28

29 private:

30 node * head;

31 node * tail;

32 };

33

lab.cpp

#include "list.h"

2 using namespace std;

3

4 const int SIZE=100;

5

6 int main()

7 {

8

9 char title[SIZE], notes[SIZE]; //temporary for journals

10 journal_entry entry; //Start creating entries!

11 list my_journal;

12

13

14 //Main has already been written for you to test out

15 //the add and find functions

16 //

17 //Notice how we use the returned value of the functions!

18 //Also notice that all communication with the user is

19 //done through main (not the ADT)

20

21

22 //Let's create some journal entries

23 do

24 {

25 cout <<"Please enter the title of your journal entry ";

26 cin.get(title, SIZE, ' '); cin.ignore(SIZE,' ');

27 cout <<"Please enter your notes ";

28 cin.get(notes, SIZE, ' '); cin.ignore(SIZE,' ');

29

30 //Now create the journal entry

31 if (entry.create_entry(title, notes))

32 //if this was successful, let's add it to the list!

33 if (! my_journal.add(entry))

34 cerr << "We were unable to add it to the list... ";

35 } while (again());

36

37 //Now display all that we have

38 cout <<" The entire list contains the following: ";

39 if (!my_journal.display())

40 cerr << "The list is empty...try again ";

41

42

43 //The following code demonstrates how to call the find function.

44 //You may use this code or modify it to fully test your lab code!

45 /*

46

47 //Is there an entry we would like to find (by title)?

48 cout <<"Enter a title which you would like to find in your journal: ";

49 cin.get(title, SIZE, ' '); cin.ignore(SIZE,' ');

50 if (my_journal.find(title, entry))

51 {

52 cout <<" We found: ";

53 if (!entry.display())

54 cerr << "Sorry, can't display it at this time ";

55 }

56 else cout <<" No match found. ";

57 */

58 return 0;

59

60 }

entry.cpp

#include "entry.h"

2

3

4 //Step #7: Implement this function

5 //This function takes the argument and copies it into

6 //the journal's data members

7 int journal_entry::copy_entry(const journal_entry & copy_from)

8 {

9

10 //Place your code here

11 }

12

13

14 //Step #8: Implement this function

15 //This function will return non-zero if the title sent

16 //in as an argument matches the data member. It supplies

17 //the matching journal back as an argument

18 int journal_entry::retrieve(char * matching_title, journal_entry & found)

19 {

20

21 //Place your code here

22

23 }

24

list.cpp

#include "list.h"

2 using namespace std;

3

4

5

6

7 //Implement these three functions

8 //Add to the end of the LLL as efficiently as possible

9 int list::add(journal_entry & to_add)

10 {

11 //Implement this function using the

12 //journal entry functions we just wrote!

13 }

14

15 //Display all journal entries

16 //Return false if there are no entries

17 int list::display(void)

18 {

19 //Your code goes here!

20

21

22 }

23

24 //Determine if there is a match with the title passed in

25 //and if so provide the matching journal entry back to the

26 //client program through the second argument.

27 //Return a zero if no match is found

28 int list::find(char matching_title[], journal_entry & found)

29 {

30 //Your code goes here!

31

32 return 0;

33 }

34

35

36 //Copy the list passed in as an argument

37 //and add the nodes to the end of the current list

38 int list::append(list & source)

39 {

40

41 //Your code goes here!

42

43 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!