Page

Library Management Program in C#

class Program
    {
        static public int[] student = new int[100];
        static public int[] i = new int[5];
        static public int[] b = new int[5];
        static public int issuelimit = 2;
        static public string bookname;
        static public int id; 
        static public int bookcount;
        static public int bookid;
        static public int choice=0;
        static public char Repeat;

        static void Main(string[] args)
        {
            int choice=1;
            Console.WriteLine(" What do u want to do?\n");
            Console.WriteLine("1.Add a book to the Library");
            Console.WriteLine("2.Register a user ");
            Console.WriteLine("3.Issue a book");
            Console.WriteLine("4.Display list of Registered user");
            Console.WriteLine("5.Display list of books in library");
            Console.WriteLine("6.Exit");

            choice = Convert.ToInt16(Console.ReadLine());        

            LibMng lb = new LibMng();
            switch (choice)
            {
                case 1:
                    {   
                        do
                        {
                        Console.WriteLine("Enter the name of the book and the author's name: ");
                        string bookname = Convert.ToString(Console.ReadLine());
                        string author = Convert.ToString(Console.ReadLine());
                        bookcount++;
                        bookid++;
                            Console.WriteLine("\nDo you wish return more from the same card??(y/n)");
                                Repeat = Convert.ToChar(Console.ReadLine());
                        } 
                            while (Repeat == 'y' || Repeat == 'Y');
                            break;                      
                    }
                case 2:
                    {
                        Console.WriteLine("Enter the name and address of user: ");
                        string studentname = Convert.ToString(Console.ReadLine());
                        string studentadd = Convert.ToString(Console.ReadLine());
                        Console.WriteLine("Enter the card ID");
                        id = Convert.ToInt16(Console.ReadLine());
                            do
                            {
                                if (student[id] != 0)
                                {
                                    lb.bookReturn();
                                }
                                else
                                {
                                    Console.WriteLine("Till no book is issued to this card");
                                    break;
                                }
                                Console.WriteLine("\nDo you wish return more from the same card??(y/n)");
                                Repeat = Convert.ToChar(Console.ReadLine());
                            } 
                            while (Repeat == 'y' || Repeat == 'Y');
                            break;                      
                    }
                case 3:
                    {
                        Console.WriteLine("Enter the Student id");
                        id = Convert.ToInt16(Console.ReadLine());
                        do
                        {
                            if (student[id] < 2)
                            {
                                lb.Issue();
                            }
                            else
                            {
                                Console.WriteLine("Sorry no more books can be issued");
                                break;
                            }

                            Console.WriteLine("\nDo you wish to issue more to the same card??(y/n)");
                            Repeat = Convert.ToChar(Console.ReadLine());
                        }
                        while (Repeat == 'y' || Repeat == 'Y');
                        break;
                    }
                case 4:
                    {
                    do
                                {
                                    Console.WriteLine("the list of registered student is:");
                                    foreach (int a in Student)
                                    {
                                        Console.WriteLine("Name: ", a.studentname);
                                        Console.WriteLine("StudentId: {0}", a.studentid);
                                        Console.WriteLine("Number of books issued: {0}", a.NoOfBooksIssues);
                                    }
                                    Console.WriteLine("do you wish to continue??(y/n)");

                                } while (Repeat == 'y' || Repeat == 'Y');
                        break;
                    }
                case 5:
                    {
                                do
                                {
                                    Console.WriteLine("the list of books in library:");
                                    foreach (int b in BookLibrary)
                                    {
                                        Console.WriteLine("Book Title: {0}", b.bookname);
                                        Console.WriteLine("Book Id: {0}", b.bookid);
                                        Console.WriteLine("Author name: {0}", b.author);
                                    }
                                    Console.WriteLine("do you wish to continue??(y/n)");

                                } while (Repeat == 'y' || Repeat == 'Y');
                        break;
                    }                
                case 6:
                    {
                        break;
                    }

            }
                    Console.ReadLine();
            }
        }
        class LibMng : Program
        {
            public void Issue()
            {                
                Console.WriteLine("Enter The Book id ");
                int reqbook = Convert.ToInt32(Console.ReadLine());
                if (reqbook == bookid)
                {
                    if (i[0] != 0)
                    {
                        i[0]--;
                        Console.WriteLine("The Book is issued to Card{0}", id);
                        student[id]++;
                    }
                    else
                        Console.WriteLine("Book is not available");
                }
            }
            public void display()
            {
                Console.WriteLine("the books taken are: ");
            }

            public void chckAvail()
            {
                Console.WriteLine("Enter The Book id");
                int req = Convert.ToInt32(Console.ReadLine());
                if (req == bookid)
                {
                    if (i[0] != 0)
                    {
                        Console.WriteLine("The number of copy of the Book is::{0}", i[0]);
                    }
                    else
                        Console.WriteLine("Book is not available");
                }
            }
        }

            class BookLibrary: Program
            {
                public int bookcount;
                public int bookid;
                public string bookname;
                public string booktitle;

                public BookLibrary(int bookcount, int bookid, string bookname, string booktitle)
                {
                    this.bookcount = bookcount;
                    this.bookid = bookid;
                    this.bookname = bookname;
                    this.booktitle = booktitle;
                }               

            }
            class Student
            {
                public int studentcount;
                public int studentid;
                public string studentname;
                public int noOfbookissues = 0;

                public Student(int studentcount, int studentid, string studentname, int noOfbooksissued)
                {
                    this.studentcount = studentcount;
                    this.studentid = studentid;
                    this.studentname = studentname;
                    this.noOfbookissues = noOfbookissues;
                }
            }
            class IssueReturn: Program
            {            
                public void bookReturn()
                {
                Console.WriteLine("Enter The Book ID");
                int req1 = Convert.ToInt32(Console.ReadLine());

                if (req1==bookid)
                {
                    if (i[0] != 1)
                    {
                    i[0]++;
                    Console.WriteLine("The Book is returned from Card {0}", id);
                    student[id]--;
                    }
                else
                    Console.WriteLine("Till the Book is not issued to this Card");
                }
                }
            }
        }
    }

No comments:

Post a Comment