Вы находитесь на странице: 1из 4

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

namespace BookShop { class Program { static void Main(string[] args) { BookStore bs = new BookStore(); bool exit = false; while (!exit) { Console.WriteLine("Select one of the following -"); Console.WriteLine("1. Add Books."); Console.WriteLine("2. Display Books."); Console.WriteLine("3. Search Books."); Console.WriteLine("4. Exit."); int choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: Console.WriteLine("Enter the Book Title: "); String title = Console.ReadLine(); Console.WriteLine("Enter the No. of Books: "); int quantity = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the Book Price: "); double price = double.Parse(Console.ReadLine()); Console.WriteLine(); Book b = new Book(title, quantity, price); bs.addBooks(b); break; case 2: bs.display(); break; case 3: bs.Search(); break; case 4: exit = true; break; } } } } } ################################################################################ #######

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

namespace BookShop { class Book { string BookName; int Quantity; double Cost; public Book(string _BOOK, int _Quan, double _Price) { BookName = _BOOK; Quantity = _Quan; Cost = _Price; } public void SetBookName(string Name) { BookName = Name; } public string GetBookName() { return BookName; } public void SetQuantity(int _Quantity) { Quantity = _Quantity; } public int GetQuantity() { return Quantity; } public void SetCost(double _Cost) { Cost = _Cost; } public double GetCost() { return Cost; }

} } ############################################################################

using using using using

System; System.Collections; System.Linq; System.Text;

namespace BookShop { class BookStore { IList s1 = new ArrayList(); /*static int Count; static BookStore() { Count = 0; } */ public void addBooks(Book b) { s1.Add(b); } public void display() { IEnumerator ar = s1.GetEnumerator(); while (ar.MoveNext()) { Book b1 = (Book)ar.Current; Console.WriteLine("Book name: " + b1.GetBookName()); Console.WriteLine("Book quantity: " + b1.GetQuantity()); Console.WriteLine("Book Price: " + b1.GetCost()); } } public void Search() { string n; int q; Console.WriteLine("Enter the book to be searched"); n=Console.ReadLine(); Console.WriteLine("Enter the quantity you want"); q=int.Parse(Console.ReadLine()); IEnumerator ar = s1.GetEnumerator(); while(ar.MoveNext()) { Book b = (Book)ar.Current; if (b.GetBookName().Equals(n))

{ if (b.GetQuantity() >= q) { Console.WriteLine("The Requested Book is available, in the quantity required."); Console.WriteLine("Total Amount: " + (q * b.GetCost()) ); } } else { Console.WriteLine("The Requested Book is available in " + (q - b.GetQuantity()) + " Quantity."); Console.WriteLine("Total Amount: " + ((q - b.GetQuantity() ) * b.GetCost())); }

} } } }

Вам также может понравиться