Answer to Question #321345 in C++ for yormi

Question #321345

2.

Assume that each of the following statements applies to the same program.

a.

Write a statement that opens file

oldmast.dat

for

input; use an ifstream object called

inOldMaster.

b.

Write a statement that opens file

trans.dat

for reading

and writing data to it; use fstream object

transFile

that can read data from the file trans.dat

as well as write data to it.

c.

Write a statement that writes a record to the transfile. The record to store consist of an integer data

accountNumber

, and a floating point data

dollarAmount



1
Expert's answer
2022-06-21T08:39:37-0400
#include <fstream>

using namespace std;

int main()
{
	// a
	ifstream inOldMaster;
	inOldMaster.open("oldmast.dat");

	// b
	fstream transFile;
	transFile.open("trans.dat");

	// c
	int accountNumber = 272445;
	double dollarAmount = 2647.27;
	transFile << accountNumber << " " << dollarAmount << endl;

	inOldMaster.close();
	transFile.close();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog