I am working on an old program I had a while back just to understand how it works. So far I have just been looking at a BST I found on this site (
http://www.cplusplus.com/forum/general/1551/ and I was trying to change all the ints to strings to be able to sort some strings and ran into a snag. "switch expression of type 'std::string' is illegal" and I'm not sure what they mean since I have included strings in the program already. These are the instructions:
Motivation You are charged with printing the "Table of Content" for a book, where Chapters, sections,
and subsections are printed with their page numbers.
However, this needs to be dynamically implemented, in that you must allow for the author to provide for
additional material, that will be included in the book. Each chapter has zero or more sections, each section
has zero or more subsections, and each subsection will have zero or more paragraph. Only paragraphs will
actually take up space on the printed page, and each paragraph takes between 1 and 5 pages. Your program
needs to be able to add paragraphs to subsections, subsections to sections, sections to chapters, and chapters
to the book.
Some Notes
1. You must implement these with the binary representation of a general tree, you must
use linked pointers, you must use recursion, and you must use C++.
2. You might be asked to insert a chapter, section, subsection, or paragraph `immediately after 0'. How-
ever, there are no chapters, sections, subsections, or paragraphs that have number 0. So this is a
mechanism to populate the particular sub-structure with its rst chapter, section, subsection, or para-
graph.
3. The title are chosen from the text of Hamlet. Each title is four, ve or six words taken from the text,
and are enclosed in double quotes. To strip the extra quotes, you may want to use filein.get();
(or use another method, such as regular expressions from the STL for 5 points extra credit).
4. Some of you have started the project already, and have populated already parts of the ToC, which is
perfectly ne. The new chapters, sections, and subsections can still be inserted
5. You may add functionality for extra credit. However, you must discuss these with me before imple-
menting, and extra credit is limited to a total of 15%
Also a sample section of our input that was given then looks like this:
chap ` the tragedy of` 0
chap `hamlet prince of denmark by william` 0
chap `shakespeare dramatis personae claudius king` 0
chap `of denmark marcellus officer hamlet son` 1
sec `to the former and nephew` 1 0
chap `to the present king` 1
sub `polonius lord chamberlain horatio friend` 1 1 0
sec `to hamlet laertes son to polonius` 4 0
par 1 1 1 1 0
sec `voltemand courtier cornelius courtier rosencrantz` 2 0
sec `courtier guildenstern courtier osric courtier a` 4 1
sec `gentleman courtier a priest` 5 0
par 4 1 1 1 1
sub `marcellus officer bernardo officer francisco a` 1 1 1
chap `soldier reynaldo servant to polonius` 2
prtb
Then it must output to look something like this:
Sample output:
Table of Content
or Limited table of Content
Chapter 1 title 1
1.1 skjdksjd 9
1.1.1 skjdksjd 17
1.1.2 skjdksjd 25
1.1.3 skjdksjd 33
1.2 skjdksjd 41
(the actual output is centered and has spacing like how a real table of contents would)
If anyone has any tips to how I would solve this problem or rebuild this program in steps it would be much appreciated since I'm kinda stuck.