Write a C++ program

timer Asked: Apr 19th, 2017

Question Description

File Input/Output in C++

#include<fstream> //header file for file I/O

ifstream infile; //declare input and output file

ofstream outfile; // stream variables (names of your choice)

//Open the input file (associate file name and location with input file stream variable)


//Open non-existent output file or append new output to existing output file.

outfile.open(“h:\\nearestint.txt”, ios::app);

/*(Now use input file stream variable inFile (instead of cin) whenever input is from a file and not from the keyboard. Examples are:

infile >> value;

infile.get (ch);

infile.ignore( 25, ‘$’);

getline(infile, str);

Use the output filestream variable outfile (instead of cout) to output strings of text and variable values to the output file.)


infile.close(); //Close input and output

outfile.close(); // files.

Lab Assignment: Write a program to convert floating point to the nearest integer, using file input and output. The output should identify both the input value and the rounded value, in a sentence.

The input file must exist, with the data in it, before you run the program. Run twice with different input values each time. The output file should contain the results of both runs.

COSC 113

Lab #1: Write a C++ program which uses a void function to “flip a coin” 7000 times, and report (to a file) the number of heads and the number of tails. Be sure that running the program a second time will result in a different sequence of heads and tails.

Lab #2: (Using an eof-terminated while loop) Write a complete program to find the minimum value in a file containing an unknown number of integers. Output the result to a file.

Note: No global variables allowed! Declare filestream variables and open files in main( ).

This question has not been answered.

Create a free account to get help with this and any other question!

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors