📄 birthary.cpp
字号:
//这个程序在本书所带软盘中。文件名为BIRTHARY.CPP
//这个程序利用结构数组来处理生日记录。
#include <iostream.h>
#include <stdio.h> //支持gets()
#include <conio.h> //支持getche()
#include <ctype.h> //支持toupper()
#include <iomanip.h> //支持setw()
struct birth { //定义一个结构类型
char name[40];
int month;
int day;
int year;
};
void main(void)
{
birth birth_rec[50]; //定义一个有50个单元的结构数组
char answer;
int i = 0;
do {
cout << "请输入第" << (i+1) << "个人的名字: ";
gets(birth_rec[i].name);
cout << "请输入第" << (i+1) << "个人的出生年份: ";
cin >> birth_rec[i].year;
cout << "请输入他的出生月份: ";
cin >> birth_rec[i].month;
cout << "请输入出生日期: ";
cin >> birth_rec[i].day;
i++; //记录单元数
cout << "想继续输入下一个人的生日记录吗? (y/n): ";
answer = getche();
cout << endl << endl;
} while (toupper(answer) == 'Y');
cout << "下面是输入的生日记录:" << endl;
for(int j = 0; j < i; j++)
cout << birth_rec[j].name << setw(5) << birth_rec[j].year << "." << birth_rec[j].month << "." << birth_rec[j].day << endl;
}
/*下面是这个程序运行后的一个典型输出结果:
请输入第1个人的名字: Le Xiao
请输入第1个人的出生年份: 67
请输入他的出生月份: 6
请输入出生日期: 5
想继续输入下一个人的生日记录吗? (y/n): y
请输入第2个人的名字: Wang Zhong
请输入第2个人的出生年份: 69
请输入他的出生月份: 2
请输入出生日期: 3
想继续输入下一个人的生日记录吗? (y/n): n
下面是输入的生日记录:
Le Xiao 67.6.5
Wang Zhong 69.2.3
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -