Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication25
- {
- public delegate void isDateValid(int falseInfo, string falseType);
- enum Months : byte { January, February, March, April, May, June, July, August, September, October, November, December, False };
- public class Date
- {
- private int year;
- private Months month;
- private int day;
- private bool isFalse = false;
- public isDateValid dateCheck;
- public Date(int year, int month, int day)
- {
- this.year = year;
- if (month > 0 && month < 13)
- {
- this.month = (Months)month-1;
- }
- else
- {
- this.month = (Months)13;
- isFalse = true;
- }
- this.day = day;
- }
- public void DayMonthCheck()
- {
- if (month != (Months) 13)
- {
- if ((int)month > 2 && (int)month < 8)
- {
- if ((int)month % 2 == 0)
- {
- if (day > 30)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- else
- {
- if (day > 31)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- }
- else if ((int)month >= 8)
- {
- if( (int) month % 2 == 0)
- {
- if (day > 31)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- else
- {
- if (day > 30)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- }
- else if ((int)month == 1)
- {
- if (day > 31)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- else if ((int)month == 2)
- {
- if (day > 28)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- }
- else
- dateCheck((int)month, "month");
- if (day < 1)
- {
- dateCheck(day, "day");
- isFalse = true;
- }
- }
- public bool MonthSearch(string month)
- {
- if(this.month.ToString() == month || Convert.ToString(Convert.ToInt32(this.month + 1)) == month)
- return true;
- return false;
- }
- public void Print()
- {
- if (!isFalse)
- {
- Console.Write("\n{0}/{1}/{2}\n\n", day, (int)month+1, year);
- }
- }
- }
- public class Phonebook
- {
- private string firstName;
- private string lastName;
- private string phoneNum;
- private string city;
- public Phonebook(string fName, string lName, string phoneNum, string city)
- {
- firstName = fName;
- lastName = lName;
- this.phoneNum = phoneNum;
- this.city = city;
- }
- public bool CitySearch(string city)
- {
- if(this.city == city)
- return true;
- return false;
- }
- public bool NameSearch(string nameFL)
- {
- if (firstName == nameFL || lastName == nameFL)
- return true;
- return false;
- }
- public void Print()
- {
- Console.Write("\nName: {0} {1}\nPhone number: {2}\nCity: {3}\nDate of birth: ", firstName, lastName, phoneNum, city);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- bool endChanges;
- int i = 0;
- Phonebook[] book = new Phonebook[100];
- Date[] dateOfBirth = new Date[100];
- for (int a = 0; a < book.Length; a++)
- {
- Console.Write("Last name: ");
- string lName = Console.ReadLine();
- Console.Write("First name: ");
- string fName = Console.ReadLine();
- Console.Write("Phone number: ");
- string phoneNum = Console.ReadLine();
- Console.Write("City: ");
- string city = Console.ReadLine();
- Console.Write("Date of birth -\nYear: ");
- int year = int.Parse(Console.ReadLine());
- Console.Write("Month: ");
- int month = int.Parse(Console.ReadLine());
- Console.Write("Day: ");
- int day = int.Parse(Console.ReadLine());
- dateOfBirth[i] = new Date(year, month, day);
- dateOfBirth[i].dateCheck = new isDateValid(DateValidation);
- dateOfBirth[i].DayMonthCheck();
- book[i] = new Phonebook(lName, fName, phoneNum, city);
- book[i].Print();
- dateOfBirth[i].Print();
- i++;
- endChanges = false;
- while (!endChanges)
- {
- Console.WriteLine("Press '1' to add new member\nPress '2' to delete member\nPress '3' to print all members\nPress '4' to search by city\nPress '5' to search by month of birth\nPress '6' to search by name");
- int selection = int.Parse(Console.ReadLine());
- switch (selection)
- {
- case 1:
- endChanges = true;
- continue;
- case 2:
- Console.WriteLine("Which member would you like to delete (enter member number)");
- int member = int.Parse(Console.ReadLine());
- book[member - 1] = null;
- dateOfBirth[member - 1] = null;
- for (int m = member - 1; m < i; m++)
- {
- book[m] = book[m + 1];
- dateOfBirth[m] = dateOfBirth[m + 1];
- }
- book[i] = null;
- dateOfBirth[i] = null;
- i--;
- Console.WriteLine();
- break;
- case 3:
- for (int k = 0; k < i; k++)
- {
- book[k].Print();
- dateOfBirth[k].Print();
- }
- break;
- case 4:
- Console.WriteLine("Specify city: ");
- string cityC = Console.ReadLine();
- for (int l = 0; l < i; l++)
- {
- if (book[l].CitySearch(cityC))
- {
- book[l].Print();
- dateOfBirth[l].Print();
- }
- }
- break;
- case 5:
- Console.WriteLine("Specify month of birth: ");
- string monthC = Console.ReadLine();
- for (int l = 0; l < i; l++)
- {
- if (dateOfBirth[l].MonthSearch(monthC))
- {
- book[l].Print();
- dateOfBirth[l].Print();
- }
- }
- break;
- case 6:
- Console.WriteLine("Specify name(first/last): ");
- string nameFL = Console.ReadLine();
- for (int l = 0; l < i; l++)
- {
- if (book[l].NameSearch(nameFL))
- {
- book[l].Print();
- dateOfBirth[l].Print();
- }
- }
- break;
- default:
- Console.WriteLine("Invalid request!\n");
- break;
- }
- }
- }
- }
- static void DateValidation(int date, string type)
- {
- Console.WriteLine("Invalid date! {0} {1} doesn't exist.", type, date);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement