c++ chap1 to chap 3
#ifndef MAIN_H_INCLUDED
#define MAIN_H_INCLUDED
struct Course
{
int id;
std::string name;
};
const int LEN = 7;
void print_help();
void print_all_course(Course* courses[LEN]);
void print_course_count(Course* courses[LEN]);
void print_maxlength(Course* courses[LEN]);
bool remove_last_course(Course* courses[LEN]);
#endif // MAIN_H_INCLUDED
#include <iostream>
#include "main.h"
using namespace std;
int main()
{
Course* courses[LEN] =
{
new Course{1,"Linux"},
new Course{2,"C++"},
new Course{3,"HTML"},
new Course{4,"NodeJS"},
new Course{5,"Shell"},
new Course{6,"Python"},
new Course{7,"C#"}
};
while(true)
{
char input = std::cin.get();
switch(input)
{
case '0':
print_help();
break;
case '1':
print_all_course(courses);
break;
case '2':
print_course_count(courses);
break;
case '3':
print_maxlength(courses);
break;
case '4':
{
bool ret = remove_last_course(courses);
if(ret)
print_all_course(courses);
else
cout << "there is no course any more !";
break;
}
case '5':
goto exit;
break;
}
}
exit:
cout << "bye !";
return 0;
}
void print_help()
{
cout << "操作命令输入0,打印出程序帮助信息,即每个操作命令的作用" << endl;
cout << "操作命令输入1,打印出程序中存储的所有课程ID和课程名" << endl;
cout << "输入2,打印出课程数量" << endl;
cout << "输入3,打印出名字最长的课程信息,如果有多个相同长度的课程名请都打印出" << endl;
cout << "输入4,删除最后一个课程,如果没有课程需要返回错误信息" << endl;
cout << "输入5,退出程序" << endl;
}
void print_all_course(Course* courses[LEN])
{
for(int i = 0; i < LEN; i++)
{
if(courses[i] != NULL)
cout << "id : " << (*courses[i]).id << "; name : " << (*courses[i]).name << endl;
}
}
void print_course_count(Course* courses[LEN])
{
int num;
for(num = 0; num < LEN; num++)
{
if(courses[num] == NULL)
break;
}
cout << "the count of course is : " << num << endl;
}
void print_maxlength(Course* courses[LEN])
{
int maxLen = 0;
for(int i = 0; i < LEN; i++)
{
if((*courses[i]).name.length() > maxLen)
maxLen = (*courses[i]).name.length();
}
cout << "the longest name of the courses : " << endl;
for(int i = 0; i < LEN; i++)
{
if((*courses[i]).name.length() == maxLen)
cout << (*courses[i]).name << endl;
}
}
bool remove_last_course(Course* courses[LEN])
{
for(int i = LEN - 1 ; i >= 0 ; i--)
{
if(courses[i] != NULL)
{
delete(courses[i]);
courses[i] = NULL;
return true;
}
}
return false;
}
c++ chap1 to chap 3的更多相关文章
- CHAP算法C++实现
CHAP是一种挑战响应式协议. CHAP全称为:Challenge Handshake Authentication Protocol. CHAP密码 = 一个字节的标识符 + MD5(一个字节的标识 ...
- 详解eNSP下的PPP之MP、PAP/CHAP认证实验配置
一.PPP MP实验(用虚拟模板配置) 1.拓扑图
- CHAP认证原理
整个过程就是PPP协商过程,分三步:LCP.认证.NCP. 一 协议概述 PPP包含以下两个层次的协议: ·链路控制协议(LCP):负责建立.配置和测试数据链路连接 ·网络控制协议(NCP):负责建立 ...
- pap与chap协议
1.pap:直接在网络上发送密码明文 2.chap: 网络上发送的是密码的密文;server给client发一段随机数(challenge),client利用随机数对密码进行加密,将用户名和加密后的密 ...
- PPP中的PAP和CHAP的区别
PAP PAP是简单认证,明文传送,客户端直接发送包含用户名/口令的认证请求,服务器端处理并回应. CHAP CHAP是加密认证,先由服务器端给客户端发送一个随机码 challenge,客户端根据 c ...
- 神州数码广域网PPP封装CHAP认证配置
实验要求:掌握PPP封装协议下的CHAP认证 拓扑如下 R1 enable 进入特权模式 config 进入全局模式 hostname R1 修改名称 interface s0/1 进入端口 ip a ...
- Chap1:全景图[Computer Science Illuminated]
参考书目:Dale N . 计算机科学概论(原书第5版)[M]. 机械工业出版社, 2016 from library Chap1:全景图 1.1计算系统 1.2计算的历史 1.3计算工具与计算学科 ...
- CHAP认证(双向)
实验要求:掌握CHAP认证配置 拓扑如下: R1enable 进入特权模式configure terminal 进入全局模式hostname R1 设置主机名 interface s0/0/0 ...
- PPP或PPPOE身份验证PAP和CHAP
PPP或PPPOE都支持身份验证,有两种验证方式:PAP和CHAP. PAP,Passwd Authentication Protocol,密码验证协议,以客户端明文方式传递用户名和密码,服务器和本省 ...
随机推荐
- Go Data Structures: Interfaces
refer:http://research.swtch.com/interfaces Go Data Structures: Interfaces Posted on Tuesday, Decembe ...
- vim使用命令
* 向前搜索当前单词 # 向后搜索当前单词 n 和 shift n(N) 向后向前跳到所匹配的单词处 C-f page down; C-b page up C-o 回到上次位置 C-i &qu ...
- ndoutils2.2.0(ndo2db)中文乱码问题解决
ndoutils插入中文时,产生数据库乱码请用下面两个文件: 适用版本:ndoutils-2.0.0 数据库初始化mysql.sql: 修改ndoutils-2.0.0/src目录中的db.c ndo ...
- Tomcat安装及配置教程
工具/原料 Tomcat7.0 eclipse 百度经验:jingyan.baidu.com java环境的配置 1 java环境的配置应该都学过吧,这里简单的讲一下. 下载安装java JDK,注意 ...
- VS中展开和折叠代码
VS2005代码编辑器的展开和折叠代码确实很方便和实用.以下是展开代码和折叠代码所用到的快捷键,很常用: Ctrl + M + O: 折叠所有方法 Ctrl + M + M: 折叠或者展开当前方法 C ...
- 全是套路——BFS
#include <iostream> #include <vector> #include <string> #include <vector> #i ...
- 微软软件开发技术二十年回顾-COM、OLE、ActiveX及COM+篇
本文摘自:http://www.job168.com/info/read_100394.html 微软的许多技术,如OLE.ActiveX.以及DirectX等都是基于COM技术而建立起来的.微软本身 ...
- TSkinData 皮肤控件后最大最小提示英文Close的解决方法
1.D:\soft\控件\VclSkin5.40-D7-D2010 New\source 控件安装位置 2.WinSkinForm.pas 查找Close 3.function TWinSkinFor ...
- lua面试基础知识
1.lua中八种基础类型:nil(空),boolean(布尔),number(数字),string(字符串),userdata(自定义类型),function(函数),thread(线程),table ...
- NLua - 基于Lua的C#脚本引擎
Nlua NLua is the bind between Lua world and the .NET world. NLua is a fork of project LuaInterface ( ...