6xii.cpp

来自「C/C++程序设计导论(第二版)》程序源文件」· C++ 代码 · 共 26 行

CPP
26
字号

// ReadItem()  Input a single data item from a patient log line
// ASSUMPTION: input lines conform to the documented format
// OUT: sex is returned as the letter `F' or `M' (if input)
//		age is returned as an integer following the input `A' (if input)
//		weight is returned as a float following the input `W' (if input)
#include <iostream.h>
const char WEIGHT = 'W';
const char AGE = 'A';
const char MALE = 'M';
const char FEMALE = 'F';
void ReadItem (char& sex, int& age, float& weight)
{	char prefix;
	cin >> prefix;					// first get the item prefix
	if (prefix == WEIGHT)
		cin >> weight;
	else if (prefix == AGE) 
		cin >> age;
	else if (prefix == MALE) 
		sex = prefix;
	else if (prefix == FEMALE)
		sex = prefix;
	else cout << " ** illegal data item in patient input **" << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?