├── Week1 ├── README.md ├── Source2 │ ├── README.md │ └── src │ │ └── Program.java └── Source1 │ ├── README.md │ └── src │ └── Program.c ├── Week10 ├── MultipleInheritance │ ├── Java │ │ ├── src │ │ │ ├── README.md │ │ │ └── pck │ │ │ │ ├── IFood.java │ │ │ │ ├── ISalad.java │ │ │ │ ├── Oven.java │ │ │ │ ├── Shredder.java │ │ │ │ ├── Test.java │ │ │ │ └── Greens.java │ │ └── README.md │ └── CPP │ │ ├── README.md │ │ └── Program.cpp ├── SoyutBenzetme │ ├── bin │ │ └── README.md │ ├── lib │ │ └── README.md │ ├── makefile │ ├── include │ │ ├── Kare.h │ │ ├── Daire.h │ │ └── Sekil.h │ └── src │ │ ├── Test.c │ │ ├── Kare.c │ │ ├── Daire.c │ │ └── Sekil.c ├── GetTime │ ├── README.md │ └── Program.c └── SoyutSınıfJava │ └── src │ └── pkt │ ├── Test.java │ ├── Kare.java │ ├── Daire.java │ └── Sekil.java ├── Week2 ├── README.md ├── Source3 │ └── src │ │ └── Program.c ├── Source2 │ └── src │ │ └── Program.c ├── Source1 │ └── src │ │ └── Program.java └── Source4 │ └── src │ └── Program.java ├── Week9 ├── Project │ ├── README.md │ └── src │ │ └── project │ │ ├── Test.java │ │ └── Number.java └── ProjectInC │ ├── bin │ └── README.md │ ├── lib │ └── README.md │ ├── README.md │ ├── makefile │ ├── include │ └── Number.h │ └── src │ ├── Test.c │ └── Number.c ├── Week11 ├── ExceptionHandlingC │ ├── bin │ │ └── readme │ ├── lib │ │ └── readme │ ├── README.md │ ├── src │ │ ├── Test.c │ │ ├── Exception.c │ │ ├── HataliMiktar.c │ │ ├── YetersizBakiye.c │ │ └── Hesap.c │ ├── include │ │ ├── HataliMiktar.h │ │ ├── YetersizBakiye.h │ │ ├── Hesap.h │ │ └── Exception.h │ └── makefile └── ExceptionHandlingJava │ ├── README.md │ └── src │ └── pkt │ ├── HataliMiktar.java │ ├── YetersizBakiye.java │ ├── Hesap.java │ └── Test.java ├── Week3 ├── Sample3 │ ├── README.md │ └── src │ │ └── pkt │ │ ├── Sayi.java │ │ └── Program.java ├── Sample5 │ └── Program.c ├── Sample4 │ └── Program.c ├── Sample1 │ └── Program.c └── Sample2 │ └── Program.c └── README.md /Week1/README.md: -------------------------------------------------------------------------------- 1 |

Week 1

2 | Bacis Topics 3 | -------------------------------------------------------------------------------- /Week1/Source2/README.md: -------------------------------------------------------------------------------- 1 | # Command line parameters 2 | -------------------------------------------------------------------------------- /Week10/MultipleInheritance/Java/src/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Week2/README.md: -------------------------------------------------------------------------------- 1 |

Week 2

2 | Data Types 3 | -------------------------------------------------------------------------------- /Week9/Project/README.md: -------------------------------------------------------------------------------- 1 |

Java Code Example

2 | -------------------------------------------------------------------------------- /Week10/SoyutBenzetme/bin/README.md: -------------------------------------------------------------------------------- 1 | This folder is empty. 2 | -------------------------------------------------------------------------------- /Week10/SoyutBenzetme/lib/README.md: -------------------------------------------------------------------------------- 1 | This folder is empty. 2 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/bin/readme: -------------------------------------------------------------------------------- 1 | this folder left empty 2 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/lib/readme: -------------------------------------------------------------------------------- 1 | This folder left empty 2 | -------------------------------------------------------------------------------- /Week9/ProjectInC/bin/README.md: -------------------------------------------------------------------------------- 1 | This folder is left Empty. 2 | -------------------------------------------------------------------------------- /Week9/ProjectInC/lib/README.md: -------------------------------------------------------------------------------- 1 | This folder is left Empty. 2 | -------------------------------------------------------------------------------- /Week10/GetTime/README.md: -------------------------------------------------------------------------------- 1 |

How to get datetime in C language

2 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/README.md: -------------------------------------------------------------------------------- 1 |

Exception Handling in C

2 | -------------------------------------------------------------------------------- /Week9/ProjectInC/README.md: -------------------------------------------------------------------------------- 1 |

Object Oriented Simulation in C

2 | -------------------------------------------------------------------------------- /Week10/MultipleInheritance/CPP/README.md: -------------------------------------------------------------------------------- 1 | Multiple class inheritance in C++ 2 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingJava/README.md: -------------------------------------------------------------------------------- 1 |

Exception Handling in Java

2 | -------------------------------------------------------------------------------- /Week10/MultipleInheritance/Java/README.md: -------------------------------------------------------------------------------- 1 | Provide multiple inheritance by interfaces 2 | -------------------------------------------------------------------------------- /Week3/Sample3/README.md: -------------------------------------------------------------------------------- 1 |

Statik Bellek Bölgesinde Sınıf Elemanı Oluşturma

2 | -------------------------------------------------------------------------------- /Week1/Source1/README.md: -------------------------------------------------------------------------------- 1 | # Program that separates an entered 4-digit number into its digits. 2 | -------------------------------------------------------------------------------- /Week10/MultipleInheritance/Java/src/pck/IFood.java: -------------------------------------------------------------------------------- 1 | package pck; 2 | 3 | public interface IFood { 4 | String getFood(); 5 | } 6 | -------------------------------------------------------------------------------- /Week10/MultipleInheritance/Java/src/pck/ISalad.java: -------------------------------------------------------------------------------- 1 | package pck; 2 | 3 | public interface ISalad { 4 | String getSalad(); 5 | } 6 | -------------------------------------------------------------------------------- /Week3/Sample3/src/pkt/Sayi.java: -------------------------------------------------------------------------------- 1 | package pkt; 2 | public class Sayi { 3 | public static int deger; 4 | public Sayi(int dgr){ 5 | deger=dgr; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Week2/Source3/src/Program.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | int main(){ 3 | float x=0.1; 4 | double y=0.1; 5 | if(x == y) printf("x ve y esit"); 6 | else printf("Esit degil"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Week2/Source2/src/Program.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | typedef enum {false, true} bool; 3 | int main(){ 4 | bool x=true; 5 | if(x == true) printf("Sakarya"); 6 | else printf("Ankara"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Week2/Source1/src/Program.java: -------------------------------------------------------------------------------- 1 | public class IlkProje { 2 | public static void main(String[] args) { 3 | char a='\u0391'; 4 | System.out.println(a); // Ekrana A harfini yazar. 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Week9/ProjectInC/makefile: -------------------------------------------------------------------------------- 1 | all: compile run 2 | 3 | compile: 4 | gcc -I ./include/ -o ./lib/Number.o -c ./src/Number.c 5 | gcc -I ./include/ -o ./bin/Test ./lib/Number.o ./src/Test.c 6 | 7 | run: 8 | ./bin/Test 9 | -------------------------------------------------------------------------------- /Week10/MultipleInheritance/Java/src/pck/Oven.java: -------------------------------------------------------------------------------- 1 | package pck; 2 | 3 | public class Oven { 4 | public void cook(IFood food){ 5 | System.out.println(food.getFood()+" hours remain to ready to eat."); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Week10/MultipleInheritance/Java/src/pck/Shredder.java: -------------------------------------------------------------------------------- 1 | package pck; 2 | 3 | public class Shredder { 4 | public void shred(ISalad salad) { 5 | System.out.println(salad.getSalad()+" will be shredded"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Week1/Source2/src/Program.java: -------------------------------------------------------------------------------- 1 | package pck; 2 | 3 | public class Program { 4 | public static void main(String[] args) { 5 | System.out.println(args[0]); 6 | System.out.println(args[1]); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Week3/Sample5/Program.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "stdlib.h" 3 | int main(){ 4 | int x=100; 5 | float a=12.5; 6 | void* obj; 7 | obj=&x; 8 | printf("%d\n",*(int*)(obj)); 9 | obj=&a; 10 | printf("%.2f\n",*(float *)(obj)); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingJava/src/pkt/HataliMiktar.java: -------------------------------------------------------------------------------- 1 | package pkt; 2 | 3 | public class HataliMiktar extends ArithmeticException { 4 | public HataliMiktar(String mesaj) { 5 | super(mesaj); 6 | } 7 | public HataliMiktar() { 8 | super("Hatalı Miktar"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingJava/src/pkt/YetersizBakiye.java: -------------------------------------------------------------------------------- 1 | package pkt; 2 | 3 | public class YetersizBakiye extends IllegalArgumentException { 4 | public YetersizBakiye(String mesaj) { 5 | super(mesaj); 6 | } 7 | public YetersizBakiye() { 8 | super("Yetersiz Bakiye"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Week3/Sample4/Program.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "stdlib.h" 3 | int main(){ 4 | int *yas = malloc(sizeof(int)); // Heap bellek bölgesi 5 | *yas = 30; 6 | printf("%d\n",*yas); 7 | int *p; // adresi yok 8 | free(yas); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Concepts Of Programming Languages 2 | It contains the codes I wrote in the concepts of programming languages course

3 | 4 | Week 1: Basic Topics
5 | Week 2: Data Types
6 | Week 3: Data Types 2
7 | Week 4: Conditions
8 | Week 5: Loop Structures
9 | -------------------------------------------------------------------------------- /Week10/SoyutSınıfJava/src/pkt/Test.java: -------------------------------------------------------------------------------- 1 | package pkt; 2 | 3 | public class Test { 4 | 5 | public static void main(String[] args) { 6 | Daire d = new Daire(12,"Mavi"); 7 | System.out.println(d); 8 | 9 | System.out.println(); 10 | 11 | Kare k = new Kare(5,"Siyah"); 12 | System.out.println(k); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Week2/Source4/src/Program.java: -------------------------------------------------------------------------------- 1 | public class Program 2 | { 3 | public static void main(String[] args) { 4 | ArrayList> liste = new ArrayList<>(); 5 | ArrayList eleman = new ArrayList<>(); 6 | eleman.add(85.78); 7 | liste.add(eleman); 8 | var tmp = liste.get(0); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Week10/SoyutBenzetme/makefile: -------------------------------------------------------------------------------- 1 | hepsi: derle calistir 2 | 3 | derle: 4 | gcc -I ./include/ -o ./lib/Sekil.o -c ./src/Sekil.c 5 | gcc -I ./include/ -o ./lib/Daire.o -c ./src/Daire.c 6 | gcc -I ./include/ -o ./lib/Kare.o -c ./src/Kare.c 7 | gcc -I ./include/ -o ./bin/Test ./lib/Sekil.o ./lib/Daire.o ./lib/Kare.o ./src/Test.c 8 | 9 | calistir: 10 | ./bin/Test 11 | -------------------------------------------------------------------------------- /Week10/MultipleInheritance/Java/src/pck/Test.java: -------------------------------------------------------------------------------- 1 | package pck; 2 | 3 | public class Test { 4 | 5 | public static void main(String[] args) { 6 | Greens chard = new Greens("Chard",2); 7 | 8 | Oven oven = new Oven(); 9 | oven.cook(chard); 10 | 11 | Shredder shredder = new Shredder(); 12 | shredder.shred(chard); 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Week10/SoyutBenzetme/include/Kare.h: -------------------------------------------------------------------------------- 1 | #ifndef KARE_H 2 | #define KARE_H 3 | 4 | #include "Sekil.h" 5 | 6 | struct KARE{ 7 | Sekil super; 8 | double kenar; 9 | 10 | void (*yoket)(struct KARE*); 11 | }; 12 | typedef struct KARE* Kare; 13 | 14 | Kare KareOlustur(double,char*); 15 | double alan(const Kare); 16 | double cevre(const Kare); 17 | void KareYoket(const Kare); 18 | #endif 19 | -------------------------------------------------------------------------------- /Week3/Sample3/src/pkt/Program.java: -------------------------------------------------------------------------------- 1 | package pkt; 2 | 3 | public class Program { 4 | public static void main(String[] args) { 5 | Sayi p = new Sayi(100); 6 | Sayi r = new Sayi(50); 7 | Sayi tmp = p; 8 | p=r; 9 | r=tmp; 10 | System.out.println("p:"+p.deger); 11 | System.out.println("r:"+r.deger); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Week10/SoyutBenzetme/include/Daire.h: -------------------------------------------------------------------------------- 1 | #ifndef DAIRE_H 2 | #define DAIRE_H 3 | 4 | #include "Sekil.h" 5 | 6 | struct DAIRE{ 7 | Sekil super; 8 | double yaricap; 9 | 10 | void (*yoket)(struct DAIRE*); 11 | }; 12 | typedef struct DAIRE* Daire; 13 | 14 | Daire DaireOlustur(double,char*); 15 | double Alan(const Daire); 16 | double Cevre(const Daire); 17 | void DaireYoket(const Daire); 18 | #endif 19 | -------------------------------------------------------------------------------- /Week10/SoyutSınıfJava/src/pkt/Kare.java: -------------------------------------------------------------------------------- 1 | package pkt; 2 | 3 | public class Kare extends Sekil { 4 | public double kenar; 5 | public Kare(double kenar,String renk) { 6 | super(renk); 7 | this.kenar = kenar; 8 | } 9 | 10 | @Override 11 | public double alan() { 12 | return Math.pow(kenar, 2); 13 | } 14 | @Override 15 | public double cevre() { 16 | return 4*kenar; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/src/Test.c: -------------------------------------------------------------------------------- 1 | #include "Hesap.h" 2 | 3 | int main(){ 4 | Hesap hesap = HesapOlustur(); 5 | 6 | try{ 7 | hesap->paraCek(hesap,1000); 8 | printf("\nBakiye: %lf",hesap->getBakiye(hesap)); 9 | } 10 | catch{ 11 | printf("\n%s",hesap->yetersizbakiye->getMessage(hesap->yetersizbakiye->super)); 12 | } 13 | tryEnd; 14 | 15 | hesap->yoket(hesap); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Week10/GetTime/Program.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "stdlib.h" 3 | #include "time.h" 4 | 5 | char* ZamanGetir(){ 6 | char* buff = malloc(sizeof(char)*100); 7 | time_t simdi = time(0); 8 | strftime(buff,100,"%Y-%m-%d %H:%M",localtime(&simdi)); 9 | return buff; 10 | } 11 | 12 | int main(){ 13 | char* zaman = ZamanGetir(); 14 | printf("Zaman: %s\n",zaman); 15 | free(zaman); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Week3/Sample1/Program.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | 3 | const char* SehirDondur(){ 4 | const char *str = "Sakarya"; 5 | return str; 6 | } 7 | char* SehirDondur2(){ 8 | char str[] = "Ankara"; 9 | return str; 10 | } 11 | 12 | int main(){ 13 | printf("%s\n",SehirDondur()); // Ekrana Sakarya yazar 14 | printf("%s\n",SehirDondur2()); // Ekrana bir şey yazmaz ve derlenmede uyarı verir. 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Week3/Sample2/Program.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | int main(){ 3 | int x=100,y=50; 4 | int *p = &x; 5 | int *r = &y; 6 | int *tmp = p; 7 | p=r; 8 | r=tmp; 9 | printf("p:%d\n",*p); 10 | printf("r:%d\n",*r); 11 | 12 | printf("p:%X\n",p); // p’nin içinde barındırdığı adres 13 | printf("r:%X\n",r); // r’nin içinde barındırdığı adres 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Week10/SoyutSınıfJava/src/pkt/Daire.java: -------------------------------------------------------------------------------- 1 | package pkt; 2 | 3 | public class Daire extends Sekil { 4 | private double yaricap; 5 | 6 | public Daire(double yaricap,String renk) { 7 | super(renk); 8 | this.yaricap = yaricap; 9 | } 10 | 11 | @Override 12 | public double alan() { 13 | return Math.PI*Math.pow(yaricap, 2); 14 | } 15 | @Override 16 | public double cevre() { 17 | return 2*Math.PI*yaricap; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Week10/SoyutBenzetme/src/Test.c: -------------------------------------------------------------------------------- 1 | #include "Daire.h" 2 | #include "Kare.h" 3 | 4 | int main(){ 5 | Daire d = DaireOlustur(12,"Mavi"); 6 | char* str = d->super->toString(d->super,d); 7 | printf("%s\n",str); 8 | free(str); 9 | 10 | printf("\n"); 11 | 12 | Kare k = KareOlustur(5,"Siyah"); 13 | str = k->super->toString(k->super,k); 14 | printf("%s\n",str); 15 | free(str); 16 | 17 | d->yoket(d); 18 | k->yoket(k); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/include/HataliMiktar.h: -------------------------------------------------------------------------------- 1 | #ifndef HATALIMIKTAR_H 2 | #define HATALIMIKTAR_H 3 | 4 | #include "Exception.h" 5 | 6 | struct HATALIMIKTAR{ 7 | Exception super; 8 | 9 | void (*yoket)(struct HATALIMIKTAR*); 10 | char* (*getMessage)(struct EXCEPTION*); 11 | }; 12 | typedef struct HATALIMIKTAR* HataliMiktar; 13 | 14 | HataliMiktar HataliMiktarOlustur(char*); 15 | void HataliMiktarYoket(const HataliMiktar); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/include/YetersizBakiye.h: -------------------------------------------------------------------------------- 1 | #ifndef YETERSIZBAKIYE_H 2 | #define YETERSIZBAKIYE_H 3 | 4 | #include "Exception.h" 5 | 6 | struct YETERSIZBAKIYE{ 7 | Exception super; 8 | 9 | char* (*getMessage)(struct EXCEPTION*); 10 | void (*yoket)(struct YETERSIZBAKIYE*); 11 | }; 12 | typedef struct YETERSIZBAKIYE* YetersizBakiye; 13 | 14 | YetersizBakiye YetersizBakiyeOlustur(char*); 15 | void YetersizBakiyeYoket(const YetersizBakiye); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingJava/src/pkt/Hesap.java: -------------------------------------------------------------------------------- 1 | package pkt; 2 | 3 | public class Hesap { 4 | private double bakiye; 5 | 6 | public Hesap() { 7 | bakiye = 0; 8 | } 9 | void paraCek(double miktar){ 10 | if(miktar > this.bakiye) throw new YetersizBakiye(); 11 | this.bakiye -= miktar; 12 | } 13 | void paraYatir(double miktar){ 14 | if(miktar <= 0) throw new HataliMiktar(); 15 | this.bakiye += miktar; 16 | } 17 | double getBakiye(){ 18 | return this.bakiye; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/makefile: -------------------------------------------------------------------------------- 1 | hepsi: derle calistir 2 | 3 | derle: 4 | gcc -I ./include/ -o ./lib/Exception.o -c ./src/Exception.c 5 | gcc -I ./include/ -o ./lib/YetersizBakiye.o -c ./src/YetersizBakiye.c 6 | gcc -I ./include/ -o ./lib/HataliMiktar.o -c ./src/HataliMiktar.c 7 | gcc -I ./include/ -o ./lib/Hesap.o -c ./src/Hesap.c 8 | gcc -I ./include/ -o ./bin/Test ./lib/Exception.o ./lib/YetersizBakiye.o ./lib/HataliMiktar.o ./lib/Hesap.o ./src/Test.c 9 | 10 | calistir: 11 | ./bin/Test 12 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/src/Exception.c: -------------------------------------------------------------------------------- 1 | #include "Exception.h" 2 | 3 | Exception ExceptionOlustur(char* mesaj){ 4 | Exception this; 5 | this = (Exception)malloc(sizeof(struct EXCEPTION)); 6 | this->mesaj = mesaj; 7 | 8 | this->getMessage = &getMessage; 9 | this->yoket = &ExceptionYoket; 10 | return this; 11 | } 12 | char* getMessage(const Exception this){ 13 | return this->mesaj; 14 | } 15 | void ExceptionYoket(const Exception this){ 16 | if(this == NULL) return; 17 | free(this); 18 | } 19 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/src/HataliMiktar.c: -------------------------------------------------------------------------------- 1 | #include "HataliMiktar.h" 2 | 3 | HataliMiktar HataliMiktarOlustur(char* mesaj){ 4 | HataliMiktar this; 5 | this = (HataliMiktar)malloc(sizeof(struct HATALIMIKTAR)); 6 | this->super = ExceptionOlustur(mesaj); 7 | this->getMessage = this->super->getMessage; 8 | this->yoket = &HataliMiktarYoket; 9 | return this; 10 | } 11 | void HataliMiktarYoket(const HataliMiktar this){ 12 | if(this == NULL) return; 13 | this->super->yoket(this->super); 14 | free(this); 15 | } 16 | -------------------------------------------------------------------------------- /Week10/MultipleInheritance/Java/src/pck/Greens.java: -------------------------------------------------------------------------------- 1 | package pck; 2 | 3 | public class Greens implements IFood,ISalad { 4 | private String name; 5 | private double cookingTime; 6 | 7 | public Greens(String name, double cookingTime) { 8 | this.name = name; 9 | this.cookingTime = cookingTime; 10 | } 11 | 12 | @Override 13 | public String getFood() { 14 | return name + " " + cookingTime; 15 | } 16 | 17 | @Override 18 | public String getSalad() { 19 | return name; 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/src/YetersizBakiye.c: -------------------------------------------------------------------------------- 1 | #include "YetersizBakiye.h" 2 | 3 | YetersizBakiye YetersizBakiyeOlustur(char* mesaj){ 4 | YetersizBakiye this; 5 | this = (YetersizBakiye)malloc(sizeof(struct YETERSIZBAKIYE)); 6 | this->super = ExceptionOlustur(mesaj); 7 | this->getMessage = this->super->getMessage; 8 | this->yoket = &YetersizBakiyeYoket; 9 | return this; 10 | } 11 | void YetersizBakiyeYoket(const YetersizBakiye this){ 12 | if(this == NULL) return; 13 | this->super->yoket(this->super); 14 | free(this); 15 | } 16 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingJava/src/pkt/Test.java: -------------------------------------------------------------------------------- 1 | package pkt; 2 | 3 | public class Test { 4 | 5 | public static void main(String[] args) { 6 | Hesap hesap = new Hesap(); 7 | 8 | try{ 9 | hesap.paraCek(1000); 10 | System.out.printf("\nBakiye: %lf",hesap.getBakiye()); 11 | } 12 | catch(YetersizBakiye ex){ 13 | System.out.printf("\n%s",ex.getMessage()); 14 | } 15 | 16 | try{ 17 | hesap.paraYatir(-50); 18 | System.out.printf("\nBakiye: %lf",hesap.getBakiye()); 19 | } 20 | catch(HataliMiktar ex){ 21 | System.out.printf("\n%s",ex.getMessage()); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Week10/SoyutBenzetme/src/Kare.c: -------------------------------------------------------------------------------- 1 | #include "Kare.h" 2 | 3 | Kare KareOlustur(double kenar,char* renk){ 4 | Kare this; 5 | this = (Kare)malloc(sizeof(struct KARE)); 6 | this->super = SekilOlustur(renk); 7 | this->kenar = kenar; 8 | this->super->alan = &alan; 9 | this->super->cevre = &cevre; 10 | this->yoket = &KareYoket; 11 | return this; 12 | } 13 | double alan(const Kare this){ 14 | return pow(this->kenar,2); 15 | } 16 | double cevre(const Kare this){ 17 | return 4*this->kenar; 18 | } 19 | void KareYoket(const Kare this){ 20 | if(this == NULL) return; 21 | this->super->yoket(this->super); 22 | free(this); 23 | } 24 | -------------------------------------------------------------------------------- /Week1/Source1/src/Program.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "locale.h" 3 | 4 | int main() 5 | { 6 | int sayi; 7 | setlocale(LC_ALL,"Turkish"); 8 | do{ 9 | printf("4 Basamaklı bir sayı girin:"); 10 | scanf("%d",&sayi); 11 | }while(sayi<1000 || sayi>10000); 12 | 13 | short birler,onlar,yuzler,binler; 14 | binler=sayi/1000; 15 | yuzler=(sayi%1000)/100; 16 | onlar=(sayi%100)/10; 17 | birler=sayi%10; 18 | printf("\nBinler:%d\n",binler); 19 | printf("\nYüzler:%d\n",yuzler); 20 | printf("\nOnlar:%d\n",onlar); 21 | printf("\nBirler:%d\n",birler); 22 | getchar(); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Week10/SoyutBenzetme/src/Daire.c: -------------------------------------------------------------------------------- 1 | #include "Daire.h" 2 | 3 | Daire DaireOlustur(double yaricap,char* renk){ 4 | Daire this; 5 | this = (Daire)malloc(sizeof(struct DAIRE)); 6 | this->super = SekilOlustur(renk); 7 | this->yaricap = yaricap; 8 | this->super->alan = &Alan; 9 | this->super->cevre = &Cevre; 10 | this->yoket = &DaireYoket; 11 | return this; 12 | } 13 | double Alan(const Daire this){ 14 | return M_PI*pow(this->yaricap,2); 15 | } 16 | double Cevre(const Daire this){ 17 | return 2*M_PI*this->yaricap; 18 | } 19 | void DaireYoket(const Daire this){ 20 | if(this == NULL) return; 21 | this->super->yoket(this->super); 22 | free(this); 23 | } 24 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/include/Hesap.h: -------------------------------------------------------------------------------- 1 | #ifndef HESAP_H 2 | #define HESAP_H 3 | 4 | #include "YetersizBakiye.h" 5 | #include "HataliMiktar.h" 6 | 7 | struct HESAP{ 8 | double bakiye; 9 | YetersizBakiye yetersizbakiye; 10 | HataliMiktar hataliMiktar; 11 | 12 | void (*paraCek)(struct HESAP*,double); 13 | void (*paraYatir)(struct HESAP*,double); 14 | double (*getBakiye)(struct HESAP*); 15 | void (*yoket)(struct HESAP*); 16 | }; 17 | typedef struct HESAP* Hesap; 18 | 19 | Hesap HesapOlustur(); 20 | void paraCek(const Hesap,double); 21 | void paraYatir(const Hesap,double); 22 | double getBakiye(const Hesap); 23 | void HesapYoket(const Hesap); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/include/Exception.h: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPTION_H 2 | #define EXCEPTION_H 3 | 4 | #include "stdio.h" 5 | #include "stdlib.h" 6 | #include "setjmp.h" 7 | 8 | jmp_buf jumper; 9 | 10 | #define try do{ if( !setjmp(jumper) ){ 11 | #define catch } else { 12 | #define tryEnd } }while(0) 13 | #define throw longjmp(jumper, 1) 14 | 15 | struct EXCEPTION{ 16 | char *mesaj; 17 | 18 | char* (*getMessage)(struct EXCEPTION*); 19 | void (*yoket)(struct EXCEPTION*); 20 | }; 21 | typedef struct EXCEPTION* Exception; 22 | 23 | Exception ExceptionOlustur(char*); 24 | char* getMessage(const Exception); 25 | void ExceptionYoket(const Exception); 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Week9/ProjectInC/include/Number.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMBER_H 2 | #define NUMBER_H 3 | 4 | #include "stdio.h" 5 | #include "stdlib.h" 6 | #include "math.h" 7 | 8 | typedef enum Bool{false, true}boolean; 9 | 10 | struct NUMBER{ 11 | int value; 12 | 13 | short* (*getDigits)(struct NUMBER*); 14 | boolean (*isPrime)(struct NUMBER*); 15 | boolean (*equals)(struct NUMBER*,struct NUMBER*); 16 | char* (*toString)(struct NUMBER*); 17 | void (*delete)(struct NUMBER*); 18 | }; 19 | typedef struct NUMBER* Number; 20 | 21 | Number new_Number(int); 22 | short* getDigits(const Number); 23 | boolean isPrime(const Number); 24 | boolean equals(const Number,const Number); 25 | char* toString(const Number); 26 | void delete_Number(const Number); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Week10/SoyutBenzetme/include/Sekil.h: -------------------------------------------------------------------------------- 1 | #ifndef SEKIL_H 2 | #define SEKIL_H 3 | 4 | #include "stdio.h" 5 | #include "stdlib.h" 6 | #include "time.h" 7 | #include "math.h" 8 | #include "string.h" 9 | 10 | struct SEKIL{ 11 | char* renk; 12 | char* olusturulmaTarihi; 13 | 14 | void (*setRenk)(struct SEKIL*,char*); 15 | char* (*getolusturulmaTarihi)(struct SEKIL*); 16 | char* (*toString)(struct SEKIL*,void*); 17 | double (*alan)(); 18 | double (*cevre)(); 19 | void (*yoket)(struct SEKIL*); 20 | }; 21 | typedef struct SEKIL* Sekil; 22 | 23 | Sekil SekilOlustur(char*); 24 | void setRenk(const Sekil,char*); 25 | char* getolusturulmaTarihi(const Sekil); 26 | char* toString(const Sekil,void*); 27 | void SekilYoket(const Sekil); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Week10/SoyutSınıfJava/src/pkt/Sekil.java: -------------------------------------------------------------------------------- 1 | package pkt; 2 | 3 | import java.util.Date; 4 | 5 | public abstract class Sekil { 6 | private String renk; 7 | private Date olusturulmaTarihi; 8 | 9 | public Sekil(String renk) { 10 | this.renk = renk; 11 | olusturulmaTarihi = new Date(); 12 | } 13 | public Date getOlusturulmaTarihi() { 14 | return olusturulmaTarihi; 15 | } 16 | public void setRenk(String renk) { 17 | this.renk = renk; 18 | } 19 | @Override 20 | public String toString() { 21 | String str = "Tarih: "+olusturulmaTarihi+ 22 | "\nRenk: "+renk+ 23 | "\nAlan: "+alan()+ 24 | "\nÇevre: "+cevre(); 25 | return str; 26 | } 27 | 28 | public abstract double alan(); 29 | public abstract double cevre(); 30 | } 31 | -------------------------------------------------------------------------------- /Week9/Project/src/project/Test.java: -------------------------------------------------------------------------------- 1 | package project; 2 | 3 | public class Test { 4 | 5 | public static void main(String[] args) { 6 | Number num1 = new Number(100); 7 | Number num2 = new Number(100); 8 | Number num3 = new Number(127); 9 | 10 | if(num1.equals(num2)) System.out.println("num1 is equal to num2"); 11 | else System.out.println("num1 and num2 are not equal"); 12 | 13 | if(num3.isPrime()) System.out.println("num3 is prime number"); 14 | else System.out.println("num3 is not prime number"); 15 | 16 | short[] num3Digits = num3.getDigits(); 17 | System.out.print("num3 digits: "); 18 | for(short digit : num3Digits) { 19 | System.out.print(digit+" "); 20 | } 21 | System.out.println(); 22 | System.out.println("num1 is "+num1); 23 | System.out.println("num2 is "+num2); 24 | System.out.println("num3 is "+num3); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Week11/ExceptionHandlingC/src/Hesap.c: -------------------------------------------------------------------------------- 1 | #include "Hesap.h" 2 | 3 | Hesap HesapOlustur(){ 4 | Hesap this; 5 | this = (Hesap)malloc(sizeof(struct HESAP)); 6 | this->bakiye = 0; 7 | this->yetersizbakiye = YetersizBakiyeOlustur("Yetersiz Bakiye"); 8 | this->hataliMiktar = HataliMiktarOlustur("Hatali Miktar"); 9 | this->paraCek = ¶Cek; 10 | this->paraYatir = ¶Yatir; 11 | this->getBakiye = &getBakiye; 12 | this->yoket= &HesapYoket; 13 | return this; 14 | } 15 | void paraCek(const Hesap this,double miktar){ 16 | if(miktar > this->bakiye) throw; 17 | this->bakiye -= miktar; 18 | } 19 | void paraYatir(const Hesap this,double miktar){ 20 | if(miktar <= 0) throw; 21 | this->bakiye += miktar; 22 | } 23 | double getBakiye(const Hesap this){ 24 | return this->bakiye; 25 | } 26 | void HesapYoket(const Hesap this){ 27 | if(this == NULL) return; 28 | this->yetersizbakiye->yoket(this->yetersizbakiye); 29 | this->hataliMiktar->yoket(this->hataliMiktar); 30 | free(this); 31 | } 32 | -------------------------------------------------------------------------------- /Week9/Project/src/project/Number.java: -------------------------------------------------------------------------------- 1 | package project; 2 | 3 | public class Number { 4 | private int value; 5 | public Number(int value) { 6 | this.value = value; 7 | } 8 | public short[] getDigits() { 9 | return splitDigits(value); 10 | } 11 | private short[] splitDigits(int val) { 12 | int digitslength = (int)Math.floor(Math.log10(Math.abs(val))) + 1; 13 | short[] digits = new short[digitslength]; 14 | for(int index=digits.length-1;index>=0;index--) { 15 | digits[index] = (short)(val % 10); 16 | val /= 10; 17 | } 18 | return digits; 19 | } 20 | public boolean isPrime() { 21 | for(int val=value-1;val>1;val--) { 22 | if(this.value%val == 0) return false; 23 | } 24 | return true; 25 | } 26 | @Override 27 | public boolean equals(Object obj) { 28 | if(obj == null || !(obj instanceof Number)) return false; 29 | Number rgt = (Number)obj; 30 | return this.value == rgt.value; 31 | } 32 | @Override 33 | public String toString() { 34 | return String.valueOf(value); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Week9/ProjectInC/src/Test.c: -------------------------------------------------------------------------------- 1 | #include "Number.h" 2 | 3 | int main(){ 4 | Number num1 = new_Number(100); 5 | Number num2 = new_Number(100); 6 | Number num3 = new_Number(127); 7 | 8 | if(num1->equals(num1,num2)) printf("num1 is equal to num2\n"); 9 | else printf("num1 and num2 are not equal\n"); 10 | 11 | if(num3->isPrime(num3)) printf("num3 is prime number\n"); 12 | else printf("num3 is not prime number\n"); 13 | 14 | short* num3Digits = num3->getDigits(num3); 15 | printf("num3 digits: "); 16 | int index; 17 | for(index =0;index<3;index++){ 18 | printf("%d ",num3Digits[index]); 19 | } 20 | free(num3Digits); 21 | printf("\n"); 22 | 23 | char* num1Str = num1->toString(num1); 24 | printf("num1 is %s\n",num1Str); 25 | 26 | char* num2Str = num2->toString(num2); 27 | printf("num2 is %s\n",num2Str); 28 | 29 | char* num3Str = num3->toString(num3); 30 | printf("num3 is %s\n",num3Str); 31 | 32 | free(num1Str); 33 | free(num2Str); 34 | free(num3Str); 35 | 36 | num1->delete(num1); 37 | num2->delete(num2); 38 | num3->delete(num3); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Week9/ProjectInC/src/Number.c: -------------------------------------------------------------------------------- 1 | #include "Number.h" 2 | 3 | Number new_Number(int value){ 4 | Number this; 5 | this = (Number)malloc(sizeof(struct NUMBER)); 6 | this->value = value; 7 | this->getDigits = &getDigits; 8 | this->isPrime = &isPrime; 9 | this->equals = = 10 | this->toString = &toString; 11 | this->delete = &delete_Number; 12 | 13 | return this; 14 | } 15 | short* splitDigits(int val){ 16 | int digitslength = floor(log10(abs(val)))+1; 17 | short* digits = (short*)malloc(sizeof(short)*digitslength); 18 | int index; 19 | for(index=digitslength-1;index>=0;index--){ 20 | digits[index]=val%10; 21 | val/=10; 22 | } 23 | return digits; 24 | } 25 | short* getDigits(const Number this){ 26 | return splitDigits(this->value); 27 | } 28 | boolean isPrime(const Number this){ 29 | int val; 30 | for(val=this->value-1;val>1;val--){ 31 | if(this->value%val == 0) return false; 32 | } 33 | return true; 34 | } 35 | boolean equals(const Number this,const Number rgt){ 36 | if(this == NULL || rgt == NULL) return false; 37 | return this->value == rgt->value; 38 | } 39 | char* toString(const Number this){ 40 | int digitslength = floor(log10(abs(this->value)))+1; 41 | char* str = (char*)malloc(sizeof(char)*digitslength+1); 42 | snprintf(str,digitslength+1,"%d",this->value); 43 | return str; 44 | } 45 | void delete_Number(const Number this){ 46 | if(this == NULL) return; 47 | free(this); 48 | } 49 | -------------------------------------------------------------------------------- /Week10/SoyutBenzetme/src/Sekil.c: -------------------------------------------------------------------------------- 1 | #include "Sekil.h" 2 | 3 | char* ZamanGetir(){ 4 | char* str = malloc(sizeof(char)*100); 5 | time_t suan = time(0); 6 | strftime(str,100,"%d %m %H:%M %Y",localtime(&suan)); 7 | return str; 8 | } 9 | int Uzunluk(double deger){ 10 | char str[50]; 11 | sprintf(str,"%lf",deger); 12 | int uzunluk = strlen(str); 13 | return uzunluk; 14 | } 15 | Sekil SekilOlustur(char* renk){ 16 | Sekil this; 17 | this = (Sekil)malloc(sizeof(struct SEKIL)); 18 | this->olusturulmaTarihi = ZamanGetir(); 19 | this->renk = renk; 20 | this->setRenk = &setRenk; 21 | this->getolusturulmaTarihi = &getolusturulmaTarihi; 22 | this->toString = &toString; 23 | this->yoket = &SekilYoket; 24 | return this; 25 | } 26 | void setRenk(const Sekil this,char* renk){ 27 | this->renk = renk; 28 | } 29 | char* getolusturulmaTarihi(const Sekil this){ 30 | return this->olusturulmaTarihi; 31 | } 32 | char* toString(const Sekil this,void* p){ 33 | int toplamUzunluk = 36; 34 | toplamUzunluk += strlen(this->olusturulmaTarihi); 35 | toplamUzunluk += strlen(this->renk); 36 | toplamUzunluk += Uzunluk(this->alan(p)); 37 | toplamUzunluk += Uzunluk(this->cevre(p)); 38 | char* str = (char*)malloc(sizeof(char)*toplamUzunluk+1); 39 | sprintf(str,"\n\nTarih: %s\nRenk: %s\nAlan: %lf\nCevre: %lf", 40 | this->olusturulmaTarihi, 41 | this->renk, 42 | this->alan(p), 43 | this->cevre(p)); 44 | return str; 45 | } 46 | void SekilYoket(const Sekil this){ 47 | if(this == NULL) return; 48 | free(this->olusturulmaTarihi); 49 | free(this); 50 | } 51 | -------------------------------------------------------------------------------- /Week10/MultipleInheritance/CPP/Program.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Food{ 5 | private: 6 | string name; 7 | double cookingTime; 8 | 9 | string DoubleToString(double val) 10 | { 11 | stringstream ss; 12 | ss << val; 13 | return ss.str(); 14 | } 15 | 16 | public: 17 | Food(string name, double cookingTime){ 18 | this->name = name; 19 | this->cookingTime = cookingTime; 20 | } 21 | Food(){ 22 | this->name = ""; 23 | this->cookingTime = 0; 24 | } 25 | string getFood(){ 26 | return name + " " + DoubleToString(cookingTime); 27 | } 28 | }; 29 | class Salad{ 30 | private: 31 | string name; 32 | 33 | public: 34 | Salad(string name){ 35 | this->name = name; 36 | } 37 | Salad(){ 38 | this->name = ""; 39 | } 40 | string getSalad(){ 41 | return name; 42 | } 43 | }; 44 | class Oven{ 45 | public: 46 | void cook(Food& food){ 47 | cout<cook(*chard); 66 | 67 | Shredder *shredder = new Shredder(); 68 | shredder->shred(*chard); 69 | 70 | delete chard; 71 | delete oven; 72 | delete shredder; 73 | return 0; 74 | } 75 | --------------------------------------------------------------------------------