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

0% found this document useful (0 votes)
2 views6 pages

Dsa PRG3

The document contains a C++ program that defines a structure for a book with chapters, sections, and subsections. It includes methods to add titles, chapters, sections, and subsections, as well as a method to display the book's index. The program is designed to create a hierarchical representation of a book's content.

Uploaded by

AYAAN TAMBOLI
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)
2 views6 pages

Dsa PRG3

The document contains a C++ program that defines a structure for a book with chapters, sections, and subsections. It includes methods to add titles, chapters, sections, and subsections, as well as a method to display the book's index. The program is designed to create a hierarchical representation of a book's content.

Uploaded by

AYAAN TAMBOLI
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/ 6

Practical No.

3
PROGRAM:
#include<iostream>

using namespace std;

struct node

string name;

node *B[5];

};

class book

int ch,se,sub;

public:

node *temp = new node;

void Getnewnode()

for(int i = 0 ; i<5 ; i++)

temp->B[i] = new node;

temp->B[i]->name = "empty";

for(int j=0; j<5; j++)

temp->B[i]->B[j] = new node;

temp->B[i]->B[j]->name = "empty";

for(int k = 0 ; k<5; k ++)

{
temp->B[i]->B[j]->B[k] = new node;

temp->B[i]->B[j]->B[k]->name = "empty";

void add_title()

cout<<"*****ENTER THE TITLE OF THE BOOK****** \n ";

cin>>temp->name;

Getnewnode();

void add_chapter()

string cname;

int cnum;

cout<<"ENTER NUMBER OF CHAPTERS IN THE BOOK : ";

cin>>cnum;

ch = cnum;

for(int i = 0 ; i < cnum ; i++)

cout<<endl<<"Chapter "<<i+1<<" = ";

cin>>cname;

temp->B[i]->name = cname;

}
void add_section()

string sname;

int snum;

int chnum;

cout<<"CHAPTER NUMBER WHERE YOU NEED TO ADD SECTIONS : ";

cin>>chnum;

cout<<"ENTER NUMBER OF SECTIONS : ";

cin>>snum;

se = snum;

for(int i = 0 ; i < snum ; i++)

cout<<endl<<"Section "<<chnum<<"."<<i+1<<" = ";

cin>>sname;

temp->B[chnum-1]->B[i]->name = sname;

void add_sub_section()

string subname;

int subnum;

int snum;

int chnum;

cout<<"CHAPTER NUMBER WHERE YOU NEED TO ADD SECTIONS : ";

cin>>chnum;
cout<<"SECTION NUMBER WHERE YOU NEED TO ADD SUB-SECTIONS : ";

cin>>snum;

cout<<"ENTER NUMBER OF SUB-SECTIONS : ";

cin>>subnum;

sub = subnum;

for(int i = 0 ; i < subnum ; i++)

cout<<endl<<"Sub-Section "<<chnum<<"."<<snum<<"."<<i+1<<" = ";

cin>>subname;

temp->B[chnum-1]->B[snum-1]->B[i]->name = subname;

void display()

cout<<endl<<"**************INDEX**************"<<endl;

cout<<endl<<"TITLE : "<<temp->name;

cout<<endl<<"CHAPTERS : "<<endl;

for(int i = 0 ; i < ch ; i++)

if(temp->B[i]->name != "empty")

cout<<endl<<" "<<i+1<<". "<<temp->B[i]->name;

for(int j = i ; j < se ; j++)

if(temp->B[i]->B[j]->name != "empty")

cout<<endl<<" "<<i+1<<"."<<j+1<<" "<<temp->B[i]->B[j]->name;

for(int k = 0 ; k < sub ; k++)


{

if(temp->B[i]->B[j]->B[k]->name != "empty")

cout<<endl<<" "<<i+1<<"."<<j+1<<" "<<temp->B[i]->B[j]->B[k]->name;

cout<<endl;

};

int main()

book s;

s.add_title();

s.add_chapter();

s.add_section();

s.add_sub_section();

s.display();

return 0;

}
OUTPUT:

You might also like