Practical guide: KĨTHUẬT C/C++ PROGRAMMING POLYTECHNIC University Of Hanoi Faculty Of Electrical Bộmôn automatic control Lesson 1: programming cơsở1 the purpose of administrative bàithựcHelp learn viênlàm uncomfortable with cụlập the VisualC ++ + +, thửnghiệm written chươngtrình by stylefunctional direction, through which to master the programming knowledge cơsởnhư: 1) Method phápthểhiện by algorithm of structures condition, loop 2) sửdụngmảng Way, pointer, dynamic bộnhớ 3) declare, implement and sửdụng function; the tv phươngpháp join sốhàm. 2 vụthí Mission experience 2.1 exercises 1. Build a function make the classification of sốchẵn and lẻtrong a sốnguyên sequence, the result is remember in the two sốmới. Sửdụng đểbiểu diễnhai sốkết quảsao ranges dynamic array for bộnhớ be cấpphát độngchỉvừa đủdùng. The quảtrảvềcủa sẽlà function sốcác sốchẵn in the initial sequence, or also the length of a sequence of results. 2. Write programs illustrate cáchsửdụnghàm in sentence 1 with two trườnghợp: -sốban the first sequence is contained in a static array vàgiá trịcác sốtrong sequence is initialized Once the declaring. -sốban the first sequence is contained in a dynamic array and trịcác price sốcần to be put on overkeyboard Two sốkết result is given screen. 2.2 vụchuẩn Mission was the morgue at sisters1) review of the cơsở knowledge outlined in part 1, review the vídụvà exercises in class. 2) construction of algorithms and written the program available on paper (hand-written, does not accept copies!) 2.3 vụtrên laboratory Mission 1) familiar with Visual C++, create a dựánmới (NewProject), programme name (for example "SortApp") vàchọn "Win32 Console Application" 2 trênmáy and lưuvào function) write a 2 files separately: Header file (for dụsort. h) contains code and function declarationsfile source (*.cpp) contains code execution function. Bổsung 2 files that vàodựán. Compile the source file (for examplesort.cpp), seeks to explain and fix problems compiling (compile error). 3) write the program illustrated in the main file (for example dụsortapp.cpp). Translate full bộdựán (Build), edit the error compiling (compile error) error, link (link error) if the thửchương vàchạy. 4) familiar sửdụng Debugger error đểtìm running (runtime error), search cáchgiải like and fix bugs if any. 5) Mởmenu "ProjectSetting" and find out the meaning of the sốlựa selected for the programme.6) Thửnghiệm thểhiệnvòng change the iteration (for... hoặcwhile..., sửdụng phápdịch means the cursorinstead of sửdụng chỉsố). 7) Thửnghiệm not use dynamic array, which uses mảngtĩnh đểchứa input range and the sốkết range quảtrong function. The đềgặp analysis. 8) notes that the practical steps designed by corporate reports. practice 3 report Each student must do a separate report, submitted to the laboratory for slow cánbộhướngdẫn is a tuầnsau practice session. Báocáo have thểviết hand or print, but the saophotocopy won't be accepted.Reports must have the following đủcácphần: 1. The whole bộmãchương process has run three files nhưhướng lead in section 2.32. tảtừngbước Tissue nhưhướng implementation guide in section 2.3. Trongmỗi steps, need the bậtcác statedwork done, the problems encountered, the error chủyếu met, explains errors and tảcách tissues. 3. the above mentioned đềmà (Ms.) see the truth out, need trainers explain kỹhơn. [1] #include [2] #include [3] int phanloai (int * a, int n, int * & chan, int * & le) { [4] int i = 0, sochan = 0; [5] while (i < n) { [6] if (a [i]% 2 == 0)//so chan [7] + + sochan; [8] + + i; [9] } [10] chan = new int [sochan]; [11] le = new int [n-sochan]; [12] i = 0; [13] ic = 0, int il = 0; [14] while (i < n) { [15] if (a [i]% 2)//alternate [16] le [il + +] = a [i]; [17] else [18] chan [ic ++] = a [i]; [19] + + i; [20]} [21] return sochan; [22]} [23] void print (int * a, int n) { [24] for (int i = 0; i < n; ++ i) [25] cout << ' ' << a [i]; [26]} [27] the void main () { [28]//delivers the essential [29] int n = 10; [30] as int [10] = {1, 2, 3, 4, 5, 6, 7, 8, with 9.10}; [31] int * c, * l; [32] int sochan = phanloai (as, n, c, l); [33] << cout "
Day versus Board of DAA:"; [34] print (as, n); [35] << cout "
Day so chan:"; [36] print (c, sochan); [37] << cout "
Day alternate:"; [38] print (l, n-sochan); [39] delete [] c; delete [] l; [40]//delivers dong [41] << cout "
Cho dai Jenny day so:"; [42] cin >> n; [43] int * ad = new int [n]; [44] for (int i = 0; i < n; ++ i) { [45] << cout "
ad [" << i << "] ="; [46] ad >> cin [i]; [47]} [48] sochan = phanloai (a, d, n, c, l); [49] << cout "
Day versus Board of DAA:"; [50] print (a, d, n); [51] << cout "
Day so chan:"; [52] print (c, sochan); [53] << cout "
Day alternate:"; [54] print (l, n-sochan); [55] delete [] c; delete [] l; [56] cout << "
Gaming mot film bat ky de ket thuc"; [57] cout. flush (); [58] getch (); [59]} The questions suggested, check out bổsung: 1. Line 1 and 2 mean? 2. Why the parameter has 3 ởdòng and le chan type int * &? 3. Explain the command lines 16 and 18 4. Why we don't thểviết, 30 ởdòng a [n] = {...} instead of a [10]? 5. Why we don't write delete, 39 ởdòng c; delete l? 6.57 Line mean? If you delete that line go? Practical guide: KĨTHUẬT C/C++ PROGRAMMING Article 2: object-oriented programming: classes and operator-husband1 the purpose of exercises The students know how to build a typical dữliệu structure as a class with common calculations, thửnghiệm writes the program object oriented style, over which master the concepts and methods such as: 1) packing dữliệu the cancel function, create Function), the function creates a copy of the math jaw, tửgán, operator's husband3) sốmặc, sốvà trảvề type parameter transmission4) build a thưviện class 2 vụthí Mission experience 2.1 exercises 1. Building a đểbiểu Vector class vector model performance in mathematics has the element (component) of type double with the following requirements: -There is a vector with dimensions thểkhai (sốchiều) any. If not put the size then it will be the default is 0. Found out all the elements are initialized trịbằng price 0. -A vector tựquản bộnhớ Li khảnăng copy and tựsao have made a similar assignmentnhưvới dữliệu cơbản models -Có thểxác định sốchiều vector cho một vector bất kỳ-Có thểtruy nhập từng phần tửvector thông qua toán tử[] với sốthứtựtính từ0 và toán tửgọi hàm () với sốthứtựtính từ1. -Có thểthực hiện các phép +, - cũng như+=, -= và các phép so sánh giữa hai vector và các phép *, / cũng như*=, /= giữa một vector và một sốthực (double), đảo dấu (-) và đồng dấu (+). 2. Viết chương trình minh họa cách sửdụng lớp Vector câu 1. Yêu cầu đưa sốchiều, giá trịcác phần tửqua bàn phím và kết quảthực hiện ra màn hình. Định nghĩa lại các toán tử<<, >> tương ứng đểcó thểsửdụng lại. 2.2 Nhiệm vụchuẩn bị ởnhà 1) Ôn lại các kiến thức cơsởnêu trong phần 1, xem lại các ví dụvà bài tập trên lớp. 2) Xây dựng thuật toán và viết chương trình sẵn trên giấy (viết tay, không chấp nhận bản sao!) 2.3 Nhiệm vụtrên phòng thí nghiệm 1) Tạo một dựán thưviện mới (New Project), đặt tên dựán (ví dụ“Mathlib”) và chọn “Win32 Static Library”. Chấp nhận các tham sốmặc định. 2) Tạo một Header file (ví dụvector.h) chưa phần khai báo lớp và một file nguồn (vector.cpp) chứa phần thực hiện các hàm thành viên còn lại. Bổsung 2 files đó vào dựán. 3) make the Vector layer according to the requirements stated in section 2.1, room full bộdựán (Build), find the solution like and fix the error. 4) Bổsung a new programme "Win32 Console Application" into the Workspace had đểviết chapter the illustrations. Bổsung thưviện ởtrên (mathlib.lib) is created on the whole and bộdựán programme the new, correct an error compiling (compile error) error, link (link error) If Yes and run the thửchương. 5) Thửnghiệm sốkiểu sốvà parameter type change trảvềtrong function to create a copy of the math jaw, tửgán and the mathematical function. The đềgặp analysis. Notes the steps designed by corporate reports. practice 3 report Each student must make a report, filed with the rolling bộhướng lead of experiments a week later practice session. The article must have the following sections: đủcác 1) Full bộmã program has run into the files nhưhướng lead in section 2.3 2 steps in tảtừng Tissue nhưhướng) lead in section 2.3. In each step, it should highlight the work done, the problems encountered, the error chủyếu met, explains errors and tảcách tissues. POLYTECHNIC University Of Hanoi Faculty Of Electrical Bộmôn automatic control Practical guide: KĨTHUẬT C/C++ PROGRAMMING Lesson 3: layers and multiple radiation cơchế derivatives1 the purpose of exercises Students understand the deep perfume cơchếthừa vềcác xạtrong multi class derivatives, through which the đềnhư Mastery: 1) tảquan hệtĩnh and tissue analysis between object classes through grade derivatives 2) control access to Member ởlớp for the effects cơsởvà derived class 3) distinguish between the virtual function and the function of normal members, regular classes and abstract classes 4) distinguished between excess and surplus kếgiao kếphần made and their effects 5) the meaning of the sửdụng the trỏtrong object oriented programming 2 vụthí Mission experience 2.1 exercises 1. Build a thưviện class (at least 4 object class) đểbiểu sửdụng function blocks took place in interviews and th
đang được dịch, vui lòng đợi..
