Advertisement
Guest User

Untitled

a guest
Dec 16th, 2010
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. /*********************************************************************
  2. input\output file example code by BitterCake
  3. **********************************************************************/
  4.  
  5. #include <string> // To use string (duh..)
  6. #include <iomanip> // To use setw\setprecision\showpoint\fixed.. etc
  7. #include <fstream> // To use ifstream and ofstream
  8. #include <iostream> // To use the cin and cout
  9. using namespace std; // So there is no need to type "std::cout" instead you just type "cout"
  10.  
  11. int main()
  12. {
  13. // Declaring the varieables
  14. string name;
  15. float price;
  16. int bags;
  17. float tax;
  18. float net;
  19.  
  20. // Going to open the output and input text documents now
  21. ifstream fin;
  22. ofstream fout;
  23. fin.open ("tickt.txt");
  24. fout.open ("fare.txt");
  25.  
  26. //Reading memory from "tickt.txt"
  27. fin >> name;
  28. fin >> price;
  29. fin >> bags;
  30.  
  31. //Setting the operations up
  32. tax = price*3/100;
  33. net = price + tax;
  34.  
  35. //And finally, writting the data to "fare.txt"!
  36. fout << setw(17) << setfill('*') << "Name: " << name << endl;
  37. fout << setw(17) << setfill('@') << "Bags: ";
  38. fout << setw(7) << setfill('0') << bags << endl;
  39. fout << setw(18) << setprecision(3) << setfill('*') << fixed << showpoint << "Ticket Price: " << price << endl;
  40. fout << setw(18) << setprecision(3) << setfill('*') << fixed << showpoint << "Airport Tax: " << tax << endl;
  41. fout << setw(18) << setprecision(3) << setfill('*') << fixed << showpoint << "Net Price: " << net << endl;
  42.  
  43. //Closing the files and ending the program
  44. fin.close();
  45. fout.close();
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement