473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

i have a simple Library management program in C#,can anyone please correct the errors

This is a program of maintaining the various work carried out in a library. My syntax and use of classes is wrong. Could anyone please correct the errors in the program and also handle the exceptions for me. I need it ASAP. Thanx a lot...

Expand|Select|Wrap|Line Numbers
  1.  
  2.     class Program
  3.     {
  4.         static public int[] student = new int[100];
  5.         static public int[] i = new int[5];
  6.         static public int[] b = new int[5];
  7.         static public int issuelimit = 2;
  8.         static public string bookname;
  9.         static public int id; 
  10.         static public int bookcount;
  11.         static public int bookid;
  12.         static public int choice=0;
  13.         static public char Repeat;
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             int choice=1;
  18.             Console.WriteLine(" What do u want to do?\n");
  19.             Console.WriteLine("1.Add a book to the Library");
  20.             Console.WriteLine("2.Register a user ");
  21.             Console.WriteLine("3.Issue a book");
  22.             Console.WriteLine("4.Display list of Registered user");
  23.             Console.WriteLine("5.Display list of books in library");
  24.             Console.WriteLine("6.Exit");
  25.  
  26.             choice = Convert.ToInt16(Console.ReadLine());        
  27.  
  28.             LibMng lb = new LibMng();
  29.             switch (choice)
  30.             {
  31.                 case 1:
  32.                     {   
  33.                         do
  34.                         {
  35.                         Console.WriteLine("Enter the name of the book and the author's name: ");
  36.                         string bookname = Convert.ToString(Console.ReadLine());
  37.                         string author = Convert.ToString(Console.ReadLine());
  38.                         bookcount++;
  39.                         bookid++;
  40.                             Console.WriteLine("\nDo you wish return more from the same card??(y/n)");
  41.                                 Repeat = Convert.ToChar(Console.ReadLine());
  42.                         } 
  43.                             while (Repeat == 'y' || Repeat == 'Y');
  44.                             break;                      
  45.                     }
  46.                 case 2:
  47.                     {
  48.                         Console.WriteLine("Enter the name and address of user: ");
  49.                         string studentname = Convert.ToString(Console.ReadLine());
  50.                         string studentadd = Convert.ToString(Console.ReadLine());
  51.                         Console.WriteLine("Enter the card ID");
  52.                         id = Convert.ToInt16(Console.ReadLine());
  53.                             do
  54.                             {
  55.                                 if (student[id] != 0)
  56.                                 {
  57.                                     lb.bookReturn();
  58.                                 }
  59.                                 else
  60.                                 {
  61.                                     Console.WriteLine("Till no book is issued to this card");
  62.                                     break;
  63.                                 }
  64.                                 Console.WriteLine("\nDo you wish return more from the same card??(y/n)");
  65.                                 Repeat = Convert.ToChar(Console.ReadLine());
  66.                             } 
  67.                             while (Repeat == 'y' || Repeat == 'Y');
  68.                             break;                      
  69.                     }
  70.                 case 3:
  71.                     {
  72.                         Console.WriteLine("Enter the Student id");
  73.                         id = Convert.ToInt16(Console.ReadLine());
  74.                         do
  75.                         {
  76.                             if (student[id] < 2)
  77.                             {
  78.                                 lb.Issue();
  79.                             }
  80.                             else
  81.                             {
  82.                                 Console.WriteLine("Sorry no more books can be issued");
  83.                                 break;
  84.                             }
  85.  
  86.                             Console.WriteLine("\nDo you wish to issue more to the same card??(y/n)");
  87.                             Repeat = Convert.ToChar(Console.ReadLine());
  88.                         }
  89.                         while (Repeat == 'y' || Repeat == 'Y');
  90.                         break;
  91.                     }
  92.                 case 4:
  93.                     {
  94.                     do
  95.                                 {
  96.                                     Console.WriteLine("the list of registered student is:");
  97.                                     foreach (int a in Student)
  98.                                     {
  99.                                         Console.WriteLine("Name: ", a.studentname);
  100.                                         Console.WriteLine("StudentId: {0}", a.studentid);
  101.                                         Console.WriteLine("Number of books issued: {0}", a.NoOfBooksIssues);
  102.                                     }
  103.                                     Console.WriteLine("do you wish to continue??(y/n)");
  104.  
  105.                                 } while (Repeat == 'y' || Repeat == 'Y');
  106.                         break;
  107.                     }
  108.                 case 5:
  109.                     {
  110.                                 do
  111.                                 {
  112.                                     Console.WriteLine("the list of books in library:");
  113.                                     foreach (int b in BookLibrary)
  114.                                     {
  115.                                         Console.WriteLine("Book Title: {0}", b.bookname);
  116.                                         Console.WriteLine("Book Id: {0}", b.bookid);
  117.                                         Console.WriteLine("Author name: {0}", b.author);
  118.                                     }
  119.                                     Console.WriteLine("do you wish to continue??(y/n)");
  120.  
  121.                                 } while (Repeat == 'y' || Repeat == 'Y');
  122.                         break;
  123.                     }                
  124.                 case 6:
  125.                     {
  126.                         break;
  127.                     }
  128.  
  129.             }
  130.                     Console.ReadLine();
  131.             }
  132.         }
  133.         class LibMng : Program
  134.         {
  135.             public void Issue()
  136.             {                
  137.                 Console.WriteLine("Enter The Book id ");
  138.                 int reqbook = Convert.ToInt32(Console.ReadLine());
  139.                 if (reqbook == bookid)
  140.                 {
  141.                     if (i[0] != 0)
  142.                     {
  143.                         i[0]--;
  144.                         Console.WriteLine("The Book is issued to Card{0}", id);
  145.                         student[id]++;
  146.                     }
  147.                     else
  148.                         Console.WriteLine("Book is not available");
  149.                 }
  150.             }
  151.             public void display()
  152.             {
  153.                 Console.WriteLine("the books taken are: ");
  154.             }
  155.  
  156.             public void chckAvail()
  157.             {
  158.                 Console.WriteLine("Enter The Book id");
  159.                 int req = Convert.ToInt32(Console.ReadLine());
  160.                 if (req == bookid)
  161.                 {
  162.                     if (i[0] != 0)
  163.                     {
  164.                         Console.WriteLine("The number of copy of the Book is::{0}", i[0]);
  165.                     }
  166.                     else
  167.                         Console.WriteLine("Book is not available");
  168.                 }
  169.             }
  170.         }
  171.  
  172.             class BookLibrary: Program
  173.             {
  174.                 public int bookcount;
  175.                 public int bookid;
  176.                 public string bookname;
  177.                 public string booktitle;
  178.  
  179.                 public BookLibrary(int bookcount, int bookid, string bookname, string booktitle)
  180.                 {
  181.                     this.bookcount = bookcount;
  182.                     this.bookid = bookid;
  183.                     this.bookname = bookname;
  184.                     this.booktitle = booktitle;
  185.                 }               
  186.  
  187.             }
  188.             class Student
  189.             {
  190.                 public int studentcount;
  191.                 public int studentid;
  192.                 public string studentname;
  193.                 public int noOfbookissues = 0;
  194.  
  195.                 public Student(int studentcount, int studentid, string studentname, int noOfbooksissued)
  196.                 {
  197.                     this.studentcount = studentcount;
  198.                     this.studentid = studentid;
  199.                     this.studentname = studentname;
  200.                     this.noOfbookissues = noOfbookissues;
  201.                 }
  202.             }
  203.             class IssueReturn: Program
  204.             {            
  205.                 public void bookReturn()
  206.                 {
  207.                 Console.WriteLine("Enter The Book ID");
  208.                 int req1 = Convert.ToInt32(Console.ReadLine());
  209.  
  210.                 if (req1==bookid)
  211.                 {
  212.                     if (i[0] != 1)
  213.                     {
  214.                     i[0]++;
  215.                     Console.WriteLine("The Book is returned from Card {0}", id);
  216.                     student[id]--;
  217.                     }
  218.                 else
  219.                     Console.WriteLine("Till the Book is not issued to this Card");
  220.                 }
  221.                 }
  222.             }
  223.         }
  224.     }
  225.  
  226.  
  227.  
Apr 16 '12 #1
5 12477
RhysW
70
There is so much wrong here that the intellisense picks up on and tells you about, have you even tried doing this yourself?
have you looked up about error catching? Were here to help solve problems that you explain to us, not to just give a lump of code and correct for you,

this is a learning environment, not a give us your code and we do it for you environment.

Now i don't like purely cynical posts so i'll help you out a bit here, first of all, in your student constructor youre assigning the properties to itself, you dont need to use this. on everything and youre variable names are so similar that youre getting confused and assigning things to the wrong places,

on the exception front i just answered in depth a question about error trapping and how to deal with it in this topic, you might want to check it out

but again, we prefer the motto "Give a man a fish and he feeds for a day, Teach a man to fish he feeds for the rest of his life" So im not being deliberately awkward, im trying to teach you to deal with your own problems, so if you come across the same one again you can do it yourself instead of having to rely on us. Hope you can see the advantage in what im doing!

RhysW
Apr 16 '12 #2
thank you for the suggestion...am doing C# for the first time and have very less knowledge about classes and functions...so... thank you for the help
Apr 16 '12 #3
RhysW
70
thats fine, were all beginners at one point! im still very very early on in my c# knowledge, only just over 2 months, youll pick it up fast if you stick to it and try to work through your problems!
Apr 16 '12 #4
The thing is that our mentor has completed teaching us C# in less than 2 weeks and now from tomorrow itself we are starting with html.....so its very hard to cope up and the particular program was part of a diagnostics....so i want to get myself clear with the classes and exception stuffs so wanted a correct version of the program. Never the less both ur suggestions were of great help to me. Hope to get more knowledge from u in the future. Thank u once again.
Apr 16 '12 #5
maybe try to use the get; set; ..?

public string stud_name { get; set; }
Apr 20 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.