Click here to Skip to main content
15,888,590 members
Home / Discussions / C#
   

C#

 
AnswerRe: Thoughts why Mini Application Stops Working once executed ? Pin
phil.o13-Feb-15 7:31
professionalphil.o13-Feb-15 7:31 
GeneralRe: Thoughts why Mini Application Stops Working once executed ? Pin
namerg13-Feb-15 7:40
namerg13-Feb-15 7:40 
AnswerRe: How to add website into compatibility view ? Pin
namerg13-Feb-15 8:09
namerg13-Feb-15 8:09 
AnswerRe: How to add website into compatibility view ? Pin
seemajoshii13-Feb-15 20:31
seemajoshii13-Feb-15 20:31 
QuestionCode Signing certificate Pin
Super Lloyd13-Feb-15 2:10
Super Lloyd13-Feb-15 2:10 
AnswerRe: Code Signing certificate Pin
manchanx13-Feb-15 3:02
professionalmanchanx13-Feb-15 3:02 
AnswerRe: Code Signing certificate Pin
Eddy Vluggen13-Feb-15 3:06
professionalEddy Vluggen13-Feb-15 3:06 
RantWant Opinion on school assignment Pin
Truck5313-Feb-15 1:51
Truck5313-Feb-15 1:51 
Hi,

My instructor and I disagree on a mark that she gave me an assignment on generics. According to the requirements stated below, could someone tell me if my could meets these requirements.

Here is the requirements:

Write a generic method, Search, that implements the linear-search algorithm. Method Search
should compare the search key with each element in its array parameter until the search key is
found or until the end of the array is reached. If the search key is found, return its location in the
array; otherwise, return -1. Write a test app that inputs and searches an int array and a double array.

And here is my code:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GenericsTest
{
    class MyArrayList
    {
        int CountInt2 { get; set;}
        int CountInt1 { get; set;}
        int CountDouble2 { get; set; }
        int CountDouble1 { get; set; }

        int[] integerArray;
        double[] doubleArray;

        public MyArrayList() 
        {
            CountInt1 = 0;
            CountInt2 = 0;
            CountDouble1 = 0;
            CountDouble2 = 0;
            integerArray = new int[5];
            doubleArray = new double[5];
            
        }

        //used to fill Student array
        public void SetArrayInfo(int number)
        {
            integerArray[CountInt1] = number;
            ++CountInt1;
        }//end SetArrayInfo<Student>

        //used to fill Student array
        public void SetArrayInfo(double number)
        {
            doubleArray[CountDouble1] = number;
            ++CountDouble1;
        }//end SetArrayInfo<Student>
           
            public int Search<T>(T number)
        {

            if (number.GetType() == typeof(int))
            {
                //used to find student info in student array
                while (CountInt2 <= integerArray.Length)
                {
                    if (CountInt2 < integerArray.Length)
                        if (integerArray[CountInt2].Equals(number))
                        {
                            Console.Clear();
                            Console.WriteLine("The number " + integerArray[CountInt2] + " was found in array index number: " + CountInt2);
                            Console.WriteLine();
                            CountInt2 = 0;
                            return -2;
                        }
                    ++CountInt2;
                }
                return -1;
            }


            else if (number.GetType() == typeof(double))
            {
                //used to find student info in student array
                while (CountDouble2 <= doubleArray.Length)
                {
                    if (CountDouble2 < doubleArray.Length)
                        if (doubleArray[CountDouble2].Equals(number))
                        {
                            Console.Clear();
                            Console.WriteLine("The double " + doubleArray[CountDouble2] + " was found in array index number: {0}", CountDouble2);
                            Console.WriteLine();
                            CountDouble2 = 0;
                            return -2;
                        }
                    ++CountDouble2;
                }
            }
            return -1;
        }//end GetArrayInfo<int>
    }
   

    class DriverProgram 
    {
        static void Main(string[] args) 
        {
            int numberInt;
            double numberDouble;
            int choice = 0;

            MyArrayList myArrayList = new MyArrayList();

            myArrayList.SetArrayInfo(8);
            myArrayList.SetArrayInfo(9);
            myArrayList.SetArrayInfo(5);
            myArrayList.SetArrayInfo(10);
            myArrayList.SetArrayInfo(21);

            myArrayList.SetArrayInfo(7.7);
            myArrayList.SetArrayInfo(3.30);
            myArrayList.SetArrayInfo(9.80);
            myArrayList.SetArrayInfo(12.3);
            myArrayList.SetArrayInfo(21.58);

            do
            {

                Console.WriteLine("1  Get Integer Array Index");
                Console.WriteLine("2  Get Double Array Index");
                Console.WriteLine("3  Exit");
                try
                {
                    Console.Write("Choose one: ");
                    choice = Convert.ToInt32(Console.ReadLine());
                }

                catch (FormatException e)
                {
                    Console.WriteLine("You have entered an invalid type");
                    Console.WriteLine("Error: " + e);
                }


                

                //return Integer array index
                if (choice == 1)
                {
                    try
                    {
                        Console.Clear();
                        Console.Write("Enter integere number: ");
                        numberInt = Convert.ToInt32(Console.ReadLine());
                        int answer = myArrayList.Search<int>(numberInt);
                        if (answer == -1)
                            Console.WriteLine("The ID number entered was not found.");
                    }

                    catch (FormatException e)
                    {
                        Console.WriteLine("You have entered an invalid type");
                        Console.WriteLine("Error: " + e);
                    }
                }

                else if (choice == 2)
                {
                    try
                    {
                        Console.Clear();
                        Console.Write("Enter double number: ");
                        numberDouble = Convert.ToDouble(Console.ReadLine());
                        int answer = myArrayList.Search<double>(numberDouble);
                        if (answer == -1)
                            Console.WriteLine("The ID number entered was not found.");
                    }

                    catch (FormatException e)
                    {
                        Console.WriteLine("You have entered an invalid type");
                        Console.WriteLine("Error: " + e);
                    }
                }

                //clear screen before exit
                else if (choice == 3) { Console.Clear(); }

                //display error message if user chooses an invalid choice
                else
                {
                    Console.Clear();
                    Console.WriteLine("The choice you made is Invalid");
                }

                //exit program
                Console.WriteLine("Press any key to continue....");
                Console.ReadKey();
                Console.Clear();

            } while (choice != 3);//end do/while loop
        }
    }
}
</<pre lang="c#">
pre>

According to my instructor's feed back, my work was among some of the worst work submitted in class. I think my program meets my instructors requirements stated above.

Any feedback would be welcome.

If I do not thank you right away it is because I'm busy in school

Thanks,
Truck53
GeneralRe: Want Opinion on school assignment Pin
Freak3013-Feb-15 2:14
Freak3013-Feb-15 2:14 
GeneralRe: Want Opinion on school assignment Pin
Truck5313-Feb-15 4:58
Truck5313-Feb-15 4:58 
GeneralRe: Want Opinion on school assignment Pin
Truck5313-Feb-15 17:13
Truck5313-Feb-15 17:13 
GeneralRe: Want Opinion on school assignment Pin
OriginalGriff13-Feb-15 2:21
mveOriginalGriff13-Feb-15 2:21 
GeneralRe: Want Opinion on school assignment Pin
Eddy Vluggen13-Feb-15 3:03
professionalEddy Vluggen13-Feb-15 3:03 
GeneralRe: Want Opinion on school assignment Pin
OriginalGriff13-Feb-15 4:34
mveOriginalGriff13-Feb-15 4:34 
GeneralRe: Want Opinion on school assignment Pin
Eddy Vluggen13-Feb-15 4:52
professionalEddy Vluggen13-Feb-15 4:52 
GeneralRe: Want Opinion on school assignment Pin
Truck5313-Feb-15 5:01
Truck5313-Feb-15 5:01 
GeneralRe: Want Opinion on school assignment Pin
Dave Kreskowiak13-Feb-15 3:03
mveDave Kreskowiak13-Feb-15 3:03 
GeneralRe: Want Opinion on school assignment Pin
Truck5313-Feb-15 5:01
Truck5313-Feb-15 5:01 
GeneralRe: Want Opinion on school assignment Pin
Pete O'Hanlon13-Feb-15 3:18
mvePete O'Hanlon13-Feb-15 3:18 
GeneralRe: Want Opinion on school assignment Pin
Truck5313-Feb-15 5:01
Truck5313-Feb-15 5:01 
Questionhow to insert wifi scan data into sql table Pin
Olu_0112-Feb-15 18:03
Olu_0112-Feb-15 18:03 
AnswerRe: how to insert wifi scan data into sql table Pin
Wendelius12-Feb-15 18:31
mentorWendelius12-Feb-15 18:31 
GeneralRe: how to insert wifi scan data into sql table Pin
Olu_0112-Feb-15 23:17
Olu_0112-Feb-15 23:17 
GeneralRe: how to insert wifi scan data into sql table Pin
Wendelius13-Feb-15 3:01
mentorWendelius13-Feb-15 3:01 
GeneralRe: how to insert wifi scan data into sql table Pin
Olu_0116-Feb-15 12:16
Olu_0116-Feb-15 12:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.