i have repaired almost all the program i only need help on
delete method
i would change the question now to
HOW CAN I DELETE ONE RECORD my delete method is empty ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace main
{
class Program
{
public class Record
{
public int ssn;
public String name;
public double pay;
public Record(int newSSN, String newName, double newPay)
{
ssn = newSSN;
name = newName;
pay = newPay;
}
}
public class RecordDB
{
private static int maxRecords = 200;
private int numRecords = 0;
private Record[] recordList = new Record[maxRecords];
public RecordDB()
{
int i;
for (i = 0; i < maxRecords; i++)
recordList[i] = new Record(0, "", 0.0);
}
public void insert(Record rec)
{
if (numRecords == maxRecords - 1)
{
return;
}
recordList[numRecords].ssn = rec.ssn;
recordList[numRecords].name = rec.name;
recordList[numRecords].pay = rec.pay;
numRecords++;
Console.Write("---------------------------------\n");
Console.Write("We are in insert\n");
printAll();
}
//--------------------------------------------------------------------------------
public void delete(int newSSN)
{ int i,j;
Console.Write("---------------------------------\n");
Console.Write("We are in delete newSSN=" + newSSN.ToString() + " numRecords=" + numRecords.ToString() + "\n");
for(i=0;i<numRecords;i++)
{
if(newSSN == recordList[i].ssn)
{
for (j = 0; j< numRecords-1; j++)
{
recordList[j].ssn = recordList[j + 1].ssn;
recordList[j].name = recordList[j + 1].name;
recordList[j].pay = recordList[j + 1].pay;
}
numRecords--;
goto outy;
}
}
outy:
printAll();
}
//--------------------------------------------------------------------------------
public Record search(int newSSN)
{
int i;
int first = 0, last = numRecords - 1;
Record Temporary=new Record(0,"",0.0);
Temporary.ssn = newSSN;
Temporary.name = "";
Temporary.pay = 0.0;
Console.Write("---------------------------------\n");
Console.Write("We are search we will search for newSSn=" + newSSN.ToString() + "\n");
for (i = 0; i < numRecords; i++)
{
if (newSSN == recordList[i].ssn)
{
Console.Write("FOUND @i="+i.ToString()+" inside search inside loop(i) " + "i=" + i.ToString() + " " + recordList[i].ssn.ToString() +
" " + recordList[i].name + " " + recordList[i].pay.ToString() + "\n");
return recordList[i];
}
}
Temporary.ssn = -1;
return Temporary;
}
//-------------------------------------------------------------------------------
private void printAll()
{
Console.Write("Hellow printAll\n");
for (int i = 0; i < numRecords; i++)
{
Console.Write(i +" "+recordList[i].ssn.ToString() +
" "+recordList[i].name+" "+recordList[i].pay.ToString()+"\n");
}
}
}
//RecordDB
//---------------------------------------------------
public static int Main(String[] args)
{
RecordDB recDB = new RecordDB();
recDB.insert(new Record(34, "John", 500));
recDB.insert(new Record(22, "Mike", 2500));
recDB.insert(new Record(13, "Mark", 1760));
recDB.insert(new Record(19, "Bob", 500));
recDB.insert(new Record(7, "Cathy", 500));
Record r = recDB.search(22);
if (r.ssn == -1) Console.Write("Not found\n"); else Console.Write("Found\n");
r = recDB.search(34);
if (r.ssn == -1) Console.Write("Not found\n"); else Console.Write("Found\n");
r = recDB.search(123456);
if (r.ssn == -1) Console.Write("Not found\n"); else Console.Write("Found\n");
recDB.delete(34);
recDB.delete(22);
recDB.delete(13);
recDB.delete(19);
recDB.delete(7);
return 0;
}
}
}