Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
47 views4 pages

C++ Book Hierarchy Program

The document describes a C++ program to create and display a binary tree representation of a book structure with chapters and sections. The program uses classes to define nodes of the tree and implements functions to create the tree by inputting book, chapter and section details, and to display the tree structure.

Uploaded by

KUNAL NALE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views4 pages

C++ Book Hierarchy Program

The document describes a C++ program to create and display a binary tree representation of a book structure with chapters and sections. The program uses classes to define nodes of the tree and implements functions to create the tree by inputting book, chapter and section details, and to display the tree structure.

Uploaded by

KUNAL NALE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<iostream>

#include<cstdlib>

#include<string.h>

using namespace std;

class node

public:

char label[10];

int ch_count;

node*child[10];

}*root;

class BST

public:

void create_tree();

void display(node*r1);

BST()

root=NULL;

};

void BST::create_tree()

int tbooks,tchapters,i,j,k;

root=new node();

cout<<"\nEnter name of book :";

cin>>root->label;

cout<<"\nEnter the number of chapters in book :";


cin>>tchapters;

root->ch_count=tchapters;

for(i=0;i<tchapters;i++)

root->child[i]=new node;

cout<<"\nEnter chapter name :";

cin>>root->child[i]->label;

cout<<"\nEnetr number of sections in chapter :";

cin>>root->child[i]->ch_count;

for(j=0;j<root->child[i]->ch_count;j++)

root->child[i]->child[j]=new node;

cout<<"\nEnter section :"<<j+1<<" name\n";

cin>>root->child[i]->child[j]->label;

void BST::display(node*r1)

int i,j,k,tchapters;

if(r1 !=NULL)

cout<<"\n-----BOOK HIERARCHY-----";

cout<<"\nBook title :"<<r1->label;

tchapters=r1->ch_count;

for(i=0;i<tchapters;i++)

cout<<"\n\n Chapter "<<j+1;

cout<<" "<<r1->child[i]->label;

cout<<"\n Sections ";


for (j=0;j<r1->child[i]->ch_count;j++)

cout<<"\n "<<r1->child[i]->child[j]->label;

int main()

int choice;

BST bst;

while(1)

int choice;

BST bst;

while(1)

cout<<"\n-----------"<<endl;

cout<<"Book Tree Creation "<<endl;

cout<<"-----------"<<endl;

cout<<"1.create"<<endl;

cout<<"2.Display"<<endl;

cout<<"3.Quit"<<endl;

cout<<"Enter your choice";

cin>>choice;

switch(choice)

case 1:

bst.create_tree();

case 2:
bst.display(root);

break;

case 3:

exit(1);

default:

cout<<"Wrong choice \n"<<endl;

You might also like