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

📄 pex2_5.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 CPP
字号:
#include <iostream.h>
#include <string.h>

enum DaysOfWeek {Sun,Mon,Tues,Wed,Thurs,Fri,Sat};

// variable of type DayName holds the day as a string
typedef char DayName[10];

// declare an array of the day names as strings
DayName dStr[7] = {"Sun","Mon","Tues","Wed","Thurs","Fri","Sat"};

void GetDay(DaysOfWeek& day)
{
	DayName str;
	int i = 0;
	
	// input a string and compare it to the day name strings. at
	// conclusion of loop, i is the integer value of day or 7
	// if the string does not correspond to a valid day
	cin >> str;
	while (strcmp(dStr[i],str) != 0 && i < 7)
		i++;
	if (i < 7)
		day = DaysOfWeek(i);
	else
	{
		cerr << str << " is not valid input." << endl;
		day = DaysOfWeek(0);
	}
}

void PutDay(DaysOfWeek day)
{
	cout << dStr[int(day)];
}

void main(void)
{
	DaysOfWeek  day;
	for (int i = 0; i < 4; i++)
	{
		GetDay(day);
		cout << "     Output: ";
		PutDay(day);
		cout << endl;
	}
}

/*
<Run>

Tues
     Output: Tues
Thurs
     Output: Thurs
Sat
     Output: Sat
Monday
Monday is not valid input.
     Output: Sun
*/

⌨️ 快捷键说明

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