-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3rd.cpp
More file actions
83 lines (68 loc) · 1.81 KB
/
3rd.cpp
File metadata and controls
83 lines (68 loc) · 1.81 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
75
76
77
78
79
80
81
82
83
#include <iostream>
using namespace std;
struct node
{
char title[20];
int node_count;
struct node *child[10];
} * base;
class book
{
public:
book()
{
base = NULL;
}
void creat()
{
int chapter, section, i, j;
base = new node();
cout << "The name of book is => ";
// cin >> base->title;
cin.getline(base->title,20);
cout << "Enter the number of chapter => ";
cin >> chapter;
base->node_count = chapter;
for (i = 0; i < chapter; i++)
{
base->child[i] = new node;
cout << "Enter the name of chapter " << i + 1 << " => ";
cin >> base->child[i]->title;
cout << "Enter the number of section => ";
cin >> section;
base->child[i]->node_count = section;
for (j = 0; j < section; j++)
{
base->child[i]->child[j] = new node;
cout << "Enter the name of section " << j + 1 << "=> ";
cin >> base->child[i]->child[j]->title;
}
}
};
void print(node *r)
{
int i, j,chapter;
if (r != NULL)
{
cout << "\nThe book name is " << r->title << endl;
chapter = r->node_count;
for (i = 0; i < chapter; i++)
{
cout << "\nChapter " << i + 1 << endl;
cout << " " << r->child[i]->title;
cout << "\n\tSection";
for (j = 0; j < r->child[i]->node_count; j++)
{
cout << "\n\t " << r->child[i]->child[j]->title;
}
}
}
}
};
int main()
{
book obj;
obj.creat();
cout << "---------------------" << endl;
obj.print(base);
}