Notices

Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

C++ DUDES ...lol

Post Reply New Thread Subscribe Search this Thread
 
 
Thread Tools
Old 05-15-12, 09:45 PM Thread Starter   #1
Xtreme Barton
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

__________________


Xtreme Barton is offline   QUOTE Thanks
Old 05-15-12, 10:47 PM   #2
pcarini
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!"
pcarini is offline   QUOTE Thanks
Old 05-15-12, 11:08 PM Thread Starter   #3
Xtreme Barton
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.

__________________


Xtreme Barton is offline   QUOTE Thanks
Old 05-16-12, 12:06 AM   #4
ssjwizard
Has slightly less legible writing
than Thideras, Member

 
ssjwizard's Avatar 

Join Date: Mar 2002
Location: Rio Rancho, NM

10 Year Badge
 
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 posts 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
ssjwizard is offline Benching Profile Folding Profile Heatware Profile   QUOTE Thanks
Old 05-16-12, 07:59 AM Thread Starter   #5
Xtreme Barton
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.
Xtreme Barton is offline   QUOTE Thanks
Old 05-16-12, 06:18 PM Thread Starter   #6
Xtreme Barton
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 ..

__________________


Xtreme Barton is offline   QUOTE Thanks
Old 05-16-12, 07:27 PM   #7
ssjwizard
Has slightly less legible writing
than Thideras, Member

 
ssjwizard's Avatar 

Join Date: Mar 2002
Location: Rio Rancho, NM

10 Year Badge
 
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 posts 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
ssjwizard is offline Benching Profile Folding Profile Heatware Profile   QUOTE Thanks
Old 05-16-12, 11:39 PM Thread Starter   #8
Xtreme Barton
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();
}

__________________


Xtreme Barton is offline   QUOTE Thanks

Post Reply New Thread Subscribe


Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Mobile Skin
All times are GMT -5. The time now is 10:33 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
You can add these icons by updating your profile information to include your Heatware ID, Benching Profile ID or your Folding/SETI profile ID. Edit your profile!
X

Welcome to Overclockers.com

Create your username to jump into the discussion!

New members like you have made this the best community on the Internet since 1998!


(4 digit year)

Why Join Us?

  • Share experience
  • Max out your hardware
  • Best forum members anywhere
  • Customized forum experience

Already a member?