📄 birth.cpp
字号:
//这个程序在本书所带软盘中。文件名为BIRTH.CPP
//这个程序演示怎样定义、赋值以及输出结构成员。
#include <iostream.h>
struct birth { //定义一个结构类型
int month;
int day;
int year;
};
void main(void)
{
birth my_birth = {8, 15, 53}; //定义并初始化一个结构变量
birth your_birth, friend_birth; //定义两个结构变量
cout << "请输入你的出生日期: "; //以下输入结构变量成员的值
cin >> your_birth.day;
cout << "请输入你的出生月份: ";
cin >> your_birth.month;
cout << "请输入你的出生年份: ";
cin >> your_birth.year;
cout << "很好!" << endl;
cout <<endl << "下面输入你的朋友的出生日期: ";
cin >> friend_birth.day;
cout << "请输入你的朋友的出生月份: ";
cin >> friend_birth.month;
cout << "请输入你的朋友的出生年份: ";
cin >> friend_birth.year;
cout << endl; //以下输出结构变量成员的值
cout << "下面显示生日信息: " << endl;
cout << "我的生日是: ";
cout << my_birth.year << "." << my_birth.month << "." << my_birth.day << endl;
cout << "你的生日是:";
cout << your_birth.year << "." << your_birth.month << "." << your_birth.day << endl;
cout << "你朋友的生日是: ";
cout << friend_birth.year << "." << friend_birth.month << "." << friend_birth.day << endl;
}
/*这个程序运行后将显示如下输出结果:
请输入你的出生日期: 1
请输入你的出生月份: 12
请输入你的出生年份: 77
很好!
下面输入你的朋友的出生日期: 5
请输入你的朋友的出生月份: 5
请输入你的朋友的出生年份: 78
下面显示生日信息:
我的生日是: 53.8.15
你的生日是:77.12.1
你朋友的生日是: 78.5.5
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -