Friday, February 28, 2014

CD_SaleRegisterWithDouble: (Wk-2) Jan 15, 2014

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

namespace SaleRegWithDouble
{
    class Program
    {
        static void Main(string[] args)
        {
            double quantity, subtotal, saletax, totalcost;

            double cdcost = 1.20;
            double tax = 0.098;

            Console.WriteLine("Enter CD purchased: ");
            quantity = Convert.ToDouble(Console.ReadLine());

            subtotal = quantity * cdcost;
            saletax = subtotal * tax;

            totalcost = subtotal + saletax;

            Console.WriteLine("Total Cost: {0:c}", totalcost);
            Console.ReadLine();
        }
    }
}

Wage Calculation with Double; (Wk-2) Jan 15, 2014

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

namespace WageCalculationWithDouble
{
    class Program
    {
        static void Main(string[] args)
        {
            double hr, wage, earning;

            Console.Write("Enter hours worked: ");
            hr = Convert.ToDouble(Console.ReadLine());

            Console.Write("Enter wage per hour: ");
            wage = Convert.ToDouble(Console.ReadLine());

            earning = hr * wage;

            Console.WriteLine("\nEmployee Earning = {0:c}", earning);

            Console.ReadLine();
        }
    }
}

Thursday, February 27, 2014

Classes of IP Address

There are five classes of available IP ranges: Class A, Class B, Class C, Class D and Class E, while only A, B and C are commonly used. Each class allows for a range of valid IP addresses


Class A      1.0.0.1      to   126.255.255.254            Supports 16 million hosts on each of 127 networks.

Class B      128.1.0.1  to   191.255.255.254             Supports 65,000 hosts on each of 16,000 networks.

Class C      192.0.1.1  to   223.255.254.254             Supports 254 hosts on each of 2 million networks.

Class D      224.0.0.0  to   239.255.255.255             Reserved for multicast groups.

Class E      240.0.0.0  to   254.255.255.254             Reserved

Array Exercises: (Wk-8), Feb 27, 2014

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

namespace ArrayMoreExercises
{
    class Program
    {
        static void Main(string[] args)
        {
            //1. Declare/Create/Initialize array with 20 values positive and negative

            int[] x = new int[20] { -1, 3, -7, 8, -21, 40, 55, -9, 0, 8, -1, -5, 23, 56, 15, -16, 17, -18, 19, 20 };

            for (int i = 0; i < x.Length; i++)
            {
                Console.WriteLine("Index: {0} value: {1}", i, x[i]);
            }

            //      Write for loop to:

            //============================ Ex-2 ================================
            Console.WriteLine("\n====================Ex-2=====================");
            //Determine / Display the number of negative values in the array


            for (int i = 0; i < x.Length; i++)
            {
                if (x[i] < 0)
                {
                    Console.WriteLine("Negative Value: {0}", x[i]);
                }

            }


            //============================ Ex-3 ================================
            Console.WriteLine("\n====================Ex-3=====================");
            //3. Determine / Display the number of odd values in the array


            for (int i = 0; i < x.Length; i++)
            {
                if (x[i] % 2 != 0)
                {
                    Console.WriteLine("Odd values are: {0}", x[i]);
                }
            }


            //============================ Ex-4 ================================
            Console.WriteLine("\n====================Ex-4=====================");
            //4. Determine / Display the average of all the values in the array.


            double total = 0;
            double avg = 0;
            for (int i = 0; i < x.Length; i++)
            {
                total += x[i];
                avg = total / x.Length;
            }
            Console.WriteLine("Total: {0} \nAverage Value: {1:f}", total, avg);


            //============================ Ex-5 ================================
            Console.WriteLine("\n====================Ex-5=====================");
            //5. Determine / Display the average of all the positive values in the array


            int positivesum = 0;
            int positivevalue = 0;

            for (int i = 0; i < x.Length; i++)
            {
                if (x[i] > 0)
                {
                    positivesum += x[i];
                    positivevalue++;
                }
            }
            double positiveaverage = positivesum / positivevalue;
            Console.WriteLine("Positive Total: {0} \nPositive Average: {1:f}", positivesum, positiveaverage);


            //============================ Ex-6 ================================
            Console.WriteLine("\n====================Ex-6=====================");
            //6. Determine / Display the average of all the even negative value....


            int evennegativesum = 0;
            int evennegativevalue = 0;

            for (int i = 0; i < x.Length; i++)
            {
                if (x[i] < 0 && x[i] % 2 == 0)
                {
                    evennegativesum += x[i];
                    evennegativevalue++;
                }
            }
            double evennegativeaverage = evennegativesum / evennegativevalue;
            Console.WriteLine("Even Negative Sum: {0} \nEven Negative Average: {1:f}", evennegativesum, evennegativeaverage);


            //============================ Ex-7 ================================
            Console.WriteLine("\n====================Ex-7=====================");
            //7. Determine / Display the max value in the array.


            //int Min = 0;
            int Max = 0;

            //for (int i = 0; i < x.Length; i++)
            //{
            //    if (Min > x[i])
            //        Min = x[i];
            //}
            //Console.WriteLine();
            //Console.WriteLine("Minimum number in Array is = {0}", Min);

            for (int i = 0; i < x.Length; i++)
            {
                if (Max < x[i])
                    Max = x[i];
            }
            Console.WriteLine("Maximum number in Array is= {0}\n", Max);
            Console.ReadKey();
        }
    }
}

Cylinder Volume w/ Double: (Wk-2), Jan 14, 14

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

namespace Volume_w_Double
{
    class Program
    {
        static void Main(string[] args)
        {
            double radius, height, perimeter, area, volume;

            Console.Write("Enter radius of cylinder: ");
            radius = Convert.ToDouble(Console.ReadLine());

            Console.Write("Enter height of cylinder: ");
            height = Convert.ToDouble(Console.ReadLine());

            perimeter = 2 * Math.PI * radius;
            area = Math.PI * radius * radius;
            volume = Math.PI * radius * radius * height;
         
            Console.WriteLine("Perimeter: {0} \nArea: {1} \nVolume: {2}", perimeter, area, volume);
            Console.ReadLine();
        }
    }
}


Calculating Average with Double: (Wk-2), Jan 14, 2014

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

namespace Average_w_Double
{
    class Program
    {
        static void Main(string[] args)
        {
            double x, y, z, average;
            Console.Write("Enter first value: ");
            x = Convert.ToDouble(Console.ReadLine());

            Console.Write("Enter second value: ");
            y = Convert.ToDouble(Console.ReadLine());

            Console.Write("Enter third value: ");
            z = Convert.ToDouble(Console.ReadLine());

            average = (x + y + z) / 3;

            Console.WriteLine("Average Value is {0}", average);

            Console.ReadLine();
        }
    }
}

Calculating Perimeter and Area with Integer: (Wk-2), Jan 14, 14

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

namespace Computing_Area_Integer
{
    class Program
    {
        static void Main(string[] args)
        {
            //Request length and width from user
            //then compute perimeter, area and display all

            int length, width, perimeter, area;

            //Request length and width from the user
            Console.Write("Enter length: ");
            length = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter width: ");
            width = Convert.ToInt32(Console.ReadLine());

            perimeter = 2 * length + 2 * width;
            area = width * length;

            Console.WriteLine("\nPerimeter = {0} \nArea = {1}", perimeter, area);

            Console.ReadLine();           
        }
    }
}

Reading Integer Values: (Wk-2) Jan 14, 14

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

namespace ReadingIntegerValues
{
    class Program
    {
        static void Main(string[] args)
        {
            //Read 2 integer values from user
            //The Console.ReadLine() formats the input into string.
            //Therefore you need to convert the string to an integer
            //Use. Convert.ToInt32() to convert string to integer


            int x, y, sum, diff, mul, quotient;

            Console.Write("Enter first integer value: ");
            x = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter second integer value: ");
            y = Convert.ToInt32(Console.ReadLine());

            //Process by: adding, multiplying,
            //Substracting and dividing

            sum = x + y;
            diff = x - y;
            mul = x * y;
            quotient = x / y;

            //display all results
            Console.WriteLine("X = {0}", x);
            Console.WriteLine("Y = {0}", y);
            Console.WriteLine("Sum = {0} Subtraction = {1} Multiplication = {2} Division = {3}", sum, diff, mul, quotient);
            Console.ReadLine();
        }
    }
}

Displaying Variables (Wk-2) Jan 13, 14

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

namespace DisplayingVariables
{
    class Program
    {
        static void Main(string[] args)
        {
            //Show how you could use a single Console.WriteLine to display multiple variables.
            int value1 = 234;
            int value2 = 567;
            int value3 = 678;
            int value4 = 390;

            //Option 1: Display value1 and value2
            Console.Write("Value 1 is =  ");
            Console.WriteLine(value1);

            Console.Write("Value 2 is =  ");
            Console.WriteLine(value2);

            //Option 2: Display value1 and value2
            //          Concatenating string and the numeric value

            Console.WriteLine("\n");
            Console.WriteLine("Value 1 is = " + value1);
            Console.WriteLine("Value 2 is = " + value2);
            Console.WriteLine("Value 3 is = " + value3);

            //Option 3: Concatenate all into a single Console.WriteLine
            Console.WriteLine("\n");
            Console.WriteLine("Value 1 is = " + value1 + "\nValue 2 is = " + value2);

            //Option 4: Uses space holders (Most preferred way)
            Console.WriteLine("\n");
            Console.WriteLine("Value 1 = {0} \nValue 2 = {1} \nValue 3 = {2} \nValue 4 = {3}", value1, value2, value3, value4);

            Console.ReadLine();
        }
    }
}

Wednesday, February 26, 2014

Reading String: (Wk-1) Jan 10, 14

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

namespace String
{
    class Program
    {
        static void Main(string[] args)
        {
            //Display a menu for a user to choose from
            //menu contains a list of items

            string burger, drink;

            Console.WriteLine("Food Menu: ");
            Console.WriteLine("\t 1. Regular Burger $3.99");
            Console.WriteLine("\t 2. Cheese Burger $4.99");
            Console.WriteLine("\t 3. Fat Burger $6.99");

            Console.Write("\n\tEnter your Selection: ");
            burger = Console.ReadLine();

            Console.WriteLine("\n\n");
            //Display menu for drinks

            Console.WriteLine("Drink Menu: ");
            Console.WriteLine("\t 1. Coke $1.99");
            Console.WriteLine("\t 2. Pepsi $2.99");
            Console.WriteLine("\t 3. Mineral Water $0.99");

            Console.Write("\n\t Enter your drink selection: ");
            drink = Console.ReadLine();

            //display all the selected items
            Console.WriteLine("\n\nYou have selected " + burger + " and " + drink);

            Console.ReadLine();
        }
    }
}

String: (Wk-1), Jan 9, 14

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

namespace ReadingString
{
    class Program
    {
        static void Main(string[] args)
        {
            //A string is a sequence of characters
            //Defined within a pair of double quotes
            //such as:  "Computer Science"

            //Use Console.ReadLine() to read data entered by the user
            //The Console.ReadLine() reads data in the form of a string

            //Example: Ask user to enter firstname and last name
            //          then, display the full name

            string firstname, lastname, fullname;
            // read string from user
            Console.Write("Enter your first name: ");
            firstname = Console.ReadLine();
            Console.Write("Enter your last name: ");
            lastname = Console.ReadLine();

            //concatenate first and last names into full name
            //then display the full name.

            fullname = firstname + " " + lastname;
            Console.Write("Your full name is: ");
            Console.Write(fullname);

            Console.ReadLine();
        }
    }
}


SumDiffProdQuotient: (Wk-1) Jan 9, 14

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

namespace SumDiffProdQuotient
{
    class Program
    {
        static void Main(string[] args)
        {
            //declare all the variables
            int x, y, sum, diff, prod, quotient;
            //assigning values to x and y;
            x = 123;
            y = 35;
            //compute sum, diff, prod, quotient;
            sum = x + y;
            diff = x - y;
            prod = x * y;
            quotient = x / y;

            //display
            Console.Write("Sum = ");
            Console.WriteLine(sum);

            Console.Write("Difference = ");
            Console.WriteLine(diff);

            Console.Write("Product = ");
            Console.WriteLine(prod);

            Console.Write("Quotient = ");
            Console.WriteLine(quotient);

            Console.ReadLine(); //pause
        }
    }
}

Integer Data Types: (Wk-1), Jan 8, 14

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

namespace IntegerDataTypes
{
    class Program
    {
        static void Main(string[] args)
        {
            //This is a line comment.
            //Each variable that you use in a program must be declared;
            //Specify its data type
            //Syntax: data type variable name;

            int x; //this tells C# that x is int meaning that x is an integer
                    //whose range of values is between -2,147, 483, 648 to 2, 147, 483, 647
                    //Once a variable is declared, you can assign a value to it.
                    //making sure that the value is within the specified range.
            x = 5;
            //display the variable x

            Console.Write("X= ");
            Console.WriteLine(x);


            Console.ReadLine();//pause
        }
    }
}

HelloWorld!: (Wk-1) Jan 7, 14

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

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.ReadLine();

        }
    }
}