Be able to use file stream for input and output Be able to format output appropr
ID: 3566107 • Letter: B
Question
Be able to use file stream for input and output Be able to format output appropriately You must name your source program yourPsuID-lab7. cpp. For example, if your PSU ID is abcSOOO, then the source program must be named abc5000-lab7. cpp. There is a text file that contains the list of airfare with the departure and destination airport. We want to increase the price by 10%. Your program will create a new file that contains the old and new prices. Your program will also format the output file so that it is more readable. You should create this text file (use Notepad) by yourself for testing. The original file (the input source of your program) is: Requirements: The programming style requirements are like previous labs and homework, including sufficient comments and appropriate, meaningful variable names. your output file should be named yoMr/, sji//9-lab7-output. txt [use your real PSU ID] The number of spaces can be flexible as long as the output looks neat and clean. Currency must contain a dollar sign with 2 decimal numbers. Your program must compile.Explanation / Answer
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main(){
ifstream infile;
infile.open("input.txt");
ofstream outfile;
outfile.open("output.txt");
outfile << " From To Current Price New Price ";
outfile << "======================================================== ";
char src[5],des[5];
double curr,newCost;
while(!infile.eof()){
infile >> src;
infile >> des;
infile >> curr;
newCost = curr + curr/10;
outfile << " " << src;
outfile << " " << des;
outfile << " $ " << curr;
outfile << " $ " << newCost;
outfile << endl;
}
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.