//Syed Rais Ahmad //CIS 610: Searching //Search and Update. #include "stdafx.h" #include "iostream.h" class record { public: int key; int val; }; class Table : public record { public: int SearchUpdate(int,int); Table() {total=-1;}; void Print(); private: record rec[20]; int total; }; int Table::SearchUpdate(int key,int val) { int i=0; //if key found update record and exit for(i=0;i<=total;i++) if (key==rec[i].key) { rec[i].val=val;return i;} //key is not found so insert one. rec[++total].key=key; rec[total].val=val; return total; } void Table::Print() { int i=0; for(;i<=total;i++) cout << '\n' << rec[i].val; } int main(int argc, char* argv[]) { Table t; t.SearchUpdate(0,4); t.SearchUpdate(1,7); t.SearchUpdate(2,6); t.SearchUpdate(1,9); t.Print(); return 0; }