[ create a new paste ] login | about

Link: http://codepad.org/Ju1OzM62    [ raw code | output | fork ]

C, pasted on Dec 8:
#include<stdio.h>
#include<conio.h>
#include<math.h>
struct Diem
{
	float x;
	float y;
};
typedef struct Diem DIEM;

void NhapDiem(DIEM &);
void XuatDiem(DIEM);

struct DuongTron
{
	DIEM I;
	float R;
};
typedef struct DuongTron DUONGTRON;

void NhapDuongTron(DUONGTRON &);
void XuatDuongTron(DUONGTRON);

float TinhChuViDuongTron(DUONGTRON);
float TinhDienTichHinhTron(DUONGTRON);

float TinhKhoangCachGiua2Diem(DIEM, DIEM);
int XetViTriTuongDoiGiua2DuongTron(DUONGTRON, DUONGTRON);


bool KiemTra1DiemCoNamTrongDuongTron(DUONGTRON, DIEM);
float TinhDienTichPhanGiaoNhauGiua2DuongTron(DUONGTRON, DUONGTRON);

void NhapDiem(DIEM &d)
{
	float temp;
	printf("\nNhap x: ");
	scanf("%f", &temp);
	d.x = temp;

	printf("\nNhap y: ");
	scanf("%f", &temp);
	d.y = temp;
}

void XuatDiem(DIEM d)
{
	printf("(%8.3f, %8.3f)" , d.x, d.y);
}

void NhapDuongTron(DUONGTRON &dt)
{
	float temp;
	NhapDiem(dt.I);
	printf("\nNhap ban kinh: ");
	scanf("%f", &temp);
	dt.R = temp;
}

void XuatDuongTron(DUONGTRON dt)
{
	printf("((%8.3f, %8.3f), %8.3f)", dt.I.x, dt.I.y, dt.R);
}

float TinhChuViDuongTron(DUONGTRON a)
{
	return 2 * PI * a.R;
}
float TinhDienTichHinhTron(DUONGTRON a)
{
	return PI * a.R * a.R;
}

float TinhKhoangCachGiua2Diem(DIEM a, DIEM b)
{
	return sqrt(pow((b.x - a.x), 2) + pow((b.y - a.y), 2));
}

int XetViTriTuongDoiGiua2DuongTron(DUONGTRON a, DUONGTRON b)
{
	int flag;
	float bkLon = (a.R > b.R) ? a.R : b.R;
	float bkNho = (a.R < b.R) ? a.R : b.R;

	float khoangcach2Tam = TinhKhoangCachGiua2Diem(a.I, b.I);
	
	if(khoangcach2Tam > bkLon + bkNho || khoangcach2Tam < bkLon - bkNho || khoangcach2Tam == 0)
	{
		flag = 1;
	}
	else if(khoangcach2Tam == bkLon + bkNho || khoangcach2Tam == bkLon - bkNho)
	{
		flag = 2;
	}
	else if(bkLon - bkNho < khoangcach2Tam && khoangcach2Tam < bkLon + bkNho)
	{
		flag = 3;
	}
	return flag;
}

bool KiemTra1DiemCoNamTrongDuongTron(DUONGTRON a, DIEM b)
{

	float kcachtutamdendiem = sqrt(pow((a.I.x - b.x), 2) + pow((a.I.y - b.y), 2));
	if(kcachtutamdendiem < a.R)
		return true;
	return false;
}

// Câu này chưa test ??
float TinhDienTichPhanGiaoNhauGiua2DuongTron(DUONGTRON a, DUONGTRON b)
{
	float Schung = 0.0;
	int flag = XetViTriTuongDoiGiua2DuongTron(a, b);
	if(flag != 3)
	{
		return -1;
	}
	else
	{
		float d = TinhKhoangCachGiua2Diem(a.I, b.I);

		float R2 = (a.R > b.R) ? a.R : b.R;
		float R1 = (a.R < b.R) ? a.R : b.R;
		float GocABC = cos(d * d + R2 * R2 - R1 * R1 ) / (2 * d * R2);
		float GocCAB = cos(d * d + R1 * R1 - R2 * R2) / (2 * d * R1);

		float alpha = 2 * GocCAB;
		float beta = 2 * GocABC;

		Schung = ((alpha * R1 * R1) / 2) - (1/2 * R1 * R1 * sin(alpha)) + ((beta * R2 * R2) / 2) - (1/2 * R2 * R2 * sin(beta));
		
	}
	return abs(Schung);
}

int main()
{
	DIEM d;
	DUONGTRON a, b;
	NhapDuongTron(a);
	XuatDuongTron(a);

	NhapDuongTron(b);
	XuatDuongTron(b);

	float ChuVi = TinhChuViDuongTron(a);
	printf("\nChu vi duong tron = %.2f", ChuVi);

	float DienTich = TinhDienTichHinhTron(a);
	printf("\nDien tich duong tron = %.2f", DienTich);

	int flag = XetViTriTuongDoiGiua2DuongTron(a, b);
	if(flag == 1)
		printf("\n 2 duong tron khong cat nhau");
	else if(flag == 2)
		printf("\n 2 duong tron tiep xuc nhau");
	else if(flag == 3)
		printf("\n 2 duong tron cat nhau");

	NhapDiem(d);
	XuatDiem(d);
	if (KiemTra1DiemCoNamTrongDuongTron(a, d))
	{
		printf("\nDiem nam trong duong tron");
	}
	else
	{
	printf("\nDiem nam ngoai duong tron");
	}

	float S = TinhDienTichPhanGiaoNhauGiua2DuongTron(a, b);
	printf("\nS = %f", S);
	getch();
	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Line 17: error: conio.h: No such file or directory
Line 11: error: expected ';', ',' or ')' before '&' token
Line 21: error: expected ';', ',' or ')' before '&' token
Line 31: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'KiemTra1DiemCoNamTrongDuongTron'
Line 34: error: expected ';', ',' or ')' before '&' token
Line 51: error: expected ';', ',' or ')' before '&' token
In function 'TinhChuViDuongTron':
Line 67: error: 'PI' undeclared (first use in this function)
Line 67: error: (Each undeclared identifier is reported only once
Line 67: error: for each function it appears in.)
In function 'TinhDienTichHinhTron':
Line 71: error: 'PI' undeclared (first use in this function)
t.c: At top level:
Line 102: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'KiemTra1DiemCoNamTrongDuongTron'


Create a new paste based on this one


Comments: