By GokiSoft.com|
09:40 01/11/2021|
C Sharp
[Examination] Thi thực hành môn C# - C Sharp
Thời Gian Thi: 14h40 - 15h40
Muộn 1 phút trừ 0.5 điểm
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![vuong huu phu [T2008A]](https://www.gravatar.com/avatar/307a5cf29780afab49706dc8b15b86c6.jpg?s=80&d=mm&r=g)
vuong huu phu
2021-05-31 07:53:54
using System;
using System.Collections;
namespace test
{
class Program
{
static void Main(string[] args)
{
String name;
String phonenumber;
Hashtable hash = new Hashtable();
int lc;
do {
menu();
Console.WriteLine("Nhap su lua chon : ");
lc = Int32.Parse(Console.ReadLine());
switch (lc) {
case 1:
Console.WriteLine("Nhap ten:");
name = Console.ReadLine();
Console.WriteLine("Nhap so dien thoai:");
phonenumber = Console.ReadLine();
hash.Add(name, phonenumber);
break;
case 2:
int c = 0;
Console.WriteLine("Nhap ten can tim :");
String names = Console.ReadLine();
ICollection key1 = hash.Keys;
foreach (String h in key1)
{
if (h == names) {
Console.WriteLine("Ten: " + h + " ,So dien thoai " + hash[h]);
c++;
}
} if (c == 0) {
Console.WriteLine("Khong co ten nay !!!");
}
break;
case 3:
ICollection key = hash.Keys;
foreach (String h in key) {
Console.WriteLine("Ten: " + h + " ,So dien thoai " + hash[h]);
}
break;
case 4:
Console.WriteLine("Thoat!!!!!");
break;
}
} while (lc > 0);
}
public static void menu() {
Console.WriteLine("1. Add new contact");
Console.WriteLine("2. Find a contact by name");
Console.WriteLine("3. Display contacts");
Console.WriteLine("4. Exit");
}
}
}
![Nguyên Phấn Đông [T2008A]](https://www.gravatar.com/avatar/c9c4f8f79ce35b9224637b6cc5fbe5c4.jpg?s=80&d=mm&r=g)
Nguyên Phấn Đông
2021-05-31 07:45:50
#main.cs
using System;
namespace baitest
{
class Test
{
static void Main(string[] args)
{
int choose;
ContactManager contactManager = new ContactManager(); ;
do
{
ShowMenu();
choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
Console.WriteLine("Number contact: ");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
contactManager.Add();
}
break;
case 2:
contactManager.Find();
break;
case 3:
Console.WriteLine("\tAddress Book");
Console.WriteLine("Contact Name\tPhone Number");
contactManager.Display();
break;
case 4:
Environment.Exit(0);
break;
default:
break;
}
} while (choose != 4);
}
static void ShowMenu()
{
Console.WriteLine("1. Add Contact");
Console.WriteLine("2. Find");
Console.WriteLine("3. Display all contact");
Console.WriteLine("4. Exit");
Console.WriteLine("Choose: ");
}
}
}
#program.cs
using System;
namespace baitest
{
public class Contact
{
public string Name { get; set; }
public string Phone { get; set; }
public Contact(string name, string phone)
{
Name = name;
Phone = phone;
}
public Contact()
{
}
public void Input()
{
Console.WriteLine("Input Name: ");
this.Name = Console.ReadLine();
Console.WriteLine("Input Phone: ");
this.Phone = Console.ReadLine();
}
public void Display()
{
Console.WriteLine(Name+"\t"+ Phone);
}
}
}
-------------------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace Project2
{
class ContactManager
{
static Hashtable table;
public ContactManager()
{
table = new Hashtable();
}
public void Add()
{
Contact cont = new Contact();
cont.Input();
table.Add(cont.Name, cont);
}
public void Display()
{
foreach (DictionaryEntry item in table)
{
((Contact)item.Value).Display();
}
}
public void Find()
{
Console.WriteLine("Finding Phonenumber: ");
string phone = Console.ReadLine();
if (table.ContainsKey(phone))
{
((Contact)table[phone]).Display();
}
else
{
Console.WriteLine("Cannot Find");
}
}
}
}
![Trần Văn Lâm [T2008A]](https://www.gravatar.com/avatar/cfc15c8cb7781ad669b013e01f9f1a6b.jpg?s=80&d=mm&r=g)
Trần Văn Lâm
2021-05-31 07:44:58
#ContactManager.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class ContactManager
{
public string ContactName { get; set; }
public string PhoneNumber { get; set; }
public ContactManager()
{
}
public ContactManager(string ContactName, string PhoneNumber)
{
this.ContactName = ContactName;
this.PhoneNumber = PhoneNumber;
}
public void Input()
{
Console.WriteLine("Nhap ten lien he:");
ContactName = Console.ReadLine();
Console.WriteLine("Nhap SDT:");
PhoneNumber = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Ten Lien He : {0}, SDT : {1}", ContactName, PhoneNumber);
}
}
}
#HasdTable.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class HasdTabe
{
static void Main(string[] args)
{
List<ContactManager> managerList = new List<ContactManager>();
int choose;
do
{
showMenu();
choose = Convert.ToInt32(Console.ReadLine());
switch (choose)
{
case 1:
AddContact(managerList);
break;
case 2:
SearchByName(managerList);
break;
case 3:
Display(managerList);
break;
case 4:
Console.WriteLine("Exit!");
break;
default:
Console.WriteLine("Nhap sai!");
break;
}
} while (choose != 6);
}
public static void Display(List<ContactManager> managerList)
{
foreach(ContactManager ctm in managerList)
{
ctm.Display();
}
}
public static void SearchByName(List<ContactManager> managerList)
{
Console.WriteLine("Nhap Ten :");
string name = Console.ReadLine();
int k = 0;
foreach (ContactManager ctm in managerList)
{
if (ctm.ContactName == name)
{
ctm.Display();
k++;
}
}
if (k==0)
{
Console.WriteLine("Khong Thay!");
}
}
public static void AddContact(List<ContactManager> managerList)
{
Console.WriteLine("Them N lien he moi:");
int N = Convert.ToInt32(Console.ReadLine());
for(int i = 0; i < N; i++)
{
ContactManager ctm = new ContactManager();
ctm.Input();
managerList.Add(ctm);
}
}
static void showMenu()
{
Console.WriteLine("1. Add new contact:");
Console.WriteLine("2. Find a contact by name");
Console.WriteLine("3. Display contacts");
Console.WriteLine("4. Exit");
Console.WriteLine("Choose:");
}
}
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2021-05-31 07:35:16
#HashTable.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Bt1564
{
class HashTable
{
public string Name { get; set; }
public string PhoneNumber { get; set; }
public HashTable() { }
public HashTable(string Name, string PhoneNumber)
{
this.Name = Name;
this.PhoneNumber = PhoneNumber;
}
public void input()
{
Console.WriteLine("Nhap Name: ");
Name = Console.ReadLine();
Console.WriteLine("Nhap PhoneNumber: ");
PhoneNumber = Console.ReadLine();
}
public void display()
{
Console.WriteLine("Name: = {0}", Name);
Console.WriteLine("PhoneNumber: = {0}", PhoneNumber);
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace Bt1564
{
class Program
{
static void Main(string[] args)
{
List<HashTable> tablelist = new List<HashTable>();
int choose;
do
{
showMenu();
choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
Console.WriteLine("Nhap so lien he: ");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
HashTable ht = new HashTable();
ht.input();
tablelist.Add(ht);
}
break;
case 2:
Console.WriteLine("Nhap ten lien he can tim: ");
string name = Console.ReadLine();
int num = 0;
foreach (HashTable ht in tablelist)
{
if (ht.Name == name)
{
ht.display();
num++;
}
} if (num == 0)
{
Console.WriteLine("khong tim thay ten");
}
break;
case 3:
for (int i = 0; i < tablelist.Count; i++)
{
tablelist[i].display();
}
break;
case 4:
Environment.Exit(0);
break;
default:
Console.WriteLine("Fail!");
break;
}
} while (choose != 4);
}
static void showMenu()
{
Console.WriteLine("1. Them lien he moi");
Console.WriteLine("2. Tim so lien lac theo ten");
Console.WriteLine("3. Hien thi");
Console.WriteLine("4. Thoat");
Console.WriteLine("Chon: ");
}
}
}
![Hoàng Quang Huy [C1907L]](https://www.gravatar.com/avatar/76e646e11f1674fba03bddd0ae020813.jpg?s=80&d=mm&r=g)
Hoàng Quang Huy
2020-07-06 09:49:48
using System;
using System.Collections.Generic;
using System.Text;
namespace Project2
{
class Test
{
static void Main(string[] args)
{
int choose;
ContactManager contactManager = new ContactManager(); ;
do
{
ShowMenu();
choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
Console.WriteLine("Number contact: ");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
contactManager.Add();
}
break;
case 2:
contactManager.Find();
break;
case 3:
Console.WriteLine("\tAddress Book");
Console.WriteLine("Contact Name\tPhone Number");
contactManager.Display();
break;
case 4:
Environment.Exit(0);
break;
default:
break;
}
} while (choose != 4);
}
static void ShowMenu()
{
Console.WriteLine("1. Add Contact");
Console.WriteLine("2. Find");
Console.WriteLine("3. Display all contact");
Console.WriteLine("4. Exit");
Console.WriteLine("Choose: ");
}
}
}
-------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace Project2
{
public class Contact
{
public string Name { get; set; }
public string Phone { get; set; }
public Contact(string name, string phone)
{
Name = name;
Phone = phone;
}
public Contact()
{
}
public void Input()
{
Console.WriteLine("Input Name: ");
this.Name = Console.ReadLine();
Console.WriteLine("Input Phone: ");
this.Phone = Console.ReadLine();
}
public void Display()
{
Console.WriteLine(Name+"\t"+ Phone);
}
}
}
-------------------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace Project2
{
class ContactManager
{
static Hashtable table;
public ContactManager()
{
table = new Hashtable();
}
public void Add()
{
Contact cont = new Contact();
cont.Input();
table.Add(cont.Name, cont);
}
public void Display()
{
foreach (DictionaryEntry item in table)
{
((Contact)item.Value).Display();
}
}
public void Find()
{
Console.WriteLine("Finding Phonenumber: ");
string phone = Console.ReadLine();
if (table.ContainsKey(phone))
{
((Contact)table[phone]).Display();
}
else
{
Console.WriteLine("Cannot Find");
}
}
}
}
![Nguyễn Hoàng Anh [C1907L]](https://www.gravatar.com/avatar/5b7bb435cae0d0a0fd414f6fdd0adc87.jpg?s=80&d=mm&r=g)
Nguyễn Hoàng Anh
2020-07-04 06:19:27
using System;
using System.Collections;
namespace Test60p
{
class Program
{
static Hashtable ContactManager = new Hashtable();
public static void Add() {
Contact contact = new Contact();
contact.input();
ContactManager.Add(contact.ContactName,contact);
}
public static void Find() {
Console.WriteLine("Enter contact name : ");
string name = Console.ReadLine();
if (ContactManager.ContainsKey(name))
{
Console.WriteLine("Contact Name Phone number");
((Contact)ContactManager[name]).display();
}
else {
Console.WriteLine("No contact name!");
}
}
public static void Show() {
Console.WriteLine("Contact Name Phone number");
foreach (Contact value in ContactManager.Values) {
value.display();
}
}
public static void Menu() {
Console.WriteLine("1.Add new contact");
Console.WriteLine("2.Find a contact by name");
Console.WriteLine("3.Display contacts");
Console.WriteLine("4.Exit");
}
static void Main(string[] args)
{
while (true) {
Menu();
int choice = int.Parse(Console.ReadLine());
switch (choice) {
case 1:
Add();
break;
case 2:
Find();
break;
case 3:
Show();
break;
case 4:
return;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Test60p
{
class Contact
{
public string ContactName { get; set; }
public string PhoneNumber { get; set; }
public Contact(string contactName, string phoneNumber)
{
ContactName = contactName;
PhoneNumber = phoneNumber;
}
public Contact()
{
}
public void input()
{
Console.WriteLine("Enter contact name : ");
ContactName = Console.ReadLine();
Console.WriteLine("Enter phone number : ");
PhoneNumber = Console.ReadLine();
}
public void display()
{
Console.WriteLine("{0} {1}", ContactName, PhoneNumber);
}
}
}
![Ngô Quang Huy [C1907L]](https://www.gravatar.com/avatar/8e54dbf5994077ce599f49278164ae79.jpg?s=80&d=mm&r=g)
Ngô Quang Huy
2020-07-03 13:49:48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContactManager
{
class Program
{
static Dictionary<string, Contact> list = new Dictionary<string, Contact>();
static void Main(string[] args)
{
while (true)
{
showMenu();
int choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
Add();
break;
case 2:
Find();
break;
case 3:
Display();
break;
case 4:
Environment.Exit(0);
break;
default:
Console.WriteLine("Invalid");
break;
}
}
}
static void showMenu()
{
Console.WriteLine("\n1. Add new contact\n2.Find a contact by name\n3.Display contacts\n4.Exit");
Console.Write("Choose: ");
}
static void Add()
{
Contact ct = new Contact();
ct.input();
list.Add(ct.Name, ct);
}
static void Find()
{
Console.Write("Insert Search Name: ");
string search = Console.ReadLine();
if (list.ContainsKey(search))
{
Console.WriteLine(list[search].Phone);
}
else
{
Console.WriteLine("Not found");
}
}
static void Display()
{
Dictionary<string, Contact>.ValueCollection value = list.Values;
Console.WriteLine("\tAddress Book");
Console.WriteLine("{0} {1}", "Contact Name".PadRight(20),"Phone Number");
foreach (Contact cont in value)
{
Console.WriteLine("{0} {1}", cont.Name.PadRight(20), cont.Name);
}
}
}
}
![trung [C1907L]](https://www.gravatar.com/avatar/67c23432e4710f33dd14e580d41b0379.jpg?s=80&d=mm&r=g)
trung
2020-07-03 13:45:58
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContactManager
{
public class ContactManager
{
public Hashtable ContactMgr;
public ContactManager()
{
ContactMgr = new Hashtable();
}
public void PrintMenu()
{
Console.WriteLine("1.Add new contact");
Console.WriteLine("2.Find a contact by name");
Console.WriteLine("3.Display contacts");
Console.WriteLine("4.Exit");
}
public void AddTelephone()
{
Contact nContact = new Contact();
nContact.Input();
ContactMgr.Add(nContact.Name, nContact);
}
public void Display()
{
Console.WriteLine("Contact name Phone Number");
foreach (DictionaryEntry ct in ContactMgr)
{
((Contact)ct.Value).Output();
}
}
public void FindTelephone()
{
string name;
Console.WriteLine("Input name to search");
name = Console.ReadLine();
if (!ContactMgr.ContainsKey(name))
{
Console.WriteLine("Not found");
return;
}
else
{
((Contact)ContactMgr[name]).Output();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContactManager
{
public class Contact
{
public string Name { get; set; }
public string Phone { get; set; }
public Contact()
{ }
public Contact(string name, string phone)
{
Name = name;
Phone = phone;
}
public void Input()
{
Console.WriteLine("Input name");
Name = Console.ReadLine();
Console.WriteLine("Input phone");
Phone = Console.ReadLine();
}
public void Output()
{
Console.WriteLine("{0} {1}", Name, Phone);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContactManager
{
public class Program
{
static void Main(string[] args)
{
ContactManager contactmgr = new ContactManager();
int choose = 0;
do
{
contactmgr.PrintMenu();
choose = int.Parse(Console.ReadLine());
switch(choose)
{
case 1:
for (int i = 0; i < 3; i++)
{
contactmgr.AddTelephone();
}
break;
case 2:
contactmgr.FindTelephone();
break;
case 3:
contactmgr.Display();
break;
case 4:
Console.WriteLine("bye bye...");
break;
default:
Console.WriteLine("Invalid input");
break;
}
}
while (choose != 4);
}
}
}
![Trần Ngọc Hải [T1907A]](https://www.gravatar.com/avatar/9f7a27af52cbf0d52c32019e1354d60a.jpg?s=80&d=mm&r=g)
Trần Ngọc Hải
2020-06-05 11:09:08
#ContactManager.cs
using System;
using System.Collections;
using System.Text;
namespace BaiThiC
{
class ContactManager
{
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
Hashtable hash = new Hashtable();
int choose;
do
{
show();
choose = Int32.Parse(Console.ReadLine());
switch (choose)
{
case 1:
Console.WriteLine("Nhập số lượng thuê bao muốn thêm: ");
int n = Int32.Parse(Console.ReadLine());
Input(n, hash);
break;
case 2:
Search(hash);
break;
case 3:
Display(hash);
break;
case 4:
Console.WriteLine("Thoát");
break;
default:
Console.WriteLine("Lỗi rồi, nhập lại : ");
break;
}
} while (choose != 4);
}
private static void show()
{
Console.WriteLine("1. Thêm số liên lạc");
Console.WriteLine("2. Tìm thông tin liên lạc");
Console.WriteLine("3. Hiển thị danh bạ");
Console.WriteLine("4. Thoát");
Console.WriteLine("Nhập: ");
}
private static void Input(int n, Hashtable hash)
{
for(int i =0; i < n; i++)
{
Tab phone = new Tab();
phone.Input();
hash.Add(phone.Name, phone.PhoneNumber);
}
}
private static void Display(Hashtable hash)
{
ICollection key = hash.Keys;
foreach (string h in key)
{
Console.WriteLine(h + ": " + hash[h]);
}
}
private static void Search(Hashtable hash)
{
ICollection key = hash.Keys;
Console.WriteLine("Nhập tên cần tìm: ");
string name = Console.ReadLine();
foreach (string l in key)
{
if (name.Equals(l))
{
Console.WriteLine(l + ": " + hash[l]);
}
}
}
}
}
#tab.csusing System;
using System.Text;
namespace BaiThiC
{
class Tab
{
public string Name { get; set; }
public int PhoneNumber { get; set; }
public void Input()
{
bool ischeck = true;
while (ischeck)
{
Console.OutputEncoding = Encoding.UTF8;
Console.Write("Nhập tên: ");
Name = Console.ReadLine();
if (string.IsNullOrEmpty(Name) == false)
{
ischeck = false;
}
else
{
Console.WriteLine("Lỗi.");
}
}
Console.WriteLine("Nhập số điện thoại: ");
PhoneNumber = Int32.Parse(Console.ReadLine());
}
public void Display()
{
Console.WriteLine("Tên: {0}; Số điện thoại: {1}", Name, PhoneNumber);
}
}
}
![hoangduyminh [T1907A]](https://www.gravatar.com/avatar/33675cc9fc3762fd323389a179aa047f.jpg?s=80&d=mm&r=g)
hoangduyminh
2020-06-05 08:50:48
using System;
using System.Collections;
using System.Collections.Generic;
namespace ThucHanh
{
class Program
{
static void Main(string[] args)
{
Hashtable hashtable = new Hashtable();
int choose;
do
{
showMenu();
choose = int.Parse(Console.ReadLine());
switch (choose)
{
case 1:
for(; ; )
{
Console.WriteLine("Nhap vao contact :");
People people = new People();
people.input();
hashtable.Add(People.Name, People.PhoneNumber);
Console.WriteLine("Ban co muon nhap tiep khong ? Y/N");
String option;
option = Console.ReadLine();
if (option.Contains("N"))
{
break;
}
}
break;
case 2:
Console.WriteLine("Moi ban nhap vao ten :");
String name;
name = Console.ReadLine();
ICollection key01 = hashtable.Keys;
foreach (string k in key01)
{
if (k.Equals(name))
{
Console.WriteLine(hashtable[k]);
}
}
if (!hashtable.ContainsKey(name))
{
Console.WriteLine("Not found");
}
break;
case 3:
ICollection key = hashtable.Keys;
foreach (string k in key)
{
Console.WriteLine(k + " :" + hashtable[k]);
}
break;
case 4:
Console.WriteLine("Thoat");
break;
default:
Console.WriteLine("Error!!");
break;
}
} while (choose != 5);
}
public static void showMenu()
{
Console.WriteLine("1. Add new contact");
Console.WriteLine("2. Find a contact by name");
Console.WriteLine("3. Display contacts");
Console.WriteLine("4. Thoat");
Console.WriteLine("Chon:");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ThucHanh
{
public class People
{
string Name { get; set; }
string PhoneNumber { get; set; }
public People()
{
}
public void input()
{
Console.WriteLine("Nhap vao Name:");
Name = Console.ReadLine();
Console.WriteLine("Nhap vao phoneNumber:");
PhoneNumber = Console.ReadLine();
}
public void display()
{
Console.WriteLine("Name : {0}, PhoneNumber: {1}", Name, PhoneNumber);
}
}
}