| | |
transfer input.txt to output.txt help prz
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2005
Posts: 5
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Jan 2005
Posts: 5
Reputation:
Solved Threads: 0
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
C++ Syntax (Toggle Plain Text)
#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); } }
What you want is a variation of this.
C++ Syntax (Toggle Plain Text)
#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; }
![]() |
Similar Threads
- won't create output .txt file :( (Java)
- searching by multiple user input and display output in textbox and picture box (VB.NET)
- problem of data output into *.txt file (C++)
- Solution for Big Integer used Linked - List. (C++)
- I need the helps, the deadline is coming soon... (C++)
- get the coordenates of a word in a puzzle (C)
- Help! Unknown bug in Writing to file (C)
Other Threads in the C++ Forum
- Previous Thread: Access Violation (Segmentation Fault) + atol
- Next Thread: help with inserting a number into an array
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





