コード例 #1
0
ファイル: Ex17.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your name");
            string username = ISSConsole.ReadString();

            Console.WriteLine("Enter your gender");
            char gender = ISSConsole.ReadChar();

            Console.WriteLine("Enter your age");
            int age = ISSConsole.ReadInt();

            if (gender == 'M')
            {
                if (age >= 40)
                {
                    Console.WriteLine("Good morning Uncle {0}", username);
                }
                else
                {
                    Console.WriteLine("Good morning Mr {0}", username);
                }
            }
            else
            {
                if (age >= 40)
                {
                    Console.WriteLine("Good morning Aunty {0}", username);
                }
                else
                {
                    Console.WriteLine("Good morning Ms. {0}", username);
                }
            }
        }
コード例 #2
0
ファイル: Exercise1.cs プロジェクト: vigneshwarikandan/class
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your name");
            string username = ISSConsole.ReadString();

            Console.WriteLine("Good morning " + username);
        }
コード例 #3
0
        public static void Ex15()
        {
            Console.Write("Please insert a number to check if it is Armstrong number: ");
            string a   = ISSConsole.ReadString();
            int    num = Convert.ToInt32(a);
            double sum = 0;

            /*for (int i = 0; i < 3; i++)
             * {
             *  char b = a[i];
             *  int c = Convert.ToInt32(new string(b, 1));
             *  sum += c * c * c;
             * }*/
            int digits = a.Length;

            for (int i = num; i > 0; i /= 10)
            {
                int rem = i % 10;
                sum += Math.Pow(rem, digits);
            }
            if (sum == num)
            {
                Console.WriteLine($"{a} is an Armstrong number.");
            }
            else
            {
                Console.WriteLine($"{a} is not an Armstrong number.");
            }
        }
コード例 #4
0
        public static void Ex44() //Character replacement program
        {
            string s  = ISSConsole.ReadString("Please insert string: ");
            char   c1 = ISSConsole.ReadChar("Character to be replaced: ");
            char   c2 = ISSConsole.ReadChar("Character chosen to replace: ");

            substitute(s, c1, c2);
        }
コード例 #5
0
        // ------------------ STRING MANIPULATION TEEHEE --------------------------------//

        public static void Ex36() //PALINDROME
        {
            string s = ISSConsole.ReadString("Please insert a string to check if it is a Palindrome:");

            s = s.ToLower();         //Properties to convert all to lower
            int    n     = s.Length; //Assign to a length of the string to a variable
            bool   check = true;
            string r     = "";

            for (int i = 0; i < n; i++)
            {
                string letter = s.Substring(i, 1);                            //First parameter determines the starting index and strings starts with [0],
                                                                              //the second parameter determines the amount of char to concatenate
                                                                              //this step breaks it down into individual letters and assign it to letter

                if (letter.CompareTo("a") >= 0 && letter.CompareTo("z") <= 0) //method instance ** Clarify this part from StackOverflow
                {
                    r += letter;
                }
            }
            //Program
            for (int i = 0; i < r.Length; i++)
            {
                if (r[n - 1 - i] != r[i])
                { //if
                    check = false;
                }
            }
            if (check != false)
            {
                Console.WriteLine($"{s} is a Palindrome.");
            }
            else
            {
                Console.WriteLine($"{s} is not a Palindrome.");
            }

            //more elegant code

            //public static boolean Palindrom(char[] word)
            //{
            //    int i1 = 0;
            //    int i2 = word.length - 1;
            //    while (i2 > i1)
            //    {
            //        if (word[i1] != word[i2])
            //        {
            //            return false;
            //        }
            //        ++i1;
            //        --i2;
            //    }
            //    return true;
            //}
        }
コード例 #6
0
        public static void Ex37() //Title Cases
        {
            string temp;
            string result = "";
            string s      = ISSConsole.ReadString("Please insert your sentence: ");

            string[] a = s.Split(' ');
            for (int i = 0; i < a.Length; i++)
            {
                temp    = a[i].Substring(0, 1).ToUpper();
                a[i]    = temp + a[i].Substring(1, a[i].Length - 1);
                result += a[i] + " ";
            }
            Console.WriteLine(result);
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your name");
            string username = ISSConsole.ReadString();

            Console.WriteLine("Enter your gender as M or F");
            char gender = ISSConsole.ReadChar();

            if (gender == 'M')
            {
                Console.WriteLine("Good morning Mr.{0}", username);
            }
            else
            {
                Console.WriteLine("Good morning Ms.{0}", username);
            }
        }
コード例 #8
0
        public static void Ex38()
        {
            int    numA = 0, numE = 0, numI = 0, numO = 0, numU = 0;
            string s = ISSConsole.ReadString("Please type a phrase to count it's vowels number: ");
            string x = s.ToLower();
            int    n = s.Length;

            for (int i = 0; i < n; i++)
            {
                if (x[i] == 'a')
                {
                    numA++;
                }
                if (x[i] == 'e')
                {
                    numE++;
                }
                if (x[i] == 'i')
                {
                    numI++;
                }
                if (x[i] == 'o')
                {
                    numO++;
                }
                if (x[i] == 'u')
                {
                    numU++;
                }
            }
            Console.WriteLine($"Number of vowel A: {numA}");
            Console.WriteLine($"Number of vowel E: {numE}");
            Console.WriteLine($"Number of vowel I: {numI}");
            Console.WriteLine($"Number of vowel O: {numO}");
            Console.WriteLine($"Number of vowel U: {numU}");
        }
コード例 #9
0
ファイル: TicTacToe.cs プロジェクト: vigneshwarikandan/class
        static void enterPosition(char side)
        {
            bool valid = false;
            int  i = 0, j = 0;

            do
            {
                bool input_invalid = false;
                Console.Write(side + " your turn:");
                string move = ISSConsole.ReadString();

                switch (move)
                {
                case "A1":
                    i = 0;
                    j = 0;
                    break;

                case "A2":
                    i = 1;
                    j = 0;
                    break;

                case "A3":
                    i = 2;
                    j = 0;
                    break;

                case "B1":
                    i = 0;
                    j = 1;
                    break;

                case "B2":
                    i = 1;
                    j = 1;
                    break;

                case "B3":
                    i = 2;
                    j = 1;
                    break;

                case "C1":
                    i = 0;
                    j = 2;
                    break;

                case "C2":
                    i = 1;
                    j = 2;
                    break;

                case "C3":
                    i = 2;
                    j = 2;
                    break;

                default:
                    input_invalid = true;
                    Console.WriteLine("Please enter a valid input");
                    break;
                }
                if (input_invalid == false)
                {
                    if (board[i, j] != ' ')
                    {
                        Console.WriteLine("That position is not empty. enter again");
                    }
                    else
                    {
                        board[i, j] = side;
                        valid       = true;
                    }
                }
            } while (valid == false);
        }
コード例 #10
0
 public static void Ex45()
 {
     string s1 = ISSConsole.ReadString("Please insert firstWord: ");
     string s2 = ISSConsole.ReadString("Please insert word to find in firstWord: ");
 }
コード例 #11
0
        //Strings and Array (Redo this for Exams) -------------
        public static void Ex40()
        {
            int    tempMark;
            string tempName;

            string[] name = new string[5] {
                "John", "Venkat", "Mary", "Victor", "Betty"
            };
            int[] mark = new int[5] {
                63, 29, 75, 82, 55
            };
            string choose = ISSConsole.ReadString("Please choose report type a/b: ").ToLower();

            //SORTING ** IMPORTANT**
            //First Report sorts the marks in descending order
            //Bubble Sort :D

            if (choose == "a")
            {
                for (int i = 0; i < 4; i++) //creating the first 4 to compare with 5 elements below
                {
                    for (int j = i + 1; j < 5; j++)
                    {
                        if (mark[i] < mark[j])   //if mark[i] is less than mark[j], //change sign for ascending
                        {
                            tempMark = mark[i];  //tempMark will be assigned the lower element
                            mark[i]  = mark[j];  //Mark[j] which is the larger numer(descending, if ascending just change sign) will be assigned to the first position
                            mark[j]  = tempMark; //mark[i]'s value whihc is stored in tempMark will be assigned to Mark[j];now in second position
                            tempName = name[i];  //likewise for the names of the students who have been assigned their respective marks
                            name[i]  = name[j];  //can consider two dimensional arrays version later on during revision
                            name[j]  = tempName;
                        }
                    }
                }
            }
            else if (choose == "b")
            {
                for (int i = 0; i < 4; i++)
                {
                    for (int j = i + 1; j < 5; j++)
                    {
                        if (name[i].CompareTo(name[j]) == 1) //returns the value 0 if the argument string is equal to this string,
                                                             //a value less than 0 if this string is lexicographically less than the
                                                             //string argument and a value greater than 0 if this string is lexicographically greater than the string argument.
                                                             //To sort by Descending alphabetical order just use -1
                        {
                            tempMark = mark[i];
                            mark[i]  = mark[j];
                            mark[j]  = tempMark;
                            tempName = name[i];
                            name[i]  = name[j];
                            name[j]  = tempName;
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Please choose a or b.");
                choose = ISSConsole.ReadString();
            }
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine($"{name[i]}\t{mark[i]}");
            }
        }