In C# Boat Slips: Create an array of numbers, representing slip numbers. For the
ID: 654703 • 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
{
static int searchSlip(int[] boatSlip, int slip){
int flag=0;
foreach (int i in boatSlip)
{
If(slip==boatSlip)
{
flag=1;
break;
}
}
return flag;
}
static void printSlip(int[] boatSlip)
{
Console.WriteLine(" Boat Slips: ");
foreach (int i in boatSlip)
{
Console.Write(" {0}", i);
}
}
static void Main(string[] args)
{
int n; // no.of.slips
Console.Write("Enter the no.of slips: ");
n = Convert.ToInt32(Console.ReadLine());
int i;
// loop for accepting values in boatSlip
for (i = 0; i < n; i++)
{
Console.Write("Enter Boat Slip number: ");
boatSlip[i]= Convert.ToInt32(Console.ReadLine());
}
char ch=