Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C++ Programming

help-I'm new in c++


hi im in a trouble with c++ i made a project with c but icant convert c
++ here is the code with c

#include<stdio.h>
#include<stdlib.h>
#include <conio.h>

static int  i=0;
static int boyut=4;
static int*tur;

union myArray{

        double doubleDizi;
    int integer;
    char charDizi[20];
    };
typedef union myArray MyArray;
MyArray* eleman;

int menu(void);
int veriTipi(void);
void integerEkle(void);
void doubleEkle(void);
void charEkle(void);
void eklemeFonksiyonlari(int);
void menuIslemleri(int);
void buyut(MyArray*,int *);
void indeksOkuma(int);
void kapasite(void);
void elemanSayisi(void);
void doluluk(void);
void elemanlar(void);
void cikis(void);

int veriTipi(void)
{
    int cevap;
        system("cls");
    printf("1\tinteger ekle\n2\tdouble ekle\n3\tstring ekle(maximum 20
uzunlugunda)\n4\tcancel\n");
    scanf("%d",&cevap);
    return cevap;
    }
int menu(void){
    int cevap;
    printf("1\tyeni eleman ekle\n2\tgirilen indeksteki elemani gor
\n3\tkac eleman oldugunu gor\n4\tdizinin kapasitesi gor\n"
         "5\tdizinin doluluk oranini gor\n6\tdizinin elemanlarini gor
\n7\tcikis\n");
         scanf("%d",&cevap);

         return cevap;
    }
 void eklemeFonksiyonlari(int number){
         system("cls");

     switch(number){
         case 1:
         integerEkle();
         break;

         case 2:
         doubleEkle();
         break;

         case 3:
         charEkle();
         break;

         case 4:
         menu();
         break;
         }

     }

 void menuIslemleri(int secim){

     switch(secim){
         case 1:
         int deger;
         deger=veriTipi();
         eklemeFonksiyonlari(deger);
         break;

         case 2:
                         int b;
                         printf("lutfen indeksi giriniz\n");
                         scanf("%d",&b);
          indeksOkuma(b);
         break;

         case 3:
          elemanSayisi();
         break;

         case 4:

                         kapasite();
        break;

        case 5:
             doluluk();
        break;

        case 6:
        elemanlar();
        break;

        case 7:
        cikis();
        break;
         }
     }

void integerEkle(void){
        if(i<boyut){
printf("lutfen degeri giriniz\n");
scanf("%d",&eleman[i]);
tur[i]=1;
i++;
        }
        else{
        buyut(eleman,tur);
        printf("lutfen degeri giriniz\n");
scanf("%d",&eleman[i]);
tur[i]=1;

        }

}

void doubleEkle(void){
        if(i<boyut){
printf("lutfen degeri giriniz\n");
scanf("%lf",&eleman[i]);
tur[i]=2;
i++;

        }
                else{
        buyut(eleman,tur);
        printf("lutfen degeri giriniz\n");
scanf("%lf",&eleman[i]);
tur[i]=2;
i++;

        }

}

void charEkle(void){

        if(i<boyut){
        printf("string giriniz\n");
        scanf("%s",&eleman[i]);
        tur[i]=3;
        i++;

        }
        else
        {
        buyut(eleman,tur);
        printf("string giriniz\n");
        scanf("%s",&eleman[i]);
        tur[i]=3;
        i++;

    }

}

void buyut(MyArray*p,int*a){
    boyut=(int)(boyut*3/2);
    p=(MyArray*)realloc(p,boyut);
        a=(int *)realloc(a,boyut);
    }
void indeksOkuma(int c){
        int j=0;
        switch(tur[c]){

        case 1:
        printf("%d\n",eleman[c]);
        system("pause");
        break;
        case 2:
        printf("%.2f\n",eleman[c]);
        system("pause");
        break;

        case 3:
                 while((eleman[i-1].charDizi[j])!='\0')
        printf("%c",eleman[i-1].charDizi[j++]);
        printf("\n");
        system("pause");
        break;

        }

}

void kapasite(void){

printf("dizimizin kapasitesi=%d\n",boyut);
system("pause");

}

void elemanSayisi(void){
printf("dizimizin eleman sayisi=%d\n",i);
system("pause");
}

void doluluk(void){
        double k;
        k=(double)((((double)i)/((double)boyut))*((double)100));

        printf("dizimizin doluluk orani = %c",37);
        printf(" %.2f\n",k);
        system("pause");

}

void elemanlar(void){

        int k=0;

        do{
                indeksOkuma(k);
                k++;

        }while((eleman[k].charDizi[0])!='\0' || (eleman[k].doubleDizi)!='\0'
||(eleman[k].integer)!='\0' );

}

void cikis(void){

exit(0);

}

int main(){

        int secim;
    eleman=(MyArray*)malloc(sizeof(MyArray)*boyut);
        tur=(int *)malloc(sizeof(int)*boyut);

        do{
        system("CLS");
    secim=menu();
    menuIslemleri(secim);
        }while(secim!=7);

        return 0;

}

it works but also c++ isnt.:((

its here icant solve the problem
#include<stdio.h>
#include<stdlib.h>
#include <conio.h>
static int  i=0;
static int boyut=4;
static int*tur;

class proje
{

        private:
    union myArray{

              double doubleDizi;
           int integer;
             char charDizi[20];
    };
    typedef union myArray MyArray;
    MyArray* eleman;

public:
int menu(void);
int veriTipi(void);
void integerEkle(void);
void doubleEkle(void);
void charEkle(void);
void eklemeFonksiyonlari(int);
void menuIslemleri(int);
void buyut(MyArray*,int *);
void indeksOkuma(int);
void kapasite(void);
void elemanSayisi(void);
void doluluk(void);
void elemanlar(void);
void cikis(void);

};

int proje::veriTipi(void){
    int cevap;
        system("cls");
    printf("1\tinteger ekle\n2\tdouble ekle\n3\tstring ekle(maximum 20
uzunlugunda)\n4\tcancel\n");
    scanf("%d",&cevap);
    return cevap;
}

int proje::menu(void){
    int cevap;
    printf("1\tyeni eleman ekle\n2\tgirilen indeksteki elemani gor
\n3\tkac eleman oldugunu gor\n4\tdizinin kapasitesi gor\n"
         "5\tdizinin doluluk oranini gor\n6\tdizinin elemanlarini gor
\n7\tcikis\n");
         scanf("%d",&cevap);

         return cevap;

}

void proje::eklemeFonksiyonlari(int number){
     system("cls");
      switch(number){
      case 1:
         integerEkle();
         break;

         case 2:
         doubleEkle();
         break;

         case 3:
         charEkle();
         break;

         case 4:
         menu();
         break;
         }

     }
void proje::menuIslemleri(int secim){
     switch(secim){
         case 1:
         int deger;
         deger=veriTipi();
         eklemeFonksiyonlari(deger);
         break;

         case 2:
                         int b;
                         printf("lutfen indeksi giriniz\n");
                         scanf("%d",&b);
          indeksOkuma(b);
         break;

         case 3:
          elemanSayisi();
         break;

         case 4:

                         kapasite();
        break;

        case 5:
             doluluk();
        break;

        case 6:
        elemanlar();
        break;

        case 7:
        cikis();
        break;
         }
     }
     void proje::integerEkle(void){
          if(i<boyut){
printf("lutfen degeri giriniz\n");
scanf("%d",&eleman[i]);
tur[i]=1;
i++;
        }
        else{
        buyut(eleman,tur);
        printf("lutfen degeri giriniz\n");
scanf("%d",&eleman[i]);
tur[i]=1;

        }

}

 void proje::doubleEkle(void){
        if(i<boyut){
printf("lutfen degeri giriniz\n");
scanf("%lf",&eleman[i]);
tur[i]=2;
i++;

        }
                else{
        buyut(eleman,tur);
        printf("lutfen degeri giriniz\n");
scanf("%lf",&eleman[i]);
tur[i]=2;
i++;

        }

}

void proje::charEkle(void){
        if(i<boyut){
        printf("string giriniz\n");
        scanf("%s",&eleman[i]);
        tur[i]=3;
        i++;

        }
        else
        {
        buyut(eleman,tur);
        printf("string giriniz\n");
        scanf("%s",&eleman[i]);
        tur[i]=3;
        i++;

    }

}

void proje::buyut(MyArray*,int*){
      boyut=(int)(boyut*3/2);
     MyArray*p=(MyArray*)realloc(p,boyut);
         int*a=(int *)realloc(a,boyut);
}

void proje::indeksOkuma(int){
     int j=0;
        switch(tur[i]){

        case 1:
        printf("%d\n",eleman[i]);
        system("pause");
        break;
        case 2:
        printf("%.2f\n",eleman[i]);
        system("pause");
        break;

        case 3:
                 while((eleman[i-1].charDizi[j])!='\0')
        printf("%c",eleman[i-1].charDizi[j++]);
        printf("\n");
        system("pause");
        break;

}

        void proje::kapasite(void){
     printf("dizimizin kapasitesi=%d\n",boyut);
     system("pause");
}

        void proje::elemanSayisi(void){
printf("dizimizin eleman sayisi=%d\n",i);
system("pause");
}

void proje::doluluk(){
     double k;
        k=(double)((((double)i)/((double)boyut))*((double)100));

        printf("dizimizin doluluk orani = %c",37);
        printf(" %.2f\n",k);
        system("pause");

}

void proje::elemanlar(void){

        int k=0;

        do{
                indeksOkuma(k);
                k++;

        }while((eleman[k].charDizi[0])!='\0' || (eleman[k].doubleDizi)!='\0'
||(eleman[k].integer)!='\0' );

};

void proje::cikis(void){

     exit(0);

};

int main(){

    int secim;
   (MyArray*)malloc(sizeof(MyArray)*boyut)=eleman;
        tur=(int *)malloc(sizeof(int)*boyut);

        do{
        system("CLS");
    secim=menu();
    menuIslemleri(int secim);
        }while(secim!=7);

        return 0;

On 3 Jun, 21:28, memo <keo@gmail.com> wrote:

> hi im in a trouble with c++ i made a project with c but icant convert c
> ++ here is the code with c

[ 8< --- massive amounts of code snipped ]

Comment out parts of the program until it compiles cleanly. When it
compiles successfully for the first time, you know that the last part
you commented out has an error as far as your C++ compiler is
concerned. Fix it.

Un-comment a little more. Repeat the fixing process as necessary.

Of course, using C-style code in a C++ program just isn't a good idea,
anyway. malloc and company are used very little indeed in C++.
std::vector<> should be used for dynamically sized arrays.

You should also look at sprinkling in some polymorphism too, perhaps,
if you're up to it, rather than littering the code with switch
statements.

Edd

On Jun 3, 1:28 pm, memo <keo@gmail.com> wrote:

...

read more »

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc