您的位置:首页 > 编程语言 > C语言/C++

开始学习C++

2011-05-14 14:11 351 查看
虽然,都已经学了好几天了,但现在说出来下,还不算晚哈.

最近的代码会略少,算法的东西前进得不多.

刚刚写了这个东西.毕竟还没有学完,就是按照当前章节的要求写出来的.

加油吧!我终于开始学习C++了!

贴咯.贴完出去打会球!

// 6-6-2011-05-14-13.08.cpp -- 第六章第六题
#include "stdafx.h"
#include <iostream>

const char NUL = '/0' ;
const int NAMESIZE = 20 ;

struct Patron
{
	char name[NAMESIZE] ;
	double money ;
} ;

int _tmain(int argc, _TCHAR* argv[])
{
	using namespace std ;
	Patron * pTP ;
	int num, i ;

	cout << "Input the number of patrons:" ;
	if (!(cin >> num) || num <= 0)
	{
		cout << "Wrong input./n" ;
		return 0 ;
	}
	cin.get () ;
	pTP = new Patron[num] ;
	for (i = 0; i < num; ++i)
	{
		cout << "Please input information of current patron, [" << i + 1 << "/" << num << "]/n" ;
		cout << "Now input name:" ;
		cin.getline (pTP[i].name, NAMESIZE) ;
		cin.clear () ;
		cout << "And money:" ;
		cin >> pTP[i].money ;
		cin.get () ;
	}
	//	Output
	cout << "Grand Patrons:/n" ;
	for (i = 0; i < num; ++i)
	{
		if (pTP[i].money > 10000.0)
		{
			if (NUL == pTP[i].name[0])
				cout << "Name : none/n" ;
			else
				cout << "Name : " << pTP[i].name << endl ;
		}
	}
	cout << "Patrons:/n" ;
	for (i = 0; i < num; ++i)
	{
		if (pTP[i].money <= 10000.0)
		{
			if (NUL == pTP[i].name[0])
				cout << "Name : none/n" ;
			else
				cout << "Name : " << pTP[i].name << endl ;
		}
	}
	delete []pTP ;

	return 0 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: