Question trying to build a list of temperatures - datastrucure needed for count

cfrank2000

Well-known member
Joined
Mar 6, 2021
Messages
71
Programming Experience
Beginner
metjelentes:
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace metjelentes
{
    using System;
    class mystruct
    {
        public string telepulesKod { get; set; }
        public string[] mertErtekek { get; set; }
        public string[] ertekek { get; set; }
        public int atlaghm { get; set; }
        public int Minhm { get; set; }
        public int Maxhm { get; set; }
    }
    class adatok0
    {
        public string telepules { get; set; }
        public string ido { get; set; }
        public string szeliranyes_erosseg { get; set; }
        public int homerseklet { get; set; }
        public int sorszam { get; set; }
    
        public int ertekek { get; set; }
   }

    class beolvasas
    {
        int db = -1;
        string ido = "";
        string utolsomeres = "";
        
        int kertszam = 0;
        int maxhom = 0;
        public int minhom = 0;
        int hom = 0;
        int maxindex = 0;
        int hossz = 0;
        string kerttelepules = "";
        public List<adatok0> lista = new List<adatok0>();
        public List<int> homersekletlista = new List<int>();
        public List<string> telepulesek = new List<string>();
        public List<string[]> idopont = new List<string[]>(2);
        public void beolvas()
        {

            string olvas = @"c:\Users\Public\textfiles\tavirathu13.txt";
            using (StreamReader sr = new StreamReader(olvas, Encoding.Default))
            {
                //StreamReader sr = new StreamReader(olvas, Encoding.Default);

                //List<adatok> lista = new List<adatok>();

                while (!sr.EndOfStream)
                {
                    string[] sor = sr.ReadLine().Split(' ');
                    //string[] elemek = sor.Split(' ');
                    adatok0 adat = new adatok0();

                    adat.telepules = sor[0];
                    adat.ido = sor[1];
                    adat.szeliranyes_erosseg = sor[2];
                    adat.homerseklet = Int32.Parse(sor[3]);
                    lista.Add(adat);
                    db++;
                    adat.sorszam = db;
                }
                Random rd = new Random();
                kertszam = rd.Next(1, db);
                hossz = db;
            }
        }
        public void szamol()
        {
            int n = -1;
            foreach (adatok0 dt in lista)
            { n++;
                if (n == kertszam)
                {

                    kerttelepules = dt.telepules;
                    ido = dt.ido;

                }
                

            }
            n = 0;
            int m = 0;
            foreach (adatok0 dt in lista)
            {
                //m++;
                //maxindex = m;
                if (lista[kertszam].telepules == dt.telepules)
                {
                    ido = dt.ido;
                   // Console.WriteLine(" m " + m + " telepules " + kerttelepules + "  " + ido + " " + hom);
                    hom = dt.homerseklet;
                    homersekletlista.Add(hom);
                    homersekletlista.Sort();
                }
                utolsomeres = ido;
            }
            //Console.WriteLine(" n " + n + " ido " + utolsomeres);

        
        foreach (int ct in homersekletlista)
            {
                //Console.WriteLine(" homerseklet " +ct);
                maxhom = ct;
            }
            minhom = homersekletlista[0];
            //Console.WriteLine(" min  homersekle   " + minhom);
            //maxhom = homersekletlista[maxindex-1];//
            //Console.WriteLine(" max  homersekle   " + maxhom);
           /*
          
            /*       */
            }
        //List<int> a = new List<int>();
        int[] a2 = new int[900];
        int i = 0;
        int j = 0;
        int k = -1;
        
        string[] tomb = new string[900];
        List<mystruct> tmb2 = new List<mystruct>();
        List<int> lst1 = new List<int>();
        List<int> lst2 = new List<int>();
        int[,] Vektor = new int[100, 400];

        // hossz = str1.Length;

        public void valogat()
        {
            for (i = 0; i < hossz; i++)
            {
                for (j = 0; j < hossz; j++)
                {
                    if (lista[j].telepules == lista[i].telepules)
                    {

                        a2[j] += 1;
                        if (a2[j] < 2)
                        {
                            //mystruct myrek = new mystruct();
                          
                            //tomb[i] = Convert.ToString(str1[i]);
                           // myrek.kar = lista[j].telepules;
                            
                            k = k + 1;
                            tomb[i]= lista[i].telepules;
                          
                        }
                        else
                        {
                            tomb[i] = "empty";
                        }

                    }
                   // Console.WriteLine(" " + tomb[i]);
                }
                //Console.WriteLine(" tomb[ " + i + " ] " + tomb[i]);
            }
            Console.WriteLine(db + " db ");
            for (i=0;i<db;i++)
            {
                //Console.WriteLine(db + " tomb[ " + i + " ] " + tomb[i]);
                if (tomb[i] != "empty")
                {
                    mystruct mydata1 = new mystruct();
                    mydata1.telepulesKod = tomb[i];
                    Console.WriteLine(" "+db+ " tomb[ " + i + " ] " + mydata1.telepulesKod);
                    tmb2.Add(mydata1);
                    if (lista[j].ido.Substring(0, 2) == ora[l].ToString() == true)
                    {
                        if (lista[j].homerseklet > 0)
                        {

                           // Console.Write(lista[j].ido.Substring(0, 2) + " ora " + lista[j].homerseklet + " fok ");
                            Vektor[i, j] = lista[j].homerseklet;
                            lst1.Add(Vektor[i, j]);


                        }

                    }

                }
            }
                
            
            foreach (mystruct dt3 in tmb2)
            {
                Console.WriteLine(" tmb2[ ] " + dt3.telepulesKod);
            }

        }

        int[] ora = new int[4] { 1, 7, 13, 19 };
        int l = 0;
        //List<int[,]> vektor = new List<int[,]>();
      

        public void meresek()
        {
            Console.WriteLine(" 1 ");
            Console.WriteLine(" tmb2 " + tmb2.Count);
            Console.WriteLine(" 2 ");
            for (int i3=0;i3< tmb2.Count; i3++)
                {
                Console.WriteLine("  ");
                Console.WriteLine("  " + tmb2.Count +"  "+ tmb2[i3].telepulesKod);
                Console.WriteLine("  ");
                for (j = 0; j < db; j++)
                    {

                        if (tmb2[i3].telepulesKod == lista[j].telepules)
                        {
                           // Console.Write(" " + lista[j].homerseklet);
                        for (l=0;l<4;l++)
                        {
                        /* */   
                            if (lista[j].ido.Substring(0, 2)==ora[l].ToString() == true)
                            {
                                if (lista[j].homerseklet > 0 )
                                {
                                   mystruct rek1 = new mystruct;
                                    List<adatok0> mert1 = new List<adatok0>();
                               // mystruct merthom = new mystruct();
                                    //Console.Write(" j "+j+" "+lista[j].ido.Substring(0, 2) + " ora " + lista[j].homerseklet + " fok ");
                                    Console.Write( "  " + lista[j].homerseklet + " fok ");
                                    Vektor[i3, j] = lista[j].homerseklet;
                                    lst1.Add(Vektor[i3, j]);
                                    rek1.ertekek[j] = lista[j].homerseklet;
                                    mert1[].ertekek.Add(lista[j].homerseklet.ToString());


                                }
                                //Console.Write("  ");
                            }
                                                      
                        }
                        
                        }
                  
                    }
                //Console.WriteLine(" ");
                

            }
            Console.WriteLine(" ");
           // foreach (int a1 in lst1)
           // {
               // Console.Write("   " + a1);

          //  }
          ///  lst1.Clear();
        }
        int i1 = 0;
        int j1 = 0;
        public void kiiras()
        {
            /*
            for (i1 = 0; i1 < 100; i1++)
            {
                for (j1 = 0; j1 < db; j1++)
                    { if (Vektor[i1, j1] != 0)
                        {
                            //Array.Sort();
                            Console.Write(" v " + Vektor[i1, j1]);
                        }
                     }
                Console.WriteLine("  ");
            }
            */
            for (int i = 0; i<db; i++)
                {
                    Console.WriteLine(" ");
                // rekordlista adat = new rekordlista();
              
                Console.WriteLine(
                         " Sorszam   " + lista[i].sorszam +
                         " Telepules " + lista[i].telepules +
                         " Ido   " + lista[i].ido +
                         " Szelirany es_erosseg " + lista[i].szeliranyes_erosseg +
                         " Homerseklet " + lista[i].homerseklet
                        );

                    //fordulo = fordulo + Int32.Parse(rlista[i].fordulo);
                    //telitalalatok = telitalalatok + Int32.Parse(rlista[i].Ndarab13p1talalat);
                    //osszeg = osszeg + rlista[i].ossznyeremeny;

                }
            Console.WriteLine(" A rekordok szama db " + db);
            Console.WriteLine("  2. Feladat ");
            Console.WriteLine("     A kert kod " + kertszam + " Telepules " + lista[kertszam].telepules+ " Ido   " + lista[kertszam].ido);
            Console.WriteLine("     A kert telepules kod " + kerttelepules);
            Console.WriteLine("     Az utolso meresi adat   " + utolsomeres);
            Console.WriteLine("  3. Feladat ");
            Console.WriteLine("     A mert homerseklet maximum "+maxhom+ " Minimum homerseklet "+minhom);
            Console.WriteLine("  4. Feladat ");
            foreach (adatok0 dt in lista )
            {
                if ("00000" == dt.szeliranyes_erosseg)
                {
                    Console.WriteLine("     szelcsend " + dt.telepules+" "+dt.ido);
                }
            }
            Console.WriteLine("  5. Feladat ");
            Console.WriteLine("     Szereplo Telepulesek kodja ");
            foreach (mystruct dt3 in tmb2)
            {
                Console.WriteLine("     Az adott Telepules " + dt3.telepulesKod);
            }
        }
        }
    
       class Program
        {
            static void Main(string[] args)
            {
            beolvasas kiir1 = new beolvasas();
            kiir1.beolvas();
            kiir1.szamol();
            kiir1.valogat();
            kiir1.meresek();
            kiir1.kiiras();
            //Console.WriteLine("Hello World!");
        }
        }
}
 
If I comment out the faulty part , it works , selects the city codes and under selected city codes the required temperatures. I need this temp. data in a data structure to get the mean value and max and min value, thank you.
 
Since this is an English language forum, it's very hard for us to understand your code where your identifiers are all in Hungarian. Can you put in a new post -- do not edit your original post -- with comments that translate some of the class member names, method names, and variables names so that we'll have half a chance of understanding your code?
 
Since this is an English language forum, it's very hard for us to understand your code where your identifiers are all in Hungarian. Can you put in a new post -- do not edit your original post -- with comments that translate some of the class member names, method names, and variables names so that we'll have half a chance of understanding your code?
thank you, I'll do it.
 
conform advice I converted Hungarian to English for making easier the help. I commented out the faulty part but signalized where I need help, thank you.
metreport:
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace metreport
{
    using System;
    class mystruct
    {
        public string localitycode { get; set; }
        public string[] measuredvalue { get; set; }
        public string[] values { get; set; }
        public int meantempr { get; set; }
        public int mintempr { get; set; }
        public int maxtempr { get; set; }
    }
    class datas0
    {
        public string locality { get; set; }
        public string time { get; set; }
        public string winddirectionandstrenght { get; set; }
        public int temperature { get; set; }
        public int lineupnm { get; set; }
    
        public int values { get; set; }
   }

    class reading
    {
        int piece = -1;
        string time = "";        string lastmeasures = "";

        
        int requirednm = 0;
        int maxtempr = 0;
        public int mintepr = 0;
        int tempr = 0;
        int maxindex = 0;
        int lenght1 = 0;
        string requiredlocality = "";
        public List<datas0> list1 = new List<datas0>();
        public List<int> temperaturelist  = new List<int>();
        public List<string> localities = new List<string>();
        public List<string[]> appointmenttime = new List<string[]>(2);
        public void read_in()
        {

            string read = @"c:\Users\Public\textfiles\tavirathu13.txt";
            using (StreamReader sr = new StreamReader(read, Encoding.Default))
            {
                //StreamReader sr = new StreamReader(olvas, Encoding.Default);

                //List<adatok> lista = new List<adatok>();

                while (!sr.EndOfStream)
                {
                    string[] row = sr.ReadLine().Split(' ');
                    //string[] elemek = sor.Split(' ');
                    datas0 data = new datas0();

                    data.locality = row[0];
                    data.time = row[1];
                    data.winddirectionandstrenght = row[2];
                    data.temperature = Int32.Parse(row[3]);
                    list1.Add(data);
                    piece++;
                    data.lineupnm = piece;
                }
                Random rd = new Random();
                requirednm = rd.Next(1, piece);
                lenght1 = piece;
            }
        }
        public void count()
        {
            int n = -1;
            foreach (datas0 dt in list1)
            { n++;
                if (n == requirednm)
                {

                    requiredlocality = dt.locality;
                    time = dt.time;

                }
                

            }
            n = 0;
            int m = 0;
            foreach (datas0 dt in list1)
            {
                //m++;
                //maxindex = m;
                if (list1[requirednm].locality == dt.locality)
                {
                    time = dt.time;
                   // Console.WriteLine(" m " + m + " telepules " + kerttelepules + "  " + ido + " " + hom);
                    tempr = dt.temperature;
                    temperaturelist.Add(tempr);
                    temperaturelist.Sort();
                }
                lastmeasures = time;
            }
            //Console.WriteLine(" n " + n + " ido " + utolsomeres);

        
        foreach (int ct in temperaturelist)
            {
                //Console.WriteLine(" homerseklet " +ct);
                maxtempr = ct;
            }
            datas0 datas11 = new datas0();
            //datas11.mintempr = temperaturelist[0];
            //Console.WriteLine(" min  homersekle   " + minhom);
            //maxhom = homersekletlista[maxindex-1];//
            //Console.WriteLine(" max  homersekle   " + maxhom);
           /*
          
            /*       */
            }
        //List<int> a = new List<int>();
        int[] a2 = new int[900];
        int i = 0;
        int j = 0;
        int k = -1;
        
        string[] tomb = new string[900];
        List<mystruct> tmb2 = new List<mystruct>();
        List<int> lst1 = new List<int>();
        List<int> lst2 = new List<int>();
        int[,] Vektor = new int[100, 400];

        // hossz = str1.Length;

        public void select()
        {
            for (i = 0; i < lenght1; i++)
            {
                for (j = 0; j < lenght1; j++)
                {
                    if (list1[j].locality == list1[i].locality)
                    {

                        a2[j] += 1;
                        if (a2[j] < 2)
                        {
                            //mystruct myrek = new mystruct();
                          
                            //tomb[i] = Convert.ToString(str1[i]);
                           // myrek.kar = lista[j].telepules;
                            
                            k = k + 1;
                            tomb[i]= list1[i].locality;
                          
                        }
                        else
                        {
                            tomb[i] = "empty";
                        }

                    }
                   // Console.WriteLine(" " + tomb[i]);
                }
                //Console.WriteLine(" tomb[ " + i + " ] " + tomb[i]);
            }
            Console.WriteLine(piece + " piece ");
            for (i=0;i<piece;i++)
            {
                //Console.WriteLine(db + " tomb[ " + i + " ] " + tomb[i]);
                if (tomb[i] != "empty")
                {
                    mystruct mydata1 = new mystruct();
                    mydata1.localitycode = tomb[i];
                    Console.WriteLine(" "+piece+ " tomb[ " + i + " ] " + mydata1.localitycode);
                    tmb2.Add(mydata1);
                    if (list1[j].time.Substring(0, 2) == ora[l].ToString() == true)
                    {
                        if (list1[j].temperature > 0)
                        {

                           // Console.Write(lista[j].ido.Substring(0, 2) + " ora " + lista[j].homerseklet + " fok ");
                            Vektor[i, j] = list1[j].temperature;
                            lst1.Add(Vektor[i, j]);


                        }

                    }

                }
            }
                
            
            foreach (mystruct dt3 in tmb2)
            {
                Console.WriteLine(" tmb2[ ] " + dt3.localitycode);
            }

        }

        int[] ora = new int[4] { 1, 7, 13, 19 };
        int l = 0;
        //List<int[,]> vektor = new List<int[,]>();
      

        public void measures()
        {
            Console.WriteLine(" help needed for datastructure ");
            Console.WriteLine(" 1 ");
            Console.WriteLine(" tmb2 " + tmb2.Count);
            Console.WriteLine(" 2 ");
            for (int i3=0;i3< tmb2.Count; i3++)
                {
                Console.WriteLine("  ");
                Console.WriteLine("  " + tmb2.Count +"  "+ tmb2[i3].localitycode);
                Console.WriteLine("  ");
                for (j = 0; j < piece; j++)
                    {

                        if (tmb2[i3].localitycode == list1[j].locality)
                        {
                           // Console.Write(" " + lista[j].homerseklet);
                        for (l=0;l<4;l++)
                        {
                        /* */   
                            if (list1[j].time.Substring(0, 2)==ora[l].ToString() == true)
                            {
                                if (list1[j].temperature > 0 )
                                {
                                   mystruct rek1 = new mystruct();
                                    List<datas0> mert1 = new List<datas0>();
                               // mystruct merthom = new mystruct();
                                    //Console.Write(" j "+j+" "+lista[j].ido.Substring(0, 2) + " ora " + lista[j].homerseklet + " fok ");
                                    Console.Write( "  " + list1[j].temperature + " degree ");
                                    Vektor[i3, j] = list1[j].temperature;
                                    lst1.Add(Vektor[i3, j]);
                                   // rek1.values[j] = list1[j].temperature;
                                   // mert1[].ertekek.Add(list1[j].homerseklet.ToString());


                                }
                                //Console.Write("  ");
                            }
                                                      
                        }
                        
                        }
                  
                    }
                //Console.WriteLine(" ");
                

            }
            Console.WriteLine(" ");
           // foreach (int a1 in lst1)
           // {
               // Console.Write("   " + a1);

          //  }
          ///  lst1.Clear();
        }
        int i1 = 0;
        int j1 = 0;
        public void displaying()
        {
            /*
            for (i1 = 0; i1 < 100; i1++)
            {
                for (j1 = 0; j1 < db; j1++)
                    { if (Vektor[i1, j1] != 0)
                        {
                            //Array.Sort();
                            Console.Write(" v " + Vektor[i1, j1]);
                        }
                     }
                Console.WriteLine("  ");
            }
            */
            for (int i = 0; i<piece; i++)
                {
                    Console.WriteLine(" ");
                // rekordlista adat = new rekordlista();
              
                Console.WriteLine(
                         " Lineup number   " + list1[i].lineupnm +
                         " LOcality " + list1[i].locality +
                         " Time   " + list1[i].time +
                         " Wind dorection and strenght " + list1[i].winddirectionandstrenght +
                         " Temperature " + list1[i].temperature
                        );

                    //fordulo = fordulo + Int32.Parse(rlista[i].fordulo);
                    //telitalalatok = telitalalatok + Int32.Parse(rlista[i].Ndarab13p1talalat);
                    //osszeg = osszeg + rlista[i].ossznyeremeny;

                }
            Console.WriteLine(" Number of records " + piece);
            Console.WriteLine("  2. Task ");
            Console.WriteLine("      Requested code " + requirednm + " Telepules " + list1[requirednm].locality+ " Ido   " + list1[requirednm].time);
            Console.WriteLine("      Required locality code " + requiredlocality);
            Console.WriteLine("      Last measured data   " + lastmeasures);
            Console.WriteLine("  3. Task ");
            Console.WriteLine("      The measured temperature maximum "+maxtempr+ " Minimum homerseklet "+mintepr);
            Console.WriteLine("  4. Task ");
            foreach (datas0 dt in list1 )
            {
                if ("00000" == dt.winddirectionandstrenght)
                {
                    Console.WriteLine("     no wind " + dt.locality+" "+dt.time);
                }
            }
            Console.WriteLine("  5. Task ");
            Console.WriteLine("     Localities taking part in measurements ");
            foreach (mystruct dt3 in tmb2)
            {
                Console.WriteLine("     Given loclity " + dt3.localitycode);
            }
        }
        }
    
       class Program
        {
            static void Main(string[] args)
            {
            reading display1 = new reading();
            display1.read_in();
            display1.count();
            display1.select();
            display1.measures();
            display1.displaying();
            //Console.WriteLine("Hello World!");
        }
        }
}
 
Help with what exactly? There's a lot of code there and I'm guessing that most of it is irrelevant. Please explain exactly what you're trying to achieve, how you're trying to achieve it and what happens when you try.
 
merged threads
 
Hi
thank you for answer. I tried internet but no luck.
thank you for answer. I try to achieve the following: running the program we can se up after locality codes help needed for data structure, I need to place al locality code related temperature measurements in some sort of ' embedded list ' to get min and max temperature for a city code plus mean temperature. by the way min temperature is not working giving 0 all the time, thank you.
update
metreport1:
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace metreport
{
    //using System;
    class mystruct
    {
        public string localitycode { get; set; }
        public string[] measuredvalue { get; set; }
        public string[] values { get; set; }
        public int meantempr { get; set; }
        public int mintempr { get; set; }
        public int maxtempr { get; set; }
    }
    class datas0
    {
        public string locality { get; set; }
        public string time { get; set; }
        public string winddirectionandstrenght { get; set; }
        public int temperature { get; set; }
        public int lineupnm { get; set; }
   
        public int values { get; set; }
   }

    class reading
    {
        int piece = -1;
        string time = "";        string lastmeasures = "";

       
        int requirednm = 0;
        int maxtempr = 0;
        public int mintepr = 0;
        int tempr = 0;
        int maxindex = 0;
        int lenght1 = 0;
        string requiredlocality = "";
        public List<datas0> list1 = new List<datas0>();
        public List<int> temperaturelist  = new List<int>();
        public List<string> localities = new List<string>();
        public List<string[]> appointmenttime = new List<string[]>(2);
        public void read_in()
        {

            string read = @"c:\Users\Public\textfiles\tavirathu13.txt";
            using (StreamReader sr = new StreamReader(read, Encoding.Default))
            {
                //StreamReader sr = new StreamReader(olvas, Encoding.Default);

                //List<adatok> lista = new List<adatok>();

                while (!sr.EndOfStream)
                {
                    string[] row = sr.ReadLine().Split(' ');
                    //string[] elemek = sor.Split(' ');
                    datas0 data = new datas0();

                    data.locality = row[0];
                    data.time = row[1];
                    data.winddirectionandstrenght = row[2];
                    data.temperature = Int32.Parse(row[3]);
                    list1.Add(data);
                    piece++;
                    data.lineupnm = piece;
                }
                Random rd = new Random();
                requirednm = rd.Next(1, piece);
                lenght1 = piece;
            }
        }
        public void count()
        {
            int n = -1;
            foreach (datas0 dt in list1)
            { n++;
                if (n == requirednm)
                {

                    requiredlocality = dt.locality;
                    time = dt.time;

                }
               

            }
            n = 0;
            int m = 0;
            foreach (datas0 dt in list1)
            {
                //m++;
                //maxindex = m;
                if (list1[requirednm].locality == dt.locality)
                {
                    time = dt.time;
                   // Console.WriteLine(" m " + m + " telepules " + kerttelepules + "  " + ido + " " + hom);
                    tempr = dt.temperature;
                    temperaturelist.Add(tempr);
                    temperaturelist.Sort();
                }
                lastmeasures = time;
            }
            //Console.WriteLine(" n " + n + " ido " + utolsomeres);

       
        foreach (int ct in temperaturelist)
            {
                //Console.WriteLine(" homerseklet " +ct);
                maxtempr = ct;
            }
            datas0 datas11 = new datas0();
            //datas11.mintempr = temperaturelist[0];
            //Console.WriteLine(" min  homersekle   " + minhom);
            //maxhom = homersekletlista[maxindex-1];//
            //Console.WriteLine(" max  homersekle   " + maxhom);
           /*
         
            /*       */
            }
        //List<int> a = new List<int>();
        int[] a2 = new int[900];
        int i = 0;
        int j = 0;
        int k = -1;
       
        string[] tomb = new string[900];
        List<mystruct> tmb2 = new List<mystruct>();
        List<int> lst1 = new List<int>();
        List<int> lst2 = new List<int>();
        int[,] Vektor = new int[100, 400];

        // hossz = str1.Length;

        public void select()
        {
            for (i = 0; i < lenght1; i++)
            {
                for (j = 0; j < lenght1; j++)
                {
                    if (list1[j].locality == list1[i].locality)
                    {

                        a2[j] += 1;
                        if (a2[j] < 2)
                        {
                            //mystruct myrek = new mystruct();
                         
                            //tomb[i] = Convert.ToString(str1[i]);
                           // myrek.kar = lista[j].telepules;
                           
                            k = k + 1;
                            tomb[i]= list1[i].locality;
                         
                        }
                        else
                        {
                            tomb[i] = "empty";
                        }

                    }
                   // Console.WriteLine(" " + tomb[i]);
                }
                //Console.WriteLine(" tomb[ " + i + " ] " + tomb[i]);
            }
            Console.WriteLine(piece + " piece ");
            for (i=0;i<piece;i++)
            {
                //Console.WriteLine(db + " tomb[ " + i + " ] " + tomb[i]);
                if (tomb[i] != "empty")
                {
                    mystruct mydata1 = new mystruct();
                    mydata1.localitycode = tomb[i];
                    Console.WriteLine(" "+piece+ " tomb[ " + i + " ] " + mydata1.localitycode);
                    tmb2.Add(mydata1);
                    if (list1[j].time.Substring(0, 2) == ora[l].ToString() == true)
                    {
                        if (list1[j].temperature > 0)
                        {

                           // Console.Write(lista[j].ido.Substring(0, 2) + " ora " + lista[j].homerseklet + " fok ");
                            Vektor[i, j] = list1[j].temperature;
                            lst1.Add(Vektor[i, j]);


                        }

                    }

                }
            }
               
           
            foreach (mystruct dt3 in tmb2)
            {
                Console.WriteLine(" tmb2[ ] " + dt3.localitycode);
            }

        }

        int[] ora = new int[4] { 1, 7, 13, 19 };
        int l = 0;
        //List<int[,]> vektor = new List<int[,]>();
     

        public void measures()
        {
            Console.WriteLine(" help needed for datastructure ");
            Console.WriteLine(" 1 ");
            Console.WriteLine(" tmb2 " + tmb2.Count);
            Console.WriteLine(" 2 ");
            for (int i3=0;i3< tmb2.Count; i3++)
                {
                Console.WriteLine("  ");
                Console.WriteLine("  " + tmb2.Count +"  "+ tmb2[i3].localitycode);
                Console.WriteLine("  ");
                for (j = 0; j < piece; j++)
                    {

                        if (tmb2[i3].localitycode == list1[j].locality)
                        {
                           // Console.Write(" " + lista[j].homerseklet);
                        for (l=0;l<4;l++)
                        {
                        /* */  
                            if (list1[j].time.Substring(0, 2)==ora[l].ToString() == true)
                            {
                                if (list1[j].temperature > 0 )
                                {
                                   mystruct rek1 = new mystruct();
                                    List<datas0> mert1 = new List<datas0>();
                               // mystruct merthom = new mystruct();
                                    //Console.Write(" j "+j+" "+lista[j].ido.Substring(0, 2) + " ora " + lista[j].homerseklet + " fok ");
                                    Console.Write( "  " + list1[j].temperature + " degree ");
                                    Vektor[i3, j] = list1[j].temperature;
                                    lst1.Add(Vektor[i3, j]);
                                   // rek1.values[j] = list1[j].temperature;
                                   // mert1[].ertekek.Add(list1[j].homerseklet.ToString());


                                }
                                //Console.Write("  ");
                            }
                                                     
                        }
                       
                        }
                 
                    }
                //Console.WriteLine(" ");
               

            }
            Console.WriteLine(" ");
           // foreach (int a1 in lst1)
           // {
               // Console.Write("   " + a1);

          //  }
          ///  lst1.Clear();
        }
        int i1 = 0;
        int j1 = 0;
        public void displaying()
        {
            /*
            for (i1 = 0; i1 < 100; i1++)
            {
                for (j1 = 0; j1 < db; j1++)
                    { if (Vektor[i1, j1] != 0)
                        {
                            //Array.Sort();
                            Console.Write(" v " + Vektor[i1, j1]);
                        }
                     }
                Console.WriteLine("  ");
            }
            */
            for (int i = 0; i<piece; i++)
                {
                    Console.WriteLine(" ");
                // rekordlista adat = new rekordlista();
             
                Console.WriteLine(
                         " Lineup number   " + list1[i].lineupnm +
                         " LOcality " + list1[i].locality +
                         " Time   " + list1[i].time +
                         " Wind dorection and strenght " + list1[i].winddirectionandstrenght +
                         " Temperature " + list1[i].temperature
                        );

                    //fordulo = fordulo + Int32.Parse(rlista[i].fordulo);
                    //telitalalatok = telitalalatok + Int32.Parse(rlista[i].Ndarab13p1talalat);
                    //osszeg = osszeg + rlista[i].ossznyeremeny;

                }
            Console.WriteLine(" Number of records " + piece);
            Console.WriteLine("  2. Task ");
            Console.WriteLine("      Requested code " + requirednm + " Locality " + list1[requirednm].locality+ " Time   " + list1[requirednm].time);
            Console.WriteLine("      Required locality code " + requiredlocality);
            Console.WriteLine("      Last measured data   " + lastmeasures);
            Console.WriteLine("  3. Task ");
            Console.WriteLine("      The measured temperature maximum "+maxtempr+ " Minimal temperature "+mintepr);
            Console.WriteLine("  4. Task ");
            foreach (datas0 dt in list1 )
            {
                if ("00000" == dt.winddirectionandstrenght)
                {
                    Console.WriteLine("     no wind " + dt.locality+" "+dt.time);
                }
            }
            Console.WriteLine("  5. Task ");
            Console.WriteLine("     Localities taking part in measurements ");
            foreach (mystruct dt3 in tmb2)
            {
                Console.WriteLine("     Given loclity " + dt3.localitycode);
            }
        }
        }
   
       class Program
        {
            static void Main(string[] args)
            {
            reading display1 = new reading();
            display1.read_in();
            display1.count();
            display1.select();
            display1.measures();
            display1.displaying();
            //Console.WriteLine("Hello World!");
        }
        }
}
 
I checked the net for solution but no luck. possibly I would need a list where list components are also lists. the problem is I tried foreach and for loop but it was wrong , useless because I don't know how to do it. the reason for this strange data is to use sort function for min and max values and count temperature mean values by city code. please help me with solution, thank you.
 
You don't need to sort to find the minimum or maximum values from a list. You certainly don't need to sort to count the number of items in a list.

Your instincts are correct that you'll likely need lists. The data structure that you are seeking, though is called a dictionary. Let me get you started with some pseudo code (assuming using C# 9.0):
C#:
record Measurement
{
    public string Locality { get; init; }
    public string Time { get; init; }
    public string WindDirectionAndStrength { get; init; }
    public int Temperature { get; init; }
    public int LineNumber { get; init; }
}

:

var localityMeasurements = new Dictionary<string, List<Measurement>>();

int lineNumeber = 1;
foreach(var line in File.ReadLines(inputFile))
{
    var columns = line.Split(' ');
    var locality = columns[0];
    var measurement = new Measurement
        {
            Locality = columns[0],
            Time = columns[1],
            WindDirectionAndStrength = columns[2],
            Temperature = int.Parse(columns[3]),
            LineNumber = lineNumber;
        };
    if (!localityMeasurements.ContainsKey(locality))
        localityMeasurements.Add(locality, new List<Measurement>());
    localityMeasurements[locality].Add(measurement);
    lineNumber++;
}

foreach(var kvp in localityMeasurements)
{
    var locality = kvp.Key;
    var measurements = kvp.Value;
    var min = measurements.Min(m => m.Temperature);
    var max = measurements.Max(m => m.Temperature);
    var ave = measurements.Average(m => m.Temperature);
    Console.Writeline($"Locality: {locality}    Mininum:{min}    Maximum:{max}    Average:{ave}    Count:{measurements.Count}");
}
 
You don't need to sort to find the minimum or maximum values from a list. You certainly don't need to sort to count the number of items in a list.

Your instincts are correct that you'll likely need lists. The data structure that you are seeking, though is called a dictionary. Let me get you started with some pseudo code (assuming using C# 9.0):
C#:
record Measurement
{
    public string Locality { get; init; }
    public string Time { get; init; }
    public string WindDirectionAndStrength { get; init; }
    public int Temperature { get; init; }
    public int LineNumber { get; init; }
}

:

var localityMeasurements = new Dictionary<string, List<Measurement>>();

int lineNumeber = 1;
foreach(var line in File.ReadLines(inputFile))
{
    var columns = line.Split(' ');
    var locality = columns[0];
    var measurement = new Measurement
        {
            Locality = columns[0],
            Time = columns[1],
            WindDirectionAndStrength = columns[2],
            Temperature = int.Parse(columns[3]),
            LineNumber = lineNumber;
        };
    if (!localityMeasurements.ContainsKey(locality))
        localityMeasurements.Add(locality, new List<Measurement>());
    localityMeasurements[locality].Add(measurement);
    lineNumber++;
}

foreach(var kvp in localityMeasurements)
{
    var locality = kvp.Key;
    var measurements = kvp.Value;
    var min = measurements.Min(m => m.Temperature);
    var max = measurements.Max(m => m.Temperature);
    var ave = measurements.Average(m => m.Temperature);
    Console.Writeline($"Locality: {locality}    Mininum:{min}    Maximum:{max}    Average:{ave}    Count:{measurements.Count}");
}
thank you for help
 
Hi
i am sorry for coming again. I tried another way something might be closer to my knowledge level but I am facing conversion problem. I just try to place displayed data in data structure.

metreport2:
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace metreport
{
    //using System;
    class mystruct
    {
        public string localitycode { get; set; }
        public string[] measuredvalue { get; set; }
        public string[] values { get; set; }
        public int meantempr { get; set; }
        public int mintempr { get; set; }
        public int maxtempr { get; set; }
    }
    class datas0
    {
        public string locality { get; set; }
        public string time { get; set; }
        public string winddirectionandstrenght { get; set; }
        public int temperature { get; set; }
        public int lineupnm { get; set; }
   
        public int values { get; set; }
   }

    class reading
    {
        int piece = -1;
        string time = ""; string lastmeasures = "";


        int requirednm = 0;
        int maxtempr = 0;
        public int mintepr = 0;
        int tempr = 0;
        int maxindex = 0;
        int lenght1 = 0;
        string requiredlocality = "";
        public List<datas0> list1 = new List<datas0>();
        public List<int> temperaturelist = new List<int>();
        public List<string> localities = new List<string>();
        public List<string[]> appointmenttime = new List<string[]>(2);
        public void read_in()
        {

            string read = @"c:\Users\Public\textfiles\tavirathu13.txt";
            using (StreamReader sr = new StreamReader(read, Encoding.Default))
            {
                //StreamReader sr = new StreamReader(olvas, Encoding.Default);

                //List<adatok> lista = new List<adatok>();

                while (!sr.EndOfStream)
                {
                    string[] row = sr.ReadLine().Split(' ');
                    //string[] elemek = sor.Split(' ');
                    datas0 data = new datas0();

                    data.locality = row[0];
                    data.time = row[1];
                    data.winddirectionandstrenght = row[2];
                    data.temperature = Int32.Parse(row[3]);
                    list1.Add(data);
                    piece++;
                    data.lineupnm = piece;
                }
                Random rd = new Random();
                requirednm = rd.Next(1, piece);
                lenght1 = piece;
            }
        }
        public void count()
        {
            int n = -1;
            foreach (datas0 dt in list1)
            { n++;
                if (n == requirednm)
                {

                    requiredlocality = dt.locality;
                    time = dt.time;

                }


            }
            n = 0;
            int m = 0;
            foreach (datas0 dt in list1)
            {
                //m++;
                //maxindex = m;
                if (list1[requirednm].locality == dt.locality)
                {
                    time = dt.time;
                    // Console.WriteLine(" m " + m + " telepules " + kerttelepules + "  " + ido + " " + hom);
                    tempr = dt.temperature;
                    temperaturelist.Add(tempr);
                    temperaturelist.Sort();
                }
                lastmeasures = time;
            }
            //Console.WriteLine(" n " + n + " ido " + utolsomeres);


            foreach (int ct in temperaturelist)
            {
                //Console.WriteLine(" homerseklet " +ct);
                maxtempr = ct;
            }
            datas0 datas11 = new datas0();
            //datas11.mintempr = temperaturelist[0];
            //Console.WriteLine(" min  homersekle   " + minhom);
            //maxhom = homersekletlista[maxindex-1];//
            //Console.WriteLine(" max  homersekle   " + maxhom);
            /*

             /*       */
        }
        //List<int> a = new List<int>();
        int[] a2 = new int[900];
        int i = 0;
        int j = 0;
        int k = -1;

        string[] tomb = new string[900];
        List<mystruct> tmb2 = new List<mystruct>();
        List<int> lst1 = new List<int>();
        List<int> lst2 = new List<int>();
        int[,] Vektor = new int[100, 400];

        // hossz = str1.Length;

        public void select()
        {
            for (i = 0; i < lenght1; i++)
            {
                for (j = 0; j < lenght1; j++)
                {
                    if (list1[j].locality == list1[i].locality)
                    {

                        a2[j] += 1;
                        if (a2[j] < 2)
                        {
                            //mystruct myrek = new mystruct();

                            //tomb[i] = Convert.ToString(str1[i]);
                            // myrek.kar = lista[j].telepules;

                            k = k + 1;
                            tomb[i] = list1[i].locality;

                        }
                        else
                        {
                            tomb[i] = "empty";
                        }

                    }
                    // Console.WriteLine(" " + tomb[i]);
                }
                //Console.WriteLine(" tomb[ " + i + " ] " + tomb[i]);
            }
            Console.WriteLine(piece + " piece ");
            for (i = 0; i < piece; i++)
            {
                //Console.WriteLine(db + " tomb[ " + i + " ] " + tomb[i]);
                if (tomb[i] != "empty")
                {
                    mystruct mydata1 = new mystruct();
                    mydata1.localitycode = tomb[i];
                    Console.WriteLine(" " + piece + " tomb[ " + i + " ] " + mydata1.localitycode);
                    tmb2.Add(mydata1);
                    if (list1[j].time.Substring(0, 2) == ora[l].ToString() == true)
                    {
                        if (list1[j].temperature > 0)
                        {

                            // Console.Write(lista[j].ido.Substring(0, 2) + " ora " + lista[j].homerseklet + " fok ");
                            Vektor[i, j] = list1[j].temperature;
                            lst1.Add(Vektor[i, j]);


                        }

                    }

                }
            }


            foreach (mystruct dt3 in tmb2)
            {
                Console.WriteLine(" tmb2[ ] " + dt3.localitycode);
            }

        }

        int[] ora = new int[4] { 1, 7, 13, 19 };
        int l = 0;
        //List<int[,]> vektor = new List<int[,]>();

        List<int> MNumbers = new List<int>();
        List<Dictionary<string, int[]>> measurements = new List<Dictionary<string, int[]>>();

        public void measures()
        {
            Console.WriteLine(" help needed for datastructure ");
            Console.WriteLine(" 1 ");
            Console.WriteLine(" tmb2 " + tmb2.Count);
            Console.WriteLine(" 2 ");
            for (int i3=0;i3< tmb2.Count; i3++)
                {
                Console.WriteLine("  ");
                Console.WriteLine("  " + tmb2.Count + " tmb2[ "+ i3+ "] " + tmb2[i3].localitycode);
                Console.WriteLine("  ");
                for (j = 0; j < piece; j++)
                    {
                   
                        if (tmb2[i3].localitycode == list1[j].locality)
                        {
                           // Console.Write(" " + lista[j].homerseklet);
                        for (l=0;l<4;l++)
                        {
                        /* */  
                            if (list1[j].time.Substring(0, 2)==ora[l].ToString() == true)
                            {
                                if (list1[j].temperature > 0 )
                                {
                                   mystruct rek1 = new mystruct();
                                    List<datas0> mert1 = new List<datas0>();
                               // mystruct merthom = new mystruct();
                                    //Console.Write(" j "+j+" "+lista[j].ido.Substring(0, 2) + " ora " + lista[j].homerseklet + " fok ");
                                    Console.Write( "  " + list1[j].temperature + " degree ");
                                    Vektor[i3, j] = list1[j].temperature;
                                    measurements[i3].Add(tmb2[i3].localitycode, Vektor[i3, j]);
                                    Console.Write("  " + Vektor[i3, j] + " degree ");

                                    lst1.Add(Vektor[i3, j]);
                                   // rek1.values[j] = list1[j].temperature;
                                   // mert1[].ertekek.Add(list1[j].homerseklet.ToString());


                                }
                                //Console.Write("  ");
                            }
                                                     
                        }
                       
                        }
                 
                    }
                //Console.WriteLine(" ");
               

            }
            Console.WriteLine(" ");
           // foreach (int a1 in lst1)
           // {
               // Console.Write("   " + a1);

          //  }
          ///  lst1.Clear();
        }
        int i1 = 0;
        int j1 = 0;
        public void displaying()
        {
            /*
            for (i1 = 0; i1 < 100; i1++)
            {
                for (j1 = 0; j1 < db; j1++)
                    { if (Vektor[i1, j1] != 0)
                        {
                            //Array.Sort();
                            Console.Write(" v " + Vektor[i1, j1]);
                        }
                     }
                Console.WriteLine("  ");
            }
            */
            for (int i = 0; i<piece; i++)
                {
                    Console.WriteLine(" ");
                // rekordlista adat = new rekordlista();
             
                Console.WriteLine(
                         " Lineup number   " + list1[i].lineupnm +
                         " LOcality " + list1[i].locality +
                         " Time   " + list1[i].time +
                         " Wind dorection and strenght " + list1[i].winddirectionandstrenght +
                         " Temperature " + list1[i].temperature
                        );

                    //fordulo = fordulo + Int32.Parse(rlista[i].fordulo);
                    //telitalalatok = telitalalatok + Int32.Parse(rlista[i].Ndarab13p1talalat);
                    //osszeg = osszeg + rlista[i].ossznyeremeny;

                }
            Console.WriteLine(" Number of records " + piece);
            Console.WriteLine("  2. Task ");
            Console.WriteLine("      Requested code " + requirednm + " Locality " + list1[requirednm].locality+ " Time   " + list1[requirednm].time);
            Console.WriteLine("      Required locality code " + requiredlocality);
            Console.WriteLine("      Last measured data   " + lastmeasures);
            Console.WriteLine("  3. Task ");
            Console.WriteLine("      The measured temperature maximum "+maxtempr+ " Minimal temperature "+mintepr);
            Console.WriteLine("  4. Task ");
            foreach (datas0 dt in list1 )
            {
                if ("00000" == dt.winddirectionandstrenght)
                {
                    Console.WriteLine("     no wind " + dt.locality+" "+dt.time);
                }
            }
            Console.WriteLine("  5. Task ");
            Console.WriteLine("     Localities taking part in measurements ");
            foreach (mystruct dt3 in tmb2)
            {
                Console.WriteLine("     Given loclity " + dt3.localitycode);
            }
        }
        }
   
       class Program
        {
            static void Main(string[] args)
            {
            reading display1 = new reading();
            display1.read_in();
            display1.count();
            display1.select();
            display1.measures();
            display1.displaying();
            //Console.WriteLine("Hello World!");
        }
        }
}
 
Last edited:
I just try to place displayed data in data structure.
Why are trying to stick the displayed data into a data structure? You should be reading values out of your data structure and displaying them on screen.
 
Why are trying to stick the displayed data into a data structure? You should be reading values out of your data structure and displaying them on screen.
thank you for answer. my reason for read data in a data structure to read out it in a created txt file named by city code. thank you.
 

Latest posts

Back
Top Bottom