MODIFY
Modify operation.
In this blog I have explained the function modify().
Modify operation is used just to modify the existing data in the file. For example suppose there is one entry having a name of book "Data structure through C" in the file and we want to modify the name of the author. For that first we have to search for that book in the file and then we can modify the name of the author. In the same way we can modify any of the field related to the book.
Now we will see how to program this function. Before finding the details of the book we want to modify we have to check whether the previous copying() function is over or not. If it is over then only we can modify the details.
void modify()
{
if(q==0)
{
copying();
q=1;
}
As we can see the function modify() starts with if loop. We have take one flag 'q' whose value is 0 until the copying is not done. When copying() function is completed we made q=1.
Before searching for the details of the book we first have to ask to the user for name of the book which he/she want to modify the details for the same.
cout<<"\n Enter the record to be modified";
cout<<"\n Enter the name of the book ";
cin>>s1;
cout<<"\n ENter the name of the author ";
cin>>s2;
Below lines of code displays the existing details of the book which user have entered above.
for(int i=0;i<=top;i++)
{
if(yash[i].name==pushkar && yash[i].author==tushkar)
{
cout<<"\n\nBOOK found its details are \n";
cout<<endl<<setw(25)<<"Name "<<setw(25)<<yash[i].name;
cout<<endl<<setw(25)<<"Author "<<setw(25)<<yash[i].author;
cout<<endl<<setw(25)<<"Publication "<<setw(25)<<yash[i].publication;
cout<<endl<<setw(25)<<"pages "<<setw(25)<<yash[i].pages;
cout<<endl<<setw(25)<<"count "<<setw(25)<<yash[i].counti;
char ch;
cout<<"\n\n Now if you want to change the specific attribute mentioned above press y/Y else n/N in front of the attribute that appears below";
cout<<"\n \nName press y/Y to modify else n/N ";
cin>>ch;
if(ch=='y' || ch=='Y')
{
cout<<"\nEnter the new name of the book ";
cin>>yash[i].name;
}
cout<<"\n \nauthor press y/Y to modify else n/N ";
cin>>ch;
if(ch=='y' || ch=='Y')
{
cout<<"\nEnter the new name of the author ";
cin>>yash[i].author;
}
cout<<"\n \nPublication press y/Y to modify else n/N ";
cin>>ch;
if(ch=='y' || ch=='Y')
{
cout<<"\nEnter the Publication ";
cin>>yash[i].publication;
}
cout<<"\n \nPages press y/Y to modify else n/N ";
cin>>ch;
if(ch=='y' || ch=='Y')
{
cout<<"\nEnter the number of pages ";
cin>>yash[i].pages;
}
cout<<"\n Count press y/Y to modify else n/N ";
cin>>ch;
if(ch=='y' || ch=='Y')
{
cout<<"\nEnter the new name of the book ";
cin>>yash[i].counti;
}
cout<<"\n \n Data successfully modified\n";
writing();
}
}
}
You can see the code is very simple. As you can see it is asked if you want to change the specific attribute mentioned above press y/Y else n/N in front of the attribute that appears below. If we press 'yes' it will go into if loop and if 'no' then else loop will execute.
cout<<"\n \n Data successfully modified\n";
writing();
After taking all new details writing() functions is called which will write the data into the file.This is all about modify function.
Before modification
Nice.....
ReplyDeleteThanks
DeleteThank you my doubts are now cleared.
ReplyDeletegood
ReplyDeleteThanks
DeleteMany doubts are cleared. All under one roof
ReplyDeleteThanks
DeleteVery information
ReplyDeleteNice Information. It is simple to understand
ReplyDeleteNice work
ReplyDeleteKeep it up
Thanks
DeleteAmazing work very helpful
ReplyDeleteNice work...
ReplyDeleteThanks
DeleteGreat ...
ReplyDeleteThanks
Deletetoo good
ReplyDeleteall that i want is here!
thank you!👌
Thanks
DeleteGreat work, very informative
ReplyDeleteThanks
DeleteArticle will help beginners to understand the concept in much better way ✌️✌️
ReplyDelete