I have a lecture is there anyone who can help me to change the source coding below to OOP C ++ I / O which uses #include so that when the file is written can be saved and when the program is closed then we can still write the data back

#include <iostream>
#include <conio.h>
#include <windows.h>
#include<stdio.h>
using namespace std;

struct daerah
{
       char kel[50];
       char kec[50];
       char kota[50];
};

struct data
{
       int nomor;
       char nama[50];
       char tinggi[20];
       char status[20];
       char pekerjaan[20];
       char tempat[20];
       char tanggal[20];
       char almt[20];
       char jenis[50];
       daerah alamat;
};

main()
{

    int menu;
    int no_sim=-1,i,j;
    int pilih;
    int namedit;
    data sim[20];
    char get[1];
    bool ketemu;

    menuutama:
    system("cls");
 cout<<" ---------------- Aplikasi Data Pelanggaran Lalu Lintas ---------------";
    cout <<" \nMENU UTAMA :\n\n";
    cout<<" 1.Menambah Data Pelanggaran\n\n";
    cout<<" 2.Mencari Data Pelanggaran\n\n";
    cout<<" 3.Menghapus Data Pelanggaran\n\n";
    cout<<" 4.Menampilkan Data Pelanggaran\n\n";
    cout<<" 5.Keluar\n\n";
    cout<<" _____________________________\n\n";
    cout<<" Masukan Pilihan Anda : "; cin>>menu;

    if(menu==1)
 {
  system("cls");
     no_sim++;
     cout<<"\n PENAMBAHAN DATABASE PELANGGARAN\n";
     cout<<" ____________________________\n\n";
     cout<<" NO Surat Izin Mengemudi(SIM): "; cin>>sim[no_sim].nomor; cin.getline(get,1);
     cout<< endl;
     cout<<" Nama Lengkap                : "; cin.getline(sim[no_sim].nama,50);
     cout<< endl;
     cout<<" Tinggi badan (CM)           : "; cin.getline(sim[no_sim].tinggi,20);
     cout<< endl;
     cout<<" Status Perkawinan           : "; cin.getline(sim[no_sim].status,20);
     cout<< endl;
     cout<<" Pekerjaan                   : "; cin.getline(sim[no_sim].pekerjaan,20);
     cout<< endl;
     cout<<" Tempat Lahir                : "; cin.getline(sim[no_sim].tempat,20);
     cout<< endl;
     cout<<" Tanggal Lahir (DD MM YYYY)  : "; cin.getline(sim[no_sim].tanggal,20);
     cout<< endl;
     cout<<" Alamat                      : "; cin.getline(sim[no_sim].almt,20);
     cout<< endl;
     cout<<" Kelurahan                   : "; cin.getline(sim[no_sim].alamat.kel,20);
     cout<< endl;
     cout<<" Kecamatan                   : "; cin.getline(sim[no_sim].alamat.kec,20);
     cout<< endl;
     cout<<" Kota                        : "; cin.getline(sim[no_sim].alamat.kota,20);
     cout<< endl;
     cout<<" Pelanggaran Lalu Lintas     : "; cin.getline(sim[no_sim].jenis,50);
     cout<<" _________________________________________________________________\n\n";
     cout<<" 1.Kembali ke Menu Utama\n\n";
     cout<<" 2.Keluar dari program\n";
     cout<<" _____________________________\n\n";
     cout<<" Masukan Pilihan Anda : "; cin>>pilih;
     cout<<endl;
     if(pilih==1)
  {
      goto menuutama;
     }
     else if(pilih==2)
  {
      goto keluar;
     }
    }

    else if(menu==2)
 {
  system ("cls");
     cout<<"\n PENCARIAN DATA PELANGGARAN\n";
     cout<<" ____________________________\n\n";
     cout<<" Masukan NO SIM : "; cin>>namedit;
     cout<<endl;

     for(i=0;i<=no_sim;i++)
  {
      if(namedit==sim[i].nomor)
   {
       cout<<" Data di temukan pada DATA PELANGGARAN"<<i<<endl<<endl;
       cout<<" Nama Lengkap      : "<<sim[i].nama<<endl;
       cout<<endl;
       cout<<" Tinggi Badan (CM) : "<<sim[i].tinggi<<endl;
       cout<<endl;
       cout<<" Status perkawinan : "<<sim[i].status<<endl;
       cout<<endl;
       cout<<" Pekerjaan         : "<<sim[i].pekerjaan<<endl;
       cout<<endl;
       cout<<" Tempat Lahir      : "<<sim[i].tempat<<endl;
       cout<<endl;
       cout<<" Tanggal Lahir     : "<<sim[i].tanggal<<endl;
       cout<<endl;
       cout<<" Alamat            : "<<sim[i].almt<<endl;
       cout<<endl;
       cout<<" Kelurahan         : "<<sim[i].alamat.kel<<endl;
       cout<<endl;
       cout<<" Kecamatan         : "<<sim[i].alamat.kec<<endl;
       cout<<endl;
       cout<<" Kota              : "<<sim[i].alamat.kota<<endl<<endl;
       cout<<endl;
       cout<<" PELANGGARAN       : "<<sim[i].jenis<<endl;
       cout<<" _____________________________________________________\n\n";

                goto menu0;
      }
     }
     cout<<" DATA YANG ANDA CARI TIDAK DI TEMUKAN !!!\n\n";
     cout<<" ________________________________________\n\n";
        menu0:
     cout<<" 1.Kembali ke Menu Utama\n\n";
     cout<<" 2.Keluar dari program\n";
     cout<<" _____________________________\n\n";
        cout<<" Masukan Pilihan Anda : "; cin>>pilih;

        if(pilih==1)
  {
      goto menuutama;
     }
     else if(pilih==2)
  {
      goto keluar;
     }
 }

 else if(menu==3)
 {
  system ("cls");
  cout<<"\n PENGHAPUSAN DATA PELANGGARAN\n";
  cout<<" ____________________________________\n\n";
  cout<<" NO SIM : "; cin>>namedit;
     cout<<endl;

        for(i=0;i<=no_sim;i++)
  {
      if(namedit==sim[i].nomor)
   {
    ketemu=true;
    if(ketemu)
    {
     for(j=i;j<=no_sim+1;j++)
     {
      sim[j]=sim[j+1];
     }
     cout<<" DATA BERHASIL DI HAPUS\n\n";
     no_sim--;
     goto menu;
    }
   }
  }
  cout<<" DATA YANG AKAN DI HAPUS TIDAK DITEMUKAN !!!\n";
  cout<<" ____________________________________________\n\n";
        menu:
     cout<<" 1.Kembali ke Menu Utama\n\n";
     cout<<" 2.Keluar dari program\n";
     cout<<" _____________________________\n\n";
        cout<<" Masukan Pilihan Anda : "; cin>>pilih;
        if(pilih==1)
  {
      goto menuutama;
     }
     else if(pilih==2)
        {
      goto keluar;
     }
 }

 else if(menu==4)
 {
  system ("PELANGGARAN");
  cout<<"\n MENAMPILKAN DATA PELANGGARAN (PELANGGARAN)\n";
  cout<<" _________________________________\n\n";
        for(i=0;i<=no_sim;i++)
  {
     cout<<" Database PELANGGARAN ke-"<<i<<endl<<endl;
     cout<<" NO SIM            : "<<sim[i].nomor<<endl<<endl;
     cout<<" Nama              : "<<sim[i].nama<<endl<<endl;
     cout<<" Tinggi Badan (CM) : "<<sim[i].tinggi<<endl<<"CM"<<endl;
     cout<<" Status perkawinan : "<<sim[i].status<<endl<<endl;
     cout<<" Pekerjaan         : "<<sim[i].pekerjaan<<endl<<endl;
     cout<<" Tempat Lahir      : "<<sim[i].tempat<<endl<<endl;
     cout<<" Tanggal Lahir     : "<<sim[i].tanggal<<endl<<endl;
     cout<<" Alamat            : "<<sim[i].almt<<endl<<endl;
     cout<<" Kelurahan         : "<<sim[i].alamat.kel<<endl<<endl;
     cout<<" Kecamatan         : "<<sim[i].alamat.kec<<endl<<endl;
     cout<<" Kota              : "<<sim[i].alamat.kota<<endl<<endl;
     cout<<" PELANGGARAN       : "<<sim[i].jenis<<endl<<endl;
  }
     cout<<" _____________________________________________\n\n";
     cout<<" 1.Kembali ke menu awal\n\n";
     cout<<" 2.keluar dari program\n";
     cout<<" _____________________________\n\n";
     cout<<" Masukan Pilihan Anda : "; cin>>pilih;
        if(pilih==1)
  {
      goto menuutama;
     }
     else if(pilih==2)
  {
      goto keluar;
     }

 keluar:
    system("PELANGGARAN");
    cout<<"\n TERIMA KASIH\n";
    getch();
    return 0;
    }
    }

Recommended Answers

If this was mine I'd step back to see what this code does and then write it in the language and methods of my choice. As I read through your code dump it doesn't look terribly complex and may be as simple as

  1. Present a menu.
  2. Get a …
Jump to Post

All 2 Replies

If this was mine I'd step back to see what this code does and then write it in the language and methods of my choice. As I read through your code dump it doesn't look terribly complex and may be as simple as

  1. Present a menu.
  2. Get a response.
  3. Set some variables according to the response.
  4. Present another menu and repeat at step 2.

As you are the new author you get to write the code. Unless this is a for hire situation in which you need to write a real RFQ with all the usual data.

If you open an output ofstream and use it not cout, the data is saved in a file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.