Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C# Boat Slips: Create an array of numbers, representing slip numbers. For the

ID: 655285 • Letter: I

Question

In C#

Boat Slips: Create an array of numbers, representing slip numbers.


For the Boat Slip array, create a program to demonstrate the following tasks:


o Populate the array with some numbers. (Note: the slip number array will not need to grow or have additions after it is defined and initially populated.)
o Prompt the user for a slip number to search for; if the number is in the array, print it; if not, indicate so.
o Indicate to the user that (rather than searching for one slip) they can print out a list of all slip numbers; tell them how and do so if they choose to.
o Continue prompting the user for more slip numbers to search for until the user indicates they no longer want to search. (You choose the way for the user to indicate this, whether they enter the word "end" or something else you decide on. Make sure you inform the user how to use your program!)

Explanation / Answer

using System;

namespace BoatSlips
{
    class Program
    {
        public static void Main(string[] args)
        {
            boat b=new boat();
            int n; // no.of.slips
            Console.Write("Enter the no.of slips: ");
            n = Convert.ToInt32(Console.ReadLine());
            b.getSlip(n);
            int  ch=1;  // yes
            while(ch==1)
            {
            Console.Write(" MENU: ");
            Console.Write(" 1. List of Boat Slips:");
            Console.Write(" 2. Search by Slip number: ");
            Console.Write("Enter Your Choice( 1 /2):");
            int c= int.Parse(Console.ReadLine());    
            if(c==1)
                b.printSlip(n);
            else{
                int slipNum;
                Console.Write("Enter Boat Slip number You want to search: ");
                slipNum = Convert.ToInt32(Console.ReadLine());
                int flag=b.searchSlip(slipNum);
                if(flag==1){
                Console.Write("Hurray!! Boat Slip is Available: ");
                }
                else
                {
                Console.Write("Hey! Boat Slip is not Available: ");
                }
                   }
            Console.Write(" Do u Want to continue Search(1/2): ");
             ch= int.Parse(Console.ReadLine());
            }
        }
    }
}


class boat
{
    int []boatSlip=new int[50];

        public int searchSlip(int slip)
        {
        int flag=0;
        for(int i=0;i<boatSlip.Length;i++)
        {
        if(slip==boatSlip[i])
        {
        flag=1;
        break;
        }
        }
        return flag;
        }

        public void getSlip(int n)
        {
            // loop for accepting values in boatSlip
               for (int i = 0; i < n; i++)
             {
               Console.Write("Enter Boat Slip number: ");
             boatSlip[i]= Convert.ToInt32(Console.ReadLine());
             }
        }
        
      public void printSlip(int n)
      {
        Console.WriteLine(" Boat Slips: ");
        for (int i = 0; i < n; i++)
             {
           Console.Write(boatSlip[i]+" ");
         }
      }
}