<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'C++ search, delete/undelete, update functions' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'C++ search, delete/undelete, update functions' posted on the 'Beginner C/C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 23:24:04 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 23:24:04 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>C++ search, delete/undelete, update functions</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/429614/429614/c++-search-deleteundelete-update-functions/</link>
      <description>&lt;pre class="sourcecode"&gt;
#include &amp;lt;cstdlib&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;iomanip&amp;gt;
#include &amp;lt;conio.h&amp;gt;
#include &amp;lt;fstream&amp;gt;

using namespace std;

const char FILE_PATH[] = "E:\\iofile";
//------------------------------------------------------------------------------

struct Student
{
*** char names [ 16 ];
*** int other;
};

fstream MyFile ( FILE_PATH , ios :: binary | ios :: in | ios :: out );

void createFile();
void mainMenu();
void funcSwitch();
void addRecord();
int displayRecord();
void updateRecord();
void deleteRecord();
void printRecords();
int searchRecord();
//------------------------------------------------------------------------------
int main ( int argc, char* argv [] )
{
*** createFile();

*** mainMenu();
}
//------------------------------------------------------------------------------
void mainMenu()
{
*** cout &amp;lt;&amp;lt; "Welcome to School Enrolment System" &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl
*** *** * &amp;lt;&amp;lt; "Please enter your selection: " &amp;lt;&amp;lt; endl
*** *** * &amp;lt;&amp;lt; "1.** Register - New Student (Add record)" &amp;lt;&amp;lt; endl
*** *** * &amp;lt;&amp;lt; "2.** Look Up - Existing Student (Display record)" &amp;lt;&amp;lt; endl
*** *** * &amp;lt;&amp;lt; "3.** Change Details (Update record)" &amp;lt;&amp;lt; endl
*** *** * &amp;lt;&amp;lt; "4.** Remove Student (Delete record)" &amp;lt;&amp;lt; endl
*** *** * &amp;lt;&amp;lt; "5.** Show all Students (Print all)" &amp;lt;&amp;lt; endl
*** *** * &amp;lt;&amp;lt; "6.** Exit " &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl
*** *** * &amp;lt;&amp;lt; "Selection: ";

*** funcSwitch();
}
//------------------------------------------------------------------------------
void funcSwitch()
{
** char choice;

*** choice = getch();
*** clrscr();
*** while ( choice != 54 )
** {
***** switch ( choice )
*** *** {
******** case '1' :
*********** addRecord();
*********** getch();
*** *** *** *** clrscr();
************** break;

******** case '2' :
*********** displayRecord();
*********** getch();
************** break;

******** case '3' :
*********** updateRecord();
*********** getch();
************** break;

******** case '4' :
*********** deleteRecord();
*********** getch();
************** break;

******** case '5' :
*********** printRecords();
*********** getch();
************** break;

******** case '6' :
*********** break;

******** default :
*** *** *** *** cout &amp;lt;&amp;lt; choice &amp;lt;&amp;lt; " is not a vaild choice" &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl
*** *** *** *** *** * &amp;lt;&amp;lt; "Press any key to choose again... ";
*********** getch();
*** *** *** *** clrscr();

***** }
***** mainMenu();
*** *** choice = getch();
*** *** clrscr();
** }
}
//------------------------------------------------------------------------------
void addRecord()
{
*** Student temp;

*** cout &amp;lt;&amp;lt; "Welcome new Student!" &amp;lt;&amp;lt; endl
*** *** * &amp;lt;&amp;lt; "We're going to set you up with a new Enrolment..." &amp;lt;&amp;lt; endl
*** *** * &amp;lt;&amp;lt; "All we need is a few details, let's begin: " &amp;lt;&amp;lt; endl;

*** cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; "Please enter first name : ";
*** cin &amp;gt;&amp;gt; temp.names;



*** cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; "Please enter your age : ";
*** cin &amp;gt;&amp;gt; temp.other;


*** MyFile.open ( FILE_PATH , ios :: binary | ios :: app | ios :: out );
*** MyFile.clear();
*** MyFile.write ( ( const char* ) &amp;amp;temp, sizeof ( Student ) );
*** MyFile.clear();
*** MyFile.close();
}
//------------------------------------------------------------------------------
int searchRecord()
{

*** return 0;
}
//------------------------------------------------------------------------------
int displayRecord()
{
*** Student temp;
*** int age;
*** int position;

*** cout &amp;lt;&amp;lt; "Enter age of person you are seeking: ";
*** cin &amp;gt;&amp;gt; age;
*** clrscr();



*** MyFile.open ( FILE_PATH , ios :: binary | ios :: in );
*** MyFile.clear();
*** MyFile.seekp ( position * sizeof ( Student ), ios :: beg );
*** MyFile.read ( ( char* ) &amp;amp;temp, sizeof ( Student ) );

*** if ( age != temp.other )
*** {
*** *** cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; "No record found. Press any key to continue...";
*** }
*** else
*** {
*** *** cout &amp;lt;&amp;lt; "We found your record: " &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl
*** *** *** * &amp;lt;&amp;lt; "Name: " &amp;lt;&amp;lt; temp.names &amp;lt;&amp;lt; endl
*** *** *** * &amp;lt;&amp;lt; "Age:* " &amp;lt;&amp;lt; temp.other &amp;lt;&amp;lt; endl;
*** }

*** *** *cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; "Press any key to continue..." &amp;lt;&amp;lt; endl;
*** *** *getch();
*** *** *clrscr();
*** *** *mainMenu();
*** *** *MyFile.close();
*** *** *return 0;

}
//------------------------------------------------------------------------------
void updateRecord()
{
*** Student temp;
*** time_t t;
*** char choice;
*** int position;

*** position = displayRecord ();

*** MyFile.open( FILE_PATH, ios :: binary | ios :: out );
*** MyFile.clear();

*** if( position != -1 )
*** {
*** *** cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; "Do you want to Update this Record( y or n )";
*** *** choice = getch();
*** }

*** if( choice == 'y' )
*** {
*** *** cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; "Enter name : ";
*** *** cin &amp;gt;&amp;gt; temp.names;

*** *** cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; "And your age : ";
*** *** cin &amp;gt;&amp;gt; temp.other;




*** *** MyFile.open( FILE_PATH, ios :: binary | ios :: out );
*** *** MyFile.clear();
*** *** MyFile.seekp( position * sizeof( Student ), ios :: beg );
***** MyFile.clear();
*** *** MyFile.write( ( const char* ) &amp;amp;temp, sizeof( Student ) );
***** MyFile.close();
*** }
}


//------------------------------------------------------------------------------
void deleteRecord()
{

*** Student temp;
*** char choice;
*** int position;

*** -MyFile.open( FILE_PATH, ios :: binary | ios :: in | ios :: out );
*** MyFile.clear();
*** MyFile.seekp( position * sizeof( Student ), ios :: beg );
*** MyFile.read( ( char* )&amp;amp;temp, sizeof( Student ) );

*** cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl;
*** cout &amp;lt;&amp;lt; "Would you like to delete this record? Yes (y) or No (n): ";
*** cin &amp;gt;&amp;gt; choice;

*** choice = getch();

*** MyFile.seekp( position * sizeof( Student ), ios :: beg );
*** MyFile.write( ( const char* )&amp;amp;temp, sizeof( Student ) );

*** getch();
*** clrscr();
*** mainMenu();

*** MyFile.close();
}

//-----------------------------------------------------------------------------

void printRecords()
{
*** Student temp;

*** MyFile.open ( FILE_PATH , ios :: binary | ios :: in );
*** MyFile.clear();
*** MyFile.read ( ( char* ) &amp;amp;temp, sizeof ( Student ) );

*** while ( ! MyFile.eof() )
*** {
*** *** cout &amp;lt;&amp;lt; "Name: " &amp;lt;&amp;lt; temp.names &amp;lt;&amp;lt; endl
*** *** *** * &amp;lt;&amp;lt; "Age:* " &amp;lt;&amp;lt; temp.other &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl;


*** *** MyFile.read ( ( char* ) &amp;amp;temp, sizeof ( Student ) );
*** }

*** cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; "Press any key to continue back to main menu" &amp;lt;&amp;lt; endl;
*** getch();
*** clrscr();
*** mainMenu();

*** MyFile.close();
}
//------------------------------------------------------------------------------
void createFile()
{
*** if( ! MyFile )
*** {
*** *** MyFile.close();
*** *** MyFile.open(FILE_PATH, ios::binary | ios::in | ios::out);
*** }

*** if ( ! MyFile )
*** {
*** *** cout &amp;lt;&amp;lt; "File Error: File does not exist. Creating new file..."
*** *** *** * &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; "Click to continue to main menu...";
*** *** getch();
*** *** clrscr();
*** }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Basically the program is a database of student enrollments.&lt;br /&gt;
&lt;br /&gt;
I cannot get the the search delete/undelete and update functions to work and need help asap. Need to implement a bool field to the delete / undelete&lt;br /&gt;
&lt;br /&gt;
Please help &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/429614/429614/c++-search-deleteundelete-update-functions/</guid>
      <pubDate>Sun, 23 Sep 2012 22:32:53 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
  </channel>
</rss>