fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. /*
  7. *Коротко о программе: программа создана для подсчёта проданных книг(по количеству,имени, цене)
  8. */
  9.  
  10.  
  11. class MainProgramCore
  12. {
  13.  
  14. public:
  15. ofstream fout;
  16. void getNameAndPrice() {
  17. int price = 0;
  18. string name = "";
  19. fout.open("soldbooks.txt", ios_base::app);
  20. cout << "Hello. I'am your own helper! Type name then press enter and type price!";
  21. cin >> name >> price;
  22. fout << name <<":"<< price<<"$" << endl;
  23. fout.close();
  24. }
  25. };
  26.  
  27. int main() {
  28. string answer;
  29. int number;
  30. MainProgramCore objMainProgramCore;
  31. ofstream fout;
  32. cout << "Hello! If you sold any book, type Y. If you didn't, just ignore this message! : ";
  33. cin >> answer;
  34. if ((answer == "Y") || (answer == "y")) {
  35. cout << "Ok! How much books did you sell? Type number: ";
  36. cin >> number;
  37. for (int i = 0; i < number; i++) {
  38. objMainProgramCore.getNameAndPrice();
  39. }
  40. system("pause");
  41. return 0;
  42.  
  43. }
  44. }
  45.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Hello! If you sold any book, type Y. If you didn't, just ignore this message! :