Answered step by step
Verified Expert Solution
Question
1 Approved Answer
THIS IS IN C++ PROGRAMMING USING MICROSOFT VISUAL STUDIO. 1. Open the data.txt file available. Append the following to its text. 5 6 pick up
THIS IS IN C++ PROGRAMMING USING MICROSOFT VISUAL STUDIO.
1. Open the data.txt file available. Append the following to its text.
5 6 pick up sticks
7 8 aint c++ great!
2. Write a code that reads three numbers from the file specified by the user, multiply the numbers, and write the sum to another file specified by the user.
3. What does the code formattingoutput.txt do? Explain it to the instructor once you figure it out..
You should create a file called rawdata yourself.
formattingoutput.txt:
//DISPLAY 6.6 Formatting Output //Illustrates output formatting instructions. //Reads all the numbers in the file rawdata.dat and writes the numbers //to the screen and to the file neat.dat in a neatly formatted way. #include#include #include #include //needed for setw using namespace std; void make_neat(ifstream& messy_file, ofstream& neat_file, int number_after_decimalpoint, int field_width); //Precondition: The streams messy_file and neat_file have been connected //to files using the function open. //Postcondition: The numbers in the file connected to messy_file have been //written to the screen and to the file connected to the stream neat_file. //The numbers are written one per line, in fixed-point notation (that is, not in //e-notation), with number_after_decimalpoint digits after the decimal point; //each number is preceded by a plus or minus sign and each number is in a field //of width field_width. (This function does not close the file.) int main( ) { ifstream fin; ofstream fout; fin.open("rawdata.txt"); if (fin.fail( )) { cout << "Input file opening failed. "; exit(1); } fout.open("neat.txt"); if (fout.fail( )) { cout << "Output file opening failed. "; exit(1); } make_neat(fin, fout, 5, 12); fin.close( ); fout.close( ); cout << "End of program. "; return 0; } //Uses iostream, fstream, and iomanip: void make_neat(ifstream& messy_file, ofstream& neat_file, int number_after_decimalpoint, int field_width) { neat_file.setf(ios::fixed); //Not in e-notation neat_file.setf(ios::showpoint); //show decimal point neat_file.setf(ios::showpos); //show +sign neat_file.precision(number_after_decimalpoint); cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.setf(ios::showpos); cout.precision(number_after_decimalpoint); double next; while (messy_file >> next) //satisfies if there is a next number to read { cout << setw(field_width) << next << endl; neat_file << setw(field_width) << next << endl; } }
data.txt:
1 2 buckle my shoe. 3 4 shut the door.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started