Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************
- input\output file example code by BitterCake
- **********************************************************************/
- #include <string> // To use string (duh..)
- #include <iomanip> // To use setw\setprecision\showpoint\fixed.. etc
- #include <fstream> // To use ifstream and ofstream
- #include <iostream> // To use the cin and cout
- using namespace std; // So there is no need to type "std::cout" instead you just type "cout"
- int main()
- {
- // Declaring the varieables
- string name;
- float price;
- int bags;
- float tax;
- float net;
- // Going to open the output and input text documents now
- ifstream fin;
- ofstream fout;
- fin.open ("tickt.txt");
- fout.open ("fare.txt");
- //Reading memory from "tickt.txt"
- fin >> name;
- fin >> price;
- fin >> bags;
- //Setting the operations up
- tax = price*3/100;
- net = price + tax;
- //And finally, writting the data to "fare.txt"!
- fout << setw(17) << setfill('*') << "Name: " << name << endl;
- fout << setw(17) << setfill('@') << "Bags: ";
- fout << setw(7) << setfill('0') << bags << endl;
- fout << setw(18) << setprecision(3) << setfill('*') << fixed << showpoint << "Ticket Price: " << price << endl;
- fout << setw(18) << setprecision(3) << setfill('*') << fixed << showpoint << "Airport Tax: " << tax << endl;
- fout << setw(18) << setprecision(3) << setfill('*') << fixed << showpoint << "Net Price: " << net << endl;
- //Closing the files and ending the program
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement