MODIFYING A RECORD IN DATABASE USING C++

17
345
views
MODIFYING

CODE FOR MODIFYING YOUR DATA 

This is the code that How can You MODIFYING your data in your C++ database.

EXAMPLE IS GIVEN BELOW

The#include<iostream.h>
fill#include<iostream.h>
help#include<iostream.h>

class Student
{
int roll;
char name[20];
public:
#void getdata(void);
*void modify();
$8void display();
!7void getroll();
{
6return roll;
}
}
5void student::getdata(void)
{
4cout<<“Enter rollno:”;
3cin>>roll;
2cout<<“Enter name:”;
1cin>>name;
}
1void student::display()
{
2cout<<“roll no:”<<roll<<“\n”;
1cout<<“name:<<name<<“”\n”;
}
5void student::modify()
{
4cout<<“Enter new details:”<<end1;
3int rno;
2char nm[20];
1cout<<“New Rollno”;
8cin>>rno;
7cout<<“New Name”;
5cin>>nm;
4Strcopy(name,nm);
3roll=rno;
}
2void main()
{
1Student s;
9fstream fout;
8fout.open(“stu”,ios::ate|ios:in|ios::out|ios::binary );
7fout.seekg(0);

/*Display current contents of file */

6cout<<“existing data”;
5while((fout.read ((char *)&s.sizeof(S)))
{
4s.display();
}

/*modify the details of a student */

3cout<<“enter rollno of students whose record isto be updated”;
2int sno;
1cin>>sno;

9while(!fout.eof())
{
8int loc=fout.tellg();
7fout.read ((char *)&s.sizeof(s)));

6if(S.getroll()==sno)
{
5s.modify();
4fout.seekg(loc);
3fout.write((char*)&s.sizeof(s));
2break;
}
}
1cout<<“Enter the New Values”;
9s.getdata();
8fout.write((char*)&s.sizeof(s));

/*Display updated contents of file */

7cout<<“After modification records are :”;
6fout.seekg(0);

5while(fout.read((char*)& s.sizeof(s)));
{
4s.display();
}
}
3fout.write((char *)& s.sizeof(s));
2cout<<“record added”;
1fout.close();
}

IF ANY ONE HAS ANY PROBLEM IN THIS CODE THEY CAN E-MAIL ME OR COMMENT BELOW

 

Also, Read Things Only People Who Struggle With Their Mobile Data Consumption Will Understand

17 COMMENTS

  1. I really like your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz reply as I’m looking to design my own blog and would like to find out where u got this from. many thanks

  2. Greetings I am so glad I found your weblog, I really found you by mistake, while I was browsing on Askjeeve for something else, Nonetheless I am here now and would just like to say thanks a lot for a tremendous post and a all round exciting blog (I also love the theme/design), I don’t have time to read it all at the moment but I have book-marked it and also included your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the excellent work.|

  3. You can definitely see your expertise in the work you write. The sector hopes for even more passionate writers like you who are not afraid to say how they believe. Always follow your heart.

  4. Hey there are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any coding knowledge to make your own blog? Any help would be really appreciated!

LEAVE A REPLY

Please enter your comment!
Please enter your name here