Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6948693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:51:23+00:00 2026-05-27T13:51:23+00:00

I am required to create a program which reads in data from a .cvs

  • 0

I am required to create a program which reads in data from a .cvs file, and use these (x, y and z) values for a series of calculations.

I read in the file as a string, and then split this into 3 smaller strings for x, y and z.

The x, y and z coordinates represents the x and y coordinates of the contours of a lake, and the depth (z).
One of the calculations which I have to do, is to calculate the surface area of the lake, using the formula (x[i]*y[i+1])-(x[i+1]*y[i]), where z(depth) = 0.

I can get my code to run perfectly, up until the x[i+1] and y[i+1], where it keeps giving me a value of 0.

Can someone please tell me how to fix this?

Here is my code;

{
    string[] ss = File.ReadAllLines(@"C:File.csv");

    for (int i = 1; i < ss.Length; i++)
    {
        string[] valuesAsString = ss[i].Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

        double[] X = new double[valuesAsString.Length];
        double[] Y = new double[valuesAsString.Length];
        double[] Z = new double[valuesAsString.Length];

        for (int n = 0; n < 1; n++)
        {
            X[n] = double.Parse(valuesAsString[0]);
            Y[n] = double.Parse(valuesAsString[1]);
        }

        do
        {
            double SurfaceArea = (X[n] * Y[n + 1]) - (X[n + 1] * Y[n]);

            Console.WriteLine(SurfaceArea);
        }

        while (Z[n] == 0);
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:51:24+00:00Added an answer on May 27, 2026 at 1:51 pm

    Ok, im not sure if i got it right, so you if you would take a look to what i did and tell me if its of any help.

    After reviewng it a little i came up with the following:

    A class for the values

        public class ValueXyz
        {
            public double X { get; set; }
            public double Y { get; set; }
            public int Z { get; set; }
    
        }
    

    A class to manange the calculation:

        public class SurfaceCalculator
        {
    
        private ValueXyz[] _valuesXyz;
        private double _surface;
        private readonly string _textWithValues;
    
        public SurfaceCalculator(string textWithValues)
        {
            _textWithValues = textWithValues;
            SetValuesToCalculate();
        }
    
        public double Surface
        {
            get { return _surface; }
        }
    
        public void CalculateSurface()
        {
    
            for (var i = 0; i < _valuesXyz.Length; i++)
            {
                if (_valuesXyz[i].Z == 0)
                    _surface = (_valuesXyz[i].X*_valuesXyz[i + 1].Y) - (_valuesXyz[i + 1].X*_valuesXyz[i].Y);
            }
    
        }
    
    
        private void SetValuesToCalculate()
        {
            var valuesXyz = _textWithValues.Split(' '); 
    
    
            _valuesXyz = valuesXyz.Select(item => new ValueXyz
                                                      {
                                                          X = Convert.ToDouble(item.Split(',')[0]),
                                                          Y = Convert.ToDouble(item.Split(',')[1]),
                                                          Z = Convert.ToInt32(item.Split(',')[2])
                                                      }).ToArray();
    
        }
    
    
    }
    

    So now your client code could do somethin like:

       [TestMethod]
        public void TestSurfaceCalculatorGetsAValue()
        {
            //var textWithValues = File.ReadAllText(@"C:File.csv");
            var textWithValues = "424.26,424.26,0 589.43,231.46,0 720.81,14.22,1";
            var calculator = new SurfaceCalculator(textWithValues);
            calculator.CalculateSurface();
    
            Assert.IsNotNull(calculator.Surface);
        }
    

    I’m not very sure i got the idea correct of how to implement the formula, but i just wanted to expose an alternative you can use, you can never have to many ways of doing one thing :).

    Cheers.

    By the way part of the intent i had, was not tying up your funcionality to the csv in case your source for the text in the future would change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when i run my hibernate tools it reads from the db and create java
It is my first time to create a program with file reading and writing
I have an assignment in college in which we are required to read in
I have a program which create a new branch when I give it the
Hey all I was trying to create a java program which will remain logged
I'm trying to create a program with some key bindings (F1-F12) which will pick
In the past, some of my projects have required me to create a movie
Entity Framework has created the required partial classes. I can add these partial classes
Specifically, I'm trying to create a unit test for a method which requires uses
I have been making a program that creates multiple CSV's from another source CSV

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.