I am having trouble with the insert function of this project, we are to use pointers to insert a dash and middle initial into the name where there is a dash. I got stuck at this point of the assignment and i need help here the code.
#include <iostream>
#include <string>
using namespace std;
class name_list
{
public:
name_list::name_list();
void name_list::readName();
void name_list::printname();
void name_list::insert();
void name_list::readName()
{
char letter = 0;
cout<<"Enter the letter, * stops input ";
while (letter !='*')
{
current= new list_node;
cin>>current->letter;
current->letter=letter;
current->next = 0;
prev->next=current;
prev=current;
cout<<" Enter the letter, * stops input ";
cin>>letter;
}
}
void name_list::printname()
{
//print the list
current=first->next;
while(current!=0)
{
cout<<current->letter<<" "<<endl;
current=current->next;
}
}
//PROBLEM AREA
void name_list::insert()
{
int position=0,i;
char initial;
cout<<"Enter middle initial ";
cin>>initial;
//SEARCH FOR THE POSITION OF THE DASH
for(i=0;i<=count;++i)
{
if(letter =='-')
{
position = i;
}
}
//SHIFT EVERYTHING BY 2
for(i=count+2;i>position;--i)
{
name[i]=name[i-2];
}