วันอังคารที่ 25 มกราคม พ.ศ. 2554

เมธอด 2 และไฟล์ข้อมูล ฉบับสมบูรณ์

ข้อที่ 1
using System;
class MainClass
{
    static void add_bonus(){
        
    }
    public static void Main(string[] args)
    {
        int s1 = 1, s2 = 2, s3 = 3;
        Console.Write("Enter Bonus: ");
        int bonus = int.Parse(Console.ReadLine());
        add_bonus(ref s1, ref s2, ref s3, bonus);
        Console.WriteLine("{0}, {1}, {2}",s1,s2,s3);
        Console.ReadKey();
    }
}
ข้อที่ 2
using System;
class MainClass
{
    static void swap(){

    }
    public static void Main(string[] args)
    {
        int sum = 0;
        Console.Write("Enter a: ");
        int a = int.Parse(Console.ReadLine());
        Console.Write("Enter b: ");
        int b = int.Parse(Console.ReadLine());
        swap();
        Console.WriteLine("Swap a and b");
        Console.WriteLine("a={0} b={1}",a,b);
        Console.ReadKey();
    }
}
ข้อ 3
using System;
class RefExample
{
    static void ReadTwoNums()
    {
        Console.WriteLine("Enter two number:");
        a = int.Parse(Console.ReadLine());
        b = int.Parse(Console.ReadLine());
    }
    static void Main()
    {
        int n1 = 0, n2 = 0;
        ReadTwoNums();
        Console.WriteLine("Numbers are {0} and {1}", n1, n2);
        Console.ReadKey();
    }
}

ข้อ 4
using System;
2: class MainClass {
3:     static void ReadPoint( )
4:     {
5: Console.Write("Enter x-coordinate: ");
6:             x = double.Parse(Console.ReadLine());
7:             Console.Write("Enter y-coordinate: ");
8:             y = double.Parse(Console.ReadLine());
9:     }
10:
11:     static double Distance( )
12:     {
13:            
14:     }
15:
16:     static void Main()
17:     {
18:             double ax, ay, bx, by;
19:             Console.WriteLine("Point A:");
20:             ReadPoint(out ax, out ay);
21:             Console.WriteLine("Point B:");
22:             ReadPoint(out bx, out by);
23:             Console.WriteLine("The distance between A and B is {0:f2}",
24:                               Distance(ax,ay,bx,by));
25:     }
26: }
ข้อ 5

using System;
class MainClass {
    static int Profit(int x)
    {
        
    }

    static void Main()
    {
        int a, b;
        Console.Write("Enter A:");
        a = int.Parse(Console.ReadLine());
        Console.Write("Enter B:");
        b = int.Parse(Console.ReadLine());

        int best = Profit(a);
        int bestAt = a;

        

        Console.WriteLine("Best profit is {0} at {1}", best, bestAt);
    }
}

ข้อ 6
using System;
class MainClass {
    static int h, d, n;

    /* this method checks if y is out of the well of depth h */
    static bool IsOut(int y, int h)
    {
       
    }

    static void ClimbUp(ref int y)
    {
       
    }

    static void FallDown(ref int y)
    {
       
    }

    static void Main()
    {
        h = int.Parse(Console.ReadLine());
        d = int.Parse(Console.ReadLine());
        n = int.Parse(Console.ReadLine());

        int day = 1;
        int y = 0;
        while(!IsOut(y,h))
        {
           
            day++;
        }
        Console.WriteLine("Get out on day {0}", day);
    }
}

ข้อ 7
using System;
class MainClass
{
    /* method IsSquare checks if y is a square. */
    static bool IsSquare(int y)
    {
        
    }

    /* method IsSquareFactor checks if f is a square factor of x */
    static bool IsSquareFactor(int f, int x)
    {
        
    }

    public static void Main(string[] args)
    {
        int x = int.Parse(Console.ReadLine());
        int i = 1;
        while()
        {
            if()
                Console.Write("{0} ", );
            i++;
        }
        Console.WriteLine();
    }
}

ข้อ 8
using System;

class Program
{
  static void CountPlusMinus()
  {
    
  }

  public static void Main(string[] args)
  {
    int plus, minus;
    CountPlusMinus();
    Console.WriteLine("Positive: {0}",plus);
    Console.WriteLine("Negative: {0}",minus);
    Console.ReadLine();
  }
}


ข้อ 9

ข้อ 10

ข้อ 11
using System;


namespace hellofile
{
    class Program
    {
        public static void Main(string[] args)
{
            StreamReader reader =
            int a = int.Parse();
            int b =
            int c =
            Console.WriteLine(a+b+c);
            Console.ReadLine();
            reader.
        }
    }
}

ข้อ 12
using System;
using System.IO;

namespace hellofile
{
    class Program
    {
        public static void Main(string[] args)
        {
            StreamReader reader = 
            int n = int.Parse();
            int i = 0;
            int total = 0;
            while(i < n)
            {
                
            }
            Console.WriteLine(total);
            Console.ReadLine();
            reader.Close();
        }
    }
}

ข้อ13
using System;
using System.IO;
namespace moving_average
{
  class Program
  {
    static void Update()
    {
      
    }

    public static void Main(string[] args)
    {
      StreamReader reader = new StreamReader("input.txt");
      int n = 0;
      double total = 0;
      double avr = 0;
      double x;
      do {
        x = double.Parse(reader.ReadLine());
        if(x != 0)
        {
          Update();
          Console.WriteLine("{0:f3} {1:f3}", total, avr);
        }
      } while();
      reader.Close();
      Console.ReadLine();
    }
  }
}

ข้อ 14

using System;
using System.IO;
namespace moving_average
{
  class Program
  {
    

    static void Update(double x)
    {
      
    }

    public static void Main(string[] args)
    {
      StreamReader reader = new StreamReader("input.txt");
      double x;
      do {
        x = double.Parse(reader.ReadLine());
        if(x != 0)
        {
          Update(x);
          Console.WriteLine("{0:f3} {1:f3}", total, avr);
        }
      } while();
      reader.Close();
      Console.ReadLine();
    }
  }
}

ข้อ 15

ข้อ 16



2 ความคิดเห็น:

  1. Pb1)
    1.1)
    ref int a,ref int b

    1.2)
    int c = a;
    a=b;
    b=c;

    1.3)
    ref a,ref b




    Pb2)
    2.1)
    out double x,out double y
    2.2)
    double ax,double ay,double bx,double by
    2.3)
    double c = Math.Sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
    return c;



    Pb3)
    3.1)
    int a =1000+ (50*x )+(150*x*x)-((int)Math.Pow(x,3));
    return a;

    3.2)
    while(abest)
    {best = Profit(a);
    bestAt = a;
    }
    }



    Pb4)
    4.1)
    if (d>=h)
    return true;
    if (y>=h)
    return true;
    else
    return false;

    4.2)
    y+=d;

    4.3)
    y-=n;

    4.4)
    ClimbUp(ref y);
    if (y0)
    plus ++;
    else
    minus ++;
    x = int.Parse(Console.ReadLine());
    }

    6.3)
    out plus,out minus




    Pb7.1)
    using System;
    using System.IO;

    namespace hellofile
    {
    class Program
    {
    public static void Main(string[] args)
    {
    StreamReader reader = new StreamReader("name.txt");
    string name = reader.ReadLine();
    string a = reader.ReadLine();
    Console.WriteLine(name);
    Console.WriteLine(a);
    Console.ReadLine();
    reader.Close();
    }
    }
    }




    Pb7.2)
    using System;
    using System.IO;

    namespace hellofile
    {
    class Program
    {
    public static void Main(string[] args)
    {
    StreamReader reader = new StreamReader("name.txt");
    string name = reader.ReadLine();
    string a = reader.ReadLine();
    Console.WriteLine(a);
    Console.WriteLine(name);
    Console.ReadLine();
    reader.Close();
    }
    }
    }




    Pb7.3)
    7.3.1)
    using System.IO;

    7.3.2)
    new StreamReader("numbers.txt");

    7.3.3)
    reader.ReadLine()

    7.3.4)
    int.Parse(reader.ReadLine());

    7.3.5)
    int.Parse(reader.ReadLine());

    7.3.6)
    Close();




    Pb8)
    8.1)
    new StreamReader("input.txt");

    8.2)
    reader.ReadLine()

    8.3)
    int s = int.Parse(reader.ReadLine());
    {
    if (s >= 0)
    total = total + s;

    }
    i++;



    Pb9)
    9.1)
    ref int n,ref double total,ref double avr,ref double x

    9.2)
    if (x!=0){
    total += x;
    avr = total/(n+1);
    n++;
    }

    9.3)
    ref n,ref total, ref avr,ref x

    9.4)
    x!=0




    Pb10)
    10.1)
    static double total = 0;
    static double avr = 0;
    static int i = 1;

    10.2)
    total+=x;
    avr = total/i;
    i++;

    10.3)
    x!=0




    Pb11)
    using System;
    using System.IO;

    namespace hellofile
    {
    class Program
    {
    public static void Main(string[] args)
    {
    StreamReader reader = new StreamReader("input.txt");
    int n = int.Parse(reader.ReadLine());
    int i = 1;
    int a = 0;
    int b = 0;
    int c = 0;
    while (i<=n)
    {
    string x = reader.ReadLine();
    if (x=="A")
    a++;
    else if (x=="B")
    b++;
    else if (x=="C")
    c++;
    i++;
    }
    Console.Write("{0} {1} {2}",a,b,c);
    Console.Read();

    }
    }
    }




    Pb bonus)

    using System;

    namespace program
    {
    class Program
    {
    static int x=1,ans=0,eror=0;
    static string y;
    static int low=0, high=1001;

    public static void Main(string[] args)
    {
    while (true)
    {
    x = int.Parse(Console.ReadLine());
    if (x==0)
    break;
    y = Console.ReadLine();
    if (y=="E")
    ans = x;
    else if (y=="L")
    if (x>=low)
    low = x;
    if (low>=high)
    eror = -1;
    else if (y=="H")
    if (x<=high)
    high = x;
    if (high<=low)
    eror = -1;
    }
    //Console.WriteLine("{0},{1},{2}",high,low,eror);
    if(high>=1001 || low <=0){
    Console.WriteLine("No solution");
    }
    else if(ans<=low && ans!=0){
    Console.WriteLine("No solution");
    }
    else if(high-low==2)
    {
    Console.WriteLine("Solution is {0}",low+1);
    }
    else if(ans!=0)
    {
    Console.WriteLine("Solution is {0}",ans);
    }
    else if(high-low>2 || eror!=-1){
    Console.WriteLine("Solution in range {0} - {1}",low+1,high-1);
    }
    else
    Console.WriteLine("No solution");
    Console.Read();
    }
    }
    }

    ตอบลบ
  2. ใรลอกแล้วไม่คิดตาม ระวังนะ จะ ตกเอา

    ตอบลบ