Results 1 to 8 of 8
  1. #1
    Member Xtreme Barton's Avatar
    Join Date
    Jan 2004
    Location
    Omaha,NE

    C++ DUDES ...lol

    back again .. cramming it in as fast as i can .. only got a couple weeks left !!

    this little project i got going now consist of reading files of certain data type and storing them in an array as they appear in the file.

    Example:

    Jan
    Feb
    Mar
    Apr
    etc..

    so i read that file into a string array .. and i can output just fine that way too. Here is the kicker. Im trying to get output as follows.

    Jan Feb Mar Apr etc.....

    Im still searching away but if anyone has some pointers

    must be able to manipulate integers also in the same fashion. Basically he wants us to reverse output direction of the stored array



  2. #2
    Member
    Join Date
    Nov 2008
    So you're talking about a 2-Dimensional array? Your code to write the file will depend on the format it needs to be.

    For the record, the most common format by far that I work with for 2D data grids is CSV. In the real world I never have to write the code to actually write the files, there are libraries for that
    "We can't stop here, this is bat country!"

  3. #3
    Member Xtreme Barton's Avatar
    Join Date
    Jan 2004
    Location
    Omaha,NE
    actually i need to stick with one dimmensional arrays .. each file will get its own array and store each set of integers or strings. i then need to output that in various ways to represent a weather chart for my local area.



  4. #4
    Has slightly less legible writing
    than Thideras, Member
    ssjwizard's Avatar
    10 Year Badge
    Join Date
    Mar 2002
    Location
    Rio Rancho, NM
    Benching Profile Folding Profile Heatware Profile
    Your on the right track,

    What compiler are you using because converting read in string to int can be done a few different ways.
    Life is what you make of it, we exist for the sole purpose of existing. Dont waste the universe efforts!
    All statements, imagery, and ideas contained within any signatures are merely retold tales of fictional acts by a figment of the universe imagination.

    So your looking for an AMD FX motherboard, things you need to know. Whats the max safe temps/volts for an FX?

    Green Gorilla, CM 690-II nVidia, FX 8320, GTX 670, liquid cooled
    Liquid Fusion, CM 690-II, A8+6670 Dual GFX, liquid cooled
    Extreme evaporative water loop 450mm^3 water cooled beast - Incomplete

  5. #5
    Member Xtreme Barton's Avatar
    Join Date
    Jan 2004
    Location
    Omaha,NE
    We are required to use visual studio 2010. And unfortunately i may not change its data type in anyway.


    I think i have it down a little better. On my way to school for my VB class so ill post what i have when i get in.

  6. #6
    Member Xtreme Barton's Avatar
    Join Date
    Jan 2004
    Location
    Omaha,NE
    string to int ??

    could read like i did string file .. store in array ..convert to int ..



  7. #7
    Has slightly less legible writing
    than Thideras, Member
    ssjwizard's Avatar
    10 Year Badge
    Join Date
    Mar 2002
    Location
    Rio Rancho, NM
    Benching Profile Folding Profile Heatware Profile
    yep

    theres a few ways to do it.

    int catch = atoi(string.cStr()); is one of the most common ways to do it.
    Life is what you make of it, we exist for the sole purpose of existing. Dont waste the universe efforts!
    All statements, imagery, and ideas contained within any signatures are merely retold tales of fictional acts by a figment of the universe imagination.

    So your looking for an AMD FX motherboard, things you need to know. Whats the max safe temps/volts for an FX?

    Green Gorilla, CM 690-II nVidia, FX 8320, GTX 670, liquid cooled
    Liquid Fusion, CM 690-II, A8+6670 Dual GFX, liquid cooled
    Extreme evaporative water loop 450mm^3 water cooled beast - Incomplete

  8. #8
    Member Xtreme Barton's Avatar
    Join Date
    Jan 2004
    Location
    Omaha,NE
    oh man .. tired ..eye's strained ..but i got it done just in the nick of time

    here is my final output .. went about it a little different .. could have done better with some array work but i was in a hurry for final output .

    Code:
    /** Malik, D.S., (2010). C++ Programming Program Design 
     Including Data Structures, 5th Edition. Boston: Course Technology.
     Modifications by Wm Bowers, 2007  2012.
     Additional modifications by D. Keller, 2012.
     Input/Output with files 2000-2012.
     Retrieved from http://www.cplusplus.com/doc/tutorial/files/
     (2012, May 16).
    */
     
    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #include <conio.h>
    #include <string>
     
    using namespace std;
     
    void getMonths();
    void getHighs();
    void getLowTemps();
    void getPrecipitation();
    void getRecordHighYear();
    void getRecordHighTemp();
    void getRecordLowYear();
    void getRecordLowTemp();
     
    
    void main()
    {
     
     cout << "\n\n  Temperature Statistics [1]";
     getMonths();
    }
    
     
    void getMonths()
    {
     string str[11];
     string line;
     ifstream months;
     
     months.open("MonthsA.txt");
     
     if(!months) 
     {
      cout << "  Error opening file" << endl;
            _getch();        
     }
      while(months.good())
        {
      for (int i = 0; i < 12; i++)
      {
       getline (months,line);                
       str[i] = line;       
      }
      
      cout << "\n\n" << "  Months ";
        
      for (int i = 0; i < 12;i++)
      {
       cout << "  " << str[i];
      }
      }
      months.close();
      cout << "\n\n" << "  Average";
      getHighs();
    }
     
     
    
    void getHighs()
    {
     ifstream numberFileH;
     int a,b,c,d,e,f,g,h,i,j,k,l;
     int num[11];
     numberFileH.open("Highs.Dat");
     
     if(!numberFileH) 
     {
      cout << "  Error opening file" << endl;
            _getch();        
     }
        
     while (numberFileH.good())
     {
      numberFileH >> a >> b >> c >> d >> e >> f >> g >> h >> i >> j >> k >> l;
     }
     num[0] = a;
     num[1] = b;
     num[2] = c;
     num[3] = d;
     num[4] = e;
     num[5] = f;
     num[6] = g;
     num[7] = h;
     num[8] = i;
     num[9] = j;
     num[10] = k;
     num[11] = l;
     
     cout << "\n  Highs     ";
     
     for (int z = 0; z < 12; z++)
     {
      cout << num[z] << "   ";
     } 
     numberFileH.close();
     getLowTemps();
    }
     
     
    
    void getLowTemps()
    {
     ifstream numberFileL;
     int m,n,o,p,q,r,s,t,u,v,w,x;
     int numL[11];
     numberFileL.open("Lows.pink");
     
     if(!numberFileL) 
     {
      cout << "  Error opening file" << endl;
            _getch();        
     }
        
     while (numberFileL.good())
     {
      numberFileL >> m >> n >> o >> p >> q >> r >> s >> t >> u >> v >> w >> x;
     }
     numL[0] = m;
     numL[1] = n;
     numL[2] = o;
     numL[3] = p;
     numL[4] = q;
     numL[5] = r;
     numL[6] = s;
     numL[7] = t;
     numL[8] = u;
     numL[9] = v;
     numL[10] = w;
     numL[11] = x;
     cout << "\n  Lows      ";
     
     for (int z = 0; z < 12; z++)
     {
      cout << numL[z] << "   ";
     } 
     numberFileL.close();
     getPrecipitation();
    }
      
     
     
    void getPrecipitation()
    {
     ifstream numberFileP;
     double m,n,o,p,q,r,s,t,u,v,w,x;
     double numL[12];
     numberFileP.open("Precipitation.wet");
     
     if(!numberFileP) 
     {
      cout << "  Error opening file" << endl;
            _getch();        
     }
        
     while (numberFileP.good())
     {
      numberFileP >> m >> n >> o >> p >> q >> r >> s >> t >> u >> v >> w >> x;
     }
     numL[0] = m;
     numL[1] = n;
     numL[2] = o;
     numL[3] = p;
     numL[4] = q;
     numL[5] = r;
     numL[6] = s;
     numL[7] = t;
     numL[8] = u;
     numL[9] = v;
     numL[10] = w;
     numL[11] = x;
     cout << "\n\n  Rainfall      \n  Inches  ";
     
     for (int z = 0; z < 12; z++)
     {
      cout << numL[z] << " ";
     } 
     numberFileP.close();
     getRecordHighYear();
    }
     
     
     
    
    void getRecordHighYear()
    {
     string str[1];
     string line;
     ifstream highY;
     highY.open("RecordHighYear.txt");
     
     if(!highY) 
     {
      cout << "  Error opening file" << endl;
            _getch();        
     }
      while(highY.good())
        {
      getline (highY,line);                
      str[0] = line;       
     }
      
      cout << "\n\n" << "  Records \n" << "  Year    ";
      cout << str[0] << endl;
     
      highY.close();
      getRecordHighTemp();
    }
     
     
    
    void getRecordHighTemp()
    {
     ifstream numberFileL;
     int m,n,o,p,q,r,s,t,u,v,w,x;
     int numL[12];
     numberFileL.open("RecordHighTemperature.txt");
     
     if(!numberFileL) 
     {
      cout << "  Error opening file" << endl;
            _getch();        
     }
        
     while (numberFileL.good())
     {
      numberFileL >> m >> n >> o >> p >> q >> r >> s >> t >> u >> v >> w >> x;
     }
     numL[0] = m;
     numL[1] = n;
     numL[2] = o;
     numL[3] = p;
     numL[4] = q;
     numL[5] = r;
     numL[6] = s;
     numL[7] = t;
     numL[8] = u;
     numL[9] = v;
     numL[10] = w;
     numL[11] = x;
     cout << "  High   ";
     
     for (int z = 0; z < 12; z++)
     {
      if (numL[z] < 100)
      {
      cout << "   " << numL[z];
      }
      else if (numL[z] > 99)
      {
      
       cout << "  " << numL[z];
      }
     }
     numberFileL.close();
     getRecordLowYear();
    }
     
     
    
    void getRecordLowYear()
    {
     string str[11];
     string line;
     ifstream lowY;
     lowY.open("RecordLowYear.txt");
     
     if(!lowY) 
     {
      cout << "  Error opening file" << endl;
            _getch();        
     }
     while (lowY.good())
     {
      for (int i = 0; i < 12; i++)
      {
       getline (lowY,line);                
       str[i] = line;       
      }
     } 
     cout << "\n\n  Year    ";
     for (int z = 0; z < 12;z++)
     {
     
      cout << str[z] << " ";
     }
      lowY.close();
      getRecordLowTemp();
    }
     
     
     
    
    void getRecordLowTemp()
    {
     ifstream numberFileL;
     int m,n,o,p,q,r,s,t,u,v,w,x;
     int numL[12];
     numberFileL.open("RecordLowTemperature.txt");
     
     if(!numberFileL) 
     {
      cout << "  Error opening file" << endl;
            _getch();        
     }
        
     while (numberFileL.good())
     {
      numberFileL >> m >> n >> o >> p >> q >> r >> s >> t >> u >> v >> w >> x;
     }
     numL[0] = m;
     numL[1] = n;
     numL[2] = o;
     numL[3] = p;
     numL[4] = q;
     numL[5] = r;
     numL[6] = s;
     numL[7] = t;
     numL[8] = u;
     numL[9] = v;
     numL[10] = w;
     numL[11] = x;
     cout << "\n  Low      ";
     
     for (int z = 0; z < 9; z++)
     {
      if (numL[z] < 0)
      {
      cout << numL[z] << "  ";
      }
      else if (numL[z] < 10 && numL[z] > -1)
      {
       cout << "  " << numL[z];
      }
      else if (numL[z] > 9)
      {
       cout << "   " << numL[z];
      }
     }
     for (int z = 9; z < 12;z++)
     {
      if (numL[z] > 0)
      {
      cout << "    " << numL[z];
      }
      else if (numL[z] < 0)
      {
       cout << "  " << numL[z];
      }
     }
     numberFileL.close();
     cout << "\n\n\n" << endl;
     cout << "  [1]  Omaha weather statistics, Accessed 5/7/2012\n";
     cout << "       http://www.weather.com/weather/wxcli...nthly/USNE0363" << endl;
     getClosing( );
     _getch();
    }



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •