0% found this document useful (0 votes)
17 views3 pages

Code t9

The document contains 4 code snippets in Vietnamese: 1. A method that checks if a year is a leap year by checking if the year is divisible by 4, 100, and 400. 2. A method that searches for a character in a character array and returns its index position. 3. A method that calculates housing price based on years of service, marital status, and location. 4. An expanded method for calculating housing price that includes exception handling and an out parameter to return a message string.

Uploaded by

ngocngangnguoc19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Code t9

The document contains 4 code snippets in Vietnamese: 1. A method that checks if a year is a leap year by checking if the year is divisible by 4, 100, and 400. 2. A method that searches for a character in a character array and returns its index position. 3. A method that calculates housing price based on years of service, marital status, and location. 4. An expanded method for calculating housing price that includes exception handling and an out parameter to return a message string.

Uploaded by

ngocngangnguoc19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1/ code năm nhuần

public bool NamNhuan (int nam, out int cachHT)


{
if (nam < 1000 || nam > 10000)
throw new Exception ("loi");
else
{
cachHT = 2020 - nam;
if (nam % 100 == 0)
if (nam % 400 == 0)
return true;
else return false;
else
if (nam % 4 == 0)
return true;
else return false;
}
}

2/ Code vòng lặp

public int isInString(char[] str, char ch)


{
int maxInt = 32767;
int pos = maxInt;
int i = 0;
while (str[i] != '\0')
{
if (str[i]== ch)
{
pos = i;
break;
}
i++;
}
return pos;
}

3/ Code kt

public float DongiaNha(Boolean lapGiaDinh, Boolean diaPhuong, int namCongTac)


{
float donGia = 0;
if (namCongTac < 10)
donGia = 16000;
else
if (namCongTac > 20)
donGia = 10000;
else
if (lapGiaDinh == true && diaPhuong == true)
donGia = 12000;
else
donGia = 14000;
return donGia;
}

4/ Mo rong
// dung cho ngoai le

[TestMethod()]
[ExpectedException(typeof(Exception))]

public void GetTotalItemPriceTest()

// tham so out: trong class

string tBao;

float dgNha = cls.DongiaNhaN(true, true, 12, out tBao);

public float DongiaNhaN(Boolean lapGiaDinh, Boolean diaPhuong, int namCongTac, out string tbao)

if (namCongTac < 0)

throw new Exception("nam cong tac am");

float donGia = 0;

if (namCongTac < 10)

donGia = 16000;

else

if (namCongTac > 20)

donGia = 10000;

else

if (lapGiaDinh == true && diaPhuong == true)

donGia = 12000;

else

donGia = 14000;

tbao = "xong";

return donGia;

You might also like