代码较多,建议先参考文档,慢慢编写,有问题再讨论:https://blog.csdn.net/qq_42330141/article/details/102247326
using System;
using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using static System.Math;
using System.Linq;
namespace ConsoleApp1
{
public class Object {
public string name { get; set; }
public int no { get; set; }
public Object() { }
public Object(String na,int n) { name = na;no = n; }
public void Show() { Console.Write("{0,-15}{1}", name, no); }
}
public class Book : Object
{
public string author { get; set; }
public Book() { }
public Book(String na, int n, String auth) : base(na, n)
{
author = auth;
}
public void ShowBook() { Console.Write("{0,-15}{1,-5}{2}", name, no, author); }
}
public class Reader : Object
{
public Book[] rent { get; set; }
public int top { get; set; }
public Reader()
{
top = 0;
rent = new Book[5];
}
public Reader(String na, int n) : base(na, n)
{
top = 0;
rent = new Book[5];
}
public void RentBook(Book b)
{
if (top > 4) throw new Exception("最多只能借5本哦~");
rent[top] = b;
top++;
}
public void ShowReader()
{
this.Show();
Console.WriteLine();
for (int i =0; i < top; i++)
{
rent[i].Show();
Console.WriteLine();
}
}
}
class Program
{
static void Main(string[] cmd)
{
var b1 = new Book("书名1", 1, "作者1");
var b2 = new Book("书名2", 2, "作者2");
var r1 = new Reader("读者", 1);
r1.RentBook(b1);
r1.RentBook(b2);
r1.ShowReader();
Console.ReadKey();
}
}
}
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632