Sunday, 9 September 2012

2.ARRAYS STRINGS METHODS

ARRAYS STRINGS METHODS

namespace inventory
{
    class shop
    {
        int n, i;
       string[] name = new string[15];
        string[] type = new string[15];
        int[] rate = new int[15];
        int[] qty = new int [15];    
   public void add1()
{
    Console.WriteLine("Enter a stock to add");
    n = int.Parse(Console.ReadLine());
    for (i = 0; i <n; i++)
    {
        Console.WriteLine("Enter name ");
        name[i] = Console.ReadLine();
        name[i]=name[i].ToUpper();
        Console.WriteLine("Enter type");
        type[i] = Console.ReadLine();
        type[i]=type[i].ToUpper();
        Console.WriteLine("Enter rate");
        rate[i] =int.Parse( Console.ReadLine());
        Console.WriteLine("Enter quantity");
        qty[i] = int.Parse(Console.ReadLine());
      }
    }
      public  void show()
        {       
            for (i = 0; i <n; i++)
                Console.WriteLine(" " + name[i] + "\t\t" + type[i] + "\t\t" + rate[i] + "\t\t" + qty[i]);
        }
    public    void sale()
        {
            int f = 0, q = 0, x;
            Console.WriteLine("Enter name of stock");
            string temp;
            temp = Console.ReadLine();
            temp = temp.ToUpper();
            Console.WriteLine("quantity 1.Increase 2.decrease");
            x = int.Parse(Console.ReadLine());
            for (i = 0; i <n; i++)
            {
                if (name[i].Equals(temp))
                {
                    Console.WriteLine("\nEnter number of quantity");
                    q = int.Parse(Console.ReadLine());
                    if (x == 1)
                        qty[i] = qty[i] + q;
                    else
                        qty[i] = qty[i] - q;
                    f = 1;
                    Console.WriteLine("product found and stock updated");
                }
                if (f == 0)
                    Console.WriteLine("product not found");
           }
        }
        static void Main(string[] args)
        {
            shop s = new shop();
      while (true)
            {
                Console.WriteLine("1.Add new");
                Console.WriteLine("2.sales");
                Console.WriteLine("3.list stock");
                Console.WriteLine("4.Exit");
                Console.WriteLine("Enter ur choice");
                int n = int.Parse(Console.ReadLine());
                switch (n)
                {
                    case 1:
                        s.add1();
                        break;
                    case 2:
                        s.sale();
                        break;
                    case 3:
                        Console.WriteLine(" "+"Name"+"\t\t"+"Type"+"\t\t"+"Rate"+"\t\t"+"Qty");
                        s.show();
                        break;
                    case 4:
                        break;
                }
            }
     }
 }

No comments:

Post a Comment