forked from adee-dev/clg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSA_practical_assignment_01.cpp
94 lines (74 loc) · 1.87 KB
/
DSA_practical_assignment_01.cpp
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
84
85
86
87
88
89
90
91
92
93
94
//Aditya Dayal
//20CO001
//SE Comp A
#include<iostream>
using namespace std;
struct node {
char lable[30];
int count;
node *child[10];
}*root;
class Book{
public:
Book(){
root = NULL;
}
void create(){
int chapters,sections;
root = new node;
cout<<"Enter the name of Book: "<<endl;
cin>>root->lable;
cout<<"Enter the numbers of Chapters is the Book: "<<endl;
cin>>chapters;
root->count = chapters;
for(int i=0;i<chapters;i++){
root->child[i] = new node;
cout<<"Enter the name of the Chapter: "<<endl;
cin>>root->child[i]->lable;
cout<<"Enter the number of sections in the Chapter: "<<root->child[i]->lable<<endl;
cin>>sections;
root->child[i]->count = sections;
for (int j=0;j<root->child[i]->count;j++){
root->child[i]->child[j] = new node;
cout<<"Enter the name of Section: "<<endl;
cin>>root->child[i]->child[j]->lable;
}
}
}
void display(node *t){
if(t!=NULL){
cout<<"Book Name : "<<root->lable<<endl;
int cha = root->count;
for (int i=0;i<cha;i++){
cout<<"Chapter : "<<i+1<<endl;
cout<<i+1<<") "<<root->child[i]->lable<<endl;
cout<<"Sections : "<<endl;
int sec = root->child[i]->count;
for(int j=0;j<sec;j++){
cout<<j+1<<") "<<root->child[i]->child[j]->lable<<endl;
}
}
}
}
};
int main(){
Book k;
int ch;
do{
cout<<"Book Tree Creation"<<endl;
cout<<"1.Create"<<endl;
cout<<"2.Display"<<endl;
cout<<"3.Quit"<<endl;
cout<<"Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
k.create();
break;
case 2:
k.display(root);
break;
}
}while(ch!=3);
}