Advertisement
Guest User

Trinh cute

a guest
Apr 5th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.                    
  4. public class Program
  5. {
  6.     class CongDan {
  7.         String Hoten;
  8.         public int Tuoi;
  9.         String Diachi;
  10.         int Nhietdo;
  11.        
  12.         public CongDan(String Hoten, int Tuoi, String Diachi, int Nhietdo) {
  13.             this.Hoten = Hoten;
  14.             this.Tuoi = Tuoi;
  15.             this.Diachi = Diachi;
  16.             this.Nhietdo = Nhietdo;
  17.         }
  18.        
  19.         public bool kiemtra() {
  20.             return this.Nhietdo > 37;
  21.         }
  22.        
  23.         public void thongtin() {
  24.             Console.WriteLine("Cong dan: " + this.Hoten + "\nTuoi: " + this.Tuoi + "\nDia chi: " + this.Diachi + "\nNhiet do: " + this.Nhietdo);
  25.         }
  26.        
  27.     }
  28.    
  29.     public static void Main()
  30.     {
  31.         List<CongDan> Danhsach = new List<CongDan>();
  32.         Console.WriteLine("Nhap lieu");
  33.         Console.WriteLine("==================");
  34.         for (int i = 0; i < 100; i++) {
  35.             Console.WriteLine("Cong dan " + (i+1) + ":");
  36.             Console.Write("Ho va ten: ");
  37.             String Hoten = Console.ReadLine();
  38.             Console.Write("Tuoi: ");
  39.             int Tuoi = Convert.ToInt32(Console.ReadLine());
  40.             Console.Write("Dia chi: ");
  41.             String Diachi = Console.ReadLine();
  42.             Console.Write("Nhiet do: ");
  43.             int Nhietdo = Convert.ToInt32(Console.ReadLine());
  44.             CongDan Congdan = new CongDan(Hoten, Tuoi, Diachi, Nhietdo);
  45.             Danhsach.Add(Congdan);
  46.             Console.WriteLine();
  47.         }
  48.        
  49.         bool hasValue = false;
  50.         Console.WriteLine("==================");
  51.         Console.WriteLine();
  52.         Console.WriteLine("Danh sach cong dan co nhiet do tren 37 do:");
  53.         foreach (CongDan Congdan in Danhsach) {
  54.             if (Congdan.kiemtra()) {
  55.                 Congdan.thongtin();
  56.                 hasValue = true;
  57.             }
  58.         }
  59.         if (!hasValue) {
  60.             Console.WriteLine("Khong co cong dan nao");
  61.         }
  62.    
  63.         hasValue = false;
  64.         Console.WriteLine("==================");
  65.         Console.WriteLine();
  66.         Console.WriteLine("Danh sach cong dan tren 35 tuoi:");
  67.  
  68.         foreach (CongDan Congdan in Danhsach) {
  69.             if (Congdan.Tuoi > 35) {
  70.                 hasValue = true;
  71.                 Congdan.thongtin();
  72.             }
  73.         }
  74.        
  75.         if (!hasValue) {
  76.             Console.WriteLine("Khong co cong dan nao");
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement