Создать базу данных, содержащую сведения о 20 клиентах банка - C#
Формулировка задачи:
12. Создать базу данных, содержащую сведения о 20 клиентах банка:
— номер по порядку (номер счета),
— фамилия клиента,
— годовой процент вклада,
— сумма вклада,
— дата совершения операции по вкладу.
Расположить список клиентов в алфавитном порядке. Вычислить сумму вклада через 5 лет для каждого клиента и
итоговую сумму для всех клиентов. Составить список тех клиентов, у которых сумма вклада расположена
в заданных пределах.
Данные задать самостоятельно.
Индекс (отсчитываемый от нуля) должен быть больше или равен нулю, но меньше размера списка аргументов.
using System; class txt { public int percent; public int n; public int p; public string d; public string y; public int s; public txt(string y1, int n1, int percent1, int p1, string d1) { y = y1; percent = percent1; n = n1; p = p1; d = d1; s = (p1 * percent1) / 100; } } class Program { static void Main(string[] args) { int ss = 0; int[] b = new int[20]; txt[] a = new txt[20]; a[0] = new txt("Тарков", 1, 10, 32000, "07.11.09"); a[1] = new txt("Федорченко", 2, 5, 31600, "02.10.10"); a[2] = new txt("Миленин", 3, 3, 27000, "08.11.10"); a[3] = new txt("Ивкин", 4, 12, 11650, "08.10.09"); a[4] = new txt("Васильев", 5, 6, 9862, "03.05.08"); a[5] = new txt("Факторов", 6, 8, 44000, "07.05.12"); a[6] = new txt("Петров", 7, 10, 96000, "26.11.13"); a[7] = new txt("Корженкова", 8, 13, 43780, "19.10.13"); a[8] = new txt("Шлепова", 9, 15, 7540, "21.11.13"); a[9] = new txt("Фраинт", 10, 9, 8000, "16.08.13"); a[10] = new txt("Мартынюк", 11, 7, 9500, "14.12.09"); a[11] = new txt("Головин", 12, 7, 7250, "12.11.10"); a[12] = new txt("Фахрутдинов", 13, 8, 9300, "11.01.13"); a[13] = new txt("Латина", 14, 5, 16000, "06.09.13"); a[14] = new txt("Коровина", 15, 3, 20500, "04.06.11"); a[15] = new txt("Аймалетдинова", 16, 11, 34000, "22.03.11"); a[16] = new txt("Дороднова", 17, 4, 36500, "14.05.13"); a[17] = new txt("Овсянников", 18, 5, 9100, "10.09.10"); a[18] = new txt("Кудряшов", 19, 9, 4200, "02.12.13"); a[19] = new txt("Цымбалова", 20, 8, 1600, "08.02.13"); Array.Sort(a, (p1, p2) => p1.y.CompareTo(p2.y)); for (int k = 0; k < a.Length; k++) ss = ss + a[k].s; Console.WriteLine("{0} {1} {2} {3} {4} {5} {6}", "Клиент", "Номер", "Процент", "Сумма вклада", "Сумма через 5 лет", "Дата"); for (int i = 0; i < a.Length; i++) Console.WriteLine("{0}\t {1}\t {2}\t {3}\t {4}\t {5} {6}", a[i].y, a[i].n, a[i].percent, a[i].p, a[i].s, a[i].d); Console.WriteLine("{0} - {1}", ss, "Итоговая сумма для всех клиентов"); Console.ReadKey(); } }
Решение задачи: «Создать базу данных, содержащую сведения о 20 клиентах банка»
textual
Листинг программы
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace текст { class Txt { public short[] percent; public short[] number_pp; public string[] date; public string[] surname; public decimal[] summa; public decimal itog_summa; public Txt(short[] num_pp, string[] name, short[] perc, decimal[] sum, string[] dat) { number_pp = num_pp; surname = name; percent = perc; summa = sum; date = dat; } public void Sum_Vklada(int t) { /*Вычислить сумму вклада через 5 лет для каждого клиента и итоговую сумму для всех клиентов.*/ for(int i=0;i<summa.Length;i++) { summa[i] = summa[i] + summa[i] * percent[i]*t/100; } Console.WriteLine("№пп\t | Фамилия\t | Сумма через 5 лет"); for (int i = 0; i < number_pp.Length; i++) Console.WriteLine(number_pp[i] + "\t | " + surname[i] + "\t | " + summa[i]); for (int i=0;i<summa.Length;i++) itog_summa += summa[i]; Console.WriteLine("Итоговая сумма:" + itog_summa); } public void Spisok(int low, int high) { /*Составить список тех клиентов, у которых сумма вклада расположена в заданных пределах.*/ if (low > high) { Console.WriteLine("Неправильно задан диапазон!"); return; } Console.WriteLine("№пп\t | Фамилия\t | Процент | Сумма \t | Дата"); for (int i = 0; i < summa.Length; i++) { if (summa[i] >= low && summa[i] <= high) { Console.WriteLine(number_pp[i] + "\t | " + surname[i] + "\t | " + percent[i] + "\t | " + summa[i] + " \t | " + date[i]); } } } public void Sort() { string[] surn = new string[surname.Length]; for (int i = 0; i < surname.Length; i++) surn[i] = surname[i] + " " + number_pp[i] + " " + percent[i] + " " + summa[i] + " " + date[i]; Array.Sort(surn); string[] str_number_pp = new string[surname.Length]; string[] str_percent = new string[surname.Length]; string[] str_summa = new string[surname.Length]; string[] str_date = new string[surname.Length]; Console.WriteLine("№пп\t | Фамилия\t | Процент | Сумма \t | Дата"); for (int i = 0; i < surname.Length; i++) { string[] split = surn[i].Split(new char[] { ' ' }); int j = 0; surname[i] = split[j]; str_number_pp[i] = split[++j]; str_percent[i] = split[++j]; str_summa[i] = split[++j]; str_date[i] = split[++j]; Console.WriteLine(str_number_pp[i] + "\t | " + surname[i] + "\t | " + str_percent[i] + "\t | " + str_summa[i] + " \t | " + str_date[i]); } } public void Show() { Console.WriteLine("№пп\t | Фамилия\t | Процент | Сумма \t | Дата"); for (int i = 0; i < number_pp.Length; i++) Console.WriteLine(number_pp[i] + "\t | " + surname[i] + "\t | " + percent[i] + "\t | " + summa[i] + " \t | " + date[i]); } } class Program { static void Main(string[] args) { try { short[] number_pp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; string[] surname ={"Тарков", "Федорченко","Миленин","Ивкин","Васильев", "Факторов","Петров","Корженкова","Шлепова","Фраинт", "Мартынюк","Головин","Фахрутдинов","Латина","Коровина","Аймалетова", "Дороднова","Овсянников","Кудряшов","Цымбалова"}; short[] percent = { 10, 16, 7, 9, 8, 12, 11, 10, 10, 9, 4, 15, 20, 19, 17, 15, 18, 13, 14, 15 }; decimal[] summa ={32000,31600,27000,11650,96000,986200,16000,8000,43780,44000,32000, 31600,27000,11650,96000,986200,16000,8000,43780,44000}; string[] date ={"07.11.2009","02.10.2010","08.11.10","08.10.2009","03.05.2008","08.11.2010", "14.12.2009","16.08.2013", "08.10.2009", "21.01.2013","26.11.2013","21.11.2013","12.11.2010", "06.09.2013","14.05.2013","08.02.2013","14.12.2009","07.05.2012", "03.05.2008","19.10.2013"}; Txt tabl = new Txt(number_pp, surname, percent, summa, date); Console.WriteLine("Выберите функцию:"); string[] function = { "Показать исходную таблицу;", "Показать всех клиентов, сумма вклада которых лежит в заданном диапазоне;", "Вычислить сумму вклада через 5 лет для каждого клиента и вывести итоговую сумму по всем клиентам;","Отсортировать фамилии в алфавитном порядке" }; for (int i = 0; i < function.Length; i++) Console.WriteLine((i + 1) + " " + function[i]); int t, low, high; while (true) { try { t = int.Parse(Console.ReadLine()); } catch { Console.WriteLine("Ошибка ввода!"); return; } switch (t) { case 1: tabl.Show(); Console.ReadLine(); return; case 2: { Console.WriteLine("Задайте нижнюю границу диапазона:"); try { low = int.Parse(Console.ReadLine()); } catch { Console.WriteLine("Ошибка ввода!"); Console.ReadLine(); return; } Console.WriteLine("Задайте верхнюю границу диапазона:"); try { high = int.Parse(Console.ReadLine()); } catch { Console.WriteLine("Ошибка ввода!"); Console.ReadLine(); return; } tabl.Spisok(low, high); Console.ReadLine(); return; } case 3: tabl.Sum_Vklada(5); Console.ReadLine(); return; case 4: tabl.Sort(); Console.ReadLine(); return; } Console.ReadKey(); } } catch { Console.WriteLine("Some Error!!!"); Console.ReadLine(); } } } }