<!DOCTYPE html>
    <html lang="vi" xmlns="https://www.w3.org/1999/xhtml" prefix="og: https://ogp.me/ns#">
    <head>
<title>Bài 2. Xây dựng lớp HOCSINH &#40;Nhập từ bàn phím, xuất ra màn hình, ghi, đọc tệp&#41;</title>
<meta name="description" content="Bài 2. Xây dựng lớp HOCSINH &#40;Nhập từ bàn phím, xuất ra màn hình, ghi, đọc tệp&#41; - Savefile - Tin Tức -...">
<meta name="author" content="DATAONLINE.IO.VN">
<meta name="copyright" content="DATAONLINE.IO.VN [support@dataonline.io.vn]">
<meta name="generator" content="NukeViet v4.5">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Bài 2. Xây dựng lớp HOCSINH &#40;Nhập từ bàn phím, xuất ra màn hình, ghi, đọc tệp&#41;">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;365.io.vn&#x002F;savefile&#x002F;lap-trinh-huong-doi-tuong-oop&#x002F;bai-2-xay-dung-lop-hocsinh-nhap-tu-ban-phim-xuat-ra-man-hinh-ghi-doc-tep-39.html">
<meta property="og:site_name" content="DATAONLINE.IO.VN">
<meta property="og:url" content="https://365.io.vn/savefile/lap-trinh-huong-doi-tuong-oop/bai-2-xay-dung-lop-hocsinh-nhap-tu-ban-phim-xuat-ra-man-hinh-ghi-doc-tep-39.html">
<link rel="shortcut icon" href="https://365.io.vn/favicon.ico">
<link rel="canonical" href="https://365.io.vn/savefile/lap-trinh-huong-doi-tuong-oop/bai-2-xay-dung-lop-hocsinh-nhap-tu-ban-phim-xuat-ra-man-hinh-ghi-doc-tep-39.html">
<link rel="alternate" href="https://365.io.vn/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tong-hop/" title="Tin Tức - Tổng hợp" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/gdpt/" title="Tin Tức - GDPT" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/cac-van-ban/" title="Tin Tức - Các văn bản" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tieu-hoc/" title="Tin Tức - Tiểu học" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lop-3/" title="Tin Tức - Lớp 3" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lop-4/" title="Tin Tức - Lớp 4" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lop-5/" title="Tin Tức - Lớp 5" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/sgk-tieu-hoc/" title="Tin Tức - SGK Tiểu học" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tin-hoc-3/" title="Tin Tức - Tin học 3" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tin-hoc-4/" title="Tin Tức - Tin học 4" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tin-hoc-5/" title="Tin Tức - Tin học 5" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/thcs/" title="Tin Tức - THCS" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lop-6-75/" title="Tin Tức - Lớp 6" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lop-7-75/" title="Tin Tức - Lớp 7" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lop-8-75/" title="Tin Tức - Lớp 8" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lop-9-75/" title="Tin Tức - Lớp 9" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/sgk-thcs/" title="Tin Tức - SGK THCS" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tin-hoc-6/" title="Tin Tức - Tin học 6" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tin-hoc-7/" title="Tin Tức - Tin học 7" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tin-hoc-8/" title="Tin Tức - Tin học 8" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tin-hoc-9/" title="Tin Tức - Tin học 9" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/thpt/" title="Tin Tức - THPT" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lop-10/" title="Tin Tức - Lớp 10" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lop-11/" title="Tin Tức - Lớp 11" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lop-12/" title="Tin Tức - Lớp 12" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/sgk-thpt/" title="Tin Tức - SGK THPT" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tin-hoc-10/" title="Tin Tức - Tin học 10" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tin-hoc-11/" title="Tin Tức - Tin học 11" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tin-hoc-12/" title="Tin Tức - Tin học 12" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/cntt/" title="Tin Tức - CNTT" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/phan-mem-quan-li-va-dieu-hanh/" title="Tin Tức - Phần mềm quản lí và điều hành" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/phan-mem-ung-dung/" title="Tin Tức - Phần mềm ứng dụng" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/ung-dung-ai/" title="Tin Tức - Ứng dụng AI" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/mang-may-tinh/" title="Tin Tức - Mạng máy tính" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lap-trinh/" title="Tin Tức - Lập trình" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/cau-truc-thi-hsg-va-ts-vao-10/" title="Tin Tức - Cấu trúc thi HSG và TS vào 10" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/tai-lieu-hoc-lap-trinh/" title="Tin Tức - Tài liệu học lập trình" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/phan-mem-lap-trinh/" title="Tin Tức - Phần mềm lập trình" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lap-trinh-truc-quan/" title="Tin Tức - Lập trình trực quan" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lap-trinh-huong-thu-tuc-pop/" title="Tin Tức - Lập trình hướng thủ tục &#40;POP&#41;" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/de-thi/" title="Tin Tức - Đề thi" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/de-hsg-tin-hoc-thcs/" title="Tin Tức - Đề HSG Tin học THCS" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/de-tin-hoc-ts-vao-10-thpt-chuyen/" title="Tin Tức - Đề Tin học TS vào 10 THPT chuyên" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/de-tin-hoc-hsg-thpt/" title="Tin Tức - Đề Tin học HSG THPT" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/cham-thi/" title="Tin Tức - Chấm thi" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/themis/" title="Tin Tức - Themis" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/vnoi/" title="Tin Tức - VNOI" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/danh-sach-hoc-sinh/" title="Tin Tức - Danh sách học sinh" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/lap-trinh-huong-doi-tuong-oop/" title="Tin Tức - Lập trình hướng đối tượng &#40;OOP&#41;" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/web-nguon-mo/" title="Tin Tức - Web nguồn mở" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/he-dieu-hanh/" title="Tin Tức - Hệ điều hành" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/microsoft-windows/" title="Tin Tức - Microsoft Windows" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/ho-linux/" title="Tin Tức - Họ Linux" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/may-chu/" title="Tin Tức - Máy chủ" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/co-so-du-lieu/" title="Tin Tức - Cơ sở dữ liệu" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/web-server/" title="Tin Tức - Web Server" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/hosting-domain-vps/" title="Tin Tức - Hosting-domain-VPS" type="application/rss+xml">
<link rel="alternate" href="https://365.io.vn/rss/ban-tin/" title="Tin Tức - Bản tin" type="application/rss+xml">
<link rel="preload" as="style" href="https://365.io.vn/assets/css/font-awesome.min.css" type="text/css">
<link rel="preload" as="style" href="https://365.io.vn/themes/default/css/bootstrap.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://365.io.vn/themes/default/css/style.css" type="text/css">
<link rel="preload" as="style" href="https://365.io.vn/themes/default/css/style.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://365.io.vn/themes/default/css/news.css" type="text/css">
<link rel="preload" as="style" href="https://365.io.vn/themes/default/css/custom.css" type="text/css">
<link rel="preload" as="script" href="https://365.io.vn/assets/js/jquery/jquery.min.js" type="text/javascript">
<link rel="preload" as="script" href="https://365.io.vn/assets/js/language/vi.js" type="text/javascript">
<link rel="preload" as="script" href="https://365.io.vn/assets/js/DOMPurify/purify3.js" type="text/javascript">
<link rel="preload" as="script" href="https://365.io.vn/assets/js/global.js" type="text/javascript">
<link rel="preload" as="script" href="https://365.io.vn/assets/js/site.js" type="text/javascript">
<link rel="preload" as="script" href="https://365.io.vn/themes/default/js/news.js" type="text/javascript">
<link rel="preload" as="script" href="https://365.io.vn/themes/default/js/main.js" type="text/javascript">
<link rel="preload" as="script" href="https://365.io.vn/themes/default/js/custom.js" type="text/javascript">
<link rel="preload" as="script" href="https://365.io.vn/themes/default/js/bootstrap.min.js" type="text/javascript">
<link rel="stylesheet" href="https://365.io.vn/assets/css/font-awesome.min.css">
<link rel="stylesheet" href="https://365.io.vn/themes/default/css/bootstrap.non-responsive.css">
<link rel="stylesheet" href="https://365.io.vn/themes/default/css/style.css">
<link rel="stylesheet" href="https://365.io.vn/themes/default/css/style.non-responsive.css">
<link rel="StyleSheet" href="https://365.io.vn/themes/default/css/news.css">
<link rel="stylesheet" href="https://365.io.vn/themes/default/css/custom.css">
<style type="text/css">
	body{background: #fff;}
</style>
    </head>
    <body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">DATAONLINE.IO.VN</h2>
		<p class="pull-right"><a title="DATAONLINE.IO.VN" href="https://365.io.vn/">https://365.io.vn</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Bài 2. Xây dựng lớp HOCSINH &#40;Nhập từ bàn phím, xuất ra màn hình, ghi, đọc tệp&#41;</h1>
		<ul class="list-inline">
			<li>Thứ hai - 21/03/2022 22:43</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
			<span style="font-family:Times New Roman,Times,serif;"><span style="font-size:14pt;">Đề bài: Sử dụng ngôn ngữ C++, thực hiện các công việc sau:<br />
•&nbsp;&nbsp; &nbsp;Xây dựng lớp HOCSINH gồm các thuộc tính: mã học sinh, họ và tên, tuổi, điểm môn toán, điểm môn văn và điểm môn anh.<br />
•&nbsp;&nbsp; &nbsp;Nhập danh sách các học sinh (ghi vào tệp: HOCSINH.DAT).<br />
•&nbsp;&nbsp; &nbsp;Tính điểm trung bình cho các đối tượng học sinh.<br />
•&nbsp;&nbsp; &nbsp;In ra danh sách các nhân sự theo thứ tự của tên.(đọc từ tệp: HOCSINH.DAT).<br />
•&nbsp;&nbsp; &nbsp;Có bao nhiêu học sinh loại: giỏi, khá, trung bình, không đạt ?&nbsp;<br />
(quy định: điểm trung bình &gt;= 8.5: loại giỏi; 7.0 &lt;= điểm trung bình &lt;8.5: loại khá;&nbsp;5.0 &lt;= điểm trung bình &lt;7.0: loại trung bình; &nbsp;điểm trung bình &lt; 5.0: không đạt)</span></span>
		</div>
		<div id="bodytext" class="clearfix">
			<span style="font-family:Times New Roman,Times,serif;"><span style="font-size:14pt;">Họ và tên:&nbsp;Vàng Văn Quyn<br />Nhóm: 01 (Bảo Thắng + Si Ma Cai)<br />Lớp: Tin A20-PH Lào Cai.<br />Môi trường:&nbsp;Visual Studio 2019 (Console)<br />* Không kiểm tra điểm nhập vào (0 &lt;= điểm &lt;= 10)</span></span><pre><code class="language-cpp">// Bai2.cpp : This file contains the &#039;main&#039; function. Program execution begins and ends there.//#include &lt;iostream&gt;#include &lt;iomanip&gt;#include &lt;fstream&gt;using namespace std;class HOCSINH {private:	char maso&#91;10&#93;, hotendem&#91;30&#93;, ten&#91;15&#93;;	int tuoi;	float toan, van, anh;public:	HOCSINH();	HOCSINH(string maso, string hotendem, string ten, int tuoi, float toan, float van, float anh);	void NHAP();	float DTB();	void INRA();	string getTen() { return this-&gt;ten; }};HOCSINH::HOCSINH() {	strcpy_s(this-&gt;maso, &quot;&quot;);	strcpy_s(this-&gt;hotendem, &quot;&quot;);	strcpy_s(this-&gt;ten, &quot;&quot;);	this-&gt;tuoi = 0;	this-&gt;toan = 0;	this-&gt;van = 0;	this-&gt;anh = 0;}HOCSINH::HOCSINH(string maso, string hotendem, string ten, int tuoi, float toan, float van, float anh) {	strcpy_s(this-&gt;maso, maso.c_str());	strcpy_s(this-&gt;hotendem, hotendem.c_str());	strcpy_s(this-&gt;ten, ten.c_str());	this-&gt;tuoi = tuoi;	this-&gt;toan = toan;	this-&gt;van = van;	this-&gt;anh = anh;}void HOCSINH::NHAP() {	cout &lt;&lt; &quot;Ma so: &quot;; cin.getline(this-&gt;maso, 10); //cin.ignore();	cout &lt;&lt; &quot;Ho va ten dem: &quot;; cin.getline(this-&gt;hotendem, 30);// cin.ignore();	cout &lt;&lt; &quot;Ten: &quot;; cin.getline(this-&gt;ten, 15); //cin.ignore();	cout &lt;&lt; &quot;Tuoi: &quot;; cin &gt;&gt; tuoi;	cout &lt;&lt; &quot;Diem toan: &quot;; cin &gt;&gt; this-&gt;toan; //cin.ignore();	cout &lt;&lt; &quot;Diem van: &quot;; cin &gt;&gt; this-&gt;van; //cin.ignore();	cout &lt;&lt; &quot;Diem T. Anh: &quot;; cin &gt;&gt; this-&gt;anh; //cin.ignore();	}float HOCSINH::DTB() {	float tb = 0;	tb = this-&gt;toan + this-&gt;van + this-&gt;anh;	tb = tb / 3.0;	return tb;}void HOCSINH::INRA() {	cout &lt;&lt; &quot;Hoc sinh: &quot; &lt;&lt; setw(10) &lt;&lt; this-&gt;maso &lt;&lt; setw(30) &lt;&lt; this-&gt;hotendem &lt;&lt; setw(15) &lt;&lt; this-&gt;ten &lt;&lt; setw(5) &lt;&lt; this-&gt;tuoi		&lt;&lt; setw(8) &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; this-&gt;toan &lt;&lt; setw(8) &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; this-&gt;van		&lt;&lt; setw(8) &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; this-&gt;anh &lt;&lt; setw(8) &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; this-&gt;DTB() &lt;&lt; endl;}class DSHOCSINH {private:		void SAPXEP(HOCSINH* ds, int soluonghocsinh, bool sapxepgiamdan);	void XEPLOAI(int gioi, int kha, int tb, int kdat) {		cout &lt;&lt; &quot;Gioi: &quot; &lt;&lt; gioi &lt;&lt; setw(20) &lt;&lt; &quot;Kha: &quot; &lt;&lt; kha &lt;&lt; setw(20) &lt;&lt; &quot;Tb: &quot; &lt;&lt; tb &lt;&lt; setw(20) &lt;&lt; &quot;Khong dat: &quot; &lt;&lt; kdat;	}public:	void NHAP();	void INRA();};void DSHOCSINH::NHAP() {	ofstream fout;		HOCSINH hs=HOCSINH();	fout.open(&quot;HOCSINH.DAT&quot;, ios::out);	char ok;		while (1) {		hs.NHAP();					fout.write((char*)&amp;hs, sizeof(hs));		if (fout.good()) {			cout &lt;&lt; &quot;Da ghi thanh cong! &quot;;		}		cout &lt;&lt; &quot;Co nhap tiep khong (C/K)?&quot;; cin &gt;&gt; ok; cin.ignore();		if ((ok == &#039;k&#039;) || (ok == &#039;K&#039;)) {			break;		}	}	fout.close();}void DSHOCSINH::SAPXEP(HOCSINH* ds, int soluonghocsinh, bool sapxepgiamdan) {	int i = soluonghocsinh;	int j1 = 0;	HOCSINH temp;	int j2 = 0;	for (j1 = 0; j1 &lt; i; j1++) {				for (j2 = 0; j2 &lt; i; j2++) {			if (sapxepgiamdan)			{				if (ds&#91;j1&#93;.getTen() &lt; ds&#91;j2&#93;.getTen()) {					temp = ds&#91;j1&#93;;					ds&#91;j1&#93; = ds&#91;j2&#93;;					ds&#91;j2&#93; = temp;				}			}			else {				if (ds&#91;j1&#93;.getTen() &gt; ds&#91;j2&#93;.getTen()) {					temp = ds&#91;j1&#93;;					ds&#91;j1&#93; = ds&#91;j2&#93;;					ds&#91;j2&#93; = temp;				}			}		}	}	}void DSHOCSINH::INRA() {	ifstream fin;	int i = 0;	HOCSINH *ds = new HOCSINH&#91;100&#93;;	fin.open(&quot;HOCSINH.DAT&quot;, ios::in);	if (fin.fail()) {		cout &lt;&lt; &quot;Mo tep bi loi!&quot;;		return;	}	int gioi = 0, kha = 0, tb = 0, khongdat = 0;	HOCSINH hs;	while (fin.read((char*)&amp;hs, sizeof(hs))) {		ds&#91;i&#93; = hs;				i++;			}	fin.close();			this-&gt;SAPXEP(ds,i, true);//Tang dan		int j1 = 0;		for (j1 = 0; j1 &lt; i; j1++) {				//bat dau xep loai            		if (ds&#91;j1&#93;.DTB() &gt;= 8.5) {			gioi++;		}		else if ((ds&#91;j1&#93;.DTB() &gt;= 7.0) &amp;&amp; (ds&#91;j1&#93;.DTB() &lt; 8.5)) {			kha++;		}		else if ((ds&#91;j1&#93;.DTB() &gt;= 5.0) &amp;&amp; (ds&#91;j1&#93;.DTB() &lt; 7.0)) {			tb++;		}		else {			khongdat++;		}		//Ket thuc xep loai		ds&#91;j1&#93;.INRA();	}		this-&gt;XEPLOAI(gioi, kha, tb, khongdat);}int main(){	DSHOCSINH hs = DSHOCSINH();	hs.NHAP();	hs.INRA();}</code></pre><span style="font-family:Times New Roman,Times,serif;"><span style="font-size:14pt;">&nbsp;* Có kiểm tra điểm nhập vào (0 &lt;= điểm &lt;= 10)</span></span><pre><code class="language-cpp">// Bai2.cpp : This file contains the &#039;main&#039; function. Program execution begins and ends there.//#include &lt;iostream&gt;#include &lt;iomanip&gt;#include &lt;fstream&gt;using namespace std;class HOCSINH {private:	char maso&#91;10&#93;, hotendem&#91;30&#93;, ten&#91;15&#93;;	int tuoi;	float toan, van, anh;	bool Kiemtranhapdiem(float diem) {		if ((diem &gt;= 0) &amp;&amp; (diem &lt;= 10)) {			return true;		}		else {			cout &lt;&lt; &quot;Thong bao loi, chi duoc nhap gia tri: 0 &lt;= &quot; &lt;&lt; &quot;Gia tri nhap vao phai&quot; &lt;&lt; &quot; &lt;= 10&quot; &lt;&lt; endl;			return false;		}	}public:	HOCSINH();	HOCSINH(string maso, string hotendem, string ten, int tuoi, float toan, float van, float anh);	void NHAP();	float DTB();	void INRA();	string getTen() { return this-&gt;ten; }};HOCSINH::HOCSINH() {	strcpy_s(this-&gt;maso, &quot;&quot;);	strcpy_s(this-&gt;hotendem, &quot;&quot;);	strcpy_s(this-&gt;ten, &quot;&quot;);	this-&gt;tuoi = 0;	this-&gt;toan = 0;	this-&gt;van = 0;	this-&gt;anh = 0;}HOCSINH::HOCSINH(string maso, string hotendem, string ten, int tuoi, float toan, float van, float anh) {	strcpy_s(this-&gt;maso, maso.c_str());	strcpy_s(this-&gt;hotendem, hotendem.c_str());	strcpy_s(this-&gt;ten, ten.c_str());	this-&gt;tuoi = tuoi;	this-&gt;toan = toan;	this-&gt;van = van;	this-&gt;anh = anh;}void HOCSINH::NHAP() {	cout &lt;&lt; &quot;Ma so: &quot;; cin.getline(this-&gt;maso, 10); //cin.ignore();	cout &lt;&lt; &quot;Ho va ten dem: &quot;; cin.getline(this-&gt;hotendem, 30);// cin.ignore();	cout &lt;&lt; &quot;Ten: &quot;; cin.getline(this-&gt;ten, 15); //cin.ignore();	cout &lt;&lt; &quot;Tuoi: &quot;; cin &gt;&gt; tuoi;	do {		cout &lt;&lt; &quot;Diem toan: &quot;; cin &gt;&gt; this-&gt;toan; //cin.ignore();	} while (!this-&gt;Kiemtranhapdiem(this-&gt;toan));	do {		cout &lt;&lt; &quot;Diem van: &quot;; cin &gt;&gt; this-&gt;van; //cin.ignore();	} while (!this-&gt;Kiemtranhapdiem(this-&gt;van));	do {		cout &lt;&lt; &quot;Diem T. Anh: &quot;; cin &gt;&gt; this-&gt;anh; //cin.ignore();		} while (!this-&gt;Kiemtranhapdiem(this-&gt;anh));}float HOCSINH::DTB() {	float tb = 0;	tb = this-&gt;toan + this-&gt;van + this-&gt;anh;	tb = tb / 3.0;	return tb;}void HOCSINH::INRA() {	cout &lt;&lt; &quot;Hoc sinh: &quot; &lt;&lt; setw(10) &lt;&lt; this-&gt;maso &lt;&lt; setw(30) &lt;&lt; this-&gt;hotendem &lt;&lt; setw(15) &lt;&lt; this-&gt;ten &lt;&lt; setw(5) &lt;&lt; this-&gt;tuoi		&lt;&lt; setw(8) &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; this-&gt;toan &lt;&lt; setw(8) &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; this-&gt;van		&lt;&lt; setw(8) &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; this-&gt;anh &lt;&lt; setw(8) &lt;&lt; setprecision(2) &lt;&lt; fixed &lt;&lt; this-&gt;DTB() &lt;&lt; endl;}class DSHOCSINH {private:		void SAPXEP(HOCSINH* ds, int soluonghocsinh, bool sapxepgiamdan);	void XEPLOAI(int gioi, int kha, int tb, int kdat) {		cout &lt;&lt; &quot;Gioi: &quot; &lt;&lt; gioi &lt;&lt; setw(20) &lt;&lt; &quot;Kha: &quot; &lt;&lt; kha &lt;&lt; setw(20) &lt;&lt; &quot;Tb: &quot; &lt;&lt; tb &lt;&lt; setw(20) &lt;&lt; &quot;Khong dat: &quot; &lt;&lt; kdat;	}public:	void NHAP();	void INRA();};void DSHOCSINH::NHAP() {	ofstream fout;		HOCSINH hs=HOCSINH();	fout.open(&quot;HOCSINH.DAT&quot;, ios::out);	char ok;		while (1) {		hs.NHAP();					fout.write((char*)&amp;hs, sizeof(hs));		if (fout.good()) {			cout &lt;&lt; &quot;Da ghi thanh cong! &quot;;		}		cout &lt;&lt; &quot;Co nhap tiep khong (C/K)?&quot;; cin &gt;&gt; ok; cin.ignore();		if ((ok == &#039;k&#039;) || (ok == &#039;K&#039;)) {			break;		}	}	fout.close();}void DSHOCSINH::SAPXEP(HOCSINH* ds, int soluonghocsinh, bool sapxepgiamdan) {	int i = soluonghocsinh;	int j1 = 0;	HOCSINH temp;	int j2 = 0;	for (j1 = 0; j1 &lt; i; j1++) {				for (j2 = 0; j2 &lt; i; j2++) {			if (sapxepgiamdan)			{				if (ds&#91;j1&#93;.getTen() &lt; ds&#91;j2&#93;.getTen()) {					temp = ds&#91;j1&#93;;					ds&#91;j1&#93; = ds&#91;j2&#93;;					ds&#91;j2&#93; = temp;				}			}			else {				if (ds&#91;j1&#93;.getTen() &gt; ds&#91;j2&#93;.getTen()) {					temp = ds&#91;j1&#93;;					ds&#91;j1&#93; = ds&#91;j2&#93;;					ds&#91;j2&#93; = temp;				}			}		}	}	}void DSHOCSINH::INRA() {	ifstream fin;	int i = 0;	HOCSINH *ds = new HOCSINH&#91;100&#93;;	fin.open(&quot;HOCSINH.DAT&quot;, ios::in);	if (!fin.good()) {		cout &lt;&lt; &quot;Mo tep bi loi!&quot;;		return;	}	int gioi = 0, kha = 0, tb = 0, khongdat = 0;	HOCSINH hs;	while (fin.read((char*)&amp;hs, sizeof(hs))) {		ds&#91;i&#93; = hs;				i++;	}	fin.close();		this-&gt;SAPXEP(ds,i, true);//Tang dan		int j1 = 0;		for (j1 = 0; j1 &lt; i; j1++) {				//bat dau xep loai            		if (ds&#91;j1&#93;.DTB() &gt;= 8.5) {			gioi++;		}		else if ((ds&#91;j1&#93;.DTB() &gt;= 7.0) &amp;&amp; (ds&#91;j1&#93;.DTB() &lt; 8.5)) {			kha++;		}		else if ((ds&#91;j1&#93;.DTB() &gt;= 5.0) &amp;&amp; (ds&#91;j1&#93;.DTB() &lt; 7.0)) {			tb++;		}		else {			khongdat++;		}		//Ket thuc xep loai		ds&#91;j1&#93;.INRA();	}		this-&gt;XEPLOAI(gioi, kha, tb, khongdat);}int main(){	DSHOCSINH hs = DSHOCSINH();	hs.NHAP();	hs.INRA();}</code></pre>
		</div>
				<div id="author">
						<p>
				<strong>Tác giả:</strong>
				<a href="https://365.io.vn/author/Vang-Van-Quyn/">Vàng Văn Quyn</a>
			</p>
		</div>
				<div class="copyright">
			Chú ý: Việc đăng lại bài viết trên ở website hoặc các phương tiện truyền thông khác mà không ghi rõ nguồn<strong> <a href="https://365.info.vn" target="_blank">https://365.io.vn</a>&nbsp;</strong>là vi phạm bản quyền
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://365.io.vn/savefile/lap-trinh-huong-doi-tuong-oop/bai-2-xay-dung-lop-hocsinh-nhap-tu-ban-phim-xuat-ra-man-hinh-ghi-doc-tep-39.html" title="Bài 2. Xây dựng lớp HOCSINH &#40;Nhập từ bàn phím, xuất ra màn hình, ghi, đọc tệp&#41;">https://365.io.vn/savefile/lap-trinh-huong-doi-tuong-oop/bai-2-xay-dung-lop-hocsinh-nhap-tu-ban-phim-xuat-ra-man-hinh-ghi-doc-tep-39.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; DATAONLINE.IO.VN
		</div>
		<div id="contact">
			<a href="mailto:support@dataonline.io.vn">support@dataonline.io.vn</a>
		</div>
	</div>
</div>
        <div class="cookie-notice"><div><button onclick="cookie_notice_hide();">&times;</button>Chúng tôi đang sử dụng cookie để cung cấp cho bạn những trải nghiệm tốt nhất trên trang web này. Bằng cách tiếp tục truy cập, bạn đồng ý với <a href="https://365.io.vn/siteterms/privacy.html">Chính sách thu thập và sử dụng cookie</a> của chúng tôi.</div></div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://365.io.vn/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
<div id="run_cronjobs" style="visibility:hidden;display:none;"><img alt="cron" src="/index.php?second=cronjobs&amp;p=b67r7L6v" width="1" height="1" /></div>
<script src="https://365.io.vn/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=0,nv_recaptcha_ver=2,nv_recaptcha_sitekey="",nv_recaptcha_type="image",XSSsanitize=1;</script>
<script src="https://365.io.vn/assets/js/language/vi.js"></script>
<script src="https://365.io.vn/assets/js/DOMPurify/purify3.js"></script>
<script src="https://365.io.vn/assets/js/global.js"></script>
<script src="https://365.io.vn/assets/js/site.js"></script>
<script src="https://365.io.vn/themes/default/js/news.js"></script>
<script src="https://365.io.vn/themes/default/js/main.js"></script>
<script src="https://365.io.vn/themes/default/js/custom.js"></script>
<script type="application/ld+json">
        {
            "@context": "https://schema.org",
            "@type": "Organization",
            "url": "https://365.io.vn",
            "logo": "https://365.io.vn/assets/images/logo.svg"
        }
        </script>
<script src="https://365.io.vn/themes/default/js/bootstrap.min.js">
        </script>
<script>
    var LIMIT = 600000; // 10 phút

    var startTime = sessionStorage.getItem("redirect_timer");
    if (!startTime) {
        startTime = Date.now();
        sessionStorage.setItem("redirect_timer", startTime);
    } else {
        startTime = parseInt(startTime, 10);
    }

    var elapsed = Date.now() - startTime;
    var remain = LIMIT - elapsed;

    if (remain > 0) {
        setTimeout(function () {
            alert("Hệ thống sẽ chuyển sang trang chấm bài.");
            window.location.replace("https://vnoj.io.vn");
        }, remain);
    } else {
        window.location.replace("https://vnoj.io.vn");
    }
</script>
</body>
</html>