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

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
struct patron
{
	double mon;
	string name;
};
int main()
{
	int num,count1=0,count2=0;
	ifstream fin;
	char filename[20];
	cout<<"Enter name of data file: ";
	cin.get(filename,20);
	fin.open(filename);
	if(!fin.is_open())
	{
		cout<<"Could not to open the file "<<filename<<endl;
		cout<<"Program termination.\n";
		exit(EXIT_FAILURE);
	}
	fin>>num;
	fin.get();
	patron *newp=new patron[num];
	for(int i=0;i<num;i++)
	{
		getline(fin,newp[i].name);
		fin>>newp[i].mon;
		fin.get();
	}
	cout<<"Grand Patrons:\n";
	for(int j=0;j<num;j++)
	{
		if(newp[j].mon>10000)
		{
			cout<<newp[j].name<<":"<<newp[j].mon<<endl;
			count1++;
		}
		if(count1==0)
			cout<<"none\n";
		cout<<"Patrons:\n";
		for(int k=0;k<num;k++)
		{
			if(newp[k].mon<=10000)
			{
				cout<<newp[k].name<<":"<<newp[k].mon<<endl;
				count2++;
			}
		}
		if(count2==0)
			cout<<"none\n";
	}
	delete [] newp;
	system("pause");
	return 0;
}

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值