473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

19
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

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace image
  10. {
  11.     public partial class Form2 : Form
  12.     {
  13.         public Form2()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.  
  18.         private void Form2_Load(object sender, EventArgs e)
  19.         {
  20.  
  21.          string[] s2=new string[] {"32.547",
  22.                                 "32.546",
  23.                                 "32.547",
  24.                                 "32.549",
  25.                                 "32.546",
  26.                                 "32.547",
  27.                                 "32.544",
  28.                                 "32.546",
  29.                                 "32.548",
  30.                                 "32.549",
  31.                                 "32.546",
  32.                                 "32.547",
  33.                                 "32.548",
  34.                                 "32.548",
  35.                                 "32.548",
  36.                                 "32.543",
  37.                                 "32.547",
  38.                                 "32.546",
  39.                                 "32.546",
  40.                                 "32.545",
  41.                                 "32.544"};
  42.          string[] s1 = new string[]{"-117.053",
  43.                                     "-117.052",
  44.                                     "-117.052",
  45.                                     "-117.052",
  46.                                     "-117.051",
  47.                                     "-117.051",
  48.                                     "-117.05",
  49.                                     "-117.049",
  50.                                     "-117.045",
  51.                                     "-117.045",
  52.                                     "-117.042",
  53.                                     "-117.042",
  54.                                     "-117.042",
  55.                                     "-117.037",
  56.                                     "-117.036",
  57.                                     "-117.034",
  58.                                     "-117.033",
  59.                                     "-117.032",
  60.                                     "-117.031",
  61.                                     "-117.03",
  62.                                     "-117.029",
  63.                                     };
  64.  
  65.  
  66.  
  67.          Point[] pts = new Point[s1.Length];
  68.          for (int i = 0; i < s1.Length; i++)
  69.          {
  70.              pts[i] = new Point(Convert.ToDouble(s1[i]), Convert.ToDouble(s2[i]));
  71.          }
  72.          Point[] chpts = Convexhull.convexhull(pts);
  73.         // Console.WriteLine("Area is " + area(chpts));
  74.          System.IO.StreamWriter sr = new System.IO.StreamWriter(@"D:/tt.txt");
  75.          string str = "";
  76.          for (int i = 0; i < chpts.Length; i++)
  77.          {
  78.              sr.WriteLine(chpts[i].ToString());
  79.          }
  80.          sr.Close();
  81.  
  82.         }
  83.     }
  84. }
  85.  
and another file

ConvexHull.cs

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Drawing.Imaging;
  3. using System.Drawing;
  4. namespace image
  5. {
  6. // ------------------------------------------------------------
  7.  
  8. // This implementation correctly handles duplicate points, and
  9. // multiple points with the same x-coordinate.
  10.  
  11. // 1. Sort the points lexicographically by increasing (x,y), thus 
  12. //    finding also a leftmost point L and a rightmost point R.
  13. // 2. Partition the point set into two lists, upper and lower, according as 
  14. //    point is above or below the segment LR.  The upper list begins with 
  15. //    L and ends with R; the lower list begins with R and ends with L.
  16. // 3. Traverse the point lists clockwise, eliminating all but the extreme
  17. //    points (thus eliminating also duplicate points).
  18. // 4. Eliminate L from lower and R from upper, if necessary.
  19. // 5. Join the point lists (in clockwise order) in an array.
  20.  
  21. class Convexhull {    
  22.   public static Point[] convexhull(Point[] pts) {
  23.     // Sort points lexicographically by increasing (x, y)
  24.     int N = pts.Length;
  25.         if (N<=1)
  26.             return pts;
  27.     Polysort.Quicksort(pts);
  28.     Point left = pts[0];      
  29.     Point right = pts[N-1];
  30.     // Partition into lower hull and upper hull
  31.     CDLL lower = new CDLL(left), upper = new CDLL(left);
  32.     for (int i=0; i<N; i++) {
  33.       double det = Point.Area2(left, right, pts[i]);
  34.       if (det > 0) 
  35.         upper = upper.Append(new CDLL(pts[i])); 
  36.       else if (det < 0) 
  37.         lower = lower.Prepend(new CDLL(pts[i]));
  38.     }      
  39.     lower = lower.Prepend(new CDLL(right)); 
  40.     upper = upper.Append(new CDLL(right)).Next;
  41.     // Eliminate points not on the hull
  42.     eliminate(lower);
  43.     eliminate(upper);
  44.     // Eliminate duplicate endpoints
  45.     if (lower.Prev.val.Equals(upper.val))
  46.       lower.Prev.Delete();
  47.     if (upper.Prev.val.Equals(lower.val))
  48.       upper.Prev.Delete();
  49.     // Join the lower and upper hull
  50.     Point[] res = new Point[lower.Size() + upper.Size()];
  51.     lower.CopyInto(res, 0);
  52.     upper.CopyInto(res, lower.Size());
  53.     return res;
  54.  
  55.   }
  56.  
  57.   // Graham's scan
  58.   private static void eliminate(CDLL start) {
  59.     CDLL v = start, w = start.Prev;
  60.     bool fwd = false;
  61.     while (v.Next != start || !fwd) {
  62.       if (v.Next == w)
  63.         fwd = true;
  64.       if (Point.Area2(v.val, v.Next.val, v.Next.Next.val) < 0) // right turn
  65.         v = v.Next;
  66.       else {                                       // left turn or straight
  67.         v.Next.Delete();
  68.         v = v.Prev;
  69.       }
  70.     }
  71.   }
  72. }
  73.  
  74. // ------------------------------------------------------------
  75.  
  76. // Points in the plane
  77.  
  78. public class Point : Ordered {
  79.   private static readonly Random rnd = new Random();
  80.  
  81.   private double x, y;
  82.  
  83.     public int X
  84.     {
  85.         get
  86.         {
  87.         return (int)x;
  88.         }
  89.         set
  90.         {
  91.         x=(double)value;
  92.         }
  93.     }
  94.     public int Y
  95.     {
  96.         get
  97.         {
  98.             return (int)y;
  99.         }
  100.         set
  101.         {
  102.             y=(double)value;
  103.         }
  104.     }
  105.  
  106.   public Point(double x, double y) { 
  107.     this.x = x; this.y = y; 
  108.   }
  109.  
  110.   public override string ToString() { 
  111.     return "(" + x + ", " + y + ")"; 
  112.   }
  113.  
  114.   public static Point Random(int w, int h) { 
  115.     return new Point(rnd.Next(w), rnd.Next(h));
  116.   }
  117.  
  118.   public bool Equals(Point p2) { 
  119.     return x == p2.x && y == p2.y; 
  120.   }
  121.  
  122.   public override bool Less(Ordered o2) { 
  123.     Point p2 = (Point)o2;
  124.     return x < p2.x || x == p2.x && y < p2.y;
  125.   }
  126.  
  127.   // Twice the signed area of the triangle (p0, p1, p2)
  128.   public static double Area2(Point p0, Point p1, Point p2) { 
  129.     return p0.x * (p1.y-p2.y) + p1.x * (p2.y-p0.y) + p2.x * (p0.y-p1.y); 
  130.   }
  131. }
  132.  
  133. // ------------------------------------------------------------
  134.  
  135. // Circular doubly linked lists of Point
  136.  
  137. class CDLL {
  138.   private CDLL prev, next;     // not null, except in deleted elements
  139.   public Point val;
  140.  
  141.   // A new CDLL node is a one-element circular list
  142.   public CDLL(Point val) { 
  143.     this.val = val; next = prev = this; 
  144.   }
  145.  
  146.   public CDLL Prev {
  147.     get { return prev; }
  148.   }
  149.  
  150.   public CDLL Next {
  151.     get { return next; }
  152.   }
  153.  
  154.   // Delete: adjust the remaining elements, make this one point nowhere
  155.   public void Delete() {
  156.     next.prev = prev; prev.next = next;
  157.     next = prev = null;
  158.   }
  159.  
  160.   public CDLL Prepend(CDLL elt) {
  161.     elt.next = this; elt.prev = prev; prev.next = elt; prev = elt;
  162.     return elt;
  163.   }
  164.  
  165.   public CDLL Append(CDLL elt) {
  166.     elt.prev = this; elt.next = next; next.prev = elt; next = elt;
  167.     return elt;
  168.   }
  169.  
  170.   public int Size() {
  171.     int count = 0;
  172.     CDLL node = this;
  173.     do {
  174.       count++;
  175.       node = node.next;
  176.     } while (node != this);
  177.     return count;
  178.   }
  179.  
  180.   public void PrintFwd() {
  181.     CDLL node = this;
  182.     do {
  183.       Console.WriteLine(node.val);
  184.       node = node.next;
  185.     } while (node != this);
  186.     Console.WriteLine();
  187.   }
  188.  
  189.   public void CopyInto(Point[] vals, int i) {
  190.     CDLL node = this;
  191.     do {
  192.       vals[i++] = node.val;    // still, implicit checkcasts at runtime 
  193.       node = node.next;
  194.     } while (node != this);
  195.   }
  196. }
  197.  
  198. // ------------------------------------------------------------
  199.  
  200. class Polysort {
  201.   private static void swap(Point[] arr, int s, int t) {
  202.     Point tmp = arr[s];  arr[s] = arr[t];  arr[t] = tmp;    
  203.   }
  204. private static void swap(Ordered[] arr, int s, int t) {
  205.     Ordered tmp = arr[s];  arr[s] = arr[t];  arr[t] = tmp;    
  206.   }
  207.  
  208.  
  209.   // Typed OO-style quicksort a la Hoare/Wirth
  210.  
  211.   private static void qsort(Ordered[] arr, int a, int b) {
  212.     // sort arr[a..b]
  213.     if (a < b) { 
  214.       int i = a, j = b;
  215.       Point x = (Point)(arr[(i+j) / 2]);             
  216.       do {                              
  217.         while (arr[i].Less(x)) i++;     
  218.         while (x.Less(arr[j])) j--;     
  219.         if (i <= j) {                           
  220.           swap(arr, i, j);                
  221.           i++; j--;                     
  222.         }                             
  223.       } while (i <= j);                 
  224.       qsort(arr, a, j);                 
  225.       qsort(arr, i, b);                 
  226.     }                                   
  227.   }
  228.  
  229.   public static void Quicksort(Ordered[] arr) {
  230.     qsort(arr, 0, arr.Length-1);
  231.   }
  232. }
  233.  
  234. public abstract class Ordered {
  235.   public abstract bool Less(Ordered that);
  236. }
  237.  
  238. anyone can help explain it to me, thanks
  239.  
Apr 1 '10 #1
4 2271
tlhintoq
3,525 Expert 2GB
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.Point
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.
Apr 1 '10 #2
aznimah
19
{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.
Expand|Select|Wrap|Line Numbers
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using System.Collections;
  11. using System.IO;
  12.  
  13. namespace JaccardRecognition
  14. {
  15.     public partial class shape : Form
  16.     {
  17.         Bitmap Image1, Image2;
  18.         String textImage1 = "";
  19.         String textImage2 = "";
  20.        // float a, b, p, q, r, jd;
  21.        // int sum1 = 0, sum2 = 0, sum3 = 0;
  22.         // bool flag = true;
  23.  
  24.         public shape()
  25.         {
  26.             InitializeComponent();
  27.         }
  28.  
  29.         private void Form1_Load(object sender, EventArgs e)
  30.         {
  31.         }
  32.  
  33.         /*Open and read the first image*/
  34.  
  35.         private void OpenFirstImageBttn_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  36.         {
  37.             openFileDialog1.FileName = "";
  38.             openFileDialog1.Title = "Images";
  39.             openFileDialog1.Filter = "All Images|*.jpg; *.bmp; *.png";//
  40.             openFileDialog1.ShowDialog();
  41.             if (openFileDialog1.FileName.ToString() != "")
  42.             {
  43.                 Box1.ImageLocation = openFileDialog1.FileName.ToString();
  44.                 Image1 = new Bitmap(openFileDialog1.FileName.ToString());
  45.                 string h = Convert.ToString(Image1.Height);
  46.                 string w = Convert.ToString(Image1.Width);
  47.                 displayh.Text = h;
  48.                 displayw.Text = w;
  49.             }
  50.         }
  51.  
  52.  
  53.  
  54.         /*Covert first image into binary*/
  55.  
  56.         private void convertImage1_Click(object sender, EventArgs e)
  57.         {
  58.             for (int i = 0; i < Image1.Height; i++)
  59.             {
  60.                 for (int j = 0; j < Image1.Width; j++)
  61.                 {
  62.                     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")
  63.                     {
  64.                         textImage1 = textImage1 + "0";
  65.                     }
  66.                     else
  67.                     {
  68.                         textImage1 = textImage1 + "1";
  69.                     }
  70.                 }
  71.                 textImage1 = textImage1 + "\r\n";
  72.             }
  73.             text1.Text = textImage1;
  74.         }
  75.         /*Open and read the second image*/
  76.  
  77.         private void OpenSecondImageBttn_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
  78.         {
  79.             openFileDialog2.FileName = "";
  80.             openFileDialog2.Title = "Images";
  81.             openFileDialog2.Filter = "All Images|*.jpg; *.bmp; *.png";//
  82.             openFileDialog2.ShowDialog();
  83.             if (openFileDialog1.FileName.ToString() != "")
  84.             {
  85.                 Box2.ImageLocation = openFileDialog2.FileName.ToString();
  86.                 Image2 = new Bitmap(openFileDialog2.FileName.ToString());
  87.                 string h2 = Convert.ToString(Image2.Height);
  88.                 string w2 = Convert.ToString(Image2.Width);
  89.                 displayh2.Text = h2;
  90.                 displayw2.Text = w2;
  91.             }
  92.         }
  93.  
  94.         /*Covert second image into binary*/
  95.         private void convertImage2_Click(object sender, EventArgs e)
  96.         {
  97.             for (int i = 0; i < Image2.Height; i++)
  98.             {
  99.                 for (int j = 0; j < Image2.Width; j++)
  100.                 {
  101.                     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")
  102.                     {
  103.                         textImage2 = textImage2 + "0";
  104.  
  105.                     }
  106.                     else
  107.                     {
  108.                         textImage2 = textImage2 + "1";
  109.                     }
  110.                 }
  111.                 textImage2 = textImage2 + "\r\n";
  112.             }
  113.             text2.Text = textImage2;
  114.         }
  115.  
  116.         /*This will compare both image from the binary data to check the similatiry measure */
  117.         /*Retrieve data in binary form to compute
  118.          --> The image size 16x16 pixels
  119.          --> looping the image 16 times where the comparison between in rows operation*/
  120.  
  121.         private void Compare_Click(object sender, EventArgs e)
  122.         {
  123.             int p = 0;
  124.             int q = 0;
  125.             int r = 0;
  126.             for (int i = 0; i < textImage1.Length; i++)
  127.             {
  128.                 if (textImage1[i] == '1')
  129.                 {
  130.                     if (textImage2[i] == '1')
  131.                     {
  132.                         p++;
  133.                     }
  134.                     else
  135.                     {
  136.                         q++;
  137.                     }
  138.                 }
  139.                 else if (textImage2[i] == '1')
  140.                 {
  141.                     r++;
  142.                 }
  143.             }
  144.  
  145.             double jd = ((double)q + r) / (p + q + r);
  146.             //double jd = 1-(p / (p + q + r));
  147.  
  148.                 string valueP = Convert.ToString(p);
  149.                 string valueQ = Convert.ToString(q);
  150.                 string valueR = Convert.ToString(r);
  151.                // string valueA = Convert.ToString(a);
  152.                // string valueB = Convert.ToString(b);
  153.                 text3.Text = valueP;
  154.                 text4.Text = valueQ;
  155.                 text5.Text = valueR;
  156.                // textqr.Text = valueA;
  157.                // textpqr.Text = valueB; 
  158.  
  159.  
  160.                 if (jd == 0)
  161.                 {
  162.                     MessageBox.Show("Images are similar,ratio results:" + jd);
  163.                 }
  164.                 else if (jd == 0.01 || jd <= 1)
  165.                 {
  166.                     MessageBox.Show("Images are dissimilar,ratio results:" + jd);
  167.                 }
  168.  
  169.                 else
  170.                     MessageBox.Show("can not compare this images");
  171.  
  172.                this.Dispose();
  173.         }
  174.     }
  175. }
Apr 1 '10 #3
tlhintoq
3,525 Expert 2GB
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.
Apr 1 '10 #4
aznimah
19
thanks a lot for helping me ;) i really appreciate.
Apr 2 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: clintonG | last post by:
Visual C# 2005 Express Edition is a simple, lightweight, integrated development environment designed for beginning programmers and non-professional developers interested in building Windows Forms,...
0
by: Maury | last post by:
I just downloaded .Net Framework Beta2 and Visual Web Developer Express Edition Beta and Visual C# Express Edition. I installed .Net Framework Beta2, then I installed Visual Web Developer...
1
by: QLD_AU | last post by:
Has anyone see the following error ? VS 2005 Installs ok, however the SQL Mobile Edition (part of a full install) fails with the following error ? With Thanks Jason
3
by: Wayne Allen | last post by:
I am receiving a compile error when attempting to include Directshow in a managed C++ program using Visual C++ 2005 Express Edition Version 8. The ..NET framework is version 2.0.50727. To...
4
by: Andrew Robinson | last post by:
My main dev machine has WinXp and VS2005 (pro). 1. I need to install VWD Express Edition so that I can do some instruction on this. Any issues with both on the same machine. Installation order?...
2
by: Progman | last post by:
I have Visual Studio 2005 Standard edition. Is ti the same thing as the Express edition or Standard is more?
6
by: Simon Brown | last post by:
Hi, I am considering buying Visual Studio Standard Edition and have these questions about the VC++ incuded. Could you also, to help me know the diffrene in capablility, answer the same questions...
1
by: Ruth | last post by:
Which edition of Visual Studio do I have? "About" says that I have Visual Studio 8.0.5.0727.42: is this the professional, express, or enterprise edition? I do not believe it is the Team edition....
6
by: ulillillia | last post by:
I've been following the tutorial here to learn Windows programming (along with the help file from the Windows Platform SDK): http://www.cprogramming.com/tutorial/opengl_windows_programming.html ...
23
by: =?Utf-8?B?TWlrZTE5NDI=?= | last post by:
This is an example that is supposed to work in VB http://support.microsoft.com/kb/175512/en-us After spending a couple of hours downloading and installing VB Express 2008 after someone told me it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.