You are on page 1of 4

Bài 9.

1:
using System;

namespace QuanlySinhVien
{
struct SinhVien
{
public string HoTen;
public float Diem1;
public float Diem2;
public float TinhDiemTB()
{
return (Diem1 + Diem2) / 2;
}
}
class Program
{
static void Main(string[] args)
{
Console.Write("Nhap so luong sinh vien trong lop: ");
int slsv = int.Parse(Console.ReadLine());
SinhVien[] sv = new SinhVien[slsv];
for (int i = 0; i < slsv; i++)
{
Console.WriteLine($"\nNhap thong tin cua sinh vien thu {i + 1}:");
Console.Write("Hp va ten: ");
sv[i].HoTen = Console.ReadLine();
Console.Write("Điem hoc ky 1: ");
sv[i].Diem1 = float.Parse(Console.ReadLine());
Console.Write("Điem hoc ky 2: ");
sv[i].Diem2 = float.Parse(Console.ReadLine());
}
Console.WriteLine("\nDanh sach hoc sinh co hoc luc yeu: ");
foreach (var sinhvien in sv)
{
float DiemTB = sinhvien.TinhDiemTB();
if (DiemTB < 5)
{
Console.WriteLine($"Ho va ten: {sinhvien.HoTen}, Diem trung binh: {DiemTB}");
}
}
Console.ReadLine();
}
}
}
Bài 9.2:
using System;
namespace QuanLyBenhNhan
{
public struct BenhNhan
{
public int MaBN;
public string HoTen;
public string Lydo;
}
class Progam
{
static void Main(string[] args)
{
Console.WriteLine("Nhap so luong benh nhan: ");
int slbn = int.Parse(Console.ReadLine());
BenhNhan[] benhnhan = new BenhNhan[slbn];
for (int i = 0; i < slbn;i++)
{
Console.WriteLine("Nhap thong tin cua benh nhan thu {i+1}: ");
Console.Write("Nhap ma benh nhan: ");
benhnhan[i].MaBN = int.Parse(Console.ReadLine());
Console.Write("Ho va ten: ");
benhnhan[i].HoTen = Console.ReadLine();
Console.Write("Ly do kham benh: ");
benhnhan[i].Lydo = Console.ReadLine();
}
}
}
}

Bài 9.3:
using System;

struct MyPham
{
public string Ten, Loai, Hang;
public int MaMau, sl;
public double GiaTien;
public DateTime HSD;
}

class Program
{
static void Main(string[] args)
{
int slmax = 100;
MyPham[] danhSachMyPham = new MyPham[slmax];
int slsp = 0;
Console.WriteLine("Nhap danh sach my pham");
while (true)
{
Console.WriteLine($"Nhap thong tin cho san pham thu {slsp + 1}");
Console.Write("Ten: ");
string ten = Console.ReadLine();
Console.Write("Loai: ");
string Loai = Console.ReadLine();
Console.Write("Hang: ");
string hang = Console.ReadLine();
Console.Write("Ma mau: ");
int Ma = int.Parse(Console.ReadLine());
Console.Write("So Luong: ");
int soLuong = Convert.ToInt32(Console.ReadLine());
Console.Write("Gia tien: ");
double giaTien = Convert.ToDouble(Console.ReadLine());
Console.Write("Han su dung (dd/MM/yyyy): ");
DateTime hanSuDung = DateTime.ParseExact(Console.ReadLine(), "dd/MM/yyyy", null);
danhSachMyPham[slsp].Ten = ten;
danhSachMyPham[slsp].Loai = Loai;
danhSachMyPham[slsp].Hang = hang;
danhSachMyPham[slsp].MaMau = Ma;
danhSachMyPham[slsp].sl= soLuong;
danhSachMyPham[slsp].GiaTien = giaTien;
danhSachMyPham[slsp].HSD = hanSuDung;
slsp++;
break;
}
Console.WriteLine("\nDanh sach my pham: ");
int i;
Console.WriteLine("Ten\t\tLoai\tHang \tHang \tMa mau \tSo luong \tGia tien \tHSD ");
for (i = 0; i < slsp; i++)
{
Console.WriteLine("{0}\t\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7} ", danhSachMyPham[slsp].Ten,
danhSachMyPham[slsp].Loai, danhSachMyPham[slsp].Hang, danhSachMyPham[slsp].MaMau,
danhSachMyPham[slsp].sl, danhSachMyPham[slsp].GiaTien, danhSachMyPham[slsp].HSD);
}
}
}

You might also like