rarment's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
8 (0.01 per day)
Joined:
27-July 12
Profile Views:
1,488
Last Active:
User is offline Aug 31 2012 03:29 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   rarment has not set their status

Posts I've Made

  1. In Topic: Finding the cube root in Scheme

    Posted 31 Aug 2012

    View Postsepp2k, on 31 August 2012 - 02:10 AM, said:

    From your code it looks like you're trying to implement Newton's method and you don't know which value to use as the second argument to the improve function - is this correct¹? If so, do you know what the second value should be logically and you just don't know how to keep track of that value in the code or don't you fully understand Newton's method?


    Yes, I am trying to implement Newton's Method and I don't know what the second value should be and don't know how to keep track of the value.

    Quote

    In general you should think about what each variable in your code is supposed to represent and then make sure that you use that variable in that way. For example the n in cube-root is supposed to be the number whose cube root you're supposed to find, correct? And the value returned by improve is supposed to be an improved guess of what the cube root might be, right? And you're then passing that possible cube root as the new value of n - does that make sense?


    Yes, that all is correct and makes sense

    Quote

    Also your good-enough? function takes 2 arguments, but uses 3.


    I see that now. I was getting so frustrated and I guess I added a variable and just didn't fully understand what I was doing. I really am having a hard time with functional programming.

    Quote

    ¹ In the future it would help if you point these things out explicitly, so I don't have to guess based on the code.


    I will be more specific in the future, thank you!
  2. In Topic: Structuring a C# program

    Posted 30 Jul 2012

    I was thinking a list of lists would work, but thought there might be an easier, less complicated, way to do it. But how you did it makes perfect sense. This is what I came up with for the list of lists, check my logic? the " 0" is what separates different entity types.

    private void readDXF(String source)
            {
                shapeList = new List<List<string>>();
    
                List<String> tempList = new List<String>();
    
                OpenFileDialog dialog = new OpenFileDialog();
    
                int m = 50;
    
                dialog.DefaultExt = ".dxf";
    
                dialog.ShowDialog();
    
                String path = dialog.FileName;
    
                StreamReader dxfFileIn = new StreamReader(path);
    
                String temp = dxfFileIn.ReadLine();
    
                while (temp != "ENTITIES")
                {
                    temp = dxfFileIn.ReadLine();
                }
                while (temp != "ENDSEC")
                {
                    temp = dxfFileIn.ReadLine();
    
                    if (temp == "  0")
                    {
                        for (int i = 0; i <= 2; i++)
                        {
                            tempList.Add(temp);
                            temp = dxfFileIn.ReadLine();
                            if (temp == "ENDSEC")
                            {
                                shapeList.RemoveAt(shapeList.Count - 1);
                            }
                        }
                    temp = m.ToString();
    
                    tempList.Add(temp);
    
                    m++;
    
                    temp = dxfFileIn.ReadLine();
                    }
                    shapeList.Add(tempList);
                }
                
                dxfFileIn.Close();
    
            }
    
    
  3. In Topic: Structuring a C# program

    Posted 30 Jul 2012

    So in the list it contains the shape type plus all of the data that is needed to build it. So I need somewhere to go through that list and pull the data out and then send it to the buildXXX methods... example code below. (listIn is the list I had to hold the data, your shapeList.

    if (listIn[j] == "LINE")
                    {
                        double startX = 0;
                        double startY = 0;
                        double endX = 0;
                        double endY = 0;
                        String lineType = "CONTINUOUS";
    
                        j++; ;
    
                        while (listIn[j] != "  0")
                        {
                            if (listIn[j] == " 10")
                            {
                                j++;
                                startX = Convert.ToDouble(listIn[j]);
                                j++;
                            }
                            else if (listIn[j] == " 20")
                            {
                                j++;
                                startY = Convert.ToDouble(listIn[j]);
                                j++;
                            }
                            else if (listIn[j] == " 11")
                            {
                                j++;
                                endX = Convert.ToDouble(listIn[j]);
                                j++;
                            }
                            else if (listIn[j] == " 21")
                            {
                                j++;
                                endY = Convert.ToDouble(listIn[j]);
                                j++;
                            }
                            else if (listIn[j] == "  6")
                            {
                                j++;
                                lineType = listIn[j];
                                j++;
                            }
                            else
                                j++;
    
    
                        }
    
                        createObjects.buildLine(startX, startY, endX, endY, lineType);
    
                    }
    
    



    View PostChrisKellyDev, on 30 July 2012 - 09:56 AM, said:

    Personally, this is how I would set up your files. I tend to get a little class happy so feel free to cut/merge things as you see fit.

    Mainwindow.xaml.cs
    - Set up your initial windows and stuff.
    - Creates a new DXF class.

    DXFFile.cs
    - Contains a constructor (probably takes a file path as a parameter).
    - Contains a ReadDXF method that reads your file into your List<string>.
    - Contains a GetList method that returns the List<String>

    ShapeBuilder.cs
    - Contains all your BuildXXX methods and logic to determine which one to use.

    Here are some sample skeletons.

    Mainwindow.xaml.cs
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Canvas mainCanvas = new Canvas();
    
            DXFFile dxfFile = new DXFFile("source file");
    
            foreach (string s in dxfFile.GetDXFList())
            {
                ShapeBuilder shape = new ShapeBuilder(s);
                mainCanvas.Children.Add(shape.Draw());
            }
        }
    }
    


    DXFFile.cs
    class DXFFile
    {
        string file;
        List<string> shapeList;
    
        public DXFFile(string sourceFile)
        {
            file = sourceFile;
            ReadDXF(file);
        }
    
        private void ReadDXF(string sourceFile)
        {
            //Your readDXF code that returns a List<string>.
            shapeList = new List<string>();
        }
    
        public List<string> GetDXFList()
        {
            return shapeList;
        }
    }
    



    ShapeBuilder.cs
    class ShapeBuilder
    {
        string shape;
    
        public ShapeBuilder(string shapeType)
        {
            shape = shapeType;
        }
    
        public UIElement Draw()
        {
            //Logic to determine what buildXXXX method to call.
            return BuildLIne();
        }
    
        private Line BuildLIne()
        {
            //buildLine code.
            return new Line();
        }
    }
    
  4. In Topic: Structuring a C# program

    Posted 30 Jul 2012

    Right now I have 3 files. I have a Mainwindow.xaml.cs which starts like this...

    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
    
            public class createObjects
            {
                Canvas mainCanvas = new Canvas();
                int hatchCounter = 1;
    
                public void buildLine(double x1in, double y1in, double x2in, double y2in, string lineType)
                {
    
    //stuff
    
     mainCanvas.Children.Add(line);
    
    


    Which actually draws the line/circle/ellipse/etc... to the canvas. I have a similar method (buildCircle) for each different type of figure I want to draw.

    Then I have another file called ReadInput which starts likes this...

    
       class ReadInput
        {
            CreateObject createObjects = new CreateObject();
    
            public void readList(List<String> listIn)
            {
    
    


    And that readList method reads through a List<String> and calls the buildXXXX method from the above class for each different type it encounters.

    And then I have a third class that I am just working on now that reads through the actual dxf file and saves the data to the List<String>. It is...

       class CreateList
        {
    
            public void readDxf()
            {
                List<String> readDxf = new List<string>();
    
                OpenFileDialog dialog = new OpenFileDialog();
    
                int m = 50;
    
                dialog.DefaultExt = ".dxf";
    
                dialog.ShowDialog();
    
                String path = dialog.FileName;
    
                StreamReader dxfFileIn = new StreamReader(path);
    
                String temp = dxfFileIn.ReadLine();
    
                while (temp != "ENTITIES")
                {
                    temp = dxfFileIn.ReadLine();
                }
                while (temp != "ENDSEC")
                {
                    temp = dxfFileIn.ReadLine();
    
                    if (temp == "  0")
                    {
                        for (int i = 0; i <= 2; i++)
                        {
                            readDxf.Add(temp);
                            temp = dxfFileIn.ReadLine();
                            if (temp == "ENDSEC")
                            {
                                readDxf.RemoveAt(readDxf.Count - 1)
                            }
                        }
                    temp = m.ToString();
    
                    readDxf.Add(temp);
    
                    m++;
    
                    temp = dxfFileIn.ReadLine();
                    }
                    readDxf.Add(temp);
                }
                
                ReadInput readIn = new ReadInput();
    
                readList(
            }
    
        }
    
    


    I'm just getting confused on how to tie all of these together and make it into a cohesive program. Oh, and for testing on the xaml I have a button that will open a filedialog to locate the dxf file, as you can see in the code.

    Thanks for any help!
  5. In Topic: Structuring a C# program

    Posted 30 Jul 2012

    I am from a java background. So these 2 groupd of functions need to be broken up into separate classes?? I'm not sure why I am having such a hard time putting this all together.

    And with the spaces in the strings, the way that the dxf file differentiates some different features is with the different indention level of the number. So there could be a "6" and a " 6" that have different meanings.

    Thanks for any help!

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

rarment hasn't added any friends yet.

Comments

rarment has no profile comments yet. Why not say hello?