Answer to Question #310882 in C# for Tkk

Question #310882

Create a class Person with attributes string Name, string Address and int age and define getter setter method using Auto Implementation Property


• Create a class PersonImplementation and implement the below given methods:

1. GetName(IList<Person> person) display the name and address of all the persons in the List

2. Average(List<Player> players) to calculate the average age of all the persons.

3. Max(IList<Player> players) to find the maximum age of the person.


1
Expert's answer
2022-03-13T11:22:17-0400

Here is my program:

 public class Person
      {
            
           public string Name { set { _name = value; } get { return _name; } }
            public string Address { set { _address = value; } get { return _address; } }
            public int Age { set { _age = value; } get { return _age; } }


            private string _name;
            private string _address;
            private int _age;


        }
      public class PersonImplementation
      {
            public void GetName(IList<Person> person)
            {
                foreach(Person p in person)
                {
                    Console.WriteLine(p.Name);
                    Console.WriteLine(p.Address);
                }
            }
            public void Average(IList<Person> person)
            {
                int average = 0;
                int r = 0;
                double resaverage = 0;
                foreach (Person p in person)
                {
                    average += p.Age;
                    r++;
                }
                resaverage = average / r;
            }
            public void Max(IList<Person> person)
            {
               Console.WriteLine(person.Max());
            }
      }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS