Examination & Test - Lập trình C# - Lập trình C Sharp
1. Tạo 1 lớp giao diện IInfor chứa hàm showInfor
2. Tạo lớp đối tượng People gồm các thuộc tính tên, tuổi, địa chỉ kế thừa từ lớp IInfor
- Tạo hàm input
Tạo lớp Car gồm các thuộc tính tên và màu -> kế thừa từ lớp IInfor
- Tạo hàm input
Viết code cho các lớp trên.
3. Trọng phương thức main của lớp Test tạo 2 đối tượng People và Car.
- tạo phương thức như sau.
public static void showInfor(List<IInfor> a) -> hàm này hiển thị thông tin tất cả đối tượng.
Viết chương trình và sử dụng hàm showInfor trong phương thức main.
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Đường Thanh Bình [T1907A]](https://www.gravatar.com/avatar/c2ef7c316acb82467912bf5677b52a8b.jpg?s=80&d=mm&r=g)
Đường Thanh Bình
2020-05-27 09:35:06
using System;
using System.Collections.Generic;
namespace Examination_Test
{
class Program
{
static void Main(string[] args)
{
List<IInfor> infor = new List<IInfor>();
People people = new People();
people.Input();
infor.Add(people);
Car car = new Car();
car.Input();
infor.Add(car);
foreach (IInfor i in infor)
{
i.ShowInfor();
}
Console.ReadKey();
}
}
}
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections.Generic;
using System.Text;
namespace Examination_Test
{
class People : IInfor
{
public string name { get; set; }
public int age { get; set; }
public string address { get; set; }
public People() { }
public void Input()
{
Console.OutputEncoding = Encoding.UTF8;
Console.Write("Nhâp tên :");
name = Console.ReadLine();
Console.Write("Nhập tuổi : ");
age = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhập địa chỉ : ");
address = Console.ReadLine();
}
public void ShowInfor()
{
Console.WriteLine("Tên : {0}, Tuổi : {1}, Địa chỉ : {2} ", name, age, address);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Examination_Test
{
public interface IInfor
{
void ShowInfor();
}
}
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace Examination_Test
{
class Car : IInfor
{
public string nameCar { get; set; }
public string color { get; set; }
public Car() { }
public void Input()
{
Console.OutputEncoding = Encoding.UTF8;
Console.Write("Tên xe : ");
nameCar = Console.ReadLine();
Console.Write("Màu xe : ");
color = Console.ReadLine();
}
public void ShowInfor()
{
Console.WriteLine("Tên xe : {0}, Màu xe : {1}", nameCar, color);
}
}
}
![Nguyễn Văn Quang [T1907A]](https://www.gravatar.com/avatar/e40ab58e34debd5a0dbf4bcfa90bded0.jpg?s=80&d=mm&r=g)
Nguyễn Văn Quang
2020-05-27 09:34:22
using System;
using System.Collections.Generic;
namespace Examination_Test
{
class Program
{
static void Main(string[] args)
{
People people = new People();
Car car = new Car();
List<IInfor> a = new List<IInfor>();
people.input();
a.Add(people);
car.Input();
a.Add(car);
car.Input();
foreach(IInfor inn in a)
{
inn.ShowIInfor();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Text;
namespace Examination_Test
{
class People : IInfor
{
public string Name { get; set; }
public int Age { get; set; }
public string Address { get; set; }
public People()
{
}
public void input()
{
Console.WriteLine("Nhap ten");
Name = Console.ReadLine();
Console.WriteLine("Nhap tuoi");
Age = Int32.Parse(Console.ReadLine());
Console.WriteLine("Nhap dia chi");
Address = Console.ReadLine();
}
public void ShowInfor()
{
Console.WriteLine("{0},{1},{2},", Name, Age, Address);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Examination_Test
{
class Car : IInfor {
public string Name { get; set; }
public string ColorCar { get; set; }
public Car()
{
}
public void Input()
{
Console.WriteLine("Nhap ten Car");
Console.ReadLine();
Console.WriteLine("Nhap ColorCar");
Console.ReadLine();
}
public void ShowInfor()
{
Console.WriteLine("{0},{1},", Name, ColorCar);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Examination_Test
{
public interface IInfor
{
void ShowIInfor();
}
}
![hoangduyminh [T1907A]](https://www.gravatar.com/avatar/33675cc9fc3762fd323389a179aa047f.jpg?s=80&d=mm&r=g)
hoangduyminh
2020-05-27 09:32:26
using System;
using System.Collections.Generic;
using System.Text;
namespace Examenation
{
class Car : IInfor
{
public Car()
{
}
public string Name { get; set; }
public string Color { get; set; }
public void intput()
{
Console.WriteLine("Nhap vao name:");
Name = Console.ReadLine();
Console.WriteLine("Nhap vao color:");
Color = Console.ReadLine();
}
public void ShowInfor()
{
Console.WriteLine("Name : {0}, Color: {1}", Name, Color);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Examenation
{
public class People: IInfor
{
public string Name { get; set; }
public int Age { get; set; }
public string Address { get; set; }
public People()
{
}
public void input()
{
Console.WriteLine("Nhap vao name:");
Name = Console.ReadLine();
Console.WriteLine("Nhap vao tuoi:");
Age = int.Parse(Console.ReadLine());
Console.WriteLine("Nhap vao dia chi:");
Address = Console.ReadLine();
}
public void ShowInfor()
{
Console.WriteLine("Name : {0}, Tuoi: {1}, Dia Chi: {2}", Name, Age, Address);
}
}
}
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
namespace Examenation
{
class Program
{
static void Main(string[] args)
{
List<IInfor> infors = new List<IInfor>();
People people = new People();
infors.Add(people);
people.input();
Car car = new Car();
infors.Add(car);
car.intput();
foreach (IInfor infor in infors)
{
infor.ShowInfor();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Examenation
{
public interface IInfor
{
void ShowInfor();
}
}
![Luong Dinh Dai [T1907A]](https://www.gravatar.com/avatar/ca08fa4090e1038e541197564747f93c.jpg?s=80&d=mm&r=g)
Luong Dinh Dai
2020-05-27 09:28:46
#Car.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace BT
{
class Car : IInfor
{
public string ten { get; set; }
public string mau { get; set; }
public void input()
{
Console.WriteLine("Nhap ten: ");
ten = Console.ReadLine();
Console.WriteLine("Nhap mau: ");
mau = Console.ReadLine();
}
void IInfor.showInfor()
{
Console.WriteLine("Ten: "+ten+"\nMau: "+mau);
}
}
}
#IInfor.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace BT
{
interface IInfor
{
void showInfor();
}
}
#People.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace BT
{
class People :IInfor
{
public string ten { get; set; }
public string tuoi { get; set; }
public string diachi { get; set; }
public void input()
{
Console.WriteLine("Nhap ten: ");
ten = Console.ReadLine();
Console.WriteLine("Nhap tuoi: ");
tuoi = Console.ReadLine();
Console.WriteLine("Nhap dia chi: ");
diachi = Console.ReadLine();
}
public void showInfor()
{
Console.WriteLine("Ten :"+ten+"\nTuoi: "+tuoi+"\nDia Chi: "+diachi);
}
}
}
#Test.cs
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace BT
{
class Test
{
public static void Main(string[] args)
{
People people = new People();
Car car = new Car();
people.input();
car.input();
List<IInfor> lst = new List<IInfor>();
lst.Add(people);
lst.Add(car);
showInfor(lst);
Console.ReadKey();
}
public static void showInfor(List<IInfor> a)
{
foreach (var item in a)
{
item.showInfor();
}
}
}
}
![lê văn phương [T1907A]](https://www.gravatar.com/avatar/a07ddfb51e1e7189c76b4e42dbdbcddc.jpg?s=80&d=mm&r=g)
lê văn phương
2020-05-27 09:25:20
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace assiment_test
{
class Program
{
static void Main(string[] args)
{
List<IInfor> infor = new List<IInfor>();
People people = new People();
people.Input();
infor.Add(people);
Car car = new Car();
car.Input();
infor.Add(car);
foreach (IInfor i in infor)
{
i.ShowInfor();
}
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace assiment_test
{
public interface IInfor
{
void ShowInfor();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace assiment_test
{
class People : IInfor
{
public string name { get; set; }
public int age { get; set; }
public string address { get; set; }
public People() { }
public void Input()
{
Console.OutputEncoding = Encoding.UTF8;
Console.Write("Nhâp tên :");
name = Console.ReadLine();
Console.Write("Nhập tuổi : ");
age = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhập địa chỉ : ");
address = Console.ReadLine();
}
public void ShowInfor()
{
Console.WriteLine("Tên : {0}, Tuổi : {1}, Địa chỉ : {2} ",name,age,address);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace assiment_test
{
class Car : IInfor
{
public string nameCar { get; set; }
public string color { get; set; }
public Car() { }
public void Input()
{
Console.OutputEncoding = Encoding.UTF8;
Console.Write("Tên xe : ");
nameCar = Console.ReadLine();
Console.Write("Màu xe : ");
color = Console.ReadLine();
}
public void ShowInfor()
{
Console.WriteLine("Tên xe : {0}, Màu xe : {1}", nameCar, color);
}
}
}
![Đỗ Văn Huấn [T1907A]](https://www.gravatar.com/avatar/04c40301dd027839d265b3c3c9dc6e6b.jpg?s=80&d=mm&r=g)
Đỗ Văn Huấn
2020-05-27 09:21:22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BaiTapNgay27_5_2020
{
class Program
{
static void Main(string[] args)
{
List<IInfor> list = new List<IInfor>();
Car car = new Car();
People people = new People();
car.Input();
people.Input();
list.Add(car);
list.Add(people);
showInfor(list);
Console.ReadKey();
}
public static void showInfor(List<IInfor> list)
{
foreach(IInfor o in list)
{
o.ShowInfor();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BaiTapNgay27_5_2020
{
class Car: IInfor
{
protected string NameCar { get; set; }
protected string Color { get; set; }
public void Input()
{
Console.WriteLine("Enter people information: ");
Console.WriteLine("Enter car name: ");
NameCar = Console.ReadLine();
Console.WriteLine("Enter color: ");
Color = Console.ReadLine();
}
public void ShowInfor()
{
Console.WriteLine("Name car: {0}, color: {1}", NameCar,Color);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BaiTapNgay27_5_2020
{
class People : IInfor
{
protected string name { get; set; }
protected int Age { get; set; }
protected string Address { get; set; }
public void Input()
{
Console.WriteLine("Enter people information: ");
Console.WriteLine("Enter name: ");
name = Console.ReadLine();
Console.WriteLine("Enter age: ");
Age = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter address: ");
Address = Console.ReadLine();
}
public void ShowInfor()
{
Console.WriteLine(" name: {0}, age: {1}, address: {2}", name, Age, Address);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BaiTapNgay27_5_2020
{
interface IInfor
{
void ShowInfor();
}
}
![Minh Nghia [T1907A]](https://www.gravatar.com/avatar/ecca255d725eed36a872105205af1b8e.jpg?s=80&d=mm&r=g)
Minh Nghia
2020-05-27 09:21:07
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
namespace Informations
{
class Program
{
static void Main(string[] args)
{
People people = new People();
Car car = new Car();
List<IInfor> a = new List<IInfor>();
people.Input();
a.Add(people);
car.Input();
a.Add(car);
showInfo(a);
}
public static void showInfo(List<IInfor> a)
{
foreach(IInfor infor in a)
{
infor.showInfo();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Informations
{
public interface IInfor
{
void showInfo();
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Informations
{
class People:IInfor
{
public string Name { get; set; }
public int Age { get; set; }
public string Address { get; set; }
public People()
{
}
public void Input()
{
Console.WriteLine("Enter Name :");
Name = Console.ReadLine();
Console.WriteLine("Enter Age :");
Age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Address :");
Address = Console.ReadLine();
}
public void showInfo()
{
Console.WriteLine("Name : {0} , Age : {1} , Address : {2}", Name, Age, Address);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Informations
{
class Car : IInfor
{
public string NameCar { get; set; }
public string Color { get; set; }
public Car() { }
public void Input()
{
Console.WriteLine("Enter Name Car :");
NameCar = Console.ReadLine();
Console.WriteLine("Enter Color :");
Color = Console.ReadLine();
}
public void showInfo()
{
Console.WriteLine("Name Car : {0} , Color : {1}", NameCar, Color);
}
}
}
![Lê Minh Bắc [T1907A]](https://www.gravatar.com/avatar/22abcac77d8ca5e01144e240abb48d22.jpg?s=80&d=mm&r=g)
Lê Minh Bắc
2020-05-27 09:14:03
using System;
using System.Collections.Generic;
namespace Lession7
{
class Test
{
static void Main(string[] args)
{
List<IInfor> a = new List<IInfor>();
People peo = new People();
Car car = new Car();
peo.input();
car.input();
a.Add(peo);
a.Add(car);
showInfor(a);
Console.ReadKey();
}
public static void showInfor(List<IInfor> a)
{
foreach(IInfor e in a )
{
e.showInfor();
}
}
}
}
using System;
namespace Lession7
{
public class People : IInfor
{
public string Name { get; set; }
public int Age { get; set; }
public string Address { get; set; }
public void input()
{
Console.Write("Nhap ten: ");
Name = Console.ReadLine();
Console.Write("Nhap tuoi: ");
Age = Convert.ToInt32(Console.ReadLine());
Console.Write("Nhap dia chi: ");
Address = Console.ReadLine();
}
public void showInfor()
{
Console.WriteLine("People:");
Console.WriteLine("Ten: {0}", Name);
Console.WriteLine("Tuoi: {0}", Age);
Console.WriteLine("Dia chi: {0}", Address);
}
}
}
using System;
namespace Lession7
{
public interface IInfor
{
void showInfor();
}
}
using System;
namespace Lession7
{
class Car : IInfor
{
public string Name { get; set; }
public string Color { get; set; }
public void input()
{
Console.Write("Nhap ten xe: ");
Name = Console.ReadLine();
Console.Write("Nhap mau: ");
Color = Console.ReadLine();
}
public void showInfor()
{
Console.WriteLine("Car:");
Console.WriteLine("Ten: ", Name);
Console.WriteLine("Mau: ", Color);
}
}
}
![nguyễn văn huy [T1907A]](https://www.gravatar.com/avatar/b107d14d7d43c142b68c12c377262371.jpg?s=80&d=mm&r=g)
nguyễn văn huy
2020-05-27 08:59:57
using System;
using System.Collections.Generic;
namespace inteface
{
class Program
{
static void Main(string[] args)
{
People people = new People();
Car car = new Car();
List<IInfor> a = new List<IInfor>();
people.input();
a.Add(people);
car.input();
a.Add(car);
foreach(IInfor inn in a)
{
inn.showInfor();
}
}
}
}
>>>>>>
using System;
using System.Collections.Generic;
using System.Text;
namespace inteface
{
class People : IInfor
{
public string Name { get; set; }
public int Age { get; set; }
public string Address { get; set; }
public People()
{
}
public void input()
{
Console.WriteLine("nhap ten:");
Name = Console.ReadLine();
Console.WriteLine("nhap tuoi:");
Age = Int32.Parse(Console.ReadLine());
Console.WriteLine("nhap dia chi:");
Address = Console.ReadLine();
}
public void showInfor()
{
Console.WriteLine("{0},{1},{2},", Name, Age, Address);
}
}
}
>>>>>
using System;
using System.Collections.Generic;
using System.Text;
namespace inteface
{
public interface IInfor
{
void showInfor();
}
}
>>>>>
using System;
using System.Collections.Generic;
using System.Text;
namespace inteface
{
class Car:IInfor
{
public string Name { get; set; }
public string Mau { get; set; }
public Car()
{
}
public void input()
{
Console.WriteLine("nhap ten:");
Name = Console.ReadLine();
Console.WriteLine("nhap mau:");
Mau = Console.ReadLine();
}
public void showInfor()
{
Console.WriteLine("{0},{1},", Name, Mau);
}
}
}
![thienphu [T1907A]](https://www.gravatar.com/avatar/c4573ea65e411176c1852fd8584f1ab1.jpg?s=80&d=mm&r=g)
thienphu
2020-05-27 08:55:57
#Car.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Examination
{
class Car : IInfor
{
public string Name { get; set; }
public string NameColor { get; set; }
public Car() { }
public void inputCar()
{
Console.WriteLine("input nameCar");
Name = Console.ReadLine();
Console.WriteLine("input nameColor");
NameColor = Console.ReadLine();
}
public void showInfor()
{
Console.WriteLine("NameCar={0},NameColor = {1}",Name,NameColor);
}
}
}
#IInfor.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Examination
{
interface IInfor
{
void showInfor();
}
}
#People.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Examination
{
class People : IInfor
{
public string FullName { get; set; }
public int Age { get; set; }
public string Address { get; set; }
public People() { }
public void inputPeople()
{
Console.WriteLine("Input fullname");
FullName = Console.ReadLine();
Console.WriteLine("Input Age");
Age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Input Address");
Address = Console.ReadLine();
}
public void showInfor()
{
Console.WriteLine("Fullname={0},Age ={1},Address ={2}",FullName,Age,Address);
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace Examination
{
class Program
{
static void Main(string[] args)
{
People people = new People();
Car car = new Car();
people.inputPeople();
car.inputCar();
List<IInfor> list = new List<IInfor>();
list.Add(people);
list.Add(car);
showInfor(list);
Console.ReadKey();
}
public static void showInfor(List<IInfor> a)
{
foreach (var item in a)
{
item.showInfor();
}
}
}
}