Tiks izdzēsta lapa "Home"
. Pārliecinieties, ka patiešām to vēlaties.
#include #include #include #include using namespace std; class CBook { private:
string id;
string name;
int total_number;
int number;
public:
CBook() {
//name = "";
//number = 0;
//total_number = 0;
//id = "";
}
CBook(string id_1, string name_1, int total_number_1, int number_1) :id(id_1), name(name_1), total_number(total_number_1), number(number_1) {}
string setid() { return id; }
string setname() { return name; }
int settotal() { return total_number; }
int setnumber() { return number; }
void borrow(string name_1)
{
if (number >= 1)
{
number--;
cout << name << " 索取号: "<<id;
//return id;
//cout << endl;
}
else
cout << name << " 该书已全部借出";
}
void print()
{
cout << id << " " << name << " " << total_number << " " << number<< endl;
}
void show()
{
int number_borrow = 0, number_leave = 0;
}
}; int main() {
int n;
cin >> n;
CBook *p = new CBook[n];
string id, name;
int total_number,number,i;
int number_borrow = 0, number_leave;
for (i = 0; i < n; i++)
{
cin >> id >> name >> total_number >> number;
if (total_number >= 0)
{
CBook sb(id, name, total_number, number);
sb.setid();
sb.setname();
sb.settotal();
sb.setnumber();
p[i] = sb;
number_borrow += p[i].settotal();
}
}
int total = number_borrow;
int m;
cin >> m;
string name_;
//int last;
while(m--)
{
cin >> name_;
for (i = 0; i < n; i++)
{
if (name_ == p[i].setname())
{
p[i].borrow(name_);
number_borrow--;
//cout << id;
}
else
continue;
}
cout << endl;
}
cout << endl;
number_leave = total - number_borrow;
for (i = 0; i < n; i++)
{
p[i].print();
}
cout << "借出图书: " << number_borrow << "本 剩余馆藏图书: " << number_leave << "本" << endl;
//system("pause");
return 0;
}
Tiks izdzēsta lapa "Home"
. Pārliecinieties, ka patiešām to vēlaties.