⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 birthday.cpp

📁 This file set two employees information and print them out and tell today is whose borthday.
💻 CPP
字号:
//*******************************************************
//       birthday.cpp ( DesignNo.9_2 )
// This file set two employees' information and print them 
// out and tell today is whose borthday. 
//*******************************************************
#include "Date.h"
#include <iostream>
#include <string>
#include <time.h>

using namespace std;

struct employee
{
  string name;
  int ID;
  Date birthday; 
};

void main()
{
  time_t now; // time_t equals long 
  tm *current; // point to struct tm{ int tm_sec; ... ; int tm_mday; ...}
  Date date1(1970,11,25); // Date object
  Date date2(1980,12,28); // Date object
  employee No1;
  employee No2;

  // assign data to struct employees No1 and No2
  No1.name="Jane";
  No1.ID=10;
  No1.birthday=date1;
  No2.name="Mark";
  No2.ID=15;
  No2.birthday=date2;

  // get system time( current time)
  time(&now); // time(time_t *timeptr), read in the current system time 
              // and save in memory the pointer timeptr pointed.
  cout <<"Current time is :  " << ctime(&now); // char *ctime(const time_t *timeptr),
                                               // change data to char array(string)   
  current=localtime(&now); //struct tm *localtime(const time_t *timeptr)
                           //save data into struct tm
  
  // print information of two employees
  cout << "The infomation of the two employees is as follows: " << endl;
  cout << No1.name << "  " << No1.ID << "  " ;
  No1.birthday.GetDate();
  cout << No2.name << "  " << No2.ID << "  " ;
  No2.birthday.GetDate();
  
  // tell and print if today is whoes birthday
  if ( No1.birthday.GetDay() == current->tm_mday )
	  cout << "Today is " << No1.name << "'s birthday." << endl;	  
  if ( No2.birthday.GetDay() == current->tm_mday )
       cout << "Today is " << No2.name << "'s birthday." << endl;  
}

⌨️ 快捷键说明

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