Professional Documents
Culture Documents
MSSV: 21200081
Lớp: 21DienTu
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab3_KeThuaDaHinh
{
public class UserInformation
{
private string userName;
private uint userAge;
private uint userID;
private double baseSalary;
public UserInformation(string name, uint age, uint id)
{
UserName = name;
UserAge = age;
UserID = id;
}
public UserInformation(string name, uint age, uint id, double bSalary): this(name, age, id)
{
BaseSalary = bSalary;
}
public double BaseSalary
{
get { return baseSalary; }
1
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
2
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
Code
3
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
Code
4
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab3_KeThuaDaHinh
{
internal class Program
{
static void Swap(UserInformation[] array, int i, int j)
{
UserInformation temp = array[i];
array[i] = array[j];
array[j] = temp;
}
static int Partition(UserInformation[] array, int low, int high)
{
double pivot = array[high].GetSalary();
int i = low - 1;
for (int j = low; j < high; j++)
{
if (array[j].GetSalary() < pivot)
{
i++;
Swap(array, j, i);
}
}
5
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
6
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
Bài 2
Code
7
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab3_KeThuaDaHinh
{
internal class BankAccount
{
private double balance;
private bool isPasswordVerified;
8
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
CheckAccessPermission();
return balance;
}
set
{
CheckAccessPermission();
balance = value;
}
}
// Method to check access permission and throw AccessDeniedException if needed
private void CheckAccessPermission()
{
if (!isPasswordVerified)
{
throw new AccessDeniedException("Access denied: Password verification required.");
}
}
// Method to verify password
public void VerifyPassword(string password)
{
// Simulate password verification process
if (password == "correctpassword")
{
isPasswordVerified = true;
}
else
{
isPasswordVerified = false;
}
}
}
}
9
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
Information
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab3_KeThuaDaHinh
{
public class UserInformation
{
private string userName;
private uint userAge;
private uint userID;
private double baseSalary;
public UserInformation(string name, uint age, uint id, double bSalary) : this(name, age, id)
{
BaseSalary = bSalary;
}
10
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
11
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab3_KeThuaDaHinh
{
public class Program
{
static void Main(string[] args)
{
try
{
BankAccount alexAccount = null;
12
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
GetUserBankAccountInformation(out alexAccount);
Console.WriteLine("Please type in your password");
string password = Console.ReadLine();
alexAccount.VerifyPassword(password);
Console.WriteLine(alexAccount.CalculateInterestMoney());
}
catch (AccessDeniedException)
{
Console.WriteLine("Access denied!");
}
catch (OverflowException ex)
{
Console.WriteLine(ex.StackTrace);
}
catch (UserAccountException ex)
{
Console.WriteLine(ex.Message);
}
// Hiển thị thông điệp và chờ người dùng nhấn một phím bất kỳ trước khi đóng cửa sổ terminal
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
13
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
account.VerifyPassword(password);
}
}
}
14
Báo cáo thực hành – Kỹ thuật lập trình nâng cao
15