Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. /*Write a program that tries to find a pair for a customer.
  8. Each person has a name, height and gender. Data should have properties. When a data field is not given
  9. it should be randomly generated.
  10. Create your own algorithm for matching two persons (e.g. different gender and age difference lower
  11. than 5 years).
  12. Create an array of 20 persons. read the data of a customer and find a pair for him/her
  13. */
  14.  
  15.  
  16.  
  17. namespace ConsoleApplication2
  18. {
  19.     enum gender {male, female}
  20.  
  21.  
  22.     class Program
  23.     {
  24.        
  25.  
  26.         static void Main(string[] args)
  27.         {
  28.             Random rand = new Random();
  29.  
  30.             const int numberOfPeople = 21;
  31.  
  32.             Person[] people = new Person[numberOfPeople];
  33.  
  34.            
  35.          
  36.  
  37.             for (int i = 0; i < people.Length; i++)
  38.             {
  39.                 Naming name = new Naming(rand);
  40.  
  41.                 string newName = name.Name;
  42.  
  43.                 Person person = new Person(rand, newName);
  44.                 people[i] = person;
  45.  
  46.  
  47.                 Console.WriteLine(person.display());
  48.  
  49.  
  50.             }
  51.  
  52.             Person you = new Person();
  53.            
  54.  
  55.  
  56.             Console.ReadKey();
  57.  
  58.  
  59.         }
  60.     }
  61.  
  62.  
  63.  
  64.    
  65.  
  66.  
  67.  
  68.  
  69.  
  70.     class Naming
  71.     {
  72.         public Naming(Random rand)
  73.         {
  74.             string s = "";
  75.             int d = rand.Next(5,10);
  76.            
  77.                
  78.                
  79.                 for (int j = 0; j < d; j++)
  80.                 {
  81.  
  82.                    
  83.                     int x = rand.Next(26);
  84.                     s = s + Convert.ToChar(x+65);
  85.  
  86.                     // creating a name
  87.                 }
  88.            
  89.             this.name = s.Substring(0, 1).ToUpper() + s.Substring(1).ToLower();
  90.            
  91.  
  92.            
  93.         }
  94.  
  95.         string name;
  96.  
  97.         public string Name
  98.         {
  99.             get { return name; }
  100.             set { name = value; }
  101.         }
  102.     }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.     class Person
  113.     {
  114.  
  115.         public Person(Random rand, string name)
  116.         {
  117.             this.age = rand.Next(20,40);
  118.             this.height = rand.Next(145,195);
  119.  
  120.             switch(rand.Next(2))
  121.             {
  122.                 case 0:
  123.                     this.gender = (gender)0;
  124.                     break;
  125.                 case 1:
  126.                     this.gender = (gender)1;
  127.                     break;
  128.             }
  129.  
  130.             this.named = name;
  131.  
  132.        
  133.         }
  134.  
  135.         public Person()
  136.         {
  137.  
  138.             Console.WriteLine("Type you name");
  139.             this.named = Console.ReadLine();
  140.             Console.WriteLine("Age");
  141.             this.age = int.Parse(Console.ReadLine());
  142.             Console.WriteLine("Height");
  143.             this.height = int.Parse(Console.ReadLine());
  144.  
  145.             do{
  146.             Console.WriteLine("Gender m\f");
  147.             char gend = char.Parse(Console.ReadLine());
  148.  
  149.             if (gend == 'm')
  150.             {
  151.                 this.gender = (gender)0;
  152.             }
  153.             else if (gend == 'f')
  154.             {
  155.                 this.gender = (gender)1;
  156.             }
  157.  
  158.             }while(gend != 'm' || gend != 'f');
  159.  
  160.  
  161.  
  162.         }
  163.  
  164.  
  165.         int age;
  166.  
  167.         public int Age
  168.         {
  169.             get { return age; }
  170.             set { age = value; }
  171.         }
  172.  
  173.         string named;
  174.  
  175.         public string Named
  176.         {
  177.             get { return named; }
  178.             set { named = value; }
  179.         }
  180.  
  181.         int height;
  182.  
  183.         public int Height
  184.         {
  185.             get { return height; }
  186.             set { height = value; }
  187.         }
  188.  
  189.         gender gender;
  190.  
  191.         internal gender Gender
  192.         {
  193.             get { return gender; }
  194.             set { gender = value; }
  195.         }
  196.  
  197.         public string display()
  198.         {
  199.             string all = "Name: " + named.PadLeft(1) + "age: ".PadLeft(15) + age + "gender: ".PadLeft(15) + gender + "height: ".PadLeft(15) + height;
  200.  
  201.             return all;
  202.         }
  203.  
  204.     }
  205.  
  206.  
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement