how to compile two .cs file in visual c# express edition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aznimah
    New Member
    • Nov 2009
    • 19

    #1

    how to compile two .cs file in visual c# express edition

    hi, if anyone can help me how to compile two .cs file? this program i refer to other programmer attachment. i really need help. thank you

    Form2.cs

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace image
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
    
            private void Form2_Load(object sender, EventArgs e)
            {
                
             string[] s2=new string[] {"32.547",
                                    "32.546",
                                    "32.547",
                                    "32.549",
                                    "32.546",
                                    "32.547",
                                    "32.544",
                                    "32.546",
                                    "32.548",
                                    "32.549",
                                    "32.546",
                                    "32.547",
                                    "32.548",
                                    "32.548",
                                    "32.548",
                                    "32.543",
                                    "32.547",
                                    "32.546",
                                    "32.546",
                                    "32.545",
                                    "32.544"};
             string[] s1 = new string[]{"-117.053",
                                        "-117.052",
                                        "-117.052",
                                        "-117.052",
                                        "-117.051",
                                        "-117.051",
                                        "-117.05",
                                        "-117.049",
                                        "-117.045",
                                        "-117.045",
                                        "-117.042",
                                        "-117.042",
                                        "-117.042",
                                        "-117.037",
                                        "-117.036",
                                        "-117.034",
                                        "-117.033",
                                        "-117.032",
                                        "-117.031",
                                        "-117.03",
                                        "-117.029",
                                        };
    
    
       
             Point[] pts = new Point[s1.Length];
             for (int i = 0; i < s1.Length; i++)
             {
                 pts[i] = new Point(Convert.ToDouble(s1[i]), Convert.ToDouble(s2[i]));
             }
             Point[] chpts = Convexhull.convexhull(pts);
            // Console.WriteLine("Area is " + area(chpts));
             System.IO.StreamWriter sr = new System.IO.StreamWriter(@"D:/tt.txt");
             string str = "";
             for (int i = 0; i < chpts.Length; i++)
             {
                 sr.WriteLine(chpts[i].ToString());
             }
             sr.Close();
    
            }
        }
    }
    and another file

    ConvexHull.cs

    Code:
    using System;
    using System.Drawing.Imaging;
    using System.Drawing;
    namespace image
    {
    // ------------------------------------------------------------
    
    // This implementation correctly handles duplicate points, and
    // multiple points with the same x-coordinate.
    
    // 1. Sort the points lexicographically by increasing (x,y), thus 
    //    finding also a leftmost point L and a rightmost point R.
    // 2. Partition the point set into two lists, upper and lower, according as 
    //    point is above or below the segment LR.  The upper list begins with 
    //    L and ends with R; the lower list begins with R and ends with L.
    // 3. Traverse the point lists clockwise, eliminating all but the extreme
    //    points (thus eliminating also duplicate points).
    // 4. Eliminate L from lower and R from upper, if necessary.
    // 5. Join the point lists (in clockwise order) in an array.
    
    class Convexhull {	
      public static Point[] convexhull(Point[] pts) {
        // Sort points lexicographically by increasing (x, y)
        int N = pts.Length;
    		if (N<=1)
    			return pts;
        Polysort.Quicksort(pts);
        Point left = pts[0];	  
    	Point right = pts[N-1];
        // Partition into lower hull and upper hull
        CDLL lower = new CDLL(left), upper = new CDLL(left);
        for (int i=0; i<N; i++) {
          double det = Point.Area2(left, right, pts[i]);
          if (det > 0) 
            upper = upper.Append(new CDLL(pts[i])); 
          else if (det < 0) 
            lower = lower.Prepend(new CDLL(pts[i]));
        }      
        lower = lower.Prepend(new CDLL(right)); 
        upper = upper.Append(new CDLL(right)).Next;
        // Eliminate points not on the hull
        eliminate(lower);
        eliminate(upper);
        // Eliminate duplicate endpoints
        if (lower.Prev.val.Equals(upper.val))
          lower.Prev.Delete();
        if (upper.Prev.val.Equals(lower.val))
          upper.Prev.Delete();
        // Join the lower and upper hull
        Point[] res = new Point[lower.Size() + upper.Size()];
        lower.CopyInto(res, 0);
        upper.CopyInto(res, lower.Size());
        return res;
    		 
      }
    
      // Graham's scan
      private static void eliminate(CDLL start) {
        CDLL v = start, w = start.Prev;
        bool fwd = false;
        while (v.Next != start || !fwd) {
          if (v.Next == w)
            fwd = true;
          if (Point.Area2(v.val, v.Next.val, v.Next.Next.val) < 0) // right turn
            v = v.Next;
          else {                                       // left turn or straight
            v.Next.Delete();
            v = v.Prev;
          }
        }
      }
    }
    
    // ------------------------------------------------------------
    
    // Points in the plane
    
    public class Point : Ordered {
      private static readonly Random rnd = new Random();
    
      private double x, y;
      
    	public int X
    	{
    		get
    		{
    		return (int)x;
    		}
    		set
    		{
    		x=(double)value;
    		}
    	}
    	public int Y
    	{
    		get
    		{
    			return (int)y;
    		}
    		set
    		{
    			y=(double)value;
    		}
    	}
    
      public Point(double x, double y) { 
        this.x = x; this.y = y; 
      }
    
      public override string ToString() { 
        return "(" + x + ", " + y + ")"; 
      }
    
      public static Point Random(int w, int h) { 
        return new Point(rnd.Next(w), rnd.Next(h));
      }
    
      public bool Equals(Point p2) { 
        return x == p2.x && y == p2.y; 
      }
    
      public override bool Less(Ordered o2) { 
        Point p2 = (Point)o2;
        return x < p2.x || x == p2.x && y < p2.y;
      }
    
      // Twice the signed area of the triangle (p0, p1, p2)
      public static double Area2(Point p0, Point p1, Point p2) { 
        return p0.x * (p1.y-p2.y) + p1.x * (p2.y-p0.y) + p2.x * (p0.y-p1.y); 
      }
    }
    
    // ------------------------------------------------------------
    
    // Circular doubly linked lists of Point
    
    class CDLL {
      private CDLL prev, next;     // not null, except in deleted elements
      public Point val;
      
      // A new CDLL node is a one-element circular list
      public CDLL(Point val) { 
        this.val = val; next = prev = this; 
      }
    
      public CDLL Prev {
        get { return prev; }
      }
    
      public CDLL Next {
        get { return next; }
      }
    
      // Delete: adjust the remaining elements, make this one point nowhere
      public void Delete() {
        next.prev = prev; prev.next = next;
        next = prev = null;
      }
    
      public CDLL Prepend(CDLL elt) {
        elt.next = this; elt.prev = prev; prev.next = elt; prev = elt;
        return elt;
      }
    
      public CDLL Append(CDLL elt) {
        elt.prev = this; elt.next = next; next.prev = elt; next = elt;
        return elt;
      }
    
      public int Size() {
        int count = 0;
        CDLL node = this;
        do {
          count++;
          node = node.next;
        } while (node != this);
        return count;
      }
    
      public void PrintFwd() {
        CDLL node = this;
        do {
          Console.WriteLine(node.val);
          node = node.next;
        } while (node != this);
        Console.WriteLine();
      }
    
      public void CopyInto(Point[] vals, int i) {
        CDLL node = this;
        do {
          vals[i++] = node.val;	// still, implicit checkcasts at runtime 
          node = node.next;
        } while (node != this);
      }
    }
    
    // ------------------------------------------------------------
    
    class Polysort {
      private static void swap(Point[] arr, int s, int t) {
        Point tmp = arr[s];  arr[s] = arr[t];  arr[t] = tmp;    
      }
    private static void swap(Ordered[] arr, int s, int t) {
        Ordered tmp = arr[s];  arr[s] = arr[t];  arr[t] = tmp;    
      }
    
    
      // Typed OO-style quicksort a la Hoare/Wirth
    
      private static void qsort(Ordered[] arr, int a, int b) {
        // sort arr[a..b]
        if (a < b) { 
          int i = a, j = b;
          Point x = (Point)(arr[(i+j) / 2]);             
          do {                              
            while (arr[i].Less(x)) i++;     
            while (x.Less(arr[j])) j--;     
            if (i <= j) {                           
              swap(arr, i, j);                
              i++; j--;                     
            }                             
          } while (i <= j);                 
          qsort(arr, a, j);                 
          qsort(arr, i, b);                 
        }                                   
      }
    
      public static void Quicksort(Ordered[] arr) {
        qsort(arr, 0, arr.Length-1);
      }
    }
    
    public abstract class Ordered {
      public abstract bool Less(Ordered that);
    }
    
    anyone can help explain it to me, thanks
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Your professor didn't cover this in class?
    • In visual studio create a new project, of type Windows Forms project.
    • It will already have a Form1 by default - your code has a Form2.
    • So add a new Form.
    • Copy/paste your code for Form2 over the default code for Form2
    • Add a new class
    • Copy/paste your code for the other classes.
    • Press F5 to compile and run


    I would HIGHLY recommend you not use the namespace you have of "image".
    It is far too close to the existing .NET object of 'Image' (with a capital i) and will just cause confusion. Be creative. This is some type of boat plotting I would guess by the class name of convexhull. So call the project BoatPlotter or something unique.

    You're also going to have a problem with your class of "Point" (second code segment line 78) as it already exists in the System.Drawing namespace, which you will want to use for doing your drawing. Yeah technically you can use it because it will be in a different namespace but you'll have to fully qualify every use of it as
    BoatPlotter.Poi nt
    to differentiate it from
    System.Drawing. Point
    Who needs that hastle? Just call it BoatPoint to make it unique.

    As a tip, break up your classes to one file each. Sure they are short now and could easily be in one file, but why get into that bad habit. Its much more manageable to have one class to one file. This also gets you into the team coding ethic where you may be working on one class of 10,000 lines while a co-worker can have another file open with a different class of 40,000 lines. If you have them all in one file then you can't share nicely with the other kids at the office.

    convexHull.cs
    boatPoint.cs
    CDDL.cs
    polySort.cs

    Its all much easier to maintain over time.

    Comment

    • aznimah
      New Member
      • Nov 2009
      • 19

      #3
      {quote of tlhintoq's entire message removed as unnessary, by tlhintoq}

      thanks tlhintoq for the explanation, i already compile the code regarding to your suggestion. seem there is no error.

      however, how about the output. it only show the form2 in blank. Did i miss somewhere. I never learn this language at university, i'm totally new to this language. i want to know the output since i'm working on image (shape recognition). i want to use the convex hull to identify the extreme points of shape example triangle.

      can you help me more. i already run an earlier program to read, and convert to binary form.
      Code:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      using System.Collections;
      using System.IO;
      
      namespace JaccardRecognition
      {
          public partial class shape : Form
          {
              Bitmap Image1, Image2;
              String textImage1 = "";
              String textImage2 = "";
             // float a, b, p, q, r, jd;
             // int sum1 = 0, sum2 = 0, sum3 = 0;
              // bool flag = true;
      
              public shape()
              {
                  InitializeComponent();
              }
      
              private void Form1_Load(object sender, EventArgs e)
              {
              }
      
              /*Open and read the first image*/
      
              private void OpenFirstImageBttn_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
              {
                  openFileDialog1.FileName = "";
                  openFileDialog1.Title = "Images";
                  openFileDialog1.Filter = "All Images|*.jpg; *.bmp; *.png";//
                  openFileDialog1.ShowDialog();
                  if (openFileDialog1.FileName.ToString() != "")
                  {
                      Box1.ImageLocation = openFileDialog1.FileName.ToString();
                      Image1 = new Bitmap(openFileDialog1.FileName.ToString());
                      string h = Convert.ToString(Image1.Height);
                      string w = Convert.ToString(Image1.Width);
                      displayh.Text = h;
                      displayw.Text = w;
                  }
              }
      
      
      
              /*Covert first image into binary*/
      
              private void convertImage1_Click(object sender, EventArgs e)
              {
                  for (int i = 0; i < Image1.Height; i++)
                  {
                      for (int j = 0; j < Image1.Width; j++)
                      {
                          if (Image1.GetPixel(j, i).A.ToString() == "255" && Image1.GetPixel(j, i).B.ToString() == "255" && Image1.GetPixel(j, i).G.ToString() == "255" && Image1.GetPixel(j, i).R.ToString() == "255")
                          {
                              textImage1 = textImage1 + "0";
                          }
                          else
                          {
                              textImage1 = textImage1 + "1";
                          }
                      }
                      textImage1 = textImage1 + "\r\n";
                  }
                  text1.Text = textImage1;
              }
              /*Open and read the second image*/
      
              private void OpenSecondImageBttn_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
              {
                  openFileDialog2.FileName = "";
                  openFileDialog2.Title = "Images";
                  openFileDialog2.Filter = "All Images|*.jpg; *.bmp; *.png";//
                  openFileDialog2.ShowDialog();
                  if (openFileDialog1.FileName.ToString() != "")
                  {
                      Box2.ImageLocation = openFileDialog2.FileName.ToString();
                      Image2 = new Bitmap(openFileDialog2.FileName.ToString());
                      string h2 = Convert.ToString(Image2.Height);
                      string w2 = Convert.ToString(Image2.Width);
                      displayh2.Text = h2;
                      displayw2.Text = w2;
                  }
              }
      
              /*Covert second image into binary*/
              private void convertImage2_Click(object sender, EventArgs e)
              {
                  for (int i = 0; i < Image2.Height; i++)
                  {
                      for (int j = 0; j < Image2.Width; j++)
                      {
                          if (Image2.GetPixel(j, i).A.ToString() == "255" && Image2.GetPixel(j, i).B.ToString() == "255" && Image2.GetPixel(j, i).G.ToString() == "255" && Image2.GetPixel(j, i).R.ToString() == "255")
                          {
                              textImage2 = textImage2 + "0";
      
                          }
                          else
                          {
                              textImage2 = textImage2 + "1";
                          }
                      }
                      textImage2 = textImage2 + "\r\n";
                  }
                  text2.Text = textImage2;
              }
      
              /*This will compare both image from the binary data to check the similatiry measure */
              /*Retrieve data in binary form to compute
               --> The image size 16x16 pixels
               --> looping the image 16 times where the comparison between in rows operation*/
      
              private void Compare_Click(object sender, EventArgs e)
              {
                  int p = 0;
                  int q = 0;
                  int r = 0;
                  for (int i = 0; i < textImage1.Length; i++)
                  {
                      if (textImage1[i] == '1')
                      {
                          if (textImage2[i] == '1')
                          {
                              p++;
                          }
                          else
                          {
                              q++;
                          }
                      }
                      else if (textImage2[i] == '1')
                      {
                          r++;
                      }
                  }
      
                  double jd = ((double)q + r) / (p + q + r);
                  //double jd = 1-(p / (p + q + r));
      
                      string valueP = Convert.ToString(p);
                      string valueQ = Convert.ToString(q);
                      string valueR = Convert.ToString(r);
                     // string valueA = Convert.ToString(a);
                     // string valueB = Convert.ToString(b);
                      text3.Text = valueP;
                      text4.Text = valueQ;
                      text5.Text = valueR;
                     // textqr.Text = valueA;
                     // textpqr.Text = valueB; 
      
      
                      if (jd == 0)
                      {
                          MessageBox.Show("Images are similar,ratio results:" + jd);
                      }
                      else if (jd == 0.01 || jd <= 1)
                      {
                          MessageBox.Show("Images are dissimilar,ratio results:" + jd);
                      }
      
                      else
                          MessageBox.Show("can not compare this images");
      
                     this.Dispose();
              }
          }
      }
      Last edited by tlhintoq; Apr 1 '10, 04:23 PM. Reason: [quote] replaced with [code]

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I wish you good luck with your project. I'm happy I was able to help with the original issue of how to compile it.
        however, how about the output. it only show the form2 in blank. Did i miss somewhere. I never learn this language at universit
        Neither did I. All self-taught by trial and error and a LOT of books and reading and experimenting and taking apart other people's codes and projects.

        re: how to compile two .cs file in visual c# express edition
        {quote of tlhintoq's entire message removed as unnessary, by tlhintoq}

        thanks tlhintoq for the explanation, i already compile the code regarding to your suggestion. seem there is no error.

        however, how about the output. it only show the form2 in blank. Did i miss somewhere. I never learn this language at university, i'm totally new to this language. i want to know the output since i'm working on image (shape recognition). i want to use the convex hull to identify the extreme points of shape example triangle.
        I'm not really looking to take on more projects or to collaborate on someone else's project. You Visual Studio project is up and running. From here you need to do what we *all* do... debug it.

        Comment

        • aznimah
          New Member
          • Nov 2009
          • 19

          #5
          thanks a lot for helping me ;) i really appreciate.

          Comment

          Working...