-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooktree.cpp
More file actions
74 lines (62 loc) · 1.88 KB
/
Copy pathBooktree.cpp
File metadata and controls
74 lines (62 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
using namespace std;
struct node{
char label[50];
int chcount;
node *child[15];
};
class BookTree{
node *root;
public:
void display();
void create();
BookTree(){
root=NULL;
}
};
void BookTree::create(){
int i,j,k;
root = new node;
cout<<"enter the name of book:";
cin>>root->label;
cout<<"\nHow many chapters:";
cin>>root->chcount;
for(i=0;i<root->chcount;i++){
root->child[i]=new node;
cout<<"enter the name of chapter "<<i+1<<":";
cin>>root->child[i]->label;
cout<<"How many sections: ";
cin>>root->child[i]->chcount;
for(j=0;j<root->child[i]->chcount;j++){
root->child[i]->child[j]=new node;
cout<<"Enter the name of section "<<j+1<<":";
cin>>root->child[i]->child[j]->label;
cout<<"\nHow many subsections:";
cin>>root->child[i]->child[j]->chcount;
for(k=0;k<root->child[i]->child[j]->chcount;k++){
root->child[i]->child[j]->child[k]=new node;
cout<<"Enter the name of subsection "<<k+1<<":";
cin>>root->child[i]->child[j]->child[k]->label;
}
}
}
}
void BookTree::display(){
int i,j,k;
cout<<"Name of book:"<<root->label<<endl;
for(i=0;i<root->chcount;i++){
cout<<" Chapter "<<i+1<<": "<<root->child[i]->label<<endl;
for(j=0;j<root->child[i]->chcount;j++){
cout<<" Section "<<j+1<<": "<<root->child[i]->child[j]->label<<endl;
for(k=0;k<root->child[i]->child[j]->chcount;k++){
cout<<" Subsection "<<k+1<<": "<<root->child[i]->child[j]->child[k]->label<<endl;
}
}
}
}
int main(){
BookTree b;
b.create();
b.display();
return 0;
}