C# 面向对象例题
来源:互联网 发布:手游源码一般多少钱 编辑:程序博客网 时间:2024/06/06 04:02
图书管理系统
请利用面向对象分析实现图片管理系统,具有录入,查询 ,删除,显示所有图书信息功能。
class Program { static void Main(string[] args) { BookManager bm = new BookManager(); bm.Init(); } } class Book { /// <summary> /// 当一个对象被创建时,必须执行Book(构造函数) /// </summary> public Book() { } public Book(string name, string author, int price) { this._name = name; this._author = author; this._price = price; } private string _name; public string name { get { return _name; } } private string _author; public string Author { get { return _author; } } private int _price; public int Price { get { return _price; } } public override string ToString() { return "<<" + name + ">> " + _author + " " + Price + "元"; } } class BookManager { public List<Book> list = new List<Book>(); public void Init() { ///Console.Clear(); Console.WriteLine("=====图书管理系统===="); Console.WriteLine("1. 录入"); Console.WriteLine("2. 查询"); Console.WriteLine("3. 删除"); Console.WriteLine("4. 显示所有图书"); Console.WriteLine("5. 退出"); Console.WriteLine("====================="); Console.WriteLine(""); Console.Write("请输入功能序号:"); int action = int.Parse(Console.ReadLine()); switch (action) { case 1: Enter(); Init(); break; case 2: Find(); Init(); break; case 3: Dele(); Init(); break; case 4: ShowAll(); Init(); break; case 5: Environment.Exit(0); break; } } public void Enter() { Console.Write("请输入书名:"); string bookname = Console.ReadLine(); Console.Write("请输入作者:"); string bookauthor = Console.ReadLine(); Console.Write("请输入价格:"); int bookprice = int.Parse(Console.ReadLine()); //利用自己定义的构造函数创建Book对象 Book book = new Book(bookname, bookauthor, bookprice); Console.WriteLine("书名:" + book.name); list.Add(book); Console.WriteLine("图书录入成功!"); } public void Find() { Console.Write("请输入要查询的书名:"); string name = Console.ReadLine(); Console.WriteLine("======查询结果如下======"); foreach (Book book in list) { if (book.name == name) { Console.WriteLine(book); } Console.WriteLine(); } Console.WriteLine(); } public void Dele() { Console.Write("请输入要删除的书名:"); string name = Console.ReadLine(); foreach (Book book in list) { if (book.name == name) { list.Remove(book); return; } } } public void ShowAll() { foreach (Book book in list) { Console.WriteLine(book); Console.WriteLine(); } } }
阅读全文
1 0
- C# 面向对象例题
- java例题学习:面向对象之长方形例题学习
- java--面向对象1-18例题
- C#如何面向对象
- C#面向对象3
- C#面向对象4
- C#面向对象
- c#面向对象
- C#面向对象编程
- C#面向对象分析
- c#面向对象基础
- C#面向对象程序设计
- c#面向对象复习
- C#面向对象基础
- C#面向对象编程
- C#面向对象分析
- c#面向对象基础
- C# 面向对象 资料
- 如何在移动开发者的寒冬中破冰而出?
- 【luogu1613】跑路(倍增)
- Eclipse 新建Servlet做doget请求出现乱码
- Difference between drawing with QPainter and (QGraphicsView + QGraphicsScene)
- hexo next主题集成gitment评论系统
- C# 面向对象例题
- hexo next主题去掉码市的Coding Pages等待页
- Java获取存储过程返回的多个结果集
- struts2中使用servlet
- bzoj1579 [Usaco2009 Feb]Revamping Trails 道路升级(分层图最短路)
- Spark1.6.3学习02——Spark Programming Guide
- BZOJ 3262: 陌上花开 CDQ
- python类与对象part3
- Linux 实用记录