Hướng dẫn conio.h c++ - conio.h c ++

Hướng dẫn conio.h c++ - conio.h c ++

admin

15/11/2020

Share

Hướng dẫn conio.h c++ - conio.h c ++

Thư viện conio.h là tên viết tắt của từ Console Input/Output.header. Đây là thư viện thường được sử dụng trong trình biên dịch của các hệ điều hành cũ MS-DOS những năm 1980.

Thư viện conio.h không nằm danh sách các thư viện chuẩn của C. Thư viện này chỉ hỗ trợ trên nền tảng của hệ điều hành Microsoft như DOS, Win32, … Vì vậy chúng ta không thể sử dụng thư viện conio.h nếu lập trình trên các hệ điều hành Linux, Unix.

Hướng dẫn conio.h c++ - conio.h c ++
conio.h

Thư viện conio.h ra đời nhằm giúp chúng ta thực hiện các thao tác input hoặc output từ màn hình console. Trong đó có 2 hàm mà các kỹ sư phần mềm thường sử dụng phổ biến nhất là:

+ clrscr(): Đây là lệnh xóa các output đã có trên màn hình console. Bạn có thể nhớ lệnh này rất dễ dàng đó bằng câu nói ” con lớn rồi sẽ có răng ” ???? vui thôi nha…

+ getch(): đây là lệnh lấy input từ màn hình console. Các kỹ sư phần mềm thường dùng điểm này của getch() để dừng màn hình console sau khi xuất kết quả).

Ví dụ dùng Thư viện conio.h
Ví dụ chương trình bạn muốn dừng màn hình console lại sau khi xuất kết quả 4+34+3 ra màn hình.

#include
#include

int main(){
int a = 3;
int b = 4;

printf(“a + b = %d \n”, a + b);
getch(); // Lợi dụng chức năng của getch để
// dừng màn hình console sau khi xuất kết quả.

return 0;
}
Trên đây là một số thông tin về thư viện Thư viện conio.h. Cũng như một số hàm thường dùng trong thư viện này.

Xem thêm các phần mềm lập trình mới nhất 2022 tại đây:

  • Download Microsoft Visual Studio 2019 full crack từ A đến Z

  • Hướng dẫn tải phần mềm Visual Studio 2013 bản mới nhất 2022

  • Tải và cài đặt phần mềm Visual Studio 2017 trong 1 nốt nhạc

BÀi 2. Kiểu dữ liệu, toán tử, ha số

Các kiểu dữ liệu cơ bản chuẩn trong c \ c ++

& nbsp; & nbsp;

1. Kiểu Số Nguynênn & nbsp; & nbsp; & nbsp; - ký hiệu: int (2 byte); & nbsp; & nbsp; & nbsp; - Các kiểu mở rộng: dài, không dấu int, không dấu dài.
    - Ký hiệu: int (2 Byte);
    - Các kiểu mở rộng: long, unsigned int, unsigned long.

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; 2. Kiểu số thực & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; - ký hiệu: float (4 byte) & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; - Các kiểu mở rộng: gấp đôi, gấp đôi dài.  2. Kiểu số thực     
    - Ký hiệu: float (4 Byte)    
    - Các kiểu mở rộng: double, long double.

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; 3. Kiểu ký tự & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; - Ký hiệu: char (1 byte).  3. Kiểu ký tự   
    - Ký hiệu: char (1 Byte).


Ép Kiểu, Chuyển Kiểu

& nbsp; & nbsp;

-Chuyển Kiểu tự Động: char -> int -> float. & Nbsp; & nbsp; & nbsp; - Ép Kiểu:
    - Ép kiểu:

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Ví dụ: Ép kiểu float thànnh int: & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; (int)x; (X Có Kiểu Float).float thành int:        
       (int)x; (x có kiểu float).


Các Toán Tử Trong C \ C ++

& nbsp; & nbsp; & nbsp; 1 - toán tử số học & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;+, -, *, /, & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;% (Chia lấy Phần dư), & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; ++ (tăng 1 Đơn vị), & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;- (Giảm 1 Đơn vị), & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; =, ... & nbsp; & nbsp; & nbsp; & nbsp; 2 - toán tử logic & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; && (và), & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; || (hoặc), & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp ;! (không). & nbsp; & nbsp; & nbsp; & nbsp; 3 - toán tử quan hệ & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; >, =,> (dịch phải), & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; <(dịch trái), & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;    1 - Toán tử số học          
          +, -, *, /,           
          % (chia lấy phần dư),           
          ++ (tăng 1 đơn vị),           
          -- (giảm 1 đơn vị),           
          =, ...
     2 - Toán tử logic      
          && (and),           
          || (or),           
          ! (not).
     3 - Toán tử quan hệ      
        >, <, >=, <=, ==, !=.      
     4 - Toán tử xử lý bit      
          >> (dịch phải),           
          << (dịch trái),           
          ~ (not bit),           
          ^ (xor bit),           
          & (and bit),           
          | (or bit).


Một Số HÀm Thôn dụng C ++

& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; getchar (), putchar (), getw (), putw (), ... & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Bảng điều khiển). & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; ; & nbsp; & nbsp; & nbsp; & nbsp; log10 (), sin (), cos (), tan (), acos (), asin (), atan (), pow (), exp (), ... & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Gồm các ha: calloc (), realloc (), malloc (), free (), farmalloc (), farcalloc (), farfree (), ... & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Khóa (), ... & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;
      1- stdio.h: Thư viện chứa các hàm vào/ ra chuẩn (standard input/output).       
           Gồm các hàm: printf(), scanf(), getc(), putc(), gets(), puts(), fflush(), fopen(), fclose(), fread(), fwrite(), getchar(), putchar(), getw(), putw(),...
      2- conio.h: Thư viện chứa các hàm vào ra trong chế độ DOS (DOS console).     
        Gồm các hàm: clrscr(), getch(), getche(), getpass(), cgets(), cputs(), putch(), clreol(),...
      3- math.h: Thư viện chứa các hàm tính toán     
        Gồm các hàm: abs(), sqrt(), log(). log10(), sin(), cos(), tan(), acos(), asin(), atan(), pow(), exp(),...
      4- alloc.h: Thư viện chứa các hàm liên quan đến việc quản lý bộ nhớ.       
        Gồm các hàm: calloc(), realloc(), malloc(), free(), farmalloc(), farcalloc(), farfree(),...
      5- io.h: Thư viện chứa các hàm vào ra cấp thấp.     
        Gồm các hàm: open(), _open(), read(), _read(), close(), _close(), creat(), _creat(), creatnew(), eof(), filelength(), lock(),...
      6- graphics.h: Thư viện chứa các hàm liên quan đến đồ họa.     
        Gồm các hàm: initgraph(), line(), circle(), putpixel(), getpixel(), setcolor(),...


Ví dụ 1:

+ Yêu cầu: tính tổng hai số nguyn aun a, b cho trước.Yêu cầu: Tính tổng hai số nguyên a, b cho trước.

+ Mã:Code:

#include 
#include 

using namespace std;

int main() {
    // khai báo biến
    int a,b;
    a=5; b=6;
    int s=a+b;
    cout<<"\n Tong "<

Ví dụ 2: & nbsp;

+ Yêu cầu: Tính Chu VI Và diện Tích Của Tam Gián Với 3 CạNH Cho Trước.Yêu cầu: Tính chu vi và diện tích của tam giác với 3 cạnh cho trước.

+ Mã:Code:

#include 
#include 
#include 

using namespace std;

int main() {
    // khai báo biến sô thực
    float a,b,c;
    a=3.0; b=4.0;c=5.0;
    float cv,dt; // chu vi, dien tich
    // tinh chu vi, dien tich
    cv=a+b+c;
    float p=cv/2; // nua chu vi
    dt=sqrt(p*(p-a)*(p-b)*(p-c));
    cout<<"\n Chu vi = "<Ví dụ 2: & nbsp;

+ Yêu cầu: Tính Chu VI Và diện Tích Của Tam Gián Với 3 CạNH Cho Trước.Yêu cầu:  
  - In ra màn hình vị trí của ký tự 'A' trong bảng mã ASCII.
  - In ra ký tự tại vị trí 67 trong bảng mã ASCII.

Ví dụ 3:Code:

#include 
#include 
#include 

using namespace std;

int main() {
    // khai báo biến ký tự
    char ch='A';
    int vt=ch;
    cout<<"\n Vi tri cua ky tu A: "<