Tải bản đầy đủ (.pdf) (8 trang)

TEMPLATE C++ LAP TRINH

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (876.76 KB, 8 trang )

<span class="text_page_counter">Trang 1</span><div class="page_container" data-page="1">

OBJECT ORIENTED PROGRAMMING USING C++

<small>TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT TP.HCMHCMC UNIVERSITY OF TECHNOLOGY AND EDUCATION</small>

<small>GV. Trần Thị Quỳnh Như</small>

<small>Email: </small>

</div><span class="text_page_counter">Trang 3</span><div class="page_container" data-page="3">

Function Templates

<b>template<class type>ret-type func-name(parameter list) {</b>

//body of the function

cout << Max<int>(5, 8) << endl;

cout << Max<double>(6.5, 4.0) << endl; cout << Max<char>('f', 'k') << endl; }

</div><span class="text_page_counter">Trang 4</span><div class="page_container" data-page="4">

cout << "STUDENT NAME: " << student_name << endl; cout << "TOTAL MARKS: " << total_marks << endl;

cout << "Type ID: " << typeid(total_marks).name()<< endl;}};

template <class type> class class-name { ………….

}

</div><span class="text_page_counter">Trang 5</span><div class="page_container" data-page="5">

Class Templates

int main() {

student<int> s1("Le A", 100);

student<double> s2("Tran B", 90.5);

student<int> s1("Le A", 100);

student<int> s2("Tran B", 90); s1.getinfo();

system("pause"); }

</div><span class="text_page_counter">Trang 6</span><div class="page_container" data-page="6">

I/O STREAM

<small>Stream-I/O template hierarchy portion showing the main file-processing templates.</small>

</div><span class="text_page_counter">Trang 8</span><div class="page_container" data-page="8">

<small>• Bài 1: Viết chương trình sắp sếp các số từ nhỏ đến lớn sử dụng Function Template• Bài 2: Viết CT máy tính đơn giản (+-*/ bình phương, căn bậc 2, ) sử dụng Class </small>

<small>• Bài 3: Viết CT đổi đơn vị chiều dài, thể tích, diện tích, khối lượng, tốc độ• Bài 4: Tìm hiểu Stream IO và file IO</small>

<small>• Bài 5: Viết chương trình mở một file có tên là iostream.txt, kiểm tra mở file thành công hay không, nếu thành công, ghi nội dung vào file và sau đó chuyển đổi thành dạng chữ hoa.</small>

</div>

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×