[重修] 計算機程式-1 Introduction to Computers, the Internet and the WWW

看到鄉民問 [問卦] C++練到超強,學任何其他語言都超快嗎?

https://www.ptt.cc/bbs/C_and_CPP/M.1418429685.A.9B5.html

整理了幾門好課 心想那就順便修了他們吧 ~ 當年學得有夠爛 現在總覺得講專業的時候 很多部分不夠精通 心裡很虛. 刷算法的時候感覺概念模糊不清. 套句前高手同事的話 "高手就是摳細節" 這次還是好好學習 把不清楚的地方一次理清楚 2017 好好補洞.

1.先聽台大開放式課程當中,台大電機系廖婉君教授的計算機程式 http://ocw.aca.ntu.edu.tw/ntu-ocw/index.php/ocw/cou/101S112 2.再聽電機系于天立教授的計算機概論 http://ocw.aca.ntu.edu.tw/ntu-ocw/index.php/ocw/cou/101S210 3.聽交大開放式課程當中,交大資工系彭文志教授的資料結構 http://ocw.nctu.edu.tw/course_detail_3.php?bgid=9&gid=0&nid=412#.VIuDgSuUena

首先第一堂課 來聽廖教授的計算機程式,

講的深入淺出 重新複習概念上 什麼是電腦 組成部分是什麼. Coding 主要用C++

沒有推薦用什麼 IDE 開始.


以下概念(technical hole) 補上,

1) Memory, Disk 和 Network 講的 kB(or kBps) 大小是不一樣的,

這裡的KB, B 都是Byte. 差別在於 Memory用的K 大小是 2^10 = 1024
網路用的K 是 10 ^ 3 = 1000

這裡有更多細節 http://www.speedguide.net/articles/bits-bytes-and-bandwidth-reference-guide-115


2) 再來Data Type宣告和 Size

值得注意的是在 Visual Studio 2015 裡, double 和 long double 都是佔8個 bytes

https://msdn.microsoft.com/en-us/library/s3f49ktz.aspx

Stackoverflow裡頭的高手給出了令人滿意的解答,

http://stackoverflow.com/questions/14221612/difference-between-long-double-and-double-in-c-and-c

To quote the C++ standard, §3.9.1 ¶8:
There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double. The value representation of floating-point types is implementation-defined. Integral and floating types are collectively called arithmetic types. Specializations of the standard template std::numeric_limits (18.3) shall specify the maximum and minimum values of each arithmetic type for an implementation.
That is to say that double takes at least as much memory for its representation as float and long double at least as much as double. That extra memory is used for more precise representation of a number.
On x86 systems, float is typically 4 bytes long and can store numbers as large as about 3×10³⁸ and about as small as 1.4×10⁻⁴⁵. It is an IEEE 754 single-precision number that stores about 7 decimal digits of a fractional number.
Also on x86 systems, double is 8 bytes long and can store numbers in the IEEE 754 double-precision format, which has a much larger range and stores numbers with more precision, about 15 decimal digits. On some other platforms, double may not be 8 bytes long and may indeed be the same as a single-precision float.
The standard only requires that long double is at least as precise as double, so some compilers will simply treat long double as if it is the same as double. But, on most x86 chips, the 10-byte extended precision format 80-bit number is available through the CPU's floating-point unit, which provides even more precision than 64-bit double, with about 21 decimal digits of precision.
Some compilers instead support a 16-byte (128-bit) IEEE 754 quadruple precision number format with yet more precise representations and a larger range.

3) I/O: destructive vs. non-destructive

destructive 這字翻譯是 "破壞性". 所以課本49-50頁 是說line_14 有存值到memory 會覆蓋 所以叫destructive 

When a value is placed in a memory location, the value overwrites the previous value in that location; thus, placing a new value into a memory location is said to be destructive.



line_19 對於number1來說 只有被讀取(read) 所以是 non-destructive

Once the program has obtained values for number1 and number2, it adds these values and places the sum into variable sum. The statement that performs the addition also replaces whatever value was stored in sum. This occurs when the calculated sum of number1 and number2 is placed into location sum (without regard to what value may already be in sum; that value is lost). After sum is calculated, memory appears as in Fig. 2.8. The values of number1 and number2 appear exactly as they did before they were used in the calculation of sum. These values were used, but not destroyed, as the computer performed the calculation. Thus, when a value is read out of a memory location, the process is nondestructive.

4) C++裡開頭為什麼要用 using namespace std;

這算省時間的做法, 不用using namespace std; 那每次cin, cout 之前都要乖乖的加 std::cout 相對來說麻煩. 

https://msdn.microsoft.com/en-us/library/5cb46ksf.aspx

A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries. All identifiers at namespace scope are visible to one another without qualification. Identifiers outside the namespace can access the members by using the fully qualified name for each identifier, for example std::vector<std::string> vec;, or else by a using Declaration for a single identifier (using std::string), or a using Directive for all the identifiers in the namespace (using namespace std;). Code in header files should always use the fully qualified namespace name.


留言