fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. /*
  7. *Коротко о программе: программа создана для подсчёта проданных книг(по количеству,имени, цене)
  8. */
  9.  
  10.  
  11.  
  12.  
  13. class MainProgramCore {
  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. // Объявление переменных
  28. void mainViarables();
  29. int price, number;
  30. string name, answer;
  31.  
  32. int main() {
  33. MainProgramCore objMainProgramCore;
  34. cout << "Hello! If you sold any book, type Y. If you didn't, just ignore this message! : ";
  35. cin >> answer;
  36. if ((answer == "Y") || (answer == "y")) {
  37. cout << "Ok! How much books did you sell? Type number: ";
  38. cin >> number;
  39. for (int i = 0; i < number; i++) {
  40. objMainProgramCore.getNameAndPrice();
  41. }
  42. system("pause");
  43. return 0;
  44.  
  45. }
  46. }
  47.  
  48.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Hello! If you sold any book, type Y. If you didn't, just ignore this message! :