⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 book类.txt

📁 编写book类。包含书籍名称
💻 TXT
字号:
/*实验目的:类和对象的综合练习;练习使用string类描述字符串。

实验原理:类和对象;静态成员;数组;string类。

实验内容:

编写book类。包含书籍名称,书号,单价,库存数量等数据成员。包含静态数据成员书籍总数量,记录
所有书籍的总数。要求用对象数组的方法登记书籍,能计算书籍总数并能按照书籍号查询需要的书籍,
并显示书籍基本信息。
*/
  
#include<iostream>
#include<string>
using namespace std;
class book
{private: string name;
          int countp;
		  double price;
          static int all;		  
public:
	string numb;
	static int count;
	book(string _name,string _numb,double _price,int _countp)
	{name=_name;numb=_numb;price=_price;count++;countp=_countp;all=all+countp;}
	static void Geta(){cout<<"库存书目:"<<count<<"种   共"<<all<<"册"<<endl;}
    void display() {cout<<"       "<<name<<"    "<<numb<<"      "<<price<<"     "<<countp<<endl;}
};
int book::count=0;
int book::all=0;
int main()
{   string numb1;
int i,as=0;
   book	ck[7]={
		book("c++ ","1",34.00,10),
		book("vc++","2",43.00,20),
		book("vb++","3",16.00,20),
		book("c#  ","4",25.00,10),
		book("c++ ","5",24.00,30),
		book("c++ ","6",13.00,40),
		book("c++ ","7",23.00,20)};
		cout<<"库存:"<<" 书名 "<<"  书号  "<<" 价格 "<<"  数量"<<endl;
		for(i=0;i<book::count;i++)
		{ck[i].display();}
		book::Geta();
		cout<<"请输入需要查询的书号:";
	    cin>>numb1;
	    cout<<"查询结果:"<<endl;;
	   for(i=0;i<book::count;i++)
		   if(numb1==ck[i].numb)
		   {ck[i].display();
		   as=1;}
		   if(as==0) cout<<"  未找到 "<<endl;
		 return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -