using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
public struct Books
{
public string name;
public string num;
public Double price;
};
public class book
{
public static Books[] books = new Books[100];
public static int len;
}
class Program
{
static void Main(string[] args)
{
int a, i; Double c, sum=0; string str, b; book.len = 0;
for (; ; )
{
Console.WriteLine("1、添加新书。\n");
Console.WriteLine("2、查询新书。\n");
Console.WriteLine("3、显示图书。\n");
Console.WriteLine("请输入你的选择:(1,2,3)\n");
a = Convert.ToInt32(Console.ReadLine());
switch (a)
{
case 1: Console.WriteLine("请输入新书的名字:\n");
str = Console.ReadLine();
Console.WriteLine("请输入新书的编号(输入小于十个字符的编号):\n");
b = Console.ReadLine();
if (b.Length > 10)
Console.WriteLine("输入太长");
else
{
Console.WriteLine("请输入新书的价格:\n");
c = Convert.ToDouble(Console.ReadLine());
add(str, b, c);
};
break;
case 2:
Console.WriteLine("输入图书编号:\n");
str = Console.ReadLine();
for (i = 0; i < book.len; i++)
{
if (str == book.books[i].num)
{
Console.WriteLine("图书名字:{0} ;图书编号:{1};图书价格:{2}。", book.books[i].name, book.books[i].num, book.books[i].price);
break;
}
}
if (i == book.len)
{
Console.WriteLine("未找到记录。\n");
}
break;
case 3:
for (int j = 0; j < book.len; j++)
{
Console.WriteLine("图书名字:{0} ;图书编号:{1};图书价格:{2}", book.books[j].name, book.books[j].num, book.books[j].price);
sum += book.books[j].price;
}
Console.WriteLine("共有 {0}本图书", book.len);
Console.WriteLine("总价格是 {0}", sum);
break;
}
}
}
static void add(string str, string b, Double c)
{
book.books[book.len].name = str;
book.books[book.len].num = b;
book.books[book.len].price = c;
book.len++;
}
}
}帮忙看看,谢谢了