1

I am writing this code because of my project. I want to do person will select his/her decisions for example He want to read History books with 10-50 dollars and 100-200 pages and my program shows History books with in 10-50 dollars ranges and 100-200 pages in ranges. I write data about books in text file but how can i read and compare please help me.

#include <iostream>
#include <fstream>
using namespace std;

class BookShop{

protected:
    int usertema;
    int userfiyat;
    int usersayfaaraligi;

public:
    int tur;

    void Karsilama(){
        cout<<"Hosgeldiniz secmek istediginiz türü seciniz"<<endl;
        cout<<"1:modern klasik \n 2:Turkedebiyati \n 3:Dunyaklasigi";
        cin>>tur;
    }

};


class ModernKlasik:public BookShop{
public:
    ModernKlasik()
    {
        cout<<"Aradiginiz kitap temasi nedir?";
        cout<<"\n1:Korku\n2:Aşk\n3:Sevgi\n4:Dram\n5:Kahramanlık\n";
        cin>>usertema;
        cout<<"Sayfa sayisi?:";
        cout<<"\n1:[0-50]\n2:[50-100]\n3:[100-200]\n4:[200-300]\n5:[400-500]\n6:[500+]";
        cin>>usersayfaaraligi;
        cout<<"Bir fiyat araligi giriniz:";
        cin>>userfiyat;
        if(userfiyat>=0 && userfiyat<=50){
             cout<<userfiyat<<endl;
        }
    }

    void fonksiyon1(){

    ofstream myFile1("Modernklasik.txt");
    myFile1<<"Kitap1:Tema= ,Sayfa sayisi=50,Fiyat=6 TL,Adý=Mecburiyet(Stefan Zweig)"<<endl;
    myFile1<<"Kitap2:Tema= ,Sayfa sayisi=70,Fiyat=8 TL,Adý=Feniçka(Lou Andreas-Salome)"<<endl;
    myFile1<<"Kitap3:Tema= ,Sayfa sayisi=74,Fiyat=8 Tl,Adý=Ayýþýðý Sokaðý(Stefan Zweig)"<<endl;
    myFile1<<"Kitap4:Tema= ,Sayfa sayisi=108,Fiyat=11 TL,Adý=Vahþetin Çaðrýsý(Jack London)"<<endl;
    myFile1<<"Kitap5:Tema= ,Sayfa sayisi=150,Fiyat=20 TL,Adý=Hayvan Çiftliði(George Orwell)"<<endl;
    myFile1<<"Kitap6:Tema= ,Sayfa sayisi=256,Fiyat=15 Tl,Adý=Karmaþýk Duygular(Stefan Zweig)"<<endl;
    }
};

class Turkedebiyati:public BookShop{
public:
    Turkedebiyati()
    {
        cout<<"Aradiginiz kitap temasi nedir?";
        cout<<"\n1:Korku\n2:Aşk\n3:Sevgi\n4:Dram\n5:Kahramanlık\n";
        cin>>usertema;
        cout<<"Sayfa sayisi?:";
        cout<<"\n1:[0-50]\n2:[50-100]\n3:[100-200]\n4:[200-300]\n5:[400-500]\n6:[500+]";
        cin>>usersayfaaraligi;
        cout<<"Fiyat araligi?:";
        cout<<"\n1:[0-10]TL\n2:[10-20]TL\n3:[20-50]TL\n4:[50-75]TL\n5:[75-100]TL\n6:[100+]TL";
        cin>>userfiyat;
    }

    void fonksiyon2(){
    ofstream myFile2 ("Turkedebiyati.txt");
    myFile2<<"Kitap1:Tema= ,Sayfa sayisi=409,Fiyat=20 TL,Adý=Çalýkuþu(Reþatnuri Gültekin)"<<endl;
    myFile2<<"Kitap2:Tema= ,Sayfa sayisi=164,Fiyat=5 TL,Adý=Kürk Mantolu Madonna(Sabahattin Ali)"<<endl;
    myFile2<<"Kitap3:Tema= ,Sayfa sayisi=112,Fiyat=8 Tl,Adý=Dokuzuncu Hariciye Koðusu(Peyami Safa)"<<endl;
    myFile2<<"Kitap4:Tema= ,Sayfa sayisi=112,Fiyat=5 TL,Adý=Vatan Yahut Silistre(Namik Kemal)"<<endl;
    myFile2<<"Kitap5:Tema= ,Sayfa sayisi=300,Fiyat=10 TL,Adý=Eylül(Mehmet Rauf)"<<endl;
    myFile2<<"Kitap6:Tema= ,Sayfa sayisi=195,Fiyat=12 Tl,Adý=Kýrmýzý Sacli Kadin(Orhan Pamuk)"<<endl;
    }

};

 class Dunyaklasikleri:public BookShop{
 public:
     Dunyaklasikleri()
     {
        cout<<"Aradiginiz kitap temasi nedir?";
        cout<<"\n1:Korku\n2:Aşk\n3:Sevgi\n4:Dram\n5:Kahramanlık\n";
        cin>>usertema;
        cout<<"Sayfa sayisi?:";
        cout<<"\n1:[0-50]\n2:[50-100]\n3:[100-200]\n4:[200-300]\n5:[400-500]\n6:[500+]";
        cin>>usersayfaaraligi;
        cout<<"Fiyat araligi?:";
        cout<<"\n1:[0-10]TL\n2:[10-20]TL\n3:[20-50]TL\n4:[50-75]TL\n5:[75-100]TL\n6:[100+]TL";
        cin>>userfiyat;
      }

      void fonksiyon3(){
      ofstream myFile3 ("Dunyaklasikleri.txt");
      myFile3<<"Kitap1:Tema= ,Sayfa sayisi=592,Fiyat= TL,Adý=Suç ve Ceza(Dostoyevski)"<<endl;
      myFile3<<"Kitap2:Tema= ,Sayfa sayisi=393,Fiyat= TL,Adý=Savaþ ve Barýþ(Tolstoy)"<<endl;
      myFile3<<"Kitap3:Tema= ,Sayfa sayisi=464,Fiyat= Tl,Adý=Ýki þehrin hikayesi(Charles Dickens)"<<endl;
      myFile3<<"Kitap4:Tema= ,Sayfa sayisi=184,Fiyat= TL,Adý=Ýnsancýklar(Dostoyevski)"<<endl;
      myFile3<<"Kitap5:Tema= ,Sayfa sayisi=128,Fiyat= TL,Adý=Fareler ve Ýnsanlar(John Steinbeck)"<<endl;
      myFile3<<"Kitap6:Tema= ,Sayfa sayisi=240,Fiyat= Tl,Adý=Romeo ve Juliet(William Shakespeare)"<<endl;
      }

};

int main()
{
    BookShop b1;

    b1.Karsilama();

    if(b1.tur==1)
    {
        ModernKlasik m1;
        m1.fonksiyon1();

    }
    if(b1.tur==2)
    {
        Turkedebiyati t1;
        t1.fonksiyon2();
    }
    if(b1.tur==3)
    {
        Dunyaklasikleri d1;
        d1.fonksiyon3();
    }
    return 0;
}
drescherjm
  • 10,365
  • 5
  • 44
  • 64
Gökhan
  • 19
  • 2
  • Normally reading code would be similar to writing code however in this case you are not using variables to write. You are instead just saving fixed strings to a text file. – drescherjm May 11 '21 at 16:09
  • `int usertema; int userfiyat; int usersayfaaraligi;` Should these all be integers (storing numbers only)? I think you should have some `std::string` variables however I don't understand the language – drescherjm May 11 '21 at 16:11
  • usertema is theme (history,drama,action vs vs) – Gökhan May 11 '21 at 16:40
  • Probably not a number. – drescherjm May 11 '21 at 16:42
  • 1
    You may want to spend some time and show your broken code that attempts to read your file. At StackOverflow we don't often write code for people where there is no attempt in the code to solve the problem that they want solved. However if there is a "good faith" attempt to solve the problem we will usually help. There are some guidelines here for this type of question: [https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions) – drescherjm May 11 '21 at 16:53
  • It is not a homework i dreamed this project... I dont want to write a code or smt just i need which functions i should use?? – Gökhan May 11 '21 at 17:11
  • The guidelines apply to non homework assignments also. – drescherjm May 11 '21 at 17:14
  • you want to use std::getline to read an entire line of text into a std::string and possibly std::istringstream to split it up if needed. Possibly like the second part of this answer: [https://stackoverflow.com/a/7868998/487892](https://stackoverflow.com/a/7868998/487892) – drescherjm May 11 '21 at 17:15
  • 3
    Always, Always search before posting. There are a *plethora* of issues, answers and examples of how to read a file in C++. For example, search the internet for "C++ read file comma separated" or "C++ read file line by line". – Thomas Matthews May 11 '21 at 17:27

0 Answers0