الأربعاء، 27 أبريل 2011

last quiz solution


below is nearly a  suggested solution for the last quiz, there are a bit differences , but idea is identical
good luck for all




using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Hash_ArrayListPro
{
    class Program
    {
        public static Hashtable geo_info = new Hashtable(); 
        static void Main(string[] args)
        {
            for (int i = 0; i < 3; i++) 
            {
                Console.WriteLine("Enter country ");
                string country = Console.ReadLine();

                Console.WriteLine("Enter country area");
                object area = Console.ReadLine();

                geo_info.Add(country, area);


            } // end for

            Console.WriteLine("Geographic information are:");
            foreach (Object Key in geo_info.Keys)
            {
                Console.WriteLine(" {0} Area is :  {1}", Key, geo_info[Key]);

            }

            Console.WriteLine("enter the country name you want to modify its area");

            string key1 = Console.ReadLine();
            if (geo_info.Contains(key1))
            {
                geo_info[key1] = 111.1111;

                Console.WriteLine("Geographic information After Modification:");
                foreach (Object Key in geo_info.Keys)
                {
                    Console.WriteLine(" {0} Area is :  {1}", Key, geo_info[Key]);

                }
            }
            else
            {
                Console.WriteLine("Not exists Country");
            }
            
            
            ArrayList list = new ArrayList();
            list.Add("ali");
            list.Add(88);
            list.Add('B');

            foreach (object x in list)
                Console.WriteLine(x);


            Console.WriteLine(list.Count);

            Console.ReadLine();
            list.Insert(1,"hasan");
            list.Reverse();
            foreach (object x in list)
                Console.WriteLine(x);
  




        }// end main
    }
}

الأحد، 3 أبريل 2011

quize 4 suggested solution



using System;
using System.Collections.Generic;
using System.Text;

namespace quize4
{
    class MobilePhone
    {
        int cost;
        int serial;
        protected string color;
        public MobilePhone()
        {
        Console.WriteLine("default values is cost =0, serial=0 and color=non");
            cost = 0;
            serial = 0;
            color = "non";
        }
        public MobilePhone(int c, int s, string co)
        {
            cost = c;
            serial = s;
            color = co;
             Console.WriteLine("general mobile object created");
             Console.WriteLine("{0},{1},{2}",cost,serial,color);

        }
        public int Cost
        {
        set {cost=value;}
        get{return cost;}
         }

       public int Serial{
        set { serial = value; }
        get { return serial; }
   
    }


        public void ComputePrice(double tax)
        {
            Console.WriteLine("total price in piaster is :");
            Console.WriteLine(tax + cost);
           
        }

    }

    class NokiPhone:MobilePhone
    {
        string model;
      
        public NokiPhone(  int c, int s,string co, string m):base(c,s,co)
        {
            model = m;
           Console.WriteLine(model);
        }



        public new void ComputePrice(double tax)
        {
            Console.WriteLine("total price in JD is :");
         
            Console.WriteLine(tax + Cost/100);
          

        }
   
    }

    class  SonyPhone: MobilePhone
    {

        public SonyPhone()
        {
            color = "blue";
            Console.WriteLine("\nthe sony color is {0} \n",color);
         }
   
    }

    class Program
    {
        static void Main(string[] args)
        {
            MobilePhone m = new MobilePhone(20,11,"red");
            m.ComputePrice(0.4);

            NokiPhone n = new NokiPhone(20, 22, "yellow","6300");
           
            n.ComputePrice(0.4);

       
         
            SonyPhone s = new SonyPhone();



        }
    }
}