Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

Nested Structure Database Program

Posted By: Easy Tutor     Category: C++ Programming     Views: 4993

Write a program which performs nested structure database operation in C++.

Code for Nested Structure Database Program in C++ Programming

/*www.DailyFreeCode.comDownload Projects, Sourcecodes, Tips and Tricks, Interview FAQs, Hotlinks and more....Logon to www.DailyFreeCode.com*///samp Program of colledge dt.17/7/00//To Enter Few Records and to sort according to the choice of//the data member.   (USING NESTED STRUCTURE)

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

//GLOBAL DECLARATION OF STRUCTUREstruct date
{
int year,month,day;
};

struct person
{
int recno;
char name[20];
date dob;          //using date structure as datatypeint salary;
};

void line(void);    //Global Declaration of function as it is called in another function other than main.void main()
{
void starting(void);
void sorting(struct person[],int);
void display(struct person[]);
void end(void);
person rec[5];            //Declaration of person datatype

starting();

textcolor(111);
textbackground(196);
clrscr();
 cout<<"\n\n"<<setw(48)<<"RECORD INFORMATION";
//for inserting records
cout<<"\n\n\n\n\tEnter 5 Records\n\n\n\n";
for(int i=0,c=1;i<5;i++)
{

    cout<<"Information for Record No. "<<c<<endl;
       c++;
    line();
    cout<<"\n\nEnter Record Number:-";
   cin>>rec[i].recno;
    cout<<"Enter Name :-";
   cin>>rec[i].name;
   cout<<"\nFOR Birth_Date\n";
   cout<<"--------------\n";
   cout<<"Enter Year:-";
   cin>>rec[i].dob.year;
   cout<<"Enter Month:-";
   cin>>rec[i].dob.month;
   cout<<"Enter Day:-";
   cin>>rec[i].dob.day;
   cout<<"\nEnter salary:-";
   cin>>rec[i].salary;
   line();
   cout<<endl<<endl;
}

clrscr();
display(rec);
clrscr();
cout<<endl<<endl;
int choice;
do
{
cout<<endl<<endl;
cout<<"\n\nWhat Operation Would you Like to Perform\n";
cout<<"1)    sort by Record Number\n";
cout<<"2)    sort by Name\n";
cout<<"3)    sort by Date\n";
cout<<"4)    sort by Salary\n";
cout<<"5)    DISPLAYING\n";
cout<<"6)    QUIT\n";
cout<<"Enter Your Choice:-";
cin>>choice;
    switch(choice)
    {
    case     1:
    case     2:
    case     3:
   case    4:sorting(rec,choice);
                 break;
    case     5:display(rec);
               break;
   case    6:gotoout;
    default:cout<<"Entered Choice is Invalid, Try Again";
    }
   getch();
   clrscr();
}while(1);
out:
}


//sorting  functionvoid sorting(struct person rec[],int choice)
{
 struct person tempq;

         //record Number wise Sortingif(choice==1)
      {
          for(int i=0;i<5;i++)
         {
             for(int j=i+1;j<5;j++)
            {
                if(rec[i].recno > rec[j].recno)
               {
                tempq        =    rec[i];
               rec[i]    =    rec[j];
               rec[j]    =    tempq;
               }
            }
         }
      }


   //namewise sortingif(choice==2)
   {
       for(int i=0;i<5;i++)
      {
          for(int j=i+1;j<5;j++)
         {
             if(strcmp(rec[i].name,rec[j].name)>0)
                {
               tempq                  =  rec[i];
               rec[i]                =  rec[j];
               rec[j]              =  tempq;
               }
         }
      }
    }

    //datewiseif(choice==3)
   {
    for(int i=0;i<5;i++)
   {
       for(int j=i+1;j<5;j++)
      {
            if(rec[i].dob.year > rec[j].dob.year)
             {
                tempq                  =  rec[i];
               rec[i]                =  rec[j];
               rec[j]              =  tempq;

               if(rec[i].dob.month > rec[j].dob.month)
                   {
                  tempq                =   rec[i];
                  rec[i]            =     rec[j];
                  rec[j]            =   tempq;

                      if(rec[i].dob.day > rec[j].dob.day)
                      {
                      tempq                    =    rec[i];
                      rec[i]                =  rec[j];
                      rec[j]                =  tempq;
                      }

                  }
               }
         }
      }
     }


     //for salary wiseif(choice==4)
     {
        for(int i=0;i<5;i++)
       {
           for(int j=i+1;j<5;j++)
          {
          if(rec[i].salary > rec[j].salary)
         {
                  tempq            =   rec[i];
                 rec[i]           =     rec[j];
                rec[j]        =   tempq;
         }
      }
   }
  }

}



//display functionvoid display(struct person rec[])
{
textcolor(106);
textbackground(104);
clrscr();
cout<<endl<<endl<<endl;
line();
cout<<setw(10)<<"Record No."<<setw(25)<<"NAME OF PERON"<<setw(20)<<"DATE OF BIRTH"<<setw(23)<<"SALARY AT PRESENT"<<endl;
line();
for(int i=0;i<5;i++)
{
cout<<endl;
cout<<setw(6)<<rec[i].recno;
cout<<setw(27)<<rec[i].name;
cout<<setw(15)<<rec[i].dob.day<<"\\"<<rec[i].dob.month<<"\\"<<rec[i].dob.year;
cout<<setw(15)<<rec[i].salary;
cout<<endl;
}
getch();
}


//Line function
void line(void)
{
    for(int i=0;i<40;i++)
    {
        cout<<"--";
    }
   cout<<endl;
}


//Starting function
void starting(void)
{
 //START OF programer details\ textcolor(105);
 textbackground(104);
clrscr();
cout<<endl;
cout<<"|";
for(int i=0;i<39;i++)
{
        cout<<"--";
}
cout<<"|";

cout<<"";
for(int i=0;i<34;i++)
    cout<<"=";

cout<<"VIVEK PATEL";

for(int i=0;i<33;i++)
    cout<<"=";

cout<<endl;

cout<<"|";
for(int i=0;i<39;i++)
{
        cout<<"--";
}
cout<<"|";
cout<<endl<<endl<<endl;
line();
cout<<setw(49)<<"WELLCOME VIEWERS\n";
line();
cout<<setw(55)<<"SAMPLE DATABASE APPLICATION\n\n";
line();
line();
cout<<setw(79)<<"Created By VIVEK PATEL\n\n";
line();
line();
cout<<setw(55)<<"EMAIL US AT VIVEK_P9@HOTMAIL.COM";
getch();

//END OF PROGRAMMER DETAILS\\
}
  
Share: 


Didn't find what you were looking for? Find more on Nested Structure Database Program Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Nested Structure Database Program is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!