bài tập nộp môn lâp trình.net1 - Pdf 21

using System; bài thực hành1 (sơ đồ lớp bài 1)
using System.Collections.Generic;
using System.Linq;
using System.Text; bài1
namespace Bai_1
{
class Program
{
static void Main(string[] args)
{
Employee a = new Employee();
a.Input();
a.Display();
}
}
class Employee
{
int id;
string name;
int yearOfBirth;
double salaryLevel, basicSalary;
public static int _id = 1;
//public static double _basicSalary;
public Employee() { this.id = _id; _id++; }
public void getId()
{
this.id = _id; HỌ TÊN:VŨ XUÂN TRƯỜNG
LỚP :51TH1
} MSSV :51131780
public void getName(string name) ĐẠI HỌC NHA TRANG
{

{
name = Console.ReadLine();
yearOfBirth = int.Parse(Console.ReadLine());
salaryLevel = Convert.ToDouble(Console.ReadLine());
basicSalary = Convert.ToDouble(Console.ReadLine());
}
public void Display()
{
Console.WriteLine(id + " " + name + " " + yearOfBirth + " " +
basicSalary + " " + getIncome());
}
public void GetLevel(double level)
{
this.salaryLevel = level;
}
public void GetBasic(double basic)
{
this.basicSalary = basic;
}

}
}
Bài 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai_2
{
class Program

if (posTop == 0) return true;
return false;
}
public bool IsFull()
{
if (posTop == size) return true;
return false;
}
public void Push(int x)
{
if (IsFull()) return;
ST[posTop++] = x;
}
public int Pop()
{
if (IsEmpty()) return int.MinValue;
return ST[ posTop];
}
}
}
Bài 3
using System;
using System.Collections.Generic;
Class stack
Int[] ST;
Int size,posTop;
Public stack()
Public stack(int size)
Public bool IsEmpty()
Public bool IsFull()

else
{
string s;
if (imag < 0) s = " - ";
else s = " + ";
Console.WriteLine("z = " + real + s + Math.Abs(imag) +
"i");
}
}
public ComPlex Cong(ref ComPlex a)
{
ComPlex tam = new ComPlex();
Class ComPlex NumBer
Double real,imag;
Public Void display()
Public ComPlex Cong(ref
ComPlex a)
Public static ComPlex
operator +(ComPlex
a,ComPlex b)
Public static ComPlex
operator -(ComPlex
a,ComPlex b)
tam.real = real + a.real;
tam.imag = imag + a.imag;
return tam;
}
public static ComPlex operator +(ComPlex a,ComPlex b)
{
ComPlex res = new ComPlex();

Int n;
Int tam;
Int [] st;
Int size,postop;
Public void Nhap()
Public void process()
Public bool IsEmpty()
Public bool IsFull()
Public void push(int x)
Public void hienthi()
}
class chuyen10sang16
{
int n;
stack s = new stack(10);
public void Nhap()
{
n = int.Parse(Console.ReadLine());
}
public void Process()
{
while (n != 0)
{
s.Push(n % 16);
n /= 16;
};
int tam;
string s1 = "";
while (!s.IsEmpty())
{

return false;
}
public void Push(int x)
{
if (IsFull()) return;
ST[posTop++] = x;
}
public int Pop()
{
if (IsEmpty()) return int.MinValue;
return ST[ posTop];
} (sơ đồ lớp bài5)
}
}
Bài 5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PhanSo
{
class Program
{
static void Main(string[] args)
{

PhanSo a = new PhanSo(3,4);
PhanSo b = new PhanSo(1,2);
Console.Write("Phan so thu 1: ");
a.Xuat();

c.Chia(a, b);
c.Xuat();
}
}
class PhanSo:ICloneable
{
int tu, mau;
public PhanSo() { tu = 0; mau = 1; }
public PhanSo(int tu, int mau)
{
if (mau == 0) throw new Exception("Khoi tao khong dung!");
this.tu = tu; this.mau = mau;
}
public void Xuat()
{
Console.WriteLine(tu + "/" + mau);
}
public void Copy(PhanSo a)
{
this.tu = a.tu; this.mau = a.mau;
}
public object Clone()
{
return MemberwiseClone();
}
public int ucln(int a, int b)
{
a = Math.Abs(a); b = Math.Abs(b);
if (b == 0) return a;
return ucln(b, a % b);

return this;
}
public PhanSo Chia(PhanSo a, PhanSo b)
{
this.tu = a.tu * b.mau;
this.mau = a.mau * b.tu;
int tam = ucln(this.tu, this.mau);
this.tu /= tam; this.mau /= tam;
return this;
}
}
}
Bài thực hành số 2
Bài1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai_1
{
class Program
{
static void Main(string[] args)
{
PhanSo a = new PhanSo(3, 5);
PhanSo b = new PhanSo(1, 3);
PhanSo c = new PhanSo();
c = a + b; c.Xuat();
c = a - b; c.Xuat();
c = a * b; c.Xuat();

phanso:ICloneable
Int tu;
Int ucln(int a,int b)
Int mau;
Public Void nhap()
Public Void xuat()
Public Void rutgon()
Public phanso(){}
Public static phanso
operator +(phanso
a,phanso b)
Public static phanso
operator +(phanso a,int
b)
Public static phanso
operator +(int b,phanso
a)
Public static phanso
operator -(phanso
a,phanso b)
Public static phanso
operator -(phanso a,int
b)
Public static phanso
operator -(int b,phanso
a)
public static PhanSo
operator *(PhanSo a,
PhanSo b)
public static PhanSo

public static PhanSo operator +(PhanSo a, PhanSo b)
{
int tu, mau;
mau = a.mau * b.mau;
tu = a.tu * b.mau + b.tu * a.mau;
PhanSo Res = new PhanSo(tu, mau);
return Res;
}
public static PhanSo operator +(PhanSo a, int b)
{
int tu, mau;
mau = a.mau;
tu = a.tu + b * a.mau;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator +(int b, PhanSo a)
{
int tu, mau;
mau = a.mau;
tu = a.tu + b * a.mau;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator -(PhanSo a, PhanSo b)
{
int tu, mau;
mau = a.mau * b.mau;

return Res;
}
public static PhanSo operator *(PhanSo a, int b)
{
int tu, mau;
mau = a.mau;
tu = a.tu * b;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator *(int b, PhanSo a)
{
int tu, mau;
mau = a.mau;
tu = a.tu * b;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator /(PhanSo a, PhanSo b)
{
int tu, mau;
mau = a.mau * b.tu;
tu = a.tu * b.mau;
PhanSo Res = new PhanSo(tu, mau);
Res.RutGon();
return Res;
}
public static PhanSo operator /(PhanSo a, int b)

class Program
{
static void Main(string[] args)
{
QuanLyHocSinh a = new QuanLyHocSinh();
a.Nhap();
a.Xuat();
a.Process();
}
}
class Hocsinh
{
string hoTen;
double dtoan, dly, dhoa;
public Hocsinh() { }
public Hocsinh(string hoTen, double dtoan, double dly, double dhoa)
{
this.hoTen = hoTen; this.dtoan = dtoan; this.dly = dly;
this.dhoa = dhoa;
}
public void Nhap()
{
Console.Write("Nhap ten: ");
hoTen = Console.ReadLine();
Console.Write("Nhap diem toan: ");
dtoan = int.Parse(Console.ReadLine());
Console.Write("Nhap diem ly: ");
dly = int.Parse(Console.ReadLine());
Console.Write("Nhap diem hoa: ");
dhoa = int.Parse(Console.ReadLine());

for (int i = 0; i < number; i++)
{
ds[i] = new Hocsinh();
ds[i].Nhap();
}
}
public void Xuat()
{
Console.WriteLine("Danh sach vua nhap: ");
for (int i = 0; i < number; i++) ds[i].xuat();
}
public void Process()
{
bool ok = false;
for (int i = 0; i < number;i++ )
if (ds[i].TB() < 5) { ok = true; break; }
if (ok == true)
{
Console.WriteLine("Danh Sach thi sinh phai thi lai: ");
Console.WriteLine();
for (int i = 0; i < number; i++)
if (ds[i].TB() < 5)
{
ds[i].xuat();
}
}
else Console.WriteLine("Khong co thi sinh nao phai thi lai!");
}
}
}

Console.Write("Nhap que quan: ");
queQuan = Console.ReadLine();
Console.Write("Nhap he so luong: ");
heSoluong = Convert.ToDouble(Console.ReadLine());
}
public void Hienthi()
{
Console.WriteLine(hoTen + " "+ queQuan + " "+heSoluong+" " +
Luong());
}
public double Luong()
{
return heSoluong * luongCoban;
}
}
class QuanlyNhanvien
{
int number;
NhanVien[] ds;
public void Nhap()
{
Class nhanvien
Class quanlynhanvien
String hoten,quequan;
Double hesoluong{get;set;}
Double luongcoban;
Int number
Public Void nhap()
Public Void hienthi()
Public void hesoluongcaonhat()

for(j=i+1;j<number;j++)
if (ds[i].heSoluong > ds[j].heSoluong)
{
tam = ds[i].heSoluong;
ds[i].heSoluong = ds[j].heSoluong;
ds[j].heSoluong = tam;
}
}
}
}
Bài 4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text (sơ đồ lớp bài4 )
namespace Bai_4
{
class Program
{
static void Main(string[] args)
{
QuanLy a = new QuanLy();
a.Nhap();
a.Xuat();
a.Xuat_LuanVan();
a.Xuat_TotNghiep();
a.Xuat_ThiLai();
}
}
class MonHoc

Public void nhap()
Public void xuat()
Public Double tb()
Public void xuatluanvan()
Public void
xuattotnghiep()
Public void xuatthilai()
public double DiemTB()
{
return diemkiemtra * tylekiemtra + diemthi * (1 - tylekiemtra);
}
}
class HocVien
{
string hoTen;
int namSinh;
MonHoc[] mh;
int number;
public void Nhap()
{
Console.Write("Nhap ho ten: "); hoTen = Console.ReadLine();
Console.Write("Nhap nam sinh: "); namSinh =
int.Parse(Console.ReadLine());
Console.Write("NHap so mon hoc: "); number =
int.Parse(Console.ReadLine());
mh = new MonHoc[number];
for (int i = 0; i < number; i++)
{
mh[i] = new MonHoc();
mh[i].Nhap();

number = int.Parse(Console.ReadLine());
ds = new HocVien[number];
danhDau = new bool[number];
for (int i = 0; i < number; i++)
{
ds[i] = new HocVien();
danhDau[i] = true;
ds[i].Nhap();
}
}
public void Xuat()
{
Console.WriteLine();
for (int i = 0; i < number; i++) ds[i].Xuat();
}
public void Xuat_LuanVan()
{
Console.WriteLine();
Console.WriteLine("Danh sach lam luan van: ");
for (int i = 0; i < number; i++)
if (ds[i].TB() > 7 && ds[i].KT_DiemTB() == true &&
danhDau[i] == true) { ds[i].Xuat(); danhDau[i] = false; }
}
public void Xuat_TotNghiep()
{
Console.WriteLine();
Console.WriteLine("Danh sach thi tot nghiep: ");
for (int i = 0; i < number; i++)
if (ds[i].TB() > 5 && ds[i].KT_DiemTB() == true &&
danhDau[i] == true) { ds[i].Xuat(); danhDau[i] = false; }

// nguoi b copy tu nguoi a qua.
Nguoi b = new Nguoi(a);
b.Xuat();
// Neu nhu ban dua data vao la: Nguoi a = new
Nguoi("a",1991,1.56,198); thi no se nem ngoai le.//
(sơ đồ lớp bài5)
b.ToString();

// thu nghiem
ThuNghiem t = new ThuNghiem();
t.Nhap();
t.HienThi();
t.Hienthi(1.7, 70);
t.Process();
*/
Nguoi a = new Nguoi("dophuchao", 1991, 1.7, 52);
Console.WriteLine(a.ToString());
}
}
class Nguoi
{
public string hoTen{get;set;}
public int namSinh { get; set; }
double chieuCao, trongLuong;
public double ChieuCao
{
get {return chieuCao;}
set
{
if (value < 1.2 || value > 1.8) throw new Exception("Nhap

{
this.hoTen = hoTen; this.namSinh = namSinh; this.chieuCao =
chieuCao; this.trongLuong = trongLuong;
}
public Nguoi(Nguoi toCopy)
{
hoTen = toCopy.hoTen;
namSinh = toCopy.namSinh;
ChieuCao = toCopy.ChieuCao;
TrongLuong = toCopy.TrongLuong;
}
public int TinhTrangSucKhoe()
{
double K;
K = trongLuong / (chieuCao * chieuCao);
if (K < 19) return -1;// yeu
if (K > 25) return 1;// manh
return 0;// binh thuong
}
public static double operator +(Nguoi a, Nguoi b)
{
return a.TrongLuong + b.TrongLuong;
}
public static double operator +(Nguoi a, double b)
{
return a.TrongLuong + b;
}
public static double operator +(double a, Nguoi b)
{
return a + b.TrongLuong;

Console.WriteLine("Danh sach vua nhap: "); Console.WriteLine();
for (int i = 0; i < 5; i++) a[i].Xuat();
}
public void Hienthi(double cc,double tl)
{
Console.WriteLine();
Console.WriteLine("Danh sach chieu cao > " + cc + " va trong
luong > " + tl + " la: "); Console.WriteLine();
for (int i = 0; i < 5; i++)
if(a[i].ChieuCao >= cc && a[i].TrongLuong >=
tl)a[i].Xuat();
}
public void Process()
{
double tam;
Console.WriteLine();
Console.WriteLine("Danh SAch nhung nguoi can tang can de dat
the trang tot: "); Console.WriteLine();
for(int i=0;i<5;i++)
if (a[i].TinhTrangSucKhoe() == -1)
{
tam = (a[i].ChieuCao * a[i].ChieuCao) * 19 -
a[i].TrongLuong;
a[i].Xuat();
Console.WriteLine("So kg phai tang them: " + tam);
}
}
}
}


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status