#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 发布