rendered paste bodyusing System;
public class PhoneBook
{
protected string Name;
protected string Address;
protected int Number;
//Constructor
public PhoneBook(string tmpname , string tmpAddress , int tmpnumber)
{
Name = tmpname;
Address = tmpAddress;
Number = tmpnumber;
Console.WriteLine("Object created");
}
public void Show()
{
Console.WriteLine("Name: {0} , Address: {1}, Phone Number : {2}", Name, Address, Number);
}
public int getnum{
get{
return Number;
}
}
public string getname{
get{
return Name;
}
}
}
public class Programm
{
protected void menu()
{
Console.WriteLine("[1]Eisagwgh Eggrafhs");
Console.WriteLine("[2]Emafanisi Eggrafwn");
Console.WriteLine("[3]Eyresh Eggrafhs apo numero");
Console.WriteLine("[4]Eyresh Eggrafhs apo Onoma");
Console.WriteLine("[5]Diagrafi Eggrafhs");
Console.WriteLine("[6]Exit");
Console.WriteLine("[+]Give Option");
}
static void Main()
{ int choice=0,count =0,arrayLenght=4 ;
Programm p = new Programm();
PhoneBook[] records = new PhoneBook[arrayLenght];
do
{
p.menu();
string epilogi =Console.ReadLine();
choice = Convert.ToInt32(epilogi);
switch (choice)
{
case 1:
if (count == arrayLenght)
{
Console.WriteLine("Cannot add a record. Memory is full");
break;
}
else
{
Console.WriteLine("You can add {0} more records", arrayLenght - count);
}
Console.WriteLine("Dose Onoma");
string onoma = Console.ReadLine();
Console.WriteLine("Dose Dieuthinsi");
string address = Console.ReadLine();
Console.WriteLine("Dose Tilefono");
string tmpphone = Console.ReadLine();
records[count]= new PhoneBook(onoma, address, Convert.ToInt32(tmpphone));
count++;
break;
case 2:
for (int i = 0; i < count; i++)
{
records[i].Show();
}
break;
case 3:
bool flag=false;
Console.WriteLine("Dose To numero");
string num = Console.ReadLine();
for(int i =0;i<count;i++){
if(records[i].getnum == Convert.ToInt32(num)){
Console.WriteLine("Found");
records[i].Show();
flag = true;
break;
}
}
if(!flag)
{
Console.WriteLine("Den vrethike");
}
break;
case 4:
flag = false;
Console.WriteLine("Dose Onoma");
onoma = Console.ReadLine();
for (int i = 0; i < count; i++)
{
if (records[i].getname == onoma)
{
Console.WriteLine("Found");
records[i].Show();
flag = true;
break;
}
}
if (!flag)
{
Console.WriteLine("Den Vrethike");
}
break;
case 5:
Console.WriteLine("Poia egrafi thes na diagrapseis");
string recordnumber = Console.ReadLine();
//Metatopisi Twn egrafwn gia na min iparxoune kena stoixeia ston pinaka kai enhmerwsh tou count
for (int i =Convert.ToInt32(recordnumber)+1;i+1<arrayLenght;i++){
records[i-1] = records[i];
}
count--;
break;
case 6:
Console.WriteLine("Exiting..");
break;
}
} while (choice != 6);
}
}