1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
using System;
using System.Collections.Generic;
using System.Text;
namespace Targil_1
{
class Program
{
static void Main(string[] args)
{
bool loop = true;
Book[] arr;
int count=0,choice;
while (loop==true)
{
Console.WriteLine("1.Add a book");
Console.WriteLine("2.Delete book by BookID");
Console.WriteLine("3.Print the entire list");
Console.WriteLine("4.Print the list by Author");
Console.WriteLine("5.Exit");
Console.WriteLine("Enter your choice :");
choice = int.Parse(Console.ReadLine());
while (choice != 1 && choice != 2 && choice != 2 && choice != 3 && choice != 4 && choice != 5)
{
Console.WriteLine("Wrong choice !Please enter again :");
choice = int.Parse(Console.ReadLine());
}
switch (choice)
{
case 1: string name, author, publisher;
uint bookidtmp;
decimal price;
Console.WriteLine("Enter the new book id :");
bookidtmp = uint.Parse(Console.ReadLine());
Console.WriteLine("Enter the book name :");
name = Console.ReadLine();
Console.WriteLine("Enter the book price :");
price = decimal.Parse(Console.ReadLine());
Console.WriteLine("Enter the book author :");
author = Console.ReadLine();
Console.WriteLine("Enter the book publisher :");
publisher = Console.ReadLine();
if (count == 0)
{
arr = new Book[1];
arr[count].BookID1 = bookidtmp;
arr[count].BookName1 = name;
arr[count].Price1 = price;
arr[count].Author1 = author;
arr[count].Publisher1 = publisher;
++count;
}
else
{
Book[] arr1 = new Book[count + 1];
for (int i = 0; i < count;++i )
arr1[i] = arr[i];
arr1[count].BookID1 = bookidtmp;
arr1[count].BookName1 = name;
arr1[count].Price1 = price;
arr1[count].Author1 = author;
arr1[count].Publisher1 = publisher;
++count;
arr = arr1;
}
break;
case 2: if (count == 0)
Console.WriteLine("The library is empty");
else
{
uint bookidtmp1;
Console.WriteLine("Please enter the book id :");
bookidtmp1 = uint.Parse(Console.ReadLine());
bool found = false;
foreach (Book a in arr)
{
if (a.BookID1 == bookidtmp1)
{
found = true;
break;
}
}
if (found)
{
int count2 = 0;
Book[] arr2 = new Book[count - 1];
foreach (Book a in arr)
{
if (a.BookID1 == bookidtmp1)
continue;
else
{
arr2[count2].BookID1 = a.BookID1;
arr2[count2].BookName1 = a.BookName1;
arr2[count2].Price1 = a.Price1;
arr2[count2].Author1 = a.Author1;
arr2[count2].Publisher1 = a.Publisher1;
}
++count2;
}
arr = arr2;
}
else
Console.WriteLine("The book isn't in the library");
}
break;
case 3: foreach(Book a in arr)
a.ToString();
break;
case 4: break;
case 5: loop = false;
break;
}
}
}
}
} |
Partager