最近看了C++宝典,看时间是2005的,对于里面的程序自己也进行了编写,由于时间过久,可能有些函数的用法发生了改变,自己也对其进行了修改,用VS2017可以编译通过。

前四章学习内容

CPlusPlusStudy.h

#pragma once
/*********************Function prototype************************/ ///////////////////////// Caption 1 & 2 //////////////////////////
//variable
void Variable_study();
void Bool_study();
void Char_study();
void Wchar_t_study();
void Int_study();
void Float_study();
void Variable_initial(); //constant
void Constant_study(); //operator
void Operator_study(); void Assign_study();
void assign_common_study();
void assign_expression_study();
void MoreVariable_assign();
void Complex_assign(); void DecrementAndIncreament_study(); void Conditional_study(); void Comma_study(); //standard input and output
void Cin_Cout_study();
void Common_cin_cout_study();
void Format_cin_cout_study(); ///////////////////////// Caption 3 & 4 //////////////////////////
//function overload
void Overload_function();
void Overload_copy();
void string_copy(char *dest, const char *src);
void string_copy(char *dest, const char *src, int len);
void Overload_format();
void display_time(const struct std::tm tim);
void display_time(time_t *tim); //goto jumper
void Goto_study();

CPlusPlusStudy.cpp

/*********************************************************/
/******************** Author: zihan **********************/
/******************** Date: 2019/7/11 ********************/
/******************** Version: 0.0.0.1 *******************/
/******************** Destination: For C++ study *********/
/******************** FileName: CPlusPlusStudy.cpp *******/
/*********************************************************/ #include "pch.h"
#include <iostream>
#include "CPlusPlusStudy.h" #include <time.h> #include <Windows.h>
/////////////////////////////////////////////////////////////////
// The main() function //
/////////////////////////////////////////////////////////////////
int main()
{
std::cout << "\nThis is main() function\n"; //Caption 1 & 2
//Variable_study();
//Constant_study();
//Operator_study();
//Cin_Cout_study(); //Caption 3 & 4
//Overload_function();
Goto_study(); std::cout << "\n===================main() end===================\n";
return 0;
} /////////////////////////////////////////////////////////////////
// Caption 1 & 2 //
///////////////////////////////////////////////////////////////// /******************************* variable **************************************/
//variable
void Variable_study() {
std::cout << "\nThis is Variable_study() function\n"; //Bool_study();
//Char_study();
//Wchar_t_study();
//Int_study();
//Float_study();
Variable_initial(); std::cout << "\n===================Variable_study() end===================\n";
} //bool variable
void Bool_study() {
std::cout << "\nThis is Bool_study() function\n"; bool senior; //bool variable
senior = true; //set to true //Test the senior variable
if (senior)
std::cout << "variable senior's value is true\n";
else {
std::cout << "\aError";//"\a" make computer product voice.
system("pause");
} std::cout << "\n===================Bool_study() end===================\n";
} //char variable
void Char_study() {
std::cout << "\nThis is Char_study() function\n"; char c; //char variable
c = 'b'; //assign 'b'
std::cout << c; //display 'b'
c = 'y'; //assign 'y'
std::cout << c; //dispaly 'y'
c = 'e'; //assign 'e'
std::cout << c; //display 'e' std::cout << "\n===================Char_study() end===================\n";
} //wchar_t variable
void Wchar_t_study() {
std::cout << "\nThis is Wchar_t_study() function\n"; wchar_t wc; //wide char variable
wc = 'b'; //assign 'b' to wc
std::wcout << wc; //display 'b'
wc = 'y'; //assgin 'y' to wc
std::wcout << wc; //display 'y'
wc = 'e'; //assign 'e' to wc std::cout << "\n===================Wchar_t_study() end===================\n";
} //int variable
void Int_study() {
std::cout << "\nThis is Int_study() function\n"; int Amount; //an int variable
Amount = 123; //assign a value
std::cout << Amount; //display the int std::cout << "\n===================Int_study() end===================\n";
} //float variable
void Float_study() {
std::cout << "\nThis is Float_study() function\n"; float realValue; //a float variable
realValue = 1.2; //assign a value //warning C4305: '=': truncation from 'double' to 'float'
std::cout << realValue; //display the float std::cout << "\n===================Float_study() end===================\n";
} //initial variable
void Variable_initial() {
std::cout << "\nThis is Variable_initial() function\n"; ////initialize variable support C++ & C
//int Amount = 3; //initialize an int
//char ch = 'A'; //initialize a char
//float Value = 1.23; //initialize a float ////Display the initialized variables
//std::cout << Amount;
//std::cout << ' ';
//std::cout << ch;
//std::cout << ' ';
//std::cout << Value; //initialize variable only support C++
int Amount(3); //initialize an int
char ch('A'); //initialize a char
float Value(1.23); //initialize a float //Display the initialized variables
std::cout << Amount;
std::cout << ' ';
std::cout << ch;
std::cout << ' ';
std::cout << Value; std::cout << "\n===================Variable_initial() end===================\n";
} /********************************* constant **************************************/
//constant
void Constant_study() {
std::cout << "\nThis is Constant_study() function\n"; std::cout <<
"This is the beginning of a very long message \n"
"that spans severral lines of code. \n"
"This format allows a program to build long \n"
"string constants without going past the \n"
"program editor's right margin. \n"; std::cout << "\n===================Constant_study() end===================\n";
} /************************************** operator *********************************/
//operator
void Operator_study() {
std::cout << "\nThis is Operator_study() function\n"; //Assign_study();
//DecrementAndIncreament_study();
//Conditional_study();
Comma_study(); std::cout << "\n===================Operator_study() end===================\n";
} /////////////////assignment statement operator
void Assign_study() {
std::cout << "\nThis is Assign_study() function\n"; //assign_common_study();
//assign_expression_study();
//MoreVariable_assign();
Complex_assign(); std::cout << "\n===================Assign_study() end===================\n";
} //common_assign
void assign_common_study() {
std::cout << "\nThis is assign_common_study() function\n"; //Declare three integers
int HourlyRate;
int HoursWorked;
int GrossPay; //Assign values to the integers
HourlyRate = 15;
HoursWorked = 40;
GrossPay = HourlyRate * HoursWorked; //Display the variables on the screen.
std::cout << HourlyRate;
std::cout << ' ';
std::cout << HoursWorked;
std::cout << ' ';
std::cout << GrossPay; std::cout << "\n===================assign_common_study() end===================\n";
} //expression_assign
void assign_expression_study() {
std::cout << "\nThis is assign_expression_study() function\n"; int Celsius, Fahrenheit; //Prompt for Fahrenheit temperature
std::cout << "\nEnter temperature as degrees Fahrenheit: "; //Read Fahrenheit tempersture from keyboard
std::cin >> Fahrenheit; //Compute Celsius
Celsius = 5 * (Fahrenheit - 32) / 9; //Display the result
std::cout << "Temperature is ";
std::cout << Celsius;
std::cout << " degrees Celsius"; std::cout << "\n===================assign_expression_study() end===================\n";
} //continuity_assgin
void MoreVariable_assign() {
std::cout << "\nThis is MoreVariable_assign() function\n"; unsigned int This, That, Those; //Assign the same value to three variables
This = That = Those = 66000; //Dispaly three ubsigned ints
std::cout << This;
std::cout << ' ';
std::cout << That;
std::cout << ' ';
std::cout << Those; std::cout << "\n===================MoreVariable_assign() end===================\n";
} //complex_assign
void Complex_assign() {
std::cout << "\nThis is Complex_assign() function\n"; long Total, SubTotal, Detail; //Initial values
Total = 10000;
SubTotal = 90;
Detail = 5;
SubTotal *= Detail; //compute SubTotal
Total += SubTotal; //compute Total //Dispaly all three
std::cout << Total;
std::cout << ' ';
std::cout << SubTotal;
std::cout << ' ';
std::cout << Detail; std::cout << "\n===================Complex_assign() end===================\n";
} //////////////////decrement and increment
void DecrementAndIncreament_study() {
std::cout << "\nThis is DecrementAndIncreament_study() function\n"; int Ctr, OldCtr, NewCtr; //Make the assignments
OldCtr = 123; //OldCtr is 123
NewCtr = ++OldCtr; //NewCtr is 124, OldCtr is 124
Ctr = NewCtr--; //Ctr is 124, NewCtr is 123 //Display the results
std::cout << OldCtr;
std::cout << ' ';
std::cout << NewCtr;
std::cout << ' ';
std::cout << Ctr; std::cout << "\n===================DecrementAndIncreament_study() end===================\n";
} //////////////////conditional operator
void Conditional_study() {
std::cout << "\nThis is Conditional_study() function\n"; float Dues; //dues amount //Read the dues
std::cout << "Enter dues amount: ";
std::cin >> Dues; //Are the dues paid on time?
std::cout << "On time?(y/n)";
char yn;
std::cin >> yn;
bool Overdue; //true if overdue, false if on time
Overdue = yn != 'y';
float AmountDue; //amount to be computed //Use conditional operator to compute
AmountDue = Overdue ? Dues * 1.10 : Dues; //Display the dues amount
std::cout << "Amount due: ";
std::cout << AmountDue; std::cout << "\n===================Conditional_study() end===================\n";
} //////////////////comma operator
void Comma_study() {
std::cout << "\nThis is Comma_study() function\n"; int Val, Amt, Tot, Cnt;
Amt = 30;
Tot = 12;
Cnt = 46; //Compute Val = rightmost expression
//Val = (Amt++, --Tot, Cnt + 3); //Compute Val = leftmost expression
Val = Amt++, --Tot, Cnt + 3; //Display the result
std::cout << Val; std::cout << "\n===================Comma_study() end===================\n";
} /************************************** standard input & output *********************************/
//cin and cout
void Cin_Cout_study() {
std::cout << "\nThis is Cin_Cout_study() function\n"; //Common_cin_cout_study();
Format_cin_cout_study(); std::cout << "\n===================Cin_Cout_study() end===================\n";
} //common usage
void Common_cin_cout_study() {
std::cout << "\nThis is common_cin_cout_study() function\n"; int Amount = 3; //initialize an int
char ch = 'A'; //initialize a char
float Value = 1.23; //initialize a float //Display the initialized variables
std::cout << Amount << ' ' << ch << ' ' << Value << std::endl; std::cout << "\n===================common_cin_cout_study() end===================\n";
} //format cin and cout
void Format_cin_cout_study() {
std::cout << "\nThis is Format_cin_cout_study() function\n"; int amount = 123; std::cout << std::dec << amount << ' '
<< std::oct << amount << ' '
<< std::hex << amount; std::cout << "\n===================Format_cin_cout_study() end===================\n";
} /************************************** Function overload *********************************/
//function overload
void Overload_function() {
std::cout << "\nThis is Overload_function() function\n"; //Overload_copy();
Overload_format(); std::cout << "\n===================Overload_function() end===================\n";
} //copy overload
void Overload_copy() {
std::cout << "\nThis is Overload_copy() function\n"; char misspiggy[20], kerrnit[20];
string_copy(misspiggy, "Miss Piggy");
string_copy(kerrnit,"Kerrnit, the file transfer protocol", 30); std::cout << kerrnit << " and " << misspiggy;
//std::cout << kerrnit; std::cout << "\n===================Overload_copy() end===================\n";
} //The first version of string_copy
void string_copy(char *dest, const char *src) {
std::cout << "\nThis is string_copy2 function\n"; while ((*dest++ = *src++) != '\0')
; std::cout << "\n===================string_copy2 end===================\n";
} //The sencond version of string_copy
void string_copy(char *dest, const char *src, int len) {
std::cout << "\nThis is string_copy3 function\n"; //char buffer[100];
//int bufsize = sizeof(buffer) / sizeof(buffer[0]);
//std::cout << bufsize; while (len-- >= 20)
;
len++;
while (len && (*dest++ = *src++) != '\0')
--len;
if (len == 0)
*dest++ = '\0'; std::cout << "\n===================string_copy3 end===================\n";
} //format overload
void Overload_format() {
std::cout << "\nThis is Overload_format() function\n"; time_t tim;
time(&tim);
struct tm t;
localtime_s(&t, &tim);
display_time(t);
display_time(&tim); std::cout << "\n===================Overload_format() end===================\n";
} //The first version of display_time()
void display_time(const struct tm tim){
std::cout << "\nThis is display_time1 function\n"; char stTmp[32];
asctime_s(stTmp, &tim);
std::cout << "1. It is now " << stTmp; std::cout << "\n===================display_time1 end===================\n";
} //The second version of display_time()
void display_time(time_t *tim) {
std::cout << "\nThis is display_time2 function\n"; char stTmp[32];
ctime_s(stTmp, 32, tim);
std::cout << "2. It is now " << stTmp; std::cout << "\n===================display_time2 end===================\n";
} /************************************** goto jumper *********************************/
//goto test
void Goto_study() {
std::cout << "\nThis is Goto_study() function\n"; for (int dept = 1; dept < 10; dept++) {
std::cout << "Department " << dept << std::endl;
int empl; do {
std::cout << "Enter Empl # "
"(0 to quit, 99 for next dept)";
std::cin >> empl; if (empl == 0)
goto done;
if (empl != 99) {
std::cout << "Dept: " << dept << ", "
<< "Empl: " << empl << std::endl;
}
} while (empl != 99); done:
std::cout << "Entry complete" << std::endl;
} std::cout << "\n===================Goto_study() end===================\n";
} /******************************* key words **************************************/
//C++ key words
//asm do inline short typeid
//auto double int signed typename
//bool dynamic_cast long sizeof union
//break else mutable static unsigned
//case enum namespace static_cast using
//catch explicit new struct virtual
//char extern operator weitch void
//class false private template volatile
//const float protected this wchar_t
//const_cast for public throw while
//continue friend register true
//default goto reinterpret_cast try
//delete if return typedef //C++ international key words
//and bitor or xor_e
//and_eq compl or_eq not_eq
//bitand not xor

希望可以看得清楚明白。有好的学习方法也会学习。

第十篇 -- 学习C++宝典2005版的更多相关文章

  1. Python 学习 第十篇 CMDB用户权限管理

    Python 学习 第十篇 CMDB用户权限管理 2016-10-10 16:29:17 标签: python 版权声明:原创作品,谢绝转载!否则将追究法律责任. 不管是什么系统,用户权限都是至关重要 ...

  2. Egret入门学习日记 --- 第二十篇(书中 9.1~9.3 节 内容 组件篇)

    第二十篇(书中 9.1~9.3 节 内容 组件篇) 第八章中的内容. 以上都是基本的Js知识,我就不录入了. 直接来看 第9章. 开始 9.1节. 以上内容告诉你,Egret官方舍弃了GUI,使用了E ...

  3. Egret入门学习日记 --- 第十篇(书中 2.9~2.13节 内容)

    第十篇(书中 2.9~2.13节 内容) 好的 2.9节 开始! 总结一下重点: 1.之前通过 ImageLoader 类加载图片的方式,改成了 RES.getResByUrl 的方式. 跟着做: 重 ...

  4. 第十篇 SQL Server安全行级安全

    本篇文章是SQL Server安全系列的第十篇,详细内容请参考原文. 不像一些其他industrial-strength数据库服务,SQL Server缺乏一个内置保护个别数据记录的机制,称为行级安全 ...

  5. 《Java程序设计》第十周学习总结

    20145224 <Java程序设计>第十周学习总结 网络编程 ·网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接收到指定的 ...

  6. 20155324 2016-2017-2 《Java程序设计》第十周学习总结

    20155324 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 Java的网络编程 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据. ...

  7. 【译】第十篇 SQL Server安全行级安全

    本篇文章是SQL Server安全系列的第十篇,详细内容请参考原文. 不像一些其他industrial-strength数据库服务,SQL Server缺乏一个内置保护个别数据记录的机制,称为行级安全 ...

  8. 20172306《Java程序设计与数据结构》第十周学习总结

    20172306<Java程序设计>第十周学习总结 教材学习内容总结 本章主要的讲的是集合有关的知识: 1.集合与数据结构 - 集合是一种对象,集合表示一个专用于保存元素的对象,并该对象还 ...

  9. 20155326 2016-2017-2 《Java程序设计》第十周学习总结

    20155326 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 计算机网络基础 1.计算机网络概述 网络编程的实质就是两个(或多个)设备(例如计算机)之间的 ...

随机推荐

  1. 11张流程图帮你搞定 Spring Bean 生命周期

    在网上已经有跟多Bean的生命周期的博客,但是很多都是基于比较老的版本了,最近吧整个流程化成了一个流程图.待会儿使用流程图,说明以及代码的形式来说明整个声明周期的流程.注意因为代码比较多,这里的流程图 ...

  2. 【模拟7.27】单(liu_runda学长的神题)

    好像用到一些高中数学知识...... 满分做法: case 0:已知a数组求b数组 因为是树状结构,设当前节点x 儿子to 我们从任意一点出发可求出b[root]来,之后我们可以通过寻找两两相连节点的 ...

  3. ORACLE中的PL/SQL

    一. 1.过程,函数,触发器是pl/sql编写.                2. 过程函数触发器是在Oracle中.                      3.pl/sql是非常强大的数据库过 ...

  4. el-upload上传列表实现 展开 收起

    # el-upload上传列表实现 展开 收起 #### 无图言*,所以先上最终效果图(想参考代码的可以直接滑到最后) ### 具体实现思路 注意: 每个人的项目环境以及需求,都不尽相同,所以这里仅仅 ...

  5. 从零开始学前端,React框架背后的核心机制和原理JSX

    什么是React React是起源于Facebook的一个前端框架,用于构建用户界面的JavaScript库,Facebook用来探索一种更加高效优雅的Javascript MVC框架来架设Insta ...

  6. 41、解决du与df统计不一致的解决方法

    41.1.案例说明: 通过df -hT和du -sh /.du -h --max-depth=1 /命令 发现磁盘的使用不量不一致,使用'df -hT'命令查看磁盘的使用量要 比使用'du -sh / ...

  7. 10、修改windows编码集

    10.1.查看Windows的字符集编码: 1.方法一: (1) 同时按住"windows"徽标键和"r"键,在弹出的"运行"框中输入&qu ...

  8. 【luogu P3807】【模板】卢卡斯定理/Lucas 定理(含 Lucas 定理证明)

    [模板]卢卡斯定理/Lucas 定理 题目链接:luogu P3807 题目大意 求 C(n,n+m)%p 的值. p 保证是质数. 思路 Lucas 定理内容 对于非负整数 \(n\),\(m\), ...

  9. HDU 4438 Hunters 区域赛水题

    本文转载于 http://blog.csdn.net/major_zhang/article/details/52197538 2012天津区域赛最水之题: 题意容易读懂,然后就是分情况求出A得分的数 ...

  10. Java hashCode&&equals

    /** 为保证向Set中添加的对象其所在的类必须要重写hashCode和equals方法: 重写的原则:hashCode和equals尽量保持一致性: 两个相同的对象equals()返回true时,那 ...