首页 > 试题广场 >

编写一个程序,记录捐助给“维护合法权利团体”的资金。该程序要

[问答题]
编写一个程序,记录捐助给“维护合法权利团体”的资金。该程序要求用户输入捐献者数目,然后要求用户输入每一个捐献者的姓名和款项。这些信息被储存在一个动态分配的结构数组中。每个结构有两个成员:用来储存姓名的字符数组(或string对象)和用来存储款项的double成员。读取所有的数据后,程序将显示所有捐款超过10000的捐款者的姓名及其捐款数额。该列表前应包含一个标题,指出下面的捐款者是重要捐款人(Grand Patrons)。然后,程序将列出其他的捐款者,该列表要以Patrons开头。如果某种类别没有捐款者,则程序将打印单词“none”。该程序只显示这两种类别,而不进行排序。
#include<iostream>
#include<cstring>
using namespace std;
struct mem
{
    string name;
	double money;
};
int main()
{
	
	int n,count;
	cin >> n;
	mem *person=new mem[n];//set a uncentainty array

	for (int i = 0; i < n; i++)
	{
        if (i == 0)
        {
            cout << "Please enter name of first person." << endl;
            cin >> person[i].name;
            cout << "Please enter contribution of first person." << endl;
            cin >> person[i].money;
        }
        else if(i==1)
        {
            cout << "Please enter name of second person." << endl;
            cin >> person[i].name;
            cout << "Please enter contribution of second person." << endl;
            cin >> person[i].money;
        }
        else if (i == 2)
        {
            cout << "Please enter name of third person." << endl;
            cin >> person[i].name;
            cout << "Please enter contribution of third person." << endl;
            cin >> person[i].money;
        }
        else
        {
            cout << "Please enter name of  " << i+1 << " th person." << endl;
            cin >> person[i].name;
            cout << "Please enter money of  " << i+1 << " th person." << endl;
            cin >> person[i].money;
        }
        cout << endl;
	}
    int num1 = 0,num2=0;
    cout << "\nGrand Patrons\n" << endl;
    for (int j = 0; j < n; j++)
    {
        if (person[j].money > 10000)
        {
            cout << person[j].name << "\t" << person[j].money << endl;
            num1++;
        }
    }
    if (num1 == 0)
        cout << "None." << endl;

    cout << "\npatrons\n" << endl;
    for (int k = 0; k < n; k++)
    {
        if (person[k].money <= 10000)
        {
            cout << person[k].name << "\t" << person[k].money << endl;
            num2++;
        }
    }
    if (num2 == 0)
        cout << "None." << endl;
	return 0;
}

发表于 2022-03-07 10:55:50 回复(0)