Search
 
SCRIPT & CODE EXAMPLE
 

CPP

fishes code in assignment expert

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


namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Fish> fishes = new List<Fish>()
            {
                new Fish(1, FishType.A),
                new Fish(1, FishType.B),
                new Fish(1, FishType.A)
            };


            Fish mainFish = new Fish(2, FishType.A);
            mainFish.Eat(fishes);
            Console.WriteLine(mainFish);
        }
    }


    class Fish 
    {
        public int Length { get; private set; }
        public FishType Type { get; private set; }


        public Fish(int length, FishType type)
        {
            Length = length;
            Type = type;
        }




        public void Eat(List<Fish> fishes)
        {
            if (Type == FishType.B)
                return;


            foreach (Fish fish in fishes)
            {
                if (fish.Type == FishType.A && fish.Length < Length 
                    || fish.Type == FishType.B)
                {
                    Length += fish.Length;
                    fishes.Remove(fish);
                    break;
                }
            }
        }


        public override string ToString()
        {
            return $"Length: {Length}, Type; {Type.ToString()}";
        }


    }
    public enum FishType
    {
        A,
        B
    }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ correct upto 3 decimal places 
Cpp :: C++ singleton prevent copy 
Cpp :: c++ enter name and surname one string 
Cpp :: c++ bind what are placeholders 
Cpp :: convert java to c++ 
Cpp :: how are c++ references implemented 
Cpp :: c++ insertion in astack 
Cpp :: c++ poitner 
Cpp :: flowchart to display factors of a number 
Cpp :: C++ OpenCV Face Recognition 
Cpp :: c++ constructor initializing list 
Cpp :: what is require to run min max function on linux in cpp 
Cpp :: how to get a section of a string in c++ 
Cpp :: high school hacking competition 
Cpp :: find maximum contiguous Sub arrays 
Cpp :: c++ caps lock key 
Cpp :: c++ sigabrt 
Cpp :: ue4 array copy c++ 
Cpp :: c++ starting syntaz 
Cpp :: distructor of the node of the link list 
Cpp :: comment savoir si un nombre est premier c++ 
Cpp :: changing key bindings in visual code not working 
Cpp :: npm wasm 
Cpp :: wap in c++ to understand function template 
Cpp :: C++ 4.3.2 (gcc-4.3.2) sample 
Cpp :: initializer before void c++ 
Cpp :: c++ map value int to string 
Cpp :: turn github into vscode 
Cpp :: how a function gives a pointer as parameter c++ 
Cpp :: math in section latex 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =