pointers structures and strings. what can i do with spaces

this is my program and i dont know what is the better strategy to display the output perfectly align with the title, when i input a long variable or short the variable move and it does not align with its title. what can i do ?
thanks :)


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
using namespace std;

struct book
{
string title,isbn;
int quantity;
book *nxt;
};

book *start_ptr=NULL;
book *start_ptra=NULL;
book *start_ptrb=NULL;
book *currenta;
book *tempa;
book *temp2a;
book *current;
book *temp;
book *temp2;
book *currentb;
book *tempb;
book *temp2b;
int option=0;

void add_node_at_end()
{
book *temp, *temp2;
temp=new book;
cout<<"\n\tEnter Title of the book:";
getline(cin,temp->title);
temp->nxt=NULL;
if (start_ptr==NULL)
{
start_ptr=temp;
current=start_ptr;
}
else
{
temp2=start_ptr;
while (temp2->nxt!=NULL)
{
temp2=temp2->nxt;
}
temp2->nxt=temp;
}
book *tempa, *temp2a;
tempa=new book;
cout<<"\tEnter ISBN : ";
cin>>tempa->isbn;
cout<<endl;
tempa->nxt=NULL;
if (start_ptra==NULL)
{
start_ptra=tempa;
currenta=start_ptra;
}
else
{
temp2a=start_ptra;
while (temp2a->nxt!=NULL)
{
temp2a=temp2a->nxt;
}
temp2a->nxt=tempa;
}

book *tempb, *temp2b;
tempb=new book;
cout<<"\tEnter Quantity : ";
cin>>tempb->quantity;
cout<<endl;
tempb->nxt=NULL;
if (start_ptrb==NULL)
{
start_ptrb=tempb;
currentb=start_ptrb;
}
else
{
temp2b=start_ptrb;
while (temp2b->nxt!=NULL)
{
temp2b=temp2b->nxt;
}
temp2b->nxt=tempb;
}
}

void display_list()
{
book *temp;
book *tempa;
book *tempb;
temp=start_ptr;
tempa=start_ptra;
tempb=start_ptrb;
cout<<endl;
if (temp==NULL && tempa==NULL && tempb==NULL)
{
cout<<"\a\n\tThe List is Empty!"<<endl;
}
else
{
temp=start_ptr;
tempa=start_ptra;
cout<<"Title:"<<setw(28);
cout<<"ISBN :"<<setw(15);
cout<<"QUANTITY :\n";;
for(int i=0;temp!=NULL;i++)
{
cout<<temp->title<<setw(15);
cout<<tempa->isbn<<setw(10);
cout<<tempb->quantity;
cout<<endl;
temp=temp->nxt;
tempa=tempa->nxt;
tempb=tempb->nxt;
}
cout<<"\a\n\t End of List!"<<endl;

}

for (int k=0;k<=80;k++)
cout<<"-";
}

void delete_start_node()
{
book *temp;
temp=start_ptr;
start_ptr=start_ptr->nxt;
delete temp;

book *tempa;
tempa=start_ptra;
start_ptra=start_ptra->nxt;
delete tempa;

book *tempb;
tempb=start_ptrb;
start_ptrb=start_ptrb->nxt;
delete tempb;
}

void delete_end_node()
{
book *temp1, *temp2;
if (start_ptr==NULL)
cout<<"The list is Empty!"<<endl;
else
{
temp1=start_ptr;
if (temp1->nxt==NULL)
{
delete temp1;
start_ptr=NULL;
}
else
{
while (temp1->nxt!=NULL)
{
temp2=temp1;
temp1=temp1->nxt;
}
delete temp1;
temp2->nxt=NULL;
}
}

book *temp1a, *temp2a;
if (start_ptra==NULL)
cout<<"The list is Empty!"<<endl;
else
{
temp1a=start_ptra;
if (temp1a->nxt==NULL)
{
delete temp1a;
start_ptra=NULL;
}
else
{
while (temp1a->nxt!=NULL)
{
temp2a=temp1a;
temp1a=temp1a->nxt;
}
delete temp1a;
temp2a->nxt=NULL;
}
}
book *temp1b, *temp2b;
if (start_ptrb==NULL)
cout<<"The list is Empty!"<<endl;
else
{
temp1b=start_ptrb;
if (temp1b->nxt==NULL)
{
delete temp1b;
start_ptrb=NULL;
}
else
{
while (temp1b->nxt!=NULL)
{
temp2b=temp1b;
temp1b=temp1b->nxt;
}
delete temp1b;
temp2b->nxt=NULL;
}
}


}

void move_current_on()
{
if (current->nxt==NULL)
cout<<"You are at the end of the List."<<endl;
else
current=current->nxt;

if (currenta->nxt==NULL)
cout<<"You are at the end of the List."<<endl;
else
currenta=currenta->nxt;

if (currentb->nxt==NULL)
cout<<"You are at the end of the List."<<endl;
else
currentb=currentb->nxt;
}

void move_current_back()
{
if (current==start_ptr)
cout<<"You are at the start of the List."<<endl;
else
{
book *previous;
previous=start_ptr;
while (previous->nxt!=current)
{
previous=previous->nxt;
}
current=previous;
}

if (currenta==start_ptra)
cout<<"You are at the start of the List."<<endl;
else
{
book *previousa;
previousa=start_ptra;
while (previousa->nxt!=currenta)
{
previousa=previousa->nxt;
}
currenta=previousa;
}

if (currentb==start_ptrb)
cout<<"You are at the start of the List."<<endl;
else
{
book *previousb;
previousb=start_ptrb;
while (previousb->nxt!=currentb)
{
previousb=previousb->nxt;
}
currentb=previousb;
}
}

void main()
{
cout<<"\t\t\tEMPLOYEES";
do
{
display_list();
cout<<endl;
cout<<endl;
cout<<"\t\tPlease select an option:"<<endl;
cout<<"\t0. Exit the program."<<endl;
cout<<"\t1. Add a book to the Inventory."<<endl;
cout<<"\t2. Delete the start book from the Inventory List."<<endl;
cout<<"\t3. Delete the end book from the Invenory List."<<endl;
cout<<endl<<"\t-->";
cin>>option;
cin.ignore(1000,'\n');
switch (option)
{
case 1: add_node_at_end();
break;
case 2: delete_start_node();
break;
case 3: delete_end_node();
break;
}
}
while (option!=0);
}
It would be helpful if you could use code tags to properly format your code. You access them with the "<>" button to the right of the edit window.
Topic archived. No new replies allowed.