appointmentbook.cpp
来自「一个APPOINMENTBOOK程序」· C++ 代码 · 共 161 行
CPP
161 行
#include <iostream>
using namespace std;
#include "AppointmentBook.h"
///////////////////////////////////////////////
//
// Date
//
///////////////////////////////////////////////
Date::Date()
{
m_iDate = 0;
m_iMonth = 0;
m_iYear = 0;
}
void
Date::Print() const
{
static char* szMonth[] = { "",
"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"
};
cout << "Date: " << szMonth[m_iMonth] << ", " << m_iDate << ", " << m_iYear << endl;
}
///////////////////////////////////////////////
//
// Appointment
//
///////////////////////////////////////////////
Appointment::Appointment()
{
m_strWhat = "";
m_strWhere = "";
}
void
Appointment::Print() const
{
m_date.Print();
cout << "What: " << m_strWhat << endl;
cout << "Where: " << m_strWhere << endl;
}
Appointment&
Appointment::operator = (const Appointment& clAppointment)
{
m_strWhat = clAppointment.m_strWhat;
m_strWhere = clAppointment.m_strWhere;
m_date = clAppointment.m_date;
return *this;
}
///////////////////////////////////////////////
//
// AppointmentBook
//
///////////////////////////////////////////////
AppointmentBook::AppointmentBook()
{
m_iNumAppointment = 0;
}
void
AppointmentBook::AddAppointment(const Appointment* pAppointment)
{
if (m_iNumAppointment >= 100) {
cout << "Appointment Book Full." << endl;
return;
}
m_clAppointment[m_iNumAppointment] = *pAppointment;
m_iNumAppointment++;
SortAppointment();
}
void
AppointmentBook::PrintAllAppointments() const
{
int i;
for (i = 0; i < m_iNumAppointment; i++) {
m_clAppointment[i].Print();
}
}
void
AppointmentBook::PrintAppointmentsForDate(const Date* pDate) const
{
int i;
for (i = 0; i < m_iNumAppointment; i++) {
if (m_clAppointment[i].m_date.m_iDate == pDate->m_iDate &&
m_clAppointment[i].m_date.m_iMonth == pDate->m_iMonth &&
m_clAppointment[i].m_date.m_iYear == pDate->m_iYear) {
m_clAppointment[i].Print();
}
}
}
void
AppointmentBook::SortAppointment()
{
int i, j;
Appointment temp;
for (i = m_iNumAppointment; i >= 0 ; i--) {
for (j = 0; j < i - 1; j++) {
if (m_clAppointment[j].m_date.m_iYear > m_clAppointment[j+1].m_date.m_iYear ||
m_clAppointment[j].m_date.m_iMonth > m_clAppointment[j+1].m_date.m_iMonth ||
m_clAppointment[j].m_date.m_iDate > m_clAppointment[j+1].m_date.m_iDate ) {
temp = m_clAppointment[j+1];
m_clAppointment[j+1] = m_clAppointment[j];
m_clAppointment[j] = temp;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?