📄 c23.cpp
字号:
// c23.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <iomanip.h>
// ------------------------------------------------------------
const int NUMEMPLOYEES = 4;
const NUMHOURS = 10;
const STARTHOUR = 8;
// ------------------------------------------------------------
int schedule[ NUMHOURS ][ NUMEMPLOYEES ];
// ------------------------------------------------------------
void Enter();
void Display();
void Calculate();
int EnterEmpnum();
void EnterHour(int);
// ------------------------------------------------------------
int main(int argc, char* argv[])
{
Enter();
Display();
Calculate();
return 0;
}
// ------------------------------------------------------------
void Enter()
{
int empnum;
empnum = EnterEmpnum();
while ( empnum != -1 )
{
EnterHour( empnum );
empnum = EnterEmpnum();
}
}
// ------------------------------------------------------------
int EnterEmpnum()
{
int empnum;
while(1)
{
cout << "Employee number?(0~3, -1 to quit):";
cin >> empnum;
if ( empnum < 0 )
return -1;
if ( empnum > NUMEMPLOYEES-1 )
cout << "Employee number is out of range\n";
else
return empnum;
}
}
// ------------------------------------------------------------
void EnterHour( int empnum )
{
int hour;
while(1)
{
cout << "Hour of appointment?(8~17, -1 to quit):";
cin >> hour;
if ( hour < 0 )
break;
if ( (STARTHOUR<=hour) && (hour<STARTHOUR+NUMHOURS) )
schedule[hour-STARTHOUR][empnum] = 1;
else
cout << "Hour is of range\n";
}
}
// ------------------------------------------------------------
void Display()
{
cout << "\nSchedule:\n";
cout << " Joe Sam Paula Mary\n";
for ( int hour = 0; hour < NUMHOURS; hour++ )
{
cout << setw(2) << (hour+STARTHOUR) << ":00";
for ( int empnum = 0; empnum < NUMEMPLOYEES; empnum++ )
{
cout << "\t";
if ( schedule[hour][empnum] != 0 )
cout << "X";
}
cout << endl;
}
}
// ------------------------------------------------------------
void Calculate()
{
cout << "\nPossible meeting time:\n";
for ( int hour = 0; hour < NUMHOURS; hour++ )
{
int k = 0;
for ( int empnum=0; empnum<NUMEMPLOYEES; empnum++ )
k += schedule[hour][empnum];
if ( k )
cout << setw(2) << (hour+STARTHOUR) << ":00\t" << k << endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -