编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习6

本文介绍了一个使用C++实现的简单程序,该程序用于输入捐款者的信息并根据捐款金额进行分类,将捐款超过10000元的人归类为Grand Patrons,其他人则为Patrons。程序使用了字符串和动态数组来存储数据,并通过条件判断实现了分类。
#include <iostream>
#include <string>
using namespace std;
const int MSIZE=100;
struct juankuan
{
	string name;
	double mon;
};
int main()
{
	int num;
	(cin>>num).get();
	int *c1=new int[num];//存储捐款超过10000的捐款个体
	int count1=0;//记录捐款超过10000的个数
	int *c2=new int[num];//存储捐款超过10000的捐款个体
	int count2=0;
	juankuan *newjk=new juankuan[num];
	int i=0;
	while(i<num)
	{
		cout<<"Enter the name of patron: ";
		getline(cin,newjk[i].name);
		cout<<"Enter the money of patron: ";
		cin>>newjk[i].mon;
		cin.get();
		if(newjk[i].mon>10000)
		{
			c1[count1++]=i+1;
		}
		else
		{
			c2[count2++]=i+1;
		}
		i++;
	}
	cout<<"Grand Patrons: "<<endl;
	int j=0,k;
	if(count1==0)
		cout<<"none"<<endl;
	else
	{ 
		while(j<count1)
		{
			k=c1[j];
			cout<<newjk[k-1].name<<":"<<newjk[k-1].mon<<endl;
			j++;
		}
	}
	int n=0,m;
	cout<<"Partons: "<<endl;
	if(count2==0)
		cout<<"none"<<endl;
	else
	{
		while(n<count2)
		{
			m=c2[n];
			cout<<newjk[m-1].name<<":"<<newjk[m-1].mon<<endl;
			n++;
		}
	}
	delete [] newjk;
	delete [] c1;
	delete [] c2;
	system("pause");
	return 0;
}



 

转载于:https://www.cnblogs.com/lynnycy/p/3454807.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值