Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 23 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
23
Dung lượng
180 KB
Nội dung
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 { this.name = name; } public void getYearOfBirth(int year) Class Employee(nhanvien ) Int id String name Int year of birth Double salary level,basic salary Public void get id() Public void get name(string name) Public void get year of birth(int year) Public double get in com() Public void input() Public void display() Public void get level(double level) Public void get basic(double basic) { this.yearOfBirth = year; } public double getIncome() { return salaryLevel * basicSalary; } public void Input() { 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 { static void Main(string[] args) { stack a = new stack(10); a.Push(1); a.Push(112); a.Push(51); a.Push(14); a.Push(21); a.Push(12); while (!a.IsEmpty()) { Console.WriteLine(a.Pop() + " "); } } } (sơ đồ lớp bài 2) class stack { int[] ST; int size, posTop; public stack() { size = 20; ST = new int[size]; posTop = 0; } public stack(int size) { this.size = size; ST = new int[size]; posTop = 0; } public bool IsEmpty() { 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() Public void Push(int x) Public int Pop() using System.Linq; using System.Text; (sơ đồ lớp bài 3) namespace Bai_3 { class Program { static void Main(string[] args) { ComPlex a = new ComPlex(4, -2); ComPlex b = new ComPlex(2,-4); ComPlex c = new ComPlex(); c = a + b; c.Display(); c = a - b; c.Display(); } } class ComPlex { double real, imag; public ComPlex() { } public ComPlex(int real, int imag) { this.real = real; this.imag = imag; } public void Display() { if (imag == 0) Console.WriteLine("z = " + real); 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(); res.real = a.real + b.real; res.imag = a.imag + b.imag; return res; } public static ComPlex operator -(ComPlex a, ComPlex b) { ComPlex res = new ComPlex(); res.real = a.real - b.real; res.imag = a.imag - b.imag; return res; } } } Bài4 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Bai_4 { class Program (sơ đồ lốp bài4) { static void Main(string[] args) { chuyen10sang16 a = new chuyen10sang16(); a.Nhap(); a.Process(); } Class chuyen10sang16 Class stack 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()) { tam = s.Pop(); if(tam > 9)s1+= (char)(tam - 10 + 65); else s1 += (char)(tam + 48); } Console.WriteLine("He 16: " + s1); } } class stack { int[] ST; int size, posTop; public stack() { size = 20; ST = new int[size]; posTop = 0; } public stack(int size) { this.size = size; ST = new int[size]; posTop = 0; } public bool IsEmpty() { 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]; } (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(); Console.Write("Phan so thu 2: "); b.Xuat(); PhanSo c = new PhanSo(); Console.Write("Cong 2 phan so: "); c.Cong(a,b); c.Xuat(); Console.Write("Cong phan so voi (c + 2): "); c.Cong(2); c.Xuat(); Console.Write("Tru 2 phan so: "); c.Tru(a, b); Class phanso:ICloneable Int tu Int mau Public Void xuat() Public Void copy(Phanso a) Public object () Public phanso cong(int a) Public phanso tru(phan so a,phan so b) Public phanso nhan(phan so a,phan so b) Public phanso chia(phan so a,phan so b) c.Xuat(); Console.Write("Nhan 2 phan so: "); c.Nhan(a, b); c.Xuat(); Console.Write("Chia 2 phan so: "); 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); } public PhanSo Cong(PhanSo a, PhanSo b) { this.tu = b.tu * a.mau + b.mau * a.tu; this.mau = b.mau * a.mau; int tam = ucln(this.tu, this.mau); this.tu /= tam; this.mau /= tam; return this; } public PhanSo Cong(int a) { this.tu = this.tu + this.mau * a; int tam = ucln(this.tu, this.mau); this.tu /= tam; this.mau /= tam; return this; } public PhanSo Tru(PhanSo a, PhanSo b) { this.tu = b.mau * a.tu - b.tu * a.mau; this.mau = b.mau * a.mau; int tam = ucln(this.tu, this.mau); this.tu /= tam; this.mau /= tam; return this; } public PhanSo Nhan(PhanSo a, PhanSo b) { this.tu = a.tu * b.tu; this.mau = b.mau * a.mau; int tam = ucln(this.tu, this.mau); this.tu /= tam; this.mau /= tam; 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(); c = a / b; c.Xuat(); c = a + 3; c.Xuat(); c = 4 + b; c.Xuat(); c = a - 2; c.Xuat(); c = 1 - b; c.Xuat(); c = a * 3; c.Xuat(); c = b * 2; c.Xuat(); c = a / 5; c.Xuat(); c = 4 / b; c.Xuat(); PhanSo d = new PhanSo(); d = (PhanSo)a.Clone(); d.Xuat(); (sơ đồ lớp bài 1) } } class PhanSo : ICloneable { int tu, mau; public PhanSo() { } public PhanSo(int tu, int mau) { this.tu = tu; this.mau = mau; } public void Nhap() { do { Console.Write("Nhap tu: "); tu = int.Parse(Console.ReadLine()); Console.Write("Nhap mau: "); Class 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 operator *(PhanSo a, int b) public static PhanSo operator /(PhanSo a, PhanSo b) public static PhanSo operator /(PhanSo a,int b) public static PhanSo operator /(int b, PhanSoa) [...]... operator /(int b, PhanSo a) { int tu, mau; tu = a.mau * b; mau = a.tu; PhanSo Res = new PhanSo(tu, mau); Res.RutGon(); return Res; } public object Clone() { return MemberwiseClone(); } } } (sơ đồ lớp bài 2) Bài 2 Class hoc sinh Class quan ly hoc sinh String hoten Double dtoan,dly,dhoa; Int number; Public void nhap() Public double TB() Public void xuat() Public void process() using using using using System;... } } } } else Console.WriteLine("Khong co thi sinh nao phai thi lai!"); } Bài 3 using using using using System; System.Collections.Generic; System.Linq; System.Text; namespace Bai_3 { class Program { static void Main(string[] args) { QuanlyNhanvien a = new QuanlyNhanvien(); a.Nhap(); a.HienThi(); a.HeSoLuongCaoNhat(); (sơ đồ lớp bài 3) Class nhanvien Class quanlynhanvien String hoten,quequan; Double... for(j=i+1;j ds[j].heSoluong) { tam = ds[i].heSoluong; ds[i].heSoluong = ds[j].heSoluong; ds[j].heSoluong = tam; } } } } Bài 4 using using using using System; System.Collections.Generic; System.Linq; System.Text namespace Bai_4 (sơ đồ lớp bài4 ) { Class monhoc Class hocvien Class quanly String tenmonhoc; Double tylekiemtra; Double diemkiemtra,diemthi; String hoten; Int namsinh;... Xuat_ThiLai() { Console.WriteLine(); Console.WriteLine("Danh sach bi thi lai: "); for (int i = 0; i < number; i++) if (ds[i].KT_DiemTB() == false && danhDau[i] == true) { ds[i].Xuat(); danhDau[i] = false; } } } } Bài 5 using using using using System; System.Collections.Generic; System.Linq; System.Text; namespace Bai_5 { class Program { static void Main(string[] args) { /* Nguoi a = new Nguoi("a", 1991, 1.67, 76);... can: " + tam); // 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.// b.ToString(); (sơ đồ lớp bài5 ) Class nguoi Class thunghiem String hoten{get;set;} Int namsinh{get;set;} Double chieucao,trongluong; Double k; Public void xuat() Public void hienthi() Public nguoi(){} Public int tinhtrangsuckhoe() . 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 { . b.imag; return res; } } } Bài4 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Bai_4 { class Program (sơ đồ lốp bài4 ) { static void Main(string[]. 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