Skip to content

Instantly share code, notes, and snippets.

@hyperion0201
Last active October 5, 2018 01:52
Show Gist options
  • Save hyperion0201/0b5963e6819ae3995580d2e89cc37de4 to your computer and use it in GitHub Desktop.
Save hyperion0201/0b5963e6819ae3995580d2e89cc37de4 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
class Diem
{
public:
void Nhap();
void Xuat();
float khoangCach(Diem b);
private:
int x;
int y;
};
class DuongTron {
private:
Diem I;
float r;
public:
void NhapDuongTron();
void InDuongTron();
float chuVi();
float dienTich();
};
class MangDuongTron {
private:
DuongTron mangdt[10]; // gia su toi da 10 duong tron
int n;
public:
void NhapMangDuongTron();
void InMangDuongTron();
DuongTron chuViNhoNhat();
DuongTron chuViLonNhat();
DuongTron dienTichNhoNhat();
DuongTron dienTichLonNhat();
void SapXepTangTheoChuVi();
void SapXepGiamTheoDienTich();
};
void Diem::Nhap(){
cout << "Nhap x : "; cin >> x;
cout << "Nhap y : "; cin >> y;
}
void Diem::Xuat(){
cout << "Toa do : " << x << "/" << y << endl;
}
float Diem::khoangCach(Diem b){
return 1.0*sqrt((x - b.x)*(x - b.x) + (y - b.y)*(y - b.y));
}
void DuongTron::NhapDuongTron() {
cout << "Nhap tam I : " << endl;
I.Nhap();
cout << "Nhap ban kinh r : "; cin >> r;
}
void DuongTron::InDuongTron(){
cout << "Toa do tam I : " << endl;
I.Xuat();
cout << "Ban kinh r : " << r;
}
float DuongTron::chuVi(){
return 3.14 * 2 * r;
}
float DuongTron::dienTich(){
return 3.14*r*r;
}
void MangDuongTron::NhapMangDuongTron(){
cout << "Nhap so duong tron (<10) : "; cin >> n;
for (int i = 0; i < n; i++) {
cout << "Nhap duong tron thu " << i << ": ";
mangdt[i].NhapDuongTron();
}
}
void MangDuongTron::InMangDuongTron(){
for (int i = 0; i < n; i++) {
cout << "Thong tin duong tron thu " << i << ":" << endl;
mangdt[i].InDuongTron();
}
}
DuongTron MangDuongTron::chuViLonNhat(){
float max = mangdt[0].chuVi();
int maxIndex = 0;
for (int i = 1; i < n; i++) {
if (max < mangdt[i].chuVi()) {
max = mangdt[i].chuVi();
maxIndex = i;
}
}
return mangdt[maxIndex];
}
DuongTron MangDuongTron::chuViNhoNhat(){
float min = mangdt[0].chuVi();
int minIndex = 0;
for (int i = 1; i < n; i++) {
if (min > mangdt[i].chuVi()) {
min = mangdt[i].chuVi();
minIndex = i;
}
}
return mangdt[minIndex];
}
DuongTron MangDuongTron::dienTichLonNhat(){
float max = mangdt[0].dienTich();
int maxIndex = 0;
for (int i = 1; i < n; i++) {
if (max < mangdt[i].dienTich()) {
max = mangdt[i].dienTich();
maxIndex = i;
}
}
return mangdt[maxIndex];
}
DuongTron MangDuongTron::dienTichNhoNhat(){
float min = mangdt[0].dienTich();
int minIndex = 0;
for (int i = 1; i < n; i++) {
if (min > mangdt[i].dienTich()) {
min = mangdt[i].dienTich();
minIndex = i;
}
}
return mangdt[minIndex];
}
void MangDuongTron::SapXepTangTheoChuVi(){
for (int i = 0; i < n - 1; i++) {
for (int j = i; j < n; j++) {
if (mangdt[i].chuVi() > mangdt[j].chuVi()) {
DuongTron temp = mangdt[i];
mangdt[i] = mangdt[j];
mangdt[j] = temp;
}
}
}
}
void MangDuongTron::SapXepGiamTheoDienTich(){
for (int i = 0; i < n - 1; i++) {
for (int j = i; j < n; j++) {
if (mangdt[i].dienTich() < mangdt[j].dienTich()) {
DuongTron temp = mangdt[i];
mangdt[i] = mangdt[j];
mangdt[j] = temp;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment