using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("请输入图书的数量:");
int number = Convert.ToInt32(Console.ReadLine());
Card[] cards = new Card[number];
for (int i = 0; i < number; i++)
{
Console.WriteLine("请输入图书的名称:");
string bookname = Console.ReadLine();
Console.WriteLine("请输入图书的作者:");
string bookauthor = Console.ReadLine();
Console.WriteLine("请输入图书的数量:");
int booknum = Convert.ToInt32(Console.ReadLine());
cards[i] = new Card();
cards[i].Store(bookname, bookauthor, booknum);
}
Console.WriteLine("请输入要查询的书名:");
string praname = Console.ReadLine();
foreach (Card thecard in cards)
{
if (thecard.Show(praname) != null)
{
string[] bookinfo = thecard.Show(praname);
Console.WriteLine("作者为:" + bookinfo[0] + " " + "图书的馆藏数量为:" + bookinfo[1]);
}
}
}
catch (Exception e)
{
Console.WriteLine("Error"+e.Message);
}
}
}
class Card
{
private string bookname;
public string Bookname
{
get { return bookname; }
set { bookname = value; }
}
private string bookauthor;
public string Bookauthor
{
get { return bookauthor; }
set { bookauthor = value; }
}
private int booknum;
public int Booknum
{
get { return booknum; }
set { booknum = value; }
}
public void Store(string prabookname,string prabookauthor,int prabooknum)
{
this.Bookname = prabookname;
this.Bookauthor = prabookauthor;
this.Booknum = prabooknum;
}
public string[] Show(string bookname)
{
if (bookname==Bookname)
{
return(Bookauthor+','+Booknum).Split(',');
}
else
{
return null;
}
}
}
}