Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Program
- {
- class CongDan {
- String Hoten;
- public int Tuoi;
- String Diachi;
- int Nhietdo;
- public CongDan(String Hoten, int Tuoi, String Diachi, int Nhietdo) {
- this.Hoten = Hoten;
- this.Tuoi = Tuoi;
- this.Diachi = Diachi;
- this.Nhietdo = Nhietdo;
- }
- public bool kiemtra() {
- return this.Nhietdo > 37;
- }
- public void thongtin() {
- Console.WriteLine("Cong dan: " + this.Hoten + "\nTuoi: " + this.Tuoi + "\nDia chi: " + this.Diachi + "\nNhiet do: " + this.Nhietdo);
- }
- }
- public static void Main()
- {
- List<CongDan> Danhsach = new List<CongDan>();
- Console.WriteLine("Nhap lieu");
- Console.WriteLine("==================");
- for (int i = 0; i < 100; i++) {
- Console.WriteLine("Cong dan " + (i+1) + ":");
- Console.Write("Ho va ten: ");
- String Hoten = Console.ReadLine();
- Console.Write("Tuoi: ");
- int Tuoi = Convert.ToInt32(Console.ReadLine());
- Console.Write("Dia chi: ");
- String Diachi = Console.ReadLine();
- Console.Write("Nhiet do: ");
- int Nhietdo = Convert.ToInt32(Console.ReadLine());
- CongDan Congdan = new CongDan(Hoten, Tuoi, Diachi, Nhietdo);
- Danhsach.Add(Congdan);
- Console.WriteLine();
- }
- bool hasValue = false;
- Console.WriteLine("==================");
- Console.WriteLine();
- Console.WriteLine("Danh sach cong dan co nhiet do tren 37 do:");
- foreach (CongDan Congdan in Danhsach) {
- if (Congdan.kiemtra()) {
- Congdan.thongtin();
- hasValue = true;
- }
- }
- if (!hasValue) {
- Console.WriteLine("Khong co cong dan nao");
- }
- hasValue = false;
- Console.WriteLine("==================");
- Console.WriteLine();
- Console.WriteLine("Danh sach cong dan tren 35 tuoi:");
- foreach (CongDan Congdan in Danhsach) {
- if (Congdan.Tuoi > 35) {
- hasValue = true;
- Congdan.thongtin();
- }
- }
- if (!hasValue) {
- Console.WriteLine("Khong co cong dan nao");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement