I just develop a simple C++ program which gets data from user and make in database form and save it to file...
compile it and share your review...

/*simple Database application
  Programmed by Piyush gautam
  email-piyush3dxyz@gmail.com */

#include <iostream>
#include <conio.h>
#include <fstream>
#include <stdio.h>

using namespace std;

struct work
{
    char name[100];
    int id;
    char job[10];
}p[10];

int main()
{
    int i,b,d;
    char f[20];
  jumpe:
  for(i=1;;)
  {

      cout<<"\nThe db++ Database application\n1-To enter the data\n2-To read the data\n3-To save the data\n";
      cin>>d;
      switch(d)
     {  case 1:
            cout << "enter the no of workers to get the data:" << endl;
            cin>>b;
            for(i=1;i<=b;++i)
            {
             cout<<"\nenter the name of the worker:\n";
             cin>>p[i].name;
             cout<<"\nenter the id no of the worker:\n";
             cin>>p[i].id;
             cout<<"\nenter the job of the worker:\n";
             cin>>p[i].job;
            }
            goto jumpe;

        case 2:

             for(i=1;i<=b;++i)
             {
                               cout<<"\nThe "<<i<<" name is "<<p[i].name<<" with id no "<<p[i].id<<"\n";

             }
             goto jumpe;

        case 3:
             ofstream file;
             file.open ("report.txt");
             for(i=1;i<=b;++i)
             {



              file <<"\nThe "<<i<<" name is "<<p[i].name<<" with id no "<<p[i].id<<"\n";


             }
             file.close();
             cout<<"the file is saved";
             getch();
             goto jumpe;



      } 

   }


}

As far as functionality goes it works; however, you shouldn't be using labels/gotos because they are a bad coding habbit and make reading the flow of your code harder. Anywhere you use a goto statement you can replace it with a loop (which is what I did in this case).

Another thing that you should think about is making variable names that actually mean something. When I saw p, f, d, b I had no idea what those were until I looked over the program. So instead of using p as a name for your array of workers you can just call it workers or something descriptive.

You should also know that most programming languages are 0 base indexed so if you want an array that has 10 entries, it starts at 0 and ends at 9.

If you wanted to make this a bit more C++ rather than C you could use strings for the name of the worker and job, also you could use a vector, list or any other STL container that can dynamically resize to however many workers you want to create (or read in from the file if you want to add that feature).

#include <iostream>
#include <fstream>
#include <conio.h>

using namespace std;

struct work
{
    char name[100];
    int id;
    char job[10];
}workers[10];

int main()
{
    int numWorkers = 0;
    int option = 0;
    ofstream file;

    while(1)
    {
        cout << "\nThe db++ Database application\n1-To enter the data\n2-To read the data\n3-To save the data\n";
        cin >> option;

        switch(option)
        {
            case 1:
                cout << "Enter the no. of workers:" << endl;
                cin >> numWorkers;
                for( int i = 0; i < numWorkers; i++ )
                {
                    cout << endl << "Enter the name of the worker:" << endl;
                    cin >> workers[i].name;

                    cout << endl << "Enter the ID no. of the worker:" << endl;
                    cin >> workers[i].id;

                    cout << endl << "Enter the job of the worker:" << endl;
                    cin >> workers[i].job;
                    cout << endl;
                }
                break;

            case 2:
                for( int i = 0; i < numWorkers; i++ )
                    cout << endl << "The worker no. " << i+1 << " is " << workers[i].name << " with an ID no. of " << workers[i].id;
                cout << endl << endl;
                break;

            case 3:
                file.open("report.txt");
                for( int i = 0; i < numWorkers; i++ )
                    file << endl << "The worker no. " << i+1 << " is " << workers[i].name << " with an ID no. of " << workers[i].id << endl;
                file << endl;
                file.close();
                cout << "The file is saved" << endl;
                getch();
                break;
        }
    }
    return 0;
}
commented: hey sfuo....i am the beginner in the c++ programming...Its only 2 month of my c++ learning.....but thax for correcting me.... +0
Be a part of the DaniWeb community

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