User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,657 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,684 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 2419 | Replies: 2
Reply
Join Date: Jan 2005
Posts: 5
Reputation: yvonnemo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
yvonnemo yvonnemo is offline Offline
Newbie Poster

transfer input.txt to output.txt help prz

  #1  
Jan 30th, 2005
Hi, I'm having trouble on transfering "input.txt" over to "output.txt" what command shall I use with C++ language? Anyways below is the question I needed to answer on monday, anyway help will be very very appreciated.

write a program to compute numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's last name, then on espace, then the student's first name, then one space, then ten quiz scores all on one line. The quiz scores are whole numbers and are separated by one space. Your program will take its input from this file and send its output to a second file. The data in the output file will be the same as the data in the input file except that there will be one additional number ( of type double ) at the end of each line. This number will be the average of the student's ten quiz scores. If this is being done as a class assignment, obtain the file names from your instructor. Use at least one function that has file streams as all or some of its arguments.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2005
Posts: 5
Reputation: yvonnemo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
yvonnemo yvonnemo is offline Offline
Newbie Poster

Re: transfer input.txt to output.txt help prz

  #2  
Jan 30th, 2005
nm I know how to transfer files from input to output now.. but i'm still having problem output the average of every line from input file.. how is it being done? my codes are below

#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;

void copy(ifstream& in_stream, ofstream& out_stream);

int main( )
{
    ifstream fin;
    ofstream fout;

    cout << "Begin editing files.\n";

    fin.open("input.txt");
    if (fin.fail( ))
    {
        cout << "Input file opening failed.\n";
        exit(1);
    }

    fout.open("output.txt");
    if (fout.fail( ))
    {
        cout << "Output file opening failed.\n";
        exit(1);
    }

    copy(fin, fout);


    fin.close( );
    fout.close( );

    cout << "End of editing files.\n";
    return 0;
}

void copy(ifstream& in_stream, ofstream& out_stream)
{
    char next;

    in_stream.get(next);
    while (! in_stream.eof( ))
    {

        out_stream << next;

        in_stream.get(next);
    }
}
Reply With Quote  
Join Date: Jan 2005
Posts: 43
Reputation: Siersan is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
Siersan's Avatar
Siersan Siersan is offline Offline
Speaker of Truth

Re: transfer input.txt to output.txt help prz

  #3  
Jan 30th, 2005
What you want is a variation of this.
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string last, first;
  int sum = 0, grade;

  cin>> last >> first;
  for (int i = 0; i < 10; i++) {
    cin>> grade;
    sum += grade;
  }

  cout<<"The average is "<< sum / 10 <<endl;
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC