Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Programming principles and practice using C++: Chapter 7 - Bjarne Stroustrup

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

This chapter spends a lot of time of the structure and looks of code; that is, factors that affect comprehension and maintainability. It is a good idea to remind the students that often they are the maintainers (maybe of their own code, a few months after they first wrote it). A useful program is never finished: it will be ported, corrected, extended, etc. | Chapter 7 Completing a Program Bjarne Stroustrup www.stroustrup.com/Programming Abstract Tokens and token streams Structs and classes Cleaning up the code Prompts Program organization constants Recovering from errors Commenting Code review Testing A word on complexity and difficulty Variables Stroustrup/Programming/2015 Completing the calculator Now wee need to Complete the implementation Token and Token_stream Get the calculator to work better Add features based on experience Clean up the code After many changes code often become a bit of a mess We want to produce maintainable code Stroustrup/Programming/2015 Token We want a type that can hold a “kind” and a value: struct Token { // define a type called Token char kind; // what kind of token double value; // used for numbers (only): a value }; // semicolon is required Token t; t.kind = '8'; // . (dot) is used to access members // (use ‘8’ to mean “number”) t.value = 2.3; Token u = t; // a Token behaves much like a . | Chapter 7 Completing a Program Bjarne Stroustrup www.stroustrup.com/Programming Abstract Tokens and token streams Structs and classes Cleaning up the code Prompts Program organization constants Recovering from errors Commenting Code review Testing A word on complexity and difficulty Variables Stroustrup/Programming/2015 Completing the calculator Now wee need to Complete the implementation Token and Token_stream Get the calculator to work better Add features based on experience Clean up the code After many changes code often become a bit of a mess We want to produce maintainable code Stroustrup/Programming/2015 Token We want a type that can hold a “kind” and a value: struct Token { // define a type called Token char kind; // what kind of token double value; // used for numbers (only): a value }; // semicolon is required Token t; t.kind = '8'; // . (dot) is used to access members // (use ‘8’ to mean “number”) t.value = 2.3; Token u = t; // a Token behaves much like a built-in type, such as int // so u becomes a copy of t cout '8' 2.3 '+' Stroustrup/Programming/2015 Token struct Token { // user-defined type called Token char kind; // what kind of token double value; // used for numbers (only): a value }; Token{‘+’}; // make a Token of “kind” ‘+’ Token{'8',4.5}; // make a Token of “kind” ‘8’ and value 4.5 A struct is the simplest form of a class “class” is C++’s term for “user-defined type” Defining types is the crucial mechanism for organizing programs in C++ as in most other modern languages a class (including structs) can have data members (to hold information), and function members (providing operations on the data) Stroustrup/Programming/2015 Token_stream A Token_stream reads characters, producing Tokens on demand We can put a Token into a Token_stream for later use A Token_stream uses a “buffer” to hold tokens we put back into it 1+2*3; empty Token_stream buffer: Input stream: For 1+2*3;, .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.