#include <iostream>
#include <string>
using namespace std;
struct DonorInfo
{
char DonorName[namssize]; // 捐款者姓名
double Fund; // 款项
};
int main()
{
int DonorNum;
int GPNum = 0, PNum = 0;
cout << "Please input the number of donors:";
cin >> DonorNum;
cin.get();
DonorInfo *Ps = new DonorInfo[DonorNum];
for (int i = 0; i < DonorNum; i++)
{
cout << "Please input the donor's name: ";
cin.getline(Ps[i].DonorName, namssize);
cout << "Please input the donor's fund: ";
cin >> Ps[i].Fund;
cin.get();
}
cout << "==================================\n";
for (int i = 0; i < DonorNum; i++)
{
if (Ps[i].Fund > 10000)
{
cout << "Grand Patrons: ";
GPNum++;
cout << "Name: " << Ps[i].DonorName << " Fund: " << Ps[i].Fund << endl;
}
else
{
cout << "Patrons: ";
PNum++;
cout << "Name: " << Ps[i].DonorName << " Fund: " << Ps[i].Fund << endl;
}
}
if (GPNum == 0)
cout << "Grand Patrons: None" << endl;
if (PNum == 0)
cout << "Patrons: None" << endl;
delete Ps;
cin.get();
return 0;
}
C++ 动态结构数组举例
最新推荐文章于 2023-09-21 20:15:03 发布
该程序用于输入并分类捐款者信息,根据捐款金额将捐赠者分为大赞助商(Grand Patrons,捐款超过10000)和赞助商(Patrons)。用户可以输入捐赠者数量及其姓名和捐款数额,程序会显示每个捐赠者的分类及详细信息。如果不存在某一类别,则会显示'None'。
摘要由CSDN通过智能技术生成