Oct 29, 2018 at 1:22pm UTC
Hi everyone, i wrote my code on visual studio first but i have to delivery my task on GNU mingw.
In visual studio code works perfect but when i try code on mingw i took a lot of does not name a type error.I have to say i split my code hpp and cpp actually to much hpp and cpp.I included hpps on cpps but still not working.Here is my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#ifndef OGRENCI_HPP
#define OGRENCI_HPP
#include "Sinif.hpp"
#include "Okul.hpp"
#include "Yonetim.hpp"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
class Ogrenci
{
private :
char Harf;
public :
Ogrenci(char );
Ogrenci();
char harfGetir();
friend ostream& operator <<(ostream& ,Ogrenci&);
};
#endif
----ogrenci.cpp----------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include "Ogrenci.hpp"
#include "Sinif.hpp"
#include "Okul.hpp"
#include "Yonetim.hpp"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
Ogrenci::Ogrenci(char harf)
{
Harf = harf;
}
Ogrenci::Ogrenci()
{
Harf = ' ' ;
}
char Ogrenci::harfGetir()
{
return Harf;
}
ostream& operator <<(ostream& ekran, Ogrenci& sag)
{
ekran << sag.Harf;
return ekran;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#ifndef SINIF_HPP
#define SINIF_HPP
#include "Ogrenci.hpp"
#include "Okul.hpp"
#include "Yonetim.hpp"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
class Sinif
{
private :
Ogrenci **ogrenci;
int sinifNumarasi;
int siradakiOgrenci;
int ogrenciSayisi;
public :
Sinif(int ,int );
~Sinif();
friend ostream& operator <<(ostream& ,Sinif&);
void Yazdir();
void ogrenciEkle(char );
Sinif();
void OgrenciDegistir(char , char );
};
#endif
------sinif.cpp-----------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#include "Ogrenci.hpp"
#include "Sinif.hpp"
#include "Okul.hpp"
#include "Yonetim.hpp"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
Sinif::Sinif(int ogrenciSayisi,int sinifNo)
{
ogrenci = new Ogrenci*[ogrenciSayisi];
sinifNumarasi = sinifNo;
this ->ogrenciSayisi = ogrenciSayisi;
}
Sinif::~Sinif()
{
delete ogrenci;
}
Sinif::ostream& operator <<(ostream& ekran,Sinif& sag)
{
sag.Yazdir();
return ekran;
}
void Sinif::Yazdir()
{
cout << "Sinif: " << sinifNumarasi << endl;
for (int i = 0; i < ogrenciSayisi; i++)
{
cout << *ogrenci[i] <<setw(5)<<"(" <<ogrenci[i]<<")" << endl;
}
}
void Sinif::ogrenciEkle(char adi)
{
ogrenci[siradakiOgrenci++] = new Ogrenci(adi);
}
Sinif::Sinif()
{
siradakiOgrenci = 0;
}
void Sinif::OgrenciDegistir(char ogrenciharfi1, char ogrenciharfi2)
{
int o1 = -1, o2 = -1;
for (int i = 0; i < ogrenciSayisi; i++)
{
if (ogrenci[i]->harfGetir() == ogrenciharfi1)
o1 = i;
if (ogrenci[i]->harfGetir() == ogrenciharfi2)
o2 = i;
}
if (o1 == -1 || o2 == -1)
{
return ;
}
Ogrenci *yedek1 = ogrenci[o1];
ogrenci[o1] = ogrenci[o2];
ogrenci[o2] = yedek1;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#ifndef OKUL_HPP
#define OKUL_HPP
#include "Ogrenci.hpp"
#include "Sinif.hpp"
#include "Yonetim.hpp"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
class Okul
{
private :
Sinif **SinifDizisi;
int siradakiSinif;
int sinifSayisi;
int ogrenciSayisi;
public :
Okul(int );
~Okul();
friend ostream& operator <<(ostream& ,Okul&);
Okul();
void OgrenciDegistir(char , char );
void sinifDegistir(int , int );
Sinif *sinifGetir(int sinifsirasi);
void sinifEkle(Sinif*);
};
#endif
----------okul.cpp--------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#include "Ogrenci.hpp"
#include "Sinif.hpp"
#include "Okul.hpp"
#include "Yonetim.hpp"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
Okul::Okul(int sinifSayisi)
{
SinifDizisi = new Sinif*[sinifSayisi];
this ->sinifSayisi = sinifSayisi;
siradakiSinif = 0;
}
Okul::~Okul()
{
delete SinifDizisi;
}
Okul::ostream& operator <<(ostream& ekran, Okul& sag)
{
for (int i = 0; i < sag.sinifSayisi; i++)
{
ekran << *sag.SinifDizisi[i];
}
return ekran;
}
Okul::Okul()
{
siradakiSinif = 0;
sinifSayisi = 0;
}
void Okul::OgrenciDegistir(char ogrenciharfi1, char ogrenciharfi2)
{
for (int i = 0; i < sinifSayisi; i++)
{
SinifDizisi[i]->OgrenciDegistir(ogrenciharfi1, ogrenciharfi2);
}
}
void Okul::sinifDegistir(int sinifsayisi1, int sinifsayisi2)
{
Sinif *yedek2 = SinifDizisi[sinifsayisi1-1];
SinifDizisi[sinifsayisi1-1] = SinifDizisi[sinifsayisi2-1];
SinifDizisi[sinifsayisi2-1] = yedek2;
}
void Okul::sinifEkle(Sinif *yeni)
{
SinifDizisi[siradakiSinif++]=yeni;
}
Sinif* Okul::sinifGetir(int sinifsirasi)
{
return SinifDizisi[sinifsirasi-1];
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#ifndef YONETIM_HPP
#define YONETIM_HPP
#include "Ogrenci.hpp"
#include "Sinif.hpp"
#include "Okul.hpp"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
class Yonetim
{
public :
Yonetim(Okul*);
void OgrenciDegistir(char ogrenciharfi1,char ogrenciharfi2);
void sinifDegistir(int sinifsayisi1,int sinifsayisi2);
~Yonetim();
private :
Ogrenci **ogrenci;
Sinif **sinif;
Okul* okul;
};
#endif
-------yonetim.cpp----------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include "Ogrenci.hpp"
#include "Sinif.hpp"
#include "Okul.hpp"
#include "Yonetim.hpp"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
Yonetim::Yonetim(Okul* okul)
{
this ->okul = okul;
}
void Yonetim::OgrenciDegistir(char ogrenciharfi1,char ogrenciharfi2)
{
okul->OgrenciDegistir(ogrenciharfi1, ogrenciharfi2);
}
void Yonetim::sinifDegistir(int sinifsayisi1,int sinifsayisi2)
{
okul->sinifDegistir(sinifsayisi1, sinifsayisi2);
}
Yonetim::~Yonetim()
{
delete ogrenci,sinif,okul;
}
and my main metod is here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
#include "Ogrenci.hpp"
#include "Sinif.hpp"
#include "Okul.hpp"
#include "Yonetim.hpp"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
int main()
{
string veriler;
string oku;
string sinifNumara;
int ogrenciSayisi;
char harfler;
int sinifSayisi = 0;
ifstream dosyaOku("okul.txt" , ios::in);
if (!dosyaOku)
{
cout << "ERROR: File could not be opened1." << endl;
}
else
{
cout << "File opened successfully1" << endl;
}
while (std::getline(dosyaOku, oku))
{
sinifSayisi++;
}
dosyaOku.close();
Okul *o1 = new Okul(sinifSayisi);
dosyaOku.open("okul.txt" , ios::in);
if (!dosyaOku)
{
cout << "ERROR: File could not be opened1." << endl;
}
else
{
cout << "File opened successfully1" << endl;
}
while (!dosyaOku.eof())
{
oku = "" ;
dosyaOku >> sinifNumara;
std::getline(dosyaOku, oku);
stringstream ss(oku);
stringstream dd(oku);
ogrenciSayisi = 0;
while (ss >> harfler)
{
ogrenciSayisi++;
}
Sinif *s1 = new Sinif(ogrenciSayisi,atoi(sinifNumara.c_str()));
while (dd >> harfler)
{
s1->ogrenciEkle(harfler);
}
o1->sinifEkle(s1);
}
dosyaOku.close();
cout << *o1;
Yonetim y(o1);
int secim;
cout << endl;
cout << "1. Sinif Degistir" << endl;
cout << "2. Ogrenci Degistir" << endl;
cout << "3. Cikis" << endl;
cout << "=> " ;
do
{
cin >> secim;
switch (secim)
{
case 1:
int sinifsayisi1, sinifsayisi2;
cout << "1. Sinif Adi: " ;
cin >> sinifsayisi1;
cout << "2. Sinif Adi: " ;
cin >> sinifsayisi2;
y.sinifDegistir(sinifsayisi1, sinifsayisi2);
break ;
case 2:
char ogrenci1, ogrenci2;
cout << "1. Ogrenci: " ;
cin >> ogrenci1;
cout << "2. Ogrenci: " ;
cin >> ogrenci2;
y.OgrenciDegistir(ogrenci1, ogrenci2);
break ;
case 3:
break ;
default : cout << "Oyle bir islem bulunmamaktadir" << endl;
cout << "=> " ;
break ;
}
cout << *o1;
} while (secim != 3);
delete o1;
system("pause" );
return 0;
}
i really need help on this case thanks for all guys.
edit: how can i add screen shot here i dont know i wanna show you the errors ?
Last edited on Oct 30, 2018 at 11:01am UTC
Oct 29, 2018 at 3:02pm UTC
HERE IS ERRORS ON CMD SCREEN
Microsoft Windows [Version 10.0.17134.345]
(c) 2018 Microsoft Corporation. Tüm hakları saklıdır.
C:\Users\1halit>cd C:\Users\1halit\Desktop\odev
C:\Users\1halit\Desktop\odev>mingw32-make
g++ -I ./include/ -o ./lib/Ogrenci.o -c ./src/Ogrenci.cpp
In file included from ./include/Okul.hpp:6:0,
from ./include/Sinif.hpp:5,
from ./include/Ogrenci.hpp:4,
from ./src/Ogrenci.cpp:1:
./include/Yonetim.hpp:19:14: error: expected ')' before '*' token
Yonetim(Okul*);
^
./include/Yonetim.hpp:24:2: error: 'Ogrenci' does not name a type
Ogrenci **ogrenci;
^~~~~~~
./include/Yonetim.hpp:25:2: error: 'Sinif' does not name a type
Sinif **sinif;
^~~~~
./include/Yonetim.hpp:26:2: error: 'Okul' does not name a type
Okul* okul;
^~~~
In file included from ./include/Sinif.hpp:5:0,
from ./include/Ogrenci.hpp:4,
from ./src/Ogrenci.cpp:1:
./include/Okul.hpp:17:2: error: 'Sinif' does not name a type
Sinif **SinifDizisi;
^~~~~
./include/Okul.hpp:28:2: error: 'Sinif' does not name a type
Sinif *sinifGetir(int sinifsirasi);
^~~~~
./include/Okul.hpp:29:17: error: 'Sinif' has not been declared
void sinifEkle(Sinif*);
^~~~~
In file included from ./include/Ogrenci.hpp:4:0,
from ./src/Ogrenci.cpp:1:
./include/Sinif.hpp:17:1: error: 'Ogrenci' does not name a type
Ogrenci **ogrenci;
^~~~~~~
makefile:3: recipe for target 'derle' failed
mingw32-make: *** [derle] Error 1
C:\Users\1halit\Desktop\odev>
Oct 29, 2018 at 3:20pm UTC
Basically, you've made a big mess with your #include
s
Look at "Ogrenci.hpp", for example. What's the first thing it tries to include?
#include "Ogrenci.hpp"
Itself. WTF?
Go through your #includes and remove all the ones that aren't needed, and then see what errors you get. Right now, this is such a mess of circular includes that it's impossible to tell what order you're actually including files in. The error "does not name a type" indicates that the compiler has not seen that type by the time it gets there. Which means your include files are all messed up because they all inculde each other for no reason.
Oct 29, 2018 at 3:26pm UTC
Also, don't get into the habit of using using namespace
in header files.
Oct 29, 2018 at 3:40pm UTC
okey i prepare my includes and thank you all errors gone now just giving this error only there is left:
Microsoft Windows [Version 10.0.17134.345]
(c) 2018 Microsoft Corporation. Tüm hakları saklıdır.
C:\Users\1halit>cd C:\Users\1halit\Desktop\odev
C:\Users\1halit\Desktop\odev>mingw32-make
makefile:5: *** missing separator. Stop.
C:\Users\1halit\Desktop\odev>mingw32-make
makefile:8: *** missing separator. Stop.
C:\Users\1halit\Desktop\odev>
and my makefile is here :
VPATH= ./src
CXXFLAGS= -I "./include"
all: derle
derle:Test.o Ogrenci.o Sinif.o Okul.o Yonetim.o
g++ Test.o Ogrenci.o Sinif.o Okul.o Yonetim.o -o derle
Test.o:Test.cpp
g++ -c $(CXXFLAGS) $<
Ogrenci.o:Ogrenci.cpp
g++ -c $(CXXFLAGS) $<
Sinif.o:Sinif.cpp
g++ -c $(CXXFLAGS) $<
Okul.o:Okul.cpp
g++ -c $(CXXFLAGS) $<
Yonetim.o:Yonetim.cpp
g++ -c $(CXXFLAGS) $<
Whats wrong now? i need finish it quickly :((
Oct 29, 2018 at 3:41pm UTC
Missing separator in a makefile usually means that you used spaces at the start of the line instead of <TAB>
Oct 29, 2018 at 3:59pm UTC
okey i wrote againg and now there is not error but still not working here is cmd screen:
Microsoft Windows [Version 10.0.17134.345]
(c) 2018 Microsoft Corporation. Tüm hakları saklıdır.
C:\Users\1halit>cd C:\Users\1halit\Desktop\odev
C:\Users\1halit\Desktop\odev>mingw32-make
g++ Test.o Ogrenci.o Sinif.o Okul.o Yonetim.o -o derle
C:\Users\1halit\Desktop\odev>derle.exe
C:\Users\1halit\Desktop\odev>
i dont know still what is wrong here THANK TO YOU GUYS all errors gone but still not working good cause the code which i made not working now
i am still need help you are awesome guys.
Oct 29, 2018 at 4:05pm UTC
What does your program do that you don't like, or what does it not do that you wish it did?
Add output lines of text to your Test.cpp file so you can see how far through main the program gets.
Last edited on Oct 29, 2018 at 4:07pm UTC
Oct 29, 2018 at 9:46pm UTC
program doesnt give output idk why?
here is cmd screen:
Microsoft Windows [Version 10.0.17134.345]
(c) 2018 Microsoft Corporation. Tüm hakları saklıdır.
C:\Users\1halit>cd C:\Users\1halit\Desktop\odev
C:\Users\1halit\Desktop\odev>mingw32-make
g++ Test.o Ogrenci.o Sinif.o Okul.o Yonetim.o -o derle
C:\Users\1halit\Desktop\odev>derle.exe
C:\Users\1halit\Desktop\odev>
there is no error cause program created the derle.exe but ehrn i click on it there is no output why?
Oct 29, 2018 at 10:35pm UTC
Add print (cout) statements before you open your file or do any other significant thing.
After you open your file, make sure it's opening correctly.
1 2 3 4 5 6 7 8 9
ifstream dosyaOku("okul.txt" , ios::in);
if (!dosyaOku)
{
cout << "ERROR: File could not be opened." << endl;
}
else
{
cout << "File opened successfully" << endl;
}
Last edited on Oct 29, 2018 at 10:36pm UTC
Oct 30, 2018 at 1:57am UTC
> Add output lines of text to your Test.cpp file so you can see how far through main the program gets.
>> Add print (cout) statements before you open your file or do any other significant thing.
use a freaking debugger and do a step-by-step run
Oct 30, 2018 at 2:40am UTC
They never listen when I say that! And it's hard to communicate because the exact setup for a debugger is different for each IDE. But I totally agree... perhaps I should make something I can copy paste.
Last edited on Oct 30, 2018 at 2:41am UTC
Oct 30, 2018 at 9:17am UTC
keskiverto if there is any error code should be not working on visual studio right ? I try to run it on visual studio and works.So its could be about mingw GNU compilar or something else idk why but i will try to set cout for see how much code goes on lines.I will add my result here.