This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/NMLT-NTTMK-K18/5-258-struct
- Loading branch information
Showing
8 changed files
with
366 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
#include <iostream> | ||
using namespace std; | ||
struct DaThuc | ||
{ | ||
float a[100]; | ||
int n; | ||
}; | ||
typedef struct DaThuc DATHUC; | ||
|
||
void Nhap(DATHUC &); | ||
void Xuat(DATHUC); | ||
|
||
int main() | ||
{ | ||
DATHUC P; | ||
Nhap(P); | ||
Xuat(P); | ||
|
||
return 0; | ||
} | ||
|
||
void Nhap(DaThuc &P) | ||
{ | ||
cout << "Nhap bac da thuc: "; | ||
cin >> P.n; | ||
for (int i = 0; i <= P.n; i++) | ||
{ | ||
cout << "Nhap he so a[" << i << "]: "; | ||
cin >> P.a[i]; | ||
} | ||
} | ||
|
||
void Xuat(DATHUC P) | ||
{ | ||
cout << "\nDa thuc: "; | ||
for (int i = 0; i <= P.n; i++) | ||
cout << P.a[i] << "x^" << i << " + "; | ||
cout << "\b\b\b "; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,54 @@ | ||
#include <iostream> | ||
using namespace std; | ||
struct DaThuc | ||
{ | ||
float a[100]; | ||
int n; | ||
}; | ||
typedef struct DaThuc DATHUC; | ||
|
||
void Nhap(DATHUC &); | ||
void Xuat(DATHUC); | ||
DATHUC operator+(DATHUC, DATHUC); | ||
|
||
int main() | ||
{ | ||
DATHUC P; | ||
Nhap(P); | ||
|
||
DATHUC Q; | ||
Nhap(Q); | ||
|
||
DATHUC R = P + Q; | ||
Xuat(R); | ||
|
||
return 0; | ||
} | ||
|
||
void Nhap(DaThuc &P) | ||
{ | ||
cout << "Nhap bac da thuc: "; | ||
cin >> P.n; | ||
for (int i = 0; i <= P.n; i++) | ||
{ | ||
cout << "Nhap he so a[" << i << "]: "; | ||
cin >> P.a[i]; | ||
} | ||
} | ||
|
||
void Xuat(DATHUC P) | ||
{ | ||
cout << "\nDa thuc: "; | ||
for (int i = 0; i <= P.n; i++) | ||
cout << P.a[i] << "x^" << i << " + "; | ||
cout << "\b\b\b "; | ||
} | ||
|
||
DATHUC operator+(DATHUC P, DATHUC Q) | ||
{ | ||
DATHUC temp; | ||
temp.n = (P.n > Q.n) ? P.n : Q.n; | ||
for (int i = 0; i <= temp.n; i++) | ||
temp.a[i] = P.a[i] + Q.a[i]; | ||
return temp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,48 @@ | ||
//not done | ||
#include <iostream> | ||
using namespace std; | ||
|
||
struct Diem | ||
{ | ||
float x; | ||
float y; | ||
}; | ||
typedef struct Diem DIEM; | ||
|
||
void Nhap(DIEM&); | ||
void Nhap(DIEM[], int&); | ||
void Xuat(DIEM); | ||
|
||
int main() | ||
{ | ||
int n; | ||
DIEM a[100]; | ||
Nhap(a, n); | ||
|
||
return 0; | ||
} | ||
} | ||
|
||
void Nhap(DIEM& P) | ||
{ | ||
cout << "Nhap x: "; | ||
cin >> P.x; | ||
cout << "Nhap y: "; | ||
cin >> P.y; | ||
} | ||
|
||
void Nhap(DIEM a[], int& n) | ||
{ | ||
cout << "Nhap so diem: "; | ||
cin >> n; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
cout << "Nhap diem " << i + 1 << ": " << endl; | ||
Nhap(a[i]); | ||
} | ||
} | ||
|
||
void Xuat(DIEM P) | ||
{ | ||
cout << "x = " << P.x << endl; | ||
cout << "y = " << P.y; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,126 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
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&); | ||
void Xuat(DIEM); | ||
float KhoangCach(DIEM, DIEM); | ||
int TuongDoi(DUONGTRON, DUONGTRON); | ||
bool ktDoiMotCatNhau(DUONGTRON[], int); | ||
DIEM TrungBinhTamDuongTron(DUONGTRON[], int); | ||
void DiemThuocTatCa(DUONGTRON[], int); | ||
|
||
int main() | ||
{ | ||
int n; | ||
DUONGTRON a[100]; | ||
Nhap(a, n); | ||
DiemThuocTatCa(a, n); | ||
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: " << endl; | ||
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 << "]:" << endl; | ||
Nhap(a[i]); | ||
} | ||
} | ||
|
||
void Xuat(DIEM P) | ||
{ | ||
cout << "x = " << P.x << endl; | ||
cout << "y = " << P.y; | ||
} | ||
|
||
float KhoangCach(DIEM P, DIEM Q) | ||
{ | ||
return sqrt((Q.x - P.x) * (Q.x - P.x) + (Q.y - P.y) * (Q.y - P.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 (kc < (c1.r + c2.r) && kc > abs(c1.r - | ||
c2.r)) | ||
return 3; | ||
if (kc == abs(c1.r - c2.r)) | ||
return 4; | ||
return 5; | ||
} | ||
|
||
bool 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; | ||
} | ||
|
||
DIEM TrungBinhTamDuongTron(DUONGTRON a[], int n) | ||
{ | ||
DIEM temp; | ||
temp.x = 0; | ||
temp.y = 0; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
temp.x += a[i].I.x; | ||
temp.y += a[i].I.y; | ||
} | ||
temp.x /= n; | ||
temp.y /= n; | ||
return temp; | ||
} | ||
|
||
void DiemThuocTatCa(DUONGTRON a[], int n) | ||
{ | ||
if (ktDoiMotCatNhau(a, n) == 1) | ||
{ | ||
cout << "Ton tai" << endl; | ||
Xuat(TrungBinhTamDuongTron(a, n)); | ||
} | ||
else | ||
cout << "Khong ton tai"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,88 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
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&); | ||
void Nhap(DIEM[], int&); | ||
void Nhap(DUONGTHANG&); | ||
void Xuat(DIEM); | ||
float KhoangCach(DUONGTHANG, DIEM); | ||
DIEM GanVaKhongThuoc(DUONGTHANG, DIEM[], int); | ||
|
||
int main() | ||
{ | ||
int n; | ||
DIEM a[100]; | ||
DUONGTHANG d; | ||
Nhap(a, n); | ||
Nhap(d); | ||
Xuat(GanVaKhongThuoc(d, a, n)); | ||
return 0; | ||
} | ||
|
||
void Nhap(DIEM& P) | ||
{ | ||
cout << "Nhap x: "; | ||
cin >> P.x; | ||
cout << "Nhap y: "; | ||
cin >> P.y; | ||
} | ||
|
||
void Nhap(DIEM a[], int& n) | ||
{ | ||
cout << "Nhap so luong diem: "; | ||
cin >> n; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
cout << "Nhap diem " << i + 1 << ": " << endl; | ||
Nhap(a[i]); | ||
} | ||
} | ||
|
||
void Nhap(DUONGTHANG& d) | ||
{ | ||
cout << "Nhap a: "; | ||
cin >> d.a; | ||
cout << "Nhap b: "; | ||
cin >> d.b; | ||
cout << "Nhap c: "; | ||
cin >> d.c; | ||
} | ||
|
||
void Xuat(DIEM P) | ||
{ | ||
cout << "x: " << P.x << endl << "y: " << P.y; | ||
} | ||
|
||
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; | ||
} | ||
|
||
DIEM GanVaKhongThuoc(DUONGTHANG d, DIEM a[], int n) | ||
{ | ||
float Min = KhoangCach(d, a[0]); | ||
for (int i = 1; i < n; i++) | ||
if (KhoangCach(d, a[i]) < Min && KhoangCach(d, a[i]) != 0) | ||
Min = KhoangCach(d, a[i]); | ||
for (int i = 0; i < n; i++) | ||
if (KhoangCach(d, a[i]) == Min) | ||
return a[i]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 NMLT - NTTMK - K18 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.