IMG-LOGO
×

Giáo Trình Học

Khoá học lập trình C# (.NET Core)

Kiến Thức Căn Bản - Khai Báo Biến, Toán Tử, Mệnh Đề Điều Kiện, Lặp

[Video] Giới thiệu về ngôn ngữ lập trình C# & .NET Framework + Khai báo biến trong C# [Video] Hướng dẫn tìm hiểu biến + toán tử trong lập trình C# [Video] Hướng dẫn tìm hiểu mệnh đề điều kiện if - else - switch trong C# [Video] Tìm dãy số nguyên tố - Lập trình C# - Loop trong C# [Video] In dãy số chẵn & lẻ từ mảng số nguyên - Lập trình C# - Loop trong C#




Trang Chủ C Sharp [Examination] Thi thực hành môn C# - C Sharp

[Examination] Thi thực hành môn C# - C Sharp

by GokiSoft.com - 09:40 01/11/2021 10,146 Lượt Xem

Thời Gian Thi: 14h40 - 15h40

Muộn 1 phút trừ 0.5 điểm 

Bình luận



Chia sẻ từ lớp học

Võ Như Việt [C2010L]

Ngày viết: 20:29 28/10/2021


#Contact.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BT1564_Exam_Csharp_
{
    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("Enter Name: ");
            Name = Console.ReadLine();
            Console.WriteLine("Enter PhoneNumber: ");
            Phone = Console.ReadLine();
        }

        public void Display()
        {
            Console.WriteLine("{0} \t {1}", Name, Phone);
        }
    }
}


#Program.cs


using System;
using System.Collections;

namespace BT1564_Exam_Csharp_
{
    class Program
    {
        static Hashtable ht = new Hashtable();
        delegate void SwitchCase();
        static void Main(string[] args)
        {
           
            SwitchCase[] options = { addContact, FindByName,Display,Exit };
            int choose;

            do {
                ShowMenu();
                choose = int.Parse(Console.ReadLine());

                if(choose > 0 && choose <= options.Length)
                {
                    options[choose - 1]();
                }
                else
                {
                    Console.WriteLine("Choose Wrong!!!");
                }
            } while (choose != options.Length);
        }

        private static void addContact()
        {
            
            Console.WriteLine("Input n person:");
            int n = int.Parse(Console.ReadLine());
            for(int i = 0; i < n; i++) {
                Contact c = new Contact();
                c.Input();
                ht.Add(c.Name,c.Phone);
            }
        }

        private static void FindByName()
        {
            
            Console.WriteLine("Input name need search: ");
            string checkname = Console.ReadLine();
            foreach (DictionaryEntry item in ht)
            {
                if( checkname.Equals(item.Key))
                {
                    Console.WriteLine("");
                    Console.WriteLine("This search: Name is {0} \t Phone number:{1}", item.Key, item.Value);
                }
            }
        }

        private static void Display()
        {
            Console.WriteLine("\t Address Book \t");
            Console.WriteLine("Contact Name \t Phone number");
            foreach (DictionaryEntry item in ht)
            {
                Console.WriteLine("{0} \t {1}" ,item.Key,item.Value);
            }
        }

        private static void Exit()
        {
            Console.WriteLine("Exit program!!!");
        }

        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");

        }
    }
}


Đào Mạnh Dũng [C2010L]

Ngày viết: 19:45 28/10/2021


#Contact.cs


using System;

namespace _1564
{
    internal 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("nhap name");
            Name = Console.ReadLine();
            Console.WriteLine("nhap phone");
            Phone = Console.ReadLine();
        }

        public void Display()
        {
            Console.WriteLine(this);
        }

        public void Display2()
        {
            Console.WriteLine(Name+"\t"+Phone);
        }

        public override string ToString()
        {
            return "Contact{" + "Name=" + Name + ", Phone=" + Phone + '}';
        }
    }
}


#ContactManager.cs


using lib;
using System;
using System.Collections.Generic;

namespace _1564
{
    internal class ContactManager
    {
        private static Dictionary<string, Contact> contactManager = new Dictionary<string, Contact>();

        private static void Main(string[] args)
        {
            SwitchCase[] menu = { ShowMenu, Add, Find, Display, Utility.Exist };
            Utility.Menu(menu);
        }

        private static void Add()
        {
            Contact contact = new Contact();
            contact.Input();
            contactManager.Add(contact.Name, contact);
        }

        private static void Find()
        {
            Console.WriteLine("nhap name cua contact");
            string name = Console.ReadLine();
            if (contactManager.ContainsKey(name))
            {
                contactManager[name].Display();
            }
            else
            {
                Console.WriteLine("Not found");
            }
        }

        private static void Display()
        {
            Console.WriteLine("\tAddress Book");
            Console.WriteLine("Contact Name Phone number");
            foreach (var item in contactManager)
            {
                item.Value.Display2();
            }
        }

        private static void ShowMenu()
        {
            Console.WriteLine(
            "o 1. Add new contact\n" +
            "o 2. Find a contact by name\n" +
            "o 3. Display contacts\n" +
            "o 4. Exit");
        }
    }
}


#Utility.cs


using Newtonsoft.Json;
using System;
using System.IO;

namespace lib
{
    internal delegate void SwitchCase();

    internal class Utility
    {
        public static void Menu(SwitchCase[] menu)
        {
            int choose;
            while (true)
            {
                menu[0]();
                choose = Utility.ReadInt();
                if (choose <= menu.Length)
                {
                    menu[choose]();
                }
                else Console.WriteLine("Dau vao khong hop le! ");
            }
        }

        public static void Exist()
        {
            Environment.Exit(0);
        }

        public static int ReadInt()
        {
            int integer;
            while (true)
            {
                try
                {
                    integer = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("du lieu dau vao khong hop le, nhap lai : ");
                }
            }
            return integer;
        }

        public static float ReadFloat()
        {
            float _float;
            while (true)
            {
                try
                {
                    _float = float.Parse(System.Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("du lieu dau vao khong hop le, nhap lai : ");
                }
            }
            return _float;
        }

        public static DateTime ReadDate()
        {
            DateTime date;
            while (true)
            {
                try
                {
                    date = ConvertDateTime(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("du lieu dau vao khong hop le, nhap lai : ");
                }
            }
            return date;
        }

        public static string ConvertDateTime(DateTime myDate)
        {
            return myDate.ToString("dd-MM-yyyy");
        }

        public static DateTime ConvertDateTime(string str)
        {
            return DateTime.ParseExact(str, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
        }

        public static T ReadfileJson<T>(string path)
        {
            return JsonConvert.DeserializeObject<T>(System.IO.File.ReadAllText(path));
        }

        public static void SavefileJson(object obj, string path)
        {
            System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(obj));
            Console.WriteLine("save file json is success!");
        }

        public static void SaveObject(object serialize, string path)
        {
            using (Stream stream = File.Open(path, FileMode.Create))
            {
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Serialize(stream, serialize);
                Console.WriteLine("save file object is success!");
            }
        }

        public static object ReadObject(string path)
        {
            using (Stream stream = File.Open(path, FileMode.Open))
            {
                return new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Deserialize(stream);
            }
        }

        public static void directoryCreate(string path)
        {
            string directoryPath = path;

            DirectoryInfo directory = new DirectoryInfo(directoryPath);

            if (!directory.Exists)
            {
                directory.Create();
            }

            Console.WriteLine("Create directory {0} is success!", directory.Name);
        }
    }
}


Hieu Ngo [community,C2009G]

Ngày viết: 11:10 28/10/2021


#Contact.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace Test1
{
    class Contact
    {
        public string ContactName { get; set; }
        public string PhoneNumber { get; set; }
        public Contact () { }

        public Contact(string contactName, string phoneNumber)
        {
            ContactName = contactName;
            PhoneNumber = phoneNumber;
        }
        public void Input()
        {
            Console.WriteLine("Enter Contact Name:");
            ContactName = Console.ReadLine();
            Console.WriteLine("Enter Phone Number:");
            PhoneNumber = Console.ReadLine();
        }

        public void Display()
        {
            Console.WriteLine("Contact Name: {0}, Phone Number: {1}", ContactName, PhoneNumber);
        }
    }
}


#Program.cs


using System;
using System.Collections.Generic;

namespace Test1
{
    class Program
    {
        delegate void SwitchCase();
        public static List<Contact> ContactList = new List<Contact>();
        static void Main(string[] args)
        {
           
            int choose;
            SwitchCase[] options = { AddNewContact, FindByName, Display, Exit };
            do
            {
                ShowMenu();
                choose = int.Parse(Console.ReadLine());
                if(choose >0 && choose <= options.Length)
                {
                    options[choose - 1]();
                }
            } while (choose != options.Length);
        }

        private static void Exit()
        {
            Console.WriteLine("Exit!!!");
        }

        private static void Display()
        {
            foreach(Contact contact in ContactList)
            {
                contact.Display();
            }
        }

        private static void FindByName()
        {
            Console.WriteLine("Enter Name Find:");
            string nameFind = Console.ReadLine();
            int count = 0;
            foreach(Contact contact in ContactList)
            {
                if(contact.ContactName == nameFind)
                {
                    count++;
                    contact.Display();
                }
            }
            if(count > 0)
            {
                Console.WriteLine("Tong so nguoi tim duoc {0}", count);
            } else
            {
                Console.WriteLine("{0} dose not exist", nameFind);
            }
        }

        private static void AddNewContact()
        {
            Console.WriteLine("Enter Number of Contact:");
            int n = int.Parse(Console.ReadLine());
            for(int i = 0; i < n; i++)
            {
                Contact contact = new Contact();
                contact.Input();
                ContactList.Add(contact);
            }
        }

        private 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:");
        }
    }
}


Nguyễn Hùng Anh [community,C2009G]

Ngày viết: 11:09 28/10/2021


#Contact.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace Bt1564
{
    class Contact
    {
        public string Fullname { get; set; }
        public string Phone { get; set; }

        public Contact()
        {
        }

        public Contact(string fullname, string phone)
        {
            Fullname = fullname;
            Phone = phone;
        }

        public void Input()
        {
            Console.WriteLine("Enter name: ");
            Fullname = Console.ReadLine();

            Console.WriteLine("Enter phone number: ");
            Phone = Console.ReadLine();
        }

        public void Display()
        {
            Console.WriteLine("{0}\t{1}", Fullname, Phone);
        }

    }
}


#Program.cs


using System;
using System.Collections.Generic;

namespace Bt1564
{
    delegate void SwitchCase();
    class Program
    {
        static List<Contact> contactList;
        static void Main(string[] args)
        {
            contactList = new List<Contact>();
            SwitchCase[] options = { Input, FindByName, Display, ExitProgram };
            int c;
            
            do
            {
                ShowMenu();
                c = int.Parse(Console.ReadLine());

                if(c > 0 && c <= options.Length)
                {
                    options[c - 1]();
                } else
                {
                    Console.WriteLine("Nhap sai!!!");
                }
            } while (c != 4);
        }

        private static void Input()
        {
            Contact contact = new Contact();
            contact.Input();

            contactList.Add(contact);
        }

        private static void FindByName()
        {
            Console.WriteLine("Enter name: ");
            string name = Console.ReadLine();

            foreach(Contact contact in contactList)
            {
                if(contact.Fullname == name)
                {
                    Console.WriteLine("Contact Name \t Phone Number");
                    contact.Display();
                    break;
                }
            }
            Console.WriteLine("Not found!!!");
        }

        private static void Display()
        {
            Console.WriteLine("\tAddress Book");
            Console.WriteLine("Contact Name \t Phone Number");
            foreach(Contact contact in contactList)
            {
                contact.Display();
            }
        }

        private static void ExitProgram()
        {
            Console.WriteLine("Exit program!!!");
        }

        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: ");
        }
    }
}


Nguyen Trung Kien [C2010G]

Ngày viết: 10:14 18/10/2021


#Contact.cs


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Lession04
{
    class Contact
    {
        public Hashtable Add(Hashtable hashtable)
        {
            Contactmanager cont = new Contactmanager();

            Console.WriteLine("Enter FullName: ");
            cont.Fullname = Console.ReadLine();

            Console.WriteLine("Enter PhoneNumber: ");
            cont.Phonenumber = Console.ReadLine();

            hashtable.Add(cont.Fullname, cont.Phonenumber);

            return hashtable;
        }
        public void Display(Hashtable hashtable)
        {
            ICollection key = hashtable.Keys;
            Console.WriteLine("\t\tAddress Book\t");
            Console.WriteLine("\tContactName\t\tPhone");
            foreach (String s in key)
            {
                Console.WriteLine("\t" + s + "\t\t\t" + hashtable[s]);
            }
        }
        public Hashtable Seach(Hashtable hashtable)
        {
            Console.WriteLine("Enter Name Sach: ");
            String name = Console.ReadLine();
            Console.WriteLine("\n\tContatName\t\tPhone");
            int flag = 0;
            ICollection key = hashtable.Keys;
            foreach (string s in key)
            {
                if (s.Equals(name))
                {
                    Console.WriteLine("\t" + s + "\t\t\t" + hashtable[s]);
                    flag = 1;
                }
            }
            if (flag == 0)
            {
                Console.WriteLine("Name not found");
            }

            return hashtable;
        }

    }
}


#Contactmanager.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace Lession04
{
    class Contactmanager
    {
        public String Fullname { get; set; }
        public String Phonenumber { get; set; }

        public Contactmanager()
        {

        }
        public Contactmanager(string fullname, string phonenumber)
        {
            Fullname = fullname;
            Phonenumber = phonenumber;
        }
        
    }

}


#Program.cs


using System;
using System.Collections;

namespace Lession04
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable hashtable = new Hashtable();
            int choose;
            do
            {
                Menu();
                choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Console.WriteLine("Enter number contact :");
                        int n = int.Parse(Console.ReadLine());
                        for (int i = 0; i < n; i++)
                        {
                            Console.WriteLine("Contact {0}", i+1);
                            new Contact().Add(hashtable);
                        }
                        break;
                    case 2:
                        new Contact().Seach(hashtable);
                        break;
                    case 3:
                        new Contact().Display(hashtable);
                        break;
                    case 4:
                        Console.WriteLine("Exit!!!!");
                        break;
                }
            } while (choose != 4);
        }
        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");

        }
    }
}


Tài Liệu Tham Khảo

Đã sao chép!!!