diff --git a/2. Bai132/Source.cpp b/2. Bai132/Source.cpp index 9e1927f..8ba9f3c 100644 --- a/2. Bai132/Source.cpp +++ b/2. Bai132/Source.cpp @@ -1,8 +1,56 @@ #include using namespace std; +struct DiemKhongGian +{ + float x; + float y; + float z; +}; +typedef struct DiemKhongGian DIEMKHONGGIAN; + +struct HinhCau +{ + DIEMKHONGGIAN I; + float R; +}; +typedef struct HinhCau HINHCAU; + +void Nhap(DIEMKHONGGIAN&); +void Nhap(HINHCAU&); + +float TheTich(HINHCAU); + int main() { + HINHCAU s; + cout << "Nhap hinh cau: \n"; + Nhap(s); + + cout << "The Tich hinh cau vua nhap: " << TheTich(s); return 0; +} + +void Nhap(DIEMKHONGGIAN& P) +{ + cout << "Nhap x: "; + cin >> P.x; + cout << "Nhap y: "; + cin >> P.y; + cout << "Nhap z: "; + cin >> P.z; +} + +void Nhap(HINHCAU& c) +{ + cout << "Nhap tam:\n"; + Nhap(c.I); + cout << "Nhap ban kinh: "; + cin >> c.R; +} + +float TheTich(HINHCAU c) +{ + return float((float)4 / 3 * 3.14 * c.R * c.R * c.R); } \ No newline at end of file diff --git a/2. Bai137/Source.cpp b/2. Bai137/Source.cpp index 9e1927f..70fcb3e 100644 --- a/2. Bai137/Source.cpp +++ b/2. Bai137/Source.cpp @@ -1,8 +1,69 @@ #include +#include using namespace std; +struct Diem +{ + float x; + float y; +}; +typedef struct Diem DIEM; + +struct TamGiac +{ + DIEM A; + DIEM B; + DIEM C; +}; +typedef struct TamGiac TAMGIAC; + +void Nhap(DIEM&); +void Xuat(DIEM); + +void Nhap(TAMGIAC&); +void Xuat(TAMGIAC); + int main() { + TAMGIAC M; + Nhap(M); + cout << "\nTam giac vua nhap:"; + Xuat(M); + return 1; +} - return 0; +void Nhap(DIEM& P) +{ + cout << "Nhap x: "; + cin >> P.x; + cout << "Nhap y: "; + cin >> P.y; +} + +void Xuat(DIEM P) +{ + cout << setw(6); + cout << setprecision(3); + cout << "\nx: " << P.x; + cout << "\ny: " << P.y; +} + +void Nhap(TAMGIAC& t) +{ + cout << "Nhap diem A:\n"; + Nhap(t.A); + cout << "Nhap diem B:\n"; + Nhap(t.B); + cout << "Nhap diem C:\n"; + Nhap(t.C); +} + +void Xuat(TAMGIAC t) +{ + cout << "\nToa do diem A: "; + Xuat(t.A); + cout << "\nToa do diem B: "; + Xuat(t.B); + cout << "\nToa do diem C: "; + Xuat(t.C); } \ No newline at end of file diff --git a/2. Bai142/Source.cpp b/2. Bai142/Source.cpp index 9e1927f..4067136 100644 --- a/2. Bai142/Source.cpp +++ b/2. Bai142/Source.cpp @@ -1,8 +1,66 @@ #include using namespace std; +struct Diem +{ + float x; + float y; +}; +typedef struct Diem DIEM; + +struct TamGiac +{ + DIEM A; + DIEM B; + DIEM C; +}; +typedef struct TamGiac TAMGIAC; + +void Nhap(DIEM&); +void Nhap(TAMGIAC&); +void Xuat(DIEM); +DIEM HoanhLonNhat(TAMGIAC t); + int main() { + TAMGIAC t; + Nhap(t); + cout << "\nDiem co Tung do lon nhat la:"; + Xuat(HoanhLonNhat(t)); return 0; -} \ No newline at end of file +} + +void Nhap(DIEM& I) +{ + cout << "\nNhap x: "; + cin >> I.x; + cout << "Nhap y: "; + cin >> I.y; +} + +void Nhap(TAMGIAC& t) +{ + cout << "\nNhap A: "; + Nhap(t.A); + cout << "\nNhap B: "; + Nhap(t.B); + cout << "\nNhap C: "; + Nhap(t.C); +} + +void Xuat(DIEM I) +{ + cout << "(" << I.x << ", " << I.y << ")"; +} + +DIEM HoanhLonNhat(TAMGIAC t) +{ + DIEM lc = t.A; + if (t.B.x > lc.x) + lc = t.B; + if (t.C.x>lc.x) + lc = t.C; + return lc; +} + diff --git a/2. Bai147/Source.cpp b/2. Bai147/Source.cpp index 9e1927f..59dac66 100644 --- a/2. Bai147/Source.cpp +++ b/2. Bai147/Source.cpp @@ -1,8 +1,39 @@ #include using namespace std; +struct DuongThang +{ + float a; + float b; + float c; +}; +typedef struct DuongThang DUONGTHANG; + +void Nhap(DUONGTHANG&); +void Xuat(DUONGTHANG); + int main() { + DUONGTHANG d; + Nhap(d); + Xuat(d); return 0; +} + +void Nhap(DUONGTHANG& d) +{ + cout << "\nNhap a: "; + cin >> d.a; + cout << "Nhap b: "; + cin >> d.b; + cout << "Nhap c: "; + cin >> d.c; +} + +void Xuat(DUONGTHANG d) +{ + cout << "\na: " << d.a; + cout << "\nb: " << d.b; + cout << "\nc: " << d.c; } \ No newline at end of file diff --git a/2. Bai152/Source.cpp b/2. Bai152/Source.cpp index 9e1927f..6cc2f78 100644 --- a/2. Bai152/Source.cpp +++ b/2. Bai152/Source.cpp @@ -1,8 +1,50 @@ #include using namespace std; +struct DuongThang +{ + float a; + float b; + float c; +}; +typedef struct DuongThang DUONGTHANG; + +void Nhap(DUONGTHANG&); +int ktSongSong(DUONGTHANG, DUONGTHANG); + int main() { + DUONGTHANG ln1; + cout << "Nhap duong thang thu nhat:\n"; + Nhap(ln1); + + DUONGTHANG ln2; + cout << "Nhap duong thang thu hai:\n"; + Nhap(ln2); + + if (ktSongSong(ln1, ln2)) + cout << "Hai duong thang Song Song nhau"; + else + cout << "Hai duong thang khong Song Song nhau"; return 0; +} + +void Nhap(DUONGTHANG& l) +{ + cout << "Nhap a: "; + cin >> l.a; + cout << "Nhap b: "; + cin >> l.b; + cout << "Nhap c: "; + cin >> l.c; +} + +int ktSongSong(DUONGTHANG d1, DUONGTHANG d2) +{ + float D = d1.a * d2.b - d2.a * d1.b; + float Dx = -d1.c * d2.b + d2.c * d1.b; + if (D == 0 && Dx != 0) + return 1; + return 0; } \ No newline at end of file diff --git a/2. Bai157/Source.cpp b/2. Bai157/Source.cpp index 9e1927f..69e0ef5 100644 --- a/2. Bai157/Source.cpp +++ b/2. Bai157/Source.cpp @@ -1,8 +1,45 @@ #include +#include + using namespace std; +struct DaThuc +{ + int n; + float a[100]; +}; +typedef struct DaThuc DATHUC; +void Nhap(DATHUC&); +void Xuat(DATHUC); + int main() { + DATHUC f; + Nhap(f); + cout << "\n Da thuc vua nhap la: "; + cout << endl; + Xuat(f); return 0; +} + +void Nhap(DATHUC& f) +{ + cout << "Nhap n: "; + cin >> f.n; + for (int i = f.n; i >= 0; i--) + { + cout << "Nhap a[" << i << "]: "; + cin >> f.a[i]; + } +} + +void Xuat(DATHUC f) +{ + for (int i = f.n; i >= 1; i--) + { + cout << setw(8) << "(" << f.a[i] << ")"; + cout << "x^" << i << "+"; + } + cout << setw(8) << "(" << f.a[0] << ")"; } \ No newline at end of file diff --git a/2. Bai162/Source.cpp b/2. Bai162/Source.cpp index 9e1927f..a9244e5 100644 --- a/2. Bai162/Source.cpp +++ b/2. Bai162/Source.cpp @@ -1,8 +1,65 @@ #include +#include using namespace std; +struct DaThuc +{ + float a[100]; + int n; +}; +typedef struct DaThuc DATHUC; + +void Nhap(DATHUC&); +void Xuat(DATHUC); + +DATHUC Tich(DATHUC, DATHUC); + int main() { + DATHUC f1; + cout << "Nhap da thuc f1:" << endl; + Nhap(f1); + + DATHUC f2; + cout << "Nhap da thuc f2:" << endl; + Nhap(f2); + + cout << "Tich da thuc: f1 * f2:" << endl; + Xuat(Tich(f1, f2)); return 0; +} + +void Nhap(DATHUC& f) +{ + cout << "Nhap bac da thuc: "; + cin >> f.n; + for (int i = f.n; i >= 0; i--) + { + cout << "Nhap he so a[" << i << "]: "; + cin >> f.a[i]; + } +} + +void Xuat(DATHUC f) +{ + for (int i = f.n; i >= 1; i--) + { + cout << f.a[i]; + cout << "x^" << i; + cout << setw(3); + } + cout << f.a[0]; +} + +DATHUC Tich(DATHUC f, DATHUC g) +{ + DATHUC temp; + temp.n = f.n + g.n; + for (int i = temp.n; i >= 0; i--) + temp.a[i] = 0; + for (int i = 0; i <= g.n; i++) + for (int j = 0; j <= f.n; j++) + temp.a[i + j] += g.a[i] * f.a[j]; + return temp; } \ No newline at end of file diff --git a/2. Bai167/Source.cpp b/2. Bai167/Source.cpp index 9e1927f..6084b2c 100644 --- a/2. Bai167/Source.cpp +++ b/2. Bai167/Source.cpp @@ -1,8 +1,49 @@ #include +#include using namespace std; +struct DaThuc +{ + float a[100]; + int n; +}; +typedef struct DaThuc DATHUC; + +void Nhap(DATHUC&); +float VT(DATHUC, float); + int main() { + DATHUC f1; + cout << "Nhap da thuc f1:" << endl; + Nhap(f1); + + float x; + cout << "Nhap so thuc x:" << endl; + cin >> x; + cout << "x= "<> f.n; + for (int i = f.n; i >= 0; i--) + { + cout << "Nhap he so a[" << i << "]: "; + cin >> f.a[i]; + } +} + +float VT(DATHUC f, float x) +{ + float s=0.0; + for (int i = 1; i <= f.n; i++) + f.a[i] = f.a[i] * pow(x, i); + for (int i = 0; i <= f.n; i++) + s += f.a[i]; + return s; } \ No newline at end of file diff --git a/2. Bai172/Source.cpp b/2. Bai172/Source.cpp index 9e1927f..2e6387c 100644 --- a/2. Bai172/Source.cpp +++ b/2. Bai172/Source.cpp @@ -1,8 +1,129 @@ #include +#include using namespace std; +struct DaThuc +{ + int n; + float a[100]; +}; +typedef struct DaThuc DATHUC; + +void Nhap(DATHUC&); +void Xuat(DATHUC); + +DATHUC operator+(DATHUC, DATHUC); +DATHUC operator-(DATHUC, DATHUC); +DATHUC operator*(DATHUC, DATHUC); +int LonNhat(int, int); +void GiamBac(DATHUC&); + +DATHUC operator/(DATHUC, DATHUC); + int main() { + DATHUC f; + cout << "Nhap f:" << endl; + Nhap(f); + + DATHUC g; + cout << "Nhap g:" << endl; + Nhap(g); + cout << "Thuong cua f / g:" << endl; + Xuat(f / g); return 0; +} + +void Nhap(DATHUC& f) +{ + cout << "Nhap bac da thuc: "; + cin >> f.n; + for (int i = f.n; i >= 0; i--) + { + cout << "Nhap he so a[" << i << "]: "; + cin >> f.a[i]; + } +} + +void Xuat(DATHUC f) +{ + cout << setw(6); + cout << setprecision(3); + for (int i = f.n; i >= 1; i--) + { + cout << f.a[i]; + cout << "x^" << i << " + "; + } + cout << f.a[0]; +} + +int LonNhat(int a, int b) +{ + if (a > b) + return a; + return b; +} + +void GiamBac(DATHUC& f) +{ + while (f.a[f.n] == 0) + f.n--; +} + +DATHUC operator+(DATHUC f, DATHUC g) +{ + DATHUC temp; + temp.n = LonNhat(f.n, g.n); + for (int i = temp.n; i >= 0; i--) + temp.a[i] = 0; + for (int i = f.n; i >= 0; i--) + temp.a[i] += f.a[i]; + for (int i = g.n; i >= 0; i--) + temp.a[i] += g.a[i]; + GiamBac(temp); + return temp; +} + +DATHUC operator-(DATHUC f, DATHUC g) +{ + for (int i = g.n; i >= 0; i--) + g.a[i] = -g.a[i]; + return (f + g); +} + +DATHUC operator*(DATHUC f, DATHUC g) +{ + DATHUC temp; + temp.n = f.n + g.n; + for (int i = temp.n; i >= 0; i--) + temp.a[i] = 0; + for (int i = f.n; i >= 0; i--) + for (int j = g.n; j >= 0; j--) + temp.a[i + j] += f.a[i] * g.a[j]; + return temp; +} + +DATHUC operator/(DATHUC f, DATHUC g) +{ + DATHUC thuong; + thuong.n = f.n - g.n; + for (int i = thuong.n; i >= 0; i--) + thuong.a[i] = 0; + for (int i = thuong.n; i >= 0; i--) + { + thuong.a[i] = f.a[i + g.n] / g.a[g.n]; + DATHUC temp; + temp.n = i; + for (int i = temp.n; i >= 0; i--) + temp.a[i] = 0; + temp.a[i] = thuong.a[i]; + DATHUC du; + du.n = i + g.n; + for (int i = du.n; i >= 0; i--) + du.a[i] = 0; + du = temp * g; + f = f - du; + } + return thuong; } \ No newline at end of file diff --git a/2. Bai177/Source.cpp b/2. Bai177/Source.cpp index 9e1927f..eb2b51d 100644 --- a/2. Bai177/Source.cpp +++ b/2. Bai177/Source.cpp @@ -1,8 +1,70 @@ #include using namespace std; +struct diem +{ + float x; + float y; +}; +typedef struct diem DIEM; + +void Nhap(DIEM&); +void Nhap(DIEM[], int&); +void Xuat(DIEM); +float KhoangCachGoc(DIEM); +DIEM GanGocNhat(DIEM[], int); + + int main() { + DIEM a[100]; + int n; + Nhap(a, n); + + cout << "Diem gan goc toa do nhat la:"; + Xuat(GanGocNhat(a, n)); return 0; -} \ No newline at end of file +} + +void Nhap(DIEM& P) +{ + cout << "Nhap x: "; + cin >> P.x; + cout << "Nhap y: "; + cin >> P.y; +} + +void Nhap(DIEM P[], int& n) +{ + cout << "Nhap so luong diem: "; + cin >> n; + for (int i = 0; i <= n - 1; i++) + { + cout << "Nhap diem thu " << i << ": " << endl; + Nhap(P[i]); + } +} + +void Xuat(DIEM P) +{ + cout << "\nx: " << P.x; + cout << "\ny: " << P.y; +} + + + +float KhoangCachGoc(DIEM P) +{ + return sqrt(P.x * P.x + P.y * P.y); +} + +DIEM GanGocNhat(DIEM a[], int n) +{ + DIEM lc = a[0]; + for (int i = 0; i <= n - 1; i++) + if (KhoangCachGoc(a[i]) < + KhoangCachGoc(lc)) + lc = a[i]; + return lc; +} diff --git a/2. Bai182/Source.cpp b/2. Bai182/Source.cpp index 9e1927f..2ad4c19 100644 --- a/2. Bai182/Source.cpp +++ b/2. Bai182/Source.cpp @@ -1,8 +1,58 @@ #include using namespace std; -int main() +struct PhanSo { + int Tu; + int Mau; +}; +typedef struct PhanSo PHANSO; + +void Nhap(PHANSO&); +void Xuat(PHANSO); +void Nhap(PHANSO[], int&); +void Xuat(PHANSO[], int); + +int main() +{ + PHANSO P[100]; + int n; + Nhap(P, n); + Xuat(P, n); return 0; +} + +void Nhap(PHANSO& P) +{ + cout << "\nNhap Tu: "; + cin >> P.Tu; + cout << "Nhap Mau: "; + cin >> P.Mau; +} + +void Xuat(PHANSO P) +{ + cout << "\nTu: " << P.Tu; + cout << "\nMau: " << P.Mau; +} + +void Nhap(PHANSO a[], int& n) +{ + cout << "Nhap so luong phan so: "; + cin >> n; + for (int i = 0; i < n; i++) + { + cout << "\nNhap a[" << i << "] = "; + Nhap(a[i]); + } +} + +void Xuat(PHANSO a[], int n) +{ + for (int i = 0; i < n; i++) + { + cout << "\na[" << i << "] = "; + Xuat(a[i]); + } } \ No newline at end of file diff --git a/2. Bai187/Source.cpp b/2. Bai187/Source.cpp index 9e1927f..71ccadb 100644 --- a/2. Bai187/Source.cpp +++ b/2. Bai187/Source.cpp @@ -1,8 +1,63 @@ #include using namespace std; -int main() +struct PhanSo { + int Tu; + int Mau; +}; +typedef struct PhanSo PHANSO; + +void Nhap(PHANSO&); +void Xuat(PHANSO); + +void Nhap(PHANSO[], int&); + +PHANSO DuongDau(PHANSO[], int); +int main() +{ + PHANSO P[100]; + int n; + Nhap(P, n); + cout << "Duong dau tien trong mang la: "; + Xuat(DuongDau(P,n)); return 0; -} \ No newline at end of file +} + +void Nhap(PHANSO& P) +{ + cout << "\nNhap Tu: "; + cin >> P.Tu; + cout << "Nhap Mau: "; + cin >> P.Mau; +} + +void Xuat(PHANSO P) +{ + cout << "\nTu: " << P.Tu; + cout << "\nMau: " << P.Mau; +} + +void Nhap(PHANSO a[], int& n) +{ + cout << "Nhap so luong phan so: "; + cin >> n; + for (int i = 0; i < n; i++) + { + cout << "\nNhap a[" << i << "] = "; + Nhap(a[i]); + } +} + +PHANSO DuongDau(PHANSO a[], int n) +{ + for (int i = 0; i < n; i++) + { + if (a[i].Tu * a[i].Mau > 0) + return a[i]; + } + PHANSO temp{ 0,1 }; + return temp; +} + diff --git a/2. Bai192/Source.cpp b/2. Bai192/Source.cpp index 9e1927f..95a9756 100644 --- a/2. Bai192/Source.cpp +++ b/2. Bai192/Source.cpp @@ -1,8 +1,42 @@ #include using namespace std; +struct SoPhuc +{ + float Thuc; + float Ao; +}; +typedef struct SoPhuc SOPHUC; + +void Nhap(SOPHUC&); +void Nhap(SOPHUC[], int&); + int main() { + SOPHUC a[100]; + int n; + Nhap(a, n); + + cout << "Da hoan thanh nhap mang mot chieu cac so phuc"; return 0; +} + +void Nhap(SOPHUC& x) +{ + cout << "Nhap thuc: "; + cin >> x.Thuc; + cout << "Nhap ao: "; + cin >> x.Ao; +} + +void Nhap(SOPHUC a[], int& n) +{ + cout << "Nhap n: "; + cin >> n; + for (int i = 0; i < n; i++) + { + cout << "Nhap a[" << i << "]: "; + Nhap(a[i]); + } } \ No newline at end of file diff --git a/2. Bai197/Source.cpp b/2. Bai197/Source.cpp index 9e1927f..73cb659 100644 --- a/2. Bai197/Source.cpp +++ b/2. Bai197/Source.cpp @@ -1,8 +1,58 @@ #include using namespace std; +struct Diem +{ + float x; + float y; +}; +typedef struct Diem DIEM; + +struct DuongTron +{ + DIEM I; + float R; +}; +typedef struct DuongTron DUONGTRON; + +void Nhap(DIEM&); +void Nhap(DUONGTRON&); +void Nhap(DUONGTRON[], int&); + int main() { + DUONGTRON a[100]; + int n; + Nhap(a, n); + + cout << "Da hoan thanh nhap mang mot chieu cac duong tron"; return 0; +} + +void Nhap(DIEM& P) +{ + cout << "Nhap x: "; + cin >> P.x; + cout << "Nhap y: "; + cin >> P.y; +} + +void Nhap(DUONGTRON& c) +{ + cout << "Nhap tam:\n"; + Nhap(c.I); + cout << "Nhap ban kinh: "; + cin >> c.R; +} + +void Nhap(DUONGTRON a[], int& n) +{ + cout << "Nhap n: "; + cin >> n; + for (int i = 0; i < n; i++) + { + cout << "Nhap a[" << i << "]: "; + Nhap(a[i]); + } } \ No newline at end of file diff --git a/2. Bai202/Source.cpp b/2. Bai202/Source.cpp index 9e1927f..27f8002 100644 --- a/2. Bai202/Source.cpp +++ b/2. Bai202/Source.cpp @@ -1,8 +1,98 @@ #include using namespace std; +struct Diem +{ + float x; + float y; +}; +typedef struct Diem DIEM; + +struct DuongTron +{ + DIEM I; + float R; +}; +typedef struct DuongTron DUONGTRON; + +void Nhap(DIEM&); +void Nhap(DUONGTRON&); +void Nhap(DUONGTRON[], int&); + +int ktDoiMotCatNhau(DUONGTRON[], int); +float KhoangCach(DIEM P, DIEM Q); +int TuongDoi(DUONGTRON c1, DUONGTRON c2); + int main() { + DUONGTRON a[100]; + int n; + Nhap(a, n); + + if (ktDoiMotCatNhau(a, n)) + cout << "Cac duong tron doi mot cat nhau"; + else + cout << "Cac duong trong khong doi mot cat nhau"; return 0; -} \ No newline at end of file +} + +void Nhap(DIEM& P) +{ + cout << "Nhap x: "; + cin >> P.x; + cout << "Nhap y: "; + cin >> P.y; +} + +void Nhap(DUONGTRON& c) +{ + cout << "\nNhap tam:\n"; + Nhap(c.I); + cout << "Nhap ban kinh: "; + cin >> c.R; +} + +void Nhap(DUONGTRON a[], int& n) +{ + cout << "Nhap n: "; + cin >> n; + for (int i = 0; i < n; i++) + { + cout << "Nhap a[" << i << "]: "; + Nhap(a[i]); + } +} + +int ktDoiMotCatNhau(DUONGTRON a[], int n) +{ + int flag = 1; + for (int i = 0; i <= n - 2; i++) + for (int j = i + 1; j <= n - 1; j++) + if (TuongDoi(a[i], a[j]) != 3) + flag = 0; + return flag; +} + +float KhoangCach(DIEM P, DIEM Q) +{ + return sqrt((P.x - Q.x) * (P.x - Q.x) + + (P.y - Q.y) * (P.y - Q.y)); +} + +int TuongDoi(DUONGTRON c1, DUONGTRON c2) +{ + float kc = KhoangCach(c1.I, c2.I); + if (kc == 0 && c1.R == c2.R) + return 0; + if (kc > c1.R + c2.R) + return 1; + if (kc == c1.R + c2.R) + return 2; + if (kcabs(c1.R - c2.R)) + return 3; + if (kc == abs(c1.R - c2.R)) + return 4; + return 5; +} + diff --git a/2. Bai207/Source.cpp b/2. Bai207/Source.cpp index 9e1927f..eac5041 100644 --- a/2. Bai207/Source.cpp +++ b/2. Bai207/Source.cpp @@ -1,8 +1,65 @@ #include using namespace std; +struct DuongThang +{ + float a; + float b; + float c; +}; +typedef struct DuongThang DUONGTHANG; + +void Nhap(DUONGTHANG&); +void Nhap(DUONGTHANG[], int&); +void Xuat(DUONGTHANG[], int); + int main() { + DUONGTHANG a[100]; + int n; + Nhap(a, n); + + Xuat(a, n); return 0; -} \ No newline at end of file +} + +void Nhap(DUONGTHANG& l) +{ + cout << "Nhap a: "; + cin >> l.a; + cout << "Nhap b: "; + cin >> l.b; + cout << "Nhap c: "; + cin >> l.c; +} + +void Nhap(DUONGTHANG a[], int& n) +{ + cout << "Nhap n: "; + cin >> n; + for (int i = 0; i < n; i++) + { + cout << "Nhap a[" << i << "]: "; + Nhap(a[i]); + } +} + +void Xuat(DUONGTHANG d) +{ + cout << "\na: " << d.a; + cout << "\nb: " << d.b; + cout << "\nc: " << d.c; +} + + +void Xuat(DUONGTHANG a[], int n) + +{ + for (int i = 0; i < n; i++) + { + cout << "Duong thang A[" << i << "]:"; + Xuat(a[i]); + cout << endl; + } +} \ No newline at end of file diff --git a/2. Bai212/Source.cpp b/2. Bai212/Source.cpp index 9e1927f..0519ba4 100644 --- a/2. Bai212/Source.cpp +++ b/2. Bai212/Source.cpp @@ -1,8 +1,91 @@ #include using namespace std; -int main() +struct Diem +{ + float x; + float y; +}; +typedef struct Diem DIEM; + +struct DuongThang { + float a; + float b; + float c; +}; +typedef struct DuongThang DUONGTHANG; + +void Nhap(DIEM& P); +void Nhap(DUONGTHANG&); +void Xuat(DUONGTHANG); +void Nhap(DUONGTHANG[], int&); + +float KhoangCach(DUONGTHANG, DIEM); +DUONGTHANG GanDiemNhat(DUONGTHANG[], int,DIEM); +int main() +{ + DUONGTHANG a[100]; + DIEM P; + int n; + Nhap(a, n); + Nhap(P); + cout << "Diem gan P nhat la:"; + Xuat(GanDiemNhat(a, n, P)); return 0; -} \ No newline at end of file +} + +void Nhap(DIEM& P) +{ + cout << "Nhap diem P:"; + cout << "\nNhap x: "; + cin >> P.x; + cout << "Nhap y: "; + cin >> P.y; +} +void Nhap(DUONGTHANG& l) +{ + cout << "\nNhap a: "; + cin >> l.a; + cout << "Nhap b: "; + cin >> l.b; + cout << "Nhap c: "; + cin >> l.c; +} + +void Nhap(DUONGTHANG a[], int& n) +{ + cout << "Nhap n: "; + cin >> n; + for (int i = 0; i < n; i++) + { + cout << "Nhap a[" << i << "]: "; + Nhap(a[i]); + } +} + + + +float KhoangCach(DUONGTHANG d, DIEM P) +{ + float tu = abs(d.a * P.x + d.b * P.y + d.c); + float mau = sqrt(d.a * d.a + d.b * d.b); + return tu / mau; +} + +DUONGTHANG GanDiemNhat(DUONGTHANG a[], int n,DIEM P) +{ + DUONGTHANG lc = a[0]; + for (int i = 0; i < n; i++) + if (KhoangCach(a[i], P) < KhoangCach(lc, P)) + lc = a[i]; + return lc; +} + +void Xuat(DUONGTHANG d) +{ + cout << "\na:" << d.a; + cout << "\nb:" << d.b; + cout << "\nc:" << d.c; +} diff --git a/2. Bai217/Source.cpp b/2. Bai217/Source.cpp index 9e1927f..1385409 100644 --- a/2. Bai217/Source.cpp +++ b/2. Bai217/Source.cpp @@ -1,8 +1,138 @@ #include +#include +#include using namespace std; +struct Ngay +{ + int Ngay; + int Thang; + int Nam; +}; +typedef struct Ngay NGAY; + +void Nhap(NGAY&); +void Xuat(NGAY); + +void Nhap(NGAY[], int&); + +int ktNhuan(NGAY); +int SoNgayToiDaTrongThang(NGAY); +int SoThuTuTrongNam(NGAY); +int SoNgayToiDaTrongNam(NGAY); +int SoThuTu(NGAY); +int KhoangCach(NGAY, NGAY); +void XaNhauNhat(NGAY[], int, NGAY&, NGAY&); + int main() { + NGAY a[100]; + int n; + cout << "Nhap cac ngay: "; + Nhap(a, n); + + NGAY x, y; + XaNhauNhat(a, n, x, y); + cout << "\nHai ngay Xa nhau nhat la: "; + cout << "\nNgay thu nhat: "; + Xuat(x); + cout << "\nNgay thu hai: "; + Xuat(y); return 0; +} + +void Nhap(NGAY& x) +{ + cout << "\nNhap ngay:"; + cin >> x.Ngay; + cout << "Nhap thang:"; + cin >> x.Thang; + cout << "Nhap nam:"; + cin >> x.Nam; +} + +void Nhap(NGAY a[], int& n) +{ + cout << "Nhap so luong ngay: "; + cin >> n; + for (int i = 0; i < n; i++) + { + cout << "\nNhap ngay thu " << i + 1 << ": "; + Nhap(a[i]); + } +} + +void Xuat(NGAY x) +{ + cout << "\nNgay: " << x.Ngay << endl; + cout << "Thang: " << x.Thang << endl; + cout << "Nam: " << x.Nam << endl; +} + +int ktNhuan(NGAY x) +{ + if (x.Nam % 4 == 0 && x.Nam % 100 != 0) + return 1; + if (x.Nam % 400 == 0) + return 1; + return 0; +} + +int SoNgayToiDaTrongThang(NGAY x) +{ + int ngaythang[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + if (ktNhuan(x)) + ngaythang[1] = 29; + return ngaythang[x.Thang - 1]; +} + +int SoThuTuTrongNam(NGAY x) +{ + int stt = 0; + for (int i = 1; i <= x.Thang - 1; i++) + { + NGAY temp = { 1, i, x.Nam }; + stt += SoNgayToiDaTrongThang(temp); + } + return (stt + x.Ngay); +} + +int SoNgayToiDaTrongNam(NGAY x) +{ + if (ktNhuan(x)) + return 366; + return 365; +} + +int SoThuTu(NGAY x) +{ + int stt = 0; + for (int i = 1; i <= x.Nam - 1; i++) + { + NGAY temp = { 1, 1, i }; + stt = stt + SoNgayToiDaTrongNam(temp); + } + return (stt + SoThuTuTrongNam(x)); +} + +int KhoangCach(NGAY x, NGAY y) +{ + int a = SoThuTu(x); + int b = SoThuTu(y); + return abs(a - b); +} + +void XaNhauNhat(NGAY a[], int n, NGAY& x, NGAY& y) +{ + x = a[0]; + y = a[1]; + for (int i = 0; i <= n - 2; i++) + for (int j = i + 1; j <= n - 1; j++) + if (KhoangCach(a[i], a[j]) > + KhoangCach(x, y)) + { + x = a[i]; + y = a[j]; + } } \ No newline at end of file diff --git a/2. Bai222/Source.cpp b/2. Bai222/Source.cpp index 9e1927f..82ffdd2 100644 --- a/2. Bai222/Source.cpp +++ b/2. Bai222/Source.cpp @@ -1,8 +1,79 @@ #include using namespace std; +struct diem +{ + float x; + float y; +}; +typedef struct diem DIEM; + +void Nhap(DIEM&); +void Nhap(DIEM[][100], int&, int&); +int DemKhongTrung(DIEM a[][100], int m, int n); +int ktTrung(DIEM, DIEM); +int TanSuat(DIEM[][100], int, int, DIEM); + int main() { + DIEM a[100][100]; + int m, n; + cout << "Nhap ma tran cac diem:" << endl; + Nhap(a, m, n); + + int kq = DemKhongTrung(a,m,n); + cout << "\nSo Luong Diem Khong Trung La:" << kq; + + return 0; +} + +void Nhap(DIEM& P) +{ + cout << "Nhap x: "; + cin >> P.x; + cout << "Nhap y: "; + cin >> P.y; +} +void Nhap(DIEM a[][100], int& m, int& n) +{ + cout << "Nhap so dong: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + int k = 1; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + { + cout << "\nNhap diem thu " << k++ << ": "; + Nhap(a[i][j]); + } +} + +int ktTrung(DIEM P, DIEM Q) +{ + if (P.x == Q.x && P.y == Q.y) + return 1; return 0; -} \ No newline at end of file +} + +int TanSuat(DIEM a[][100], int m, int n, DIEM P) + +{ + int dem = 0; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + if (ktTrung(a[i][j], P)) + dem++; + return dem; +} + +int DemKhongTrung(DIEM a[][100], int m, int n) +{ + int dem = 0; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + if (TanSuat(a, m, n, a[i][j]) == 1) + dem++; + return dem; +} diff --git a/2. Bai227/Source.cpp b/2. Bai227/Source.cpp index 9e1927f..a71928e 100644 --- a/2. Bai227/Source.cpp +++ b/2. Bai227/Source.cpp @@ -1,8 +1,63 @@ #include using namespace std; -int main() +struct PhanSo { + int Tu; + int Mau; +}; +typedef struct PhanSo PHANSO; + +void Nhap(PHANSO&); +void Nhap(PHANSO[][100], int&, int&); +void Xuat(PHANSO); +void Xuat(PHANSO[][100], int, int); + +int main() +{ + PHANSO a[100][100]; + int m, n; + Nhap(a, m, n); + Xuat(a, m, n); return 0; +} + +void Nhap(PHANSO& x) +{ + cout << "\nNhap Tu:"; + cin >> x.Tu; + cout << "Nhap Mau:"; + cin >> x.Mau; +} + +void Nhap(PHANSO a[][100], int& m, int& n) +{ + cout << "Nhap so hang: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + { + cout << "Nhap a[" << i << "][" << j << "]:\n"; + Nhap(a[i][j]); + } +} + + +void Xuat(PHANSO x) +{ + cout << x.Tu << "/" << x.Mau << endl; +} + +void Xuat(PHANSO a[][100], int m, int n) +{ + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + { + cout << "a[" << i << "][" << j << "]:"; + Xuat(a[i][j]); + cout << endl; + } } \ No newline at end of file diff --git a/2. Bai232/Source.cpp b/2. Bai232/Source.cpp index 9e1927f..b98a73e 100644 --- a/2. Bai232/Source.cpp +++ b/2. Bai232/Source.cpp @@ -1,8 +1,113 @@ #include +#include + using namespace std; +struct PhanSo +{ + int Tu; + int Mau; +}; +typedef struct PhanSo PHANSO; + +void Nhap(PHANSO&); +void Nhap(PHANSO[][100], int&, int&); + +void Xuat(PHANSO); +void Xuat(PHANSO[], int); +void Xuat(PHANSO[][100], int, int); + +void HoanVi(PHANSO&, PHANSO&); +void SapTang(PHANSO[][100], int, int); + + int main() { + PHANSO a[100][100]; + int m, n; + Nhap(a, m, n); + SapTang(a, m, n); + Xuat(a, m, n); + return 0; +} + +void Nhap(PHANSO& x) +{ + cout << "\nNhap Tu:"; + cin >> x.Tu; + cout << "Nhap Mau:"; + cin >> x.Mau; +} + +void Nhap(PHANSO a[][100], int& m, int& n) +{ + cout << "Nhap so hang: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + { + cout << "Nhap a[" << i << "][" << j << "]:\n"; + Nhap(a[i][j]); + } +} + + +void Xuat(PHANSO x) +{ + cout<< setw(5); + cout << x.Tu << "/" << x.Mau ; +} + +void Xuat(PHANSO a[], int n) +{ + for (int i = 0; i < n; i++) + { + cout << "\na[" << i << "] = "; + Xuat(a[i]); + } +} + +void Xuat(PHANSO a[][100], int m, int n) +{ + for (int i = 0; i < m; i++) + { + cout << endl; + for (int j = 0; j < n; j++) + { + Xuat(a[i][j]); + + } + } +} + +void HoanVi(PHANSO& a, PHANSO& b) +{ + PHANSO temp{}; + temp = a; + a = b; + b = temp; +} + +int SoSanh(PHANSO a, PHANSO b) +{ + float m = (float)a.Tu / a.Mau; + float n = (float)b.Tu / b.Mau; + if (m > n) + return 1; + if (m < n) + return -1; return 0; -} \ No newline at end of file +} + +void SapTang(PHANSO a[][100], int m, int n) +{ + for (int i = 0; i <= m * n - 2; i++) + for (int j = i + 1; j <= m * n - 1; j++) + if (SoSanh(a[i / n][i % n], + a[j / n][j % n]) == 1) + HoanVi(a[i / n][i % n], a[j / n][j % n]); +} + diff --git a/2. Bai237/Source.cpp b/2. Bai237/Source.cpp index 9e1927f..0c2191a 100644 --- a/2. Bai237/Source.cpp +++ b/2. Bai237/Source.cpp @@ -1,8 +1,72 @@ #include using namespace std; +struct SoPhuc +{ + float Thuc; + float Ao; +}; +typedef struct SoPhuc SOPHUC; + +void Nhap(SOPHUC&); +void Nhap(SOPHUC[][100], int&, int&); +void Xuat(SOPHUC); + +SOPHUC ThucAoAmCuoi(SOPHUC[][100], int, int); + int main() { + SOPHUC a[100][100]; + int m, n; + cout << "Nhap ma tran cac so phuc:" << endl; + Nhap(a, m, n); + + SOPHUC kq = ThucAoAmCuoi(a, m, n); + + if (kq.Thuc == 0 && kq.Ao == 0) + cout << "Khong co so phuc co phan thuc & phan ao am" << endl; + else + { + cout << "\nSo phuc co phan thuc & phan ao am cuoi cung la: "; + Xuat(kq); + } return 0; +} + +void Nhap(SOPHUC& x) +{ + cout << "\nNhap thuc: "; + cin >> x.Thuc; + cout << "Nhap ao: "; + cin >> x.Ao; +} + +void Nhap(SOPHUC a[][100], int& m, int& n) +{ + cout << "Nhap so hang: "; + cin >> m; + cout << "Nhap so cot: "; + cin >> n; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + { + cout << "\nNhap so phuc thu a[" << i << "][" << j << "]: "; + Nhap(a[i][j]); + } +} + +void Xuat(SOPHUC x) +{ + cout << "\nThuc: " << x.Thuc; + cout << "\nAo: " << x.Ao; +} + +SOPHUC ThucAoAmCuoi(SOPHUC a[][100], int m, int n) +{ + for (int i = m-1; i >=0; i--) + for (int j = n-1; j >=0; j--) + if (a[i][j].Thuc < 0 && a[i][j].Ao < 0) + return a[i][j]; + return { 0, 0 }; } \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 9f880a4..1df7121 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,7 +13,7 @@ [![GitHub contributors](https://img.shields.io/github/contributors/NMLT-NTTMK-K18/5-258-struct?style=for-the-badge&color=FBF0B2)](../../../graphs/contributors) [![CodeFactor](https://img.shields.io/codefactor/grade/github/nmlt-nttmk-k18/5-258-struct?style=for-the-badge)](https://www.codefactor.io/repository/github/nmlt-nttmk-k18/5-258-struct) -[![WorkedProject Badge](https://img.shields.io/badge/progress-234%20%2F%20258-82A0D8?style=for-the-badge)](./UnworkedProject.md) +[![WorkedProject Badge](https://img.shields.io/badge/progress-256%20%2F%20258-82A0D8?style=for-the-badge)](./UnworkedProject.md) [![RAR Source](https://img.shields.io/badge/rar_source-download-FF8080?style=for-the-badge)](../../../releases/download/RAR/23520161_23520730_23520623_23521049_23521734_BT05.rar/) [![TXT Github Link](https://img.shields.io/badge/txt_github_link-download-8CB369?style=for-the-badge)](../../../releases/download/RAR/23520161_23520730_23520623_23521049_23521734_BT05.txt/) diff --git a/docs/UnworkedProject.md b/docs/UnworkedProject.md index d748aa8..130c792 100644 --- a/docs/UnworkedProject.md +++ b/docs/UnworkedProject.md @@ -3,27 +3,5 @@ List các file `Source.cpp` chưa làm: -1. [2. Bai132](../2.%20Bai132/Source.cpp) -2. [2. Bai137](../2.%20Bai137/Source.cpp) -3. [2. Bai142](../2.%20Bai142/Source.cpp) -4. [2. Bai147](../2.%20Bai147/Source.cpp) -5. [2. Bai152](../2.%20Bai152/Source.cpp) -6. [2. Bai157](../2.%20Bai157/Source.cpp) -7. [2. Bai162](../2.%20Bai162/Source.cpp) -8. [2. Bai163](../2.%20Bai163/Source.cpp) -9. [2. Bai167](../2.%20Bai167/Source.cpp) -10. [2. Bai172](../2.%20Bai172/Source.cpp) -11. [2. Bai177](../2.%20Bai177/Source.cpp) -12. [2. Bai182](../2.%20Bai182/Source.cpp) -13. [2. Bai187](../2.%20Bai187/Source.cpp) -14. [2. Bai192](../2.%20Bai192/Source.cpp) -15. [2. Bai197](../2.%20Bai197/Source.cpp) -16. [2. Bai202](../2.%20Bai202/Source.cpp) -17. [2. Bai204](../2.%20Bai204/Source.cpp) -18. [2. Bai207](../2.%20Bai207/Source.cpp) -19. [2. Bai212](../2.%20Bai212/Source.cpp) -20. [2. Bai217](../2.%20Bai217/Source.cpp) -21. [2. Bai222](../2.%20Bai222/Source.cpp) -22. [2. Bai227](../2.%20Bai227/Source.cpp) -23. [2. Bai232](../2.%20Bai232/Source.cpp) -24. [2. Bai237](../2.%20Bai237/Source.cpp) +1. [2. Bai163](../2.%20Bai163/Source.cpp) +2. [2. Bai204](../2.%20Bai204/Source.cpp)