Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes

 
c++ assignment
Reply
Posted 2007-05-20, 07:37 PM
i got the first part done but i have second part that confuse me i have to write a write function that write in outputdata.dat all total of number in inputdata.dat.

here the code i got it work to display what inside inputdata.dat.

Code:
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
 
#define BUF_SIZE    21
#define IN_FILE        "InputData.dat"
 
extern void main( void )
{
    ifstream    ifInputFile;
    ofstream stream;
    char        sBuffer[BUF_SIZE];
    bool        bDataExists(true);
 
    ifInputFile.open("InputData.dat");
 
    if( ifInputFile.is_open() != 1 )
    {
        cout << "File " << IN_FILE << " could not be opened!" << endl;
        cout << "Exiting program, good bye." << endl;
    }
    else
    {
        while( bDataExists == true )
        {
            ifInputFile.getline( sBuffer, 40 );
            if( ifInputFile.eof() == 1 )
            {
                bDataExists = false;
            }
            else
            {
                cout << sBuffer << endl;
            }
        }
 
        ifInputFile.close();
    }
}
here what it display

23
36
54
75
88
64

i have to write a code that add all this number and use write function to put it in output.dat file. It confuses me i get alot of errors. Thanks for helping me.

Last edited by Lenny; 2007-05-22 at 04:51 AM.
Old
Profile PM WWW Search
osmoses-jones is neither ape nor machine; has so far settled for the in-betweenosmoses-jones is neither ape nor machine; has so far settled for the in-between
 
osmoses-jones
 



 
Reply
Posted 2007-05-21, 05:24 PM in reply to osmoses-jones's post "c++ assignment"
arent u that crazy african guy that was in a tribe
Old
Profile PM WWW Search
slaynish enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzslaynish enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
slaynish
 



 
Reply
Posted 2007-05-21, 06:06 PM in reply to slaynish's post starting "arent u that crazy african guy that was..."
The only person that knows the answer is Kagom! *queue dramatic music* You're goin to have to earn that answer, too .
Old
Profile PM WWW Search
Willkillforfood read his obituary with confusionWillkillforfood read his obituary with confusionWillkillforfood read his obituary with confusionWillkillforfood read his obituary with confusion
 
 
Willkillforfood
 



 
Reply
Posted 2007-05-21, 11:49 PM in reply to Willkillforfood's post starting "The only person that knows the answer..."
Could a mod please add some code tags to the OP? It's difficult to follow without them.

Oj, I've never used iostream, but it seems like a fairly trivial assignment. Are you having trouble adding the numbers together or using the write function from IOStream? If it's the latter, I would suggest looking up some documentation on the function at google or going through some code that uses the write function at www.krugle.com or some other code repository. If it's the former, it should be easily doable with a for loop.

It looks to me as if you're saving the input as a string, which seems like a difficult way to go about doing things. I'd use an integer array to store them rather than using a single string to store multiple numbers.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 



 
Reply
Posted 2007-05-22, 07:15 PM in reply to Demosthenes's post starting "Could a mod please add some code tags..."
I figure it out damn it was easy when you finds out but at first is realy hard. Anyway if you guys want to see complete code i can post it.
Old
Profile PM WWW Search
osmoses-jones is neither ape nor machine; has so far settled for the in-betweenosmoses-jones is neither ape nor machine; has so far settled for the in-between
 
osmoses-jones
 



 
Reply
Posted 2007-05-23, 07:25 AM in reply to osmoses-jones's post starting "I figure it out damn it was easy when..."
I'd be interested to see it, if only for me to try and work out what it does.

I think I ended up doing a similar thing in my VB project (well, it was a database - everyone else in both sets did it in Access, apart from a friend and I, who did it in VB) - having to save data in a random access file. Maybe not the exact same thing that you're doing, but a bit similar.
Old
Profile PM WWW Search
Lenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basics
 
 
Lenny
 



 
Reply
Posted 2007-05-25, 04:01 PM in reply to Lenny's post starting "I'd be interested to see it, if only..."
here

Code:
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
 
#define BUF_SIZE    21
#define IN_FILE        "InputData.dat"
#define OUT_FILE "OutputData.dat"
 
 
extern void main( void )
{
    ifstream    ifInputFile;
    ofstream output;
    char        sBuffer[BUF_SIZE];
    bool        bDataExists(true);
    int total;
    total = 0;
 
    ifInputFile.open("InputData.dat");
    output.open("OutputData.dat",ios::out);
 
    if( ifInputFile.is_open() != 1 )
    {
        cout << "File " << IN_FILE << " could not be opened!" << endl;
        cout << "Exiting program, good bye." << endl;
    }
    else
    {
        while( bDataExists == true )
        {
            ifInputFile.getline( sBuffer, 40 );
            if( ifInputFile.eof() == 1 )
            {
                bDataExists = false;
            }
            else
            {
                cout << sBuffer << endl;
                total=total+atoi(sBuffer);
            }
        }
        cout << total;
        ifInputFile.close();
 
        if (output.is_open() != 1)
        {
            cout << "File" << OUT_FILE << " could not be opened!" << endl;
            cout << " Exiting program.good bye" << endl;
        }
        else
        {
            output << total;
            output.close();
        }
 
    }
}

Last edited by Lenny; 2007-05-25 at 04:08 PM.
Old
Profile PM WWW Search
osmoses-jones is neither ape nor machine; has so far settled for the in-betweenosmoses-jones is neither ape nor machine; has so far settled for the in-between
 
osmoses-jones
 



 
Reply
Posted 2007-05-25, 04:04 PM in reply to osmoses-jones's post starting "here #include <iostream.h>..."
PLEASE include some code tags next time.
Old
Profile PM WWW Search
Demosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to beDemosthenes seldom sees opportunities until they cease to be
 
Demosthenes
 
 

Bookmarks

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules [Forum Rules]
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 01:11 AM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.