Showing posts with label Projects (C). Show all posts
Showing posts with label Projects (C). Show all posts

Wednesday, 13 February 2013

How to disable the close button of console using C

The code for making the close button  disabled is given below. It disables the close button and hence user cannot close console. But one can close console using Task Manager.
#define _WIN32_WINNT 0x0500
#include <stdio.h>
#include <windows.h>
int main(int argc, _TCHAR* argv[])
{
    HWND h;
    HMENU sm;
    int i, j, c;
    LPTSTR buf;
    // get the handle to the console
    h = GetConsoleWindow();
    // get handle to the System Menu
    sm = GetSystemMenu(h, 0);
    // how many items are there?
    c = GetMenuItemCount(sm);
    j = -1;
    buf = (TCHAR*) malloc (256 *sizeof(TCHAR));
    for (i=0; i<c; i++) {
        // find the one we want
        GetMenuString(sm, i, buf, 255, MF_BYPOSITION);
        if (!strcmp(buf, "&Close")) {
            j = i;
            break;
        }
    }
    // if found, remove that menu item
    if (j >= 0)
        RemoveMenu(sm, j, MF_BYPOSITION);
    return 0;
}

How to resize the console window using C

The code for resizing the console window is given below
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
HANDLE wHnd;    // Handle to write to the console.
HANDLE rHnd;    // Handle to read from the console.
int main(int argc, char* argv[]) {
    // Set up the handles for reading/writing:
    wHnd = GetStdHandle(STD_OUTPUT_HANDLE);
    rHnd = GetStdHandle(STD_INPUT_HANDLE);
    // Change the window title:
    SetConsoleTitle("Advanced C tutorial - programming-technique.blogspot.com");
    // Set up the required window size:
    SMALL_RECT windowSize = {0, 0, 50, 10};
    SetConsoleWindowInfo(wHnd, 1, &windowSize);
    // Change the console window size:
        // Create a COORD to hold the buffer size:
    COORD bufferSize = {10, 10};
    SetConsoleScreenBufferSize(wHnd, bufferSize);
    // Exit
    return 0;
}

Tuesday, 12 February 2013

List Of Project

Mini project snake game in c

Mini project in C many Student do management project like library management ,Hotel management etc.But Snake Game is mini project of first semester build by my friend which is very different.It is console application without graphic library that's why it is more interesting.This game is perfect without any error and better user interface.It is complied in code::block using c language.Here goes a source code you can copy and compiled it in code::block.I hope it can help and become a reference for your project.





#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include<time.h>
#include<ctype.h>
#include <time.h>
#include <windows.h>
#include <process.h>
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
int length;
int bend_no;
int len;
char key;
void record();
void load();
int life;
void Delay(long double);
void Move();
void gotoxy(int x, int y);
void GotoXY(int x,int y);
void Bend();
void Boarder();
void Down();
void Left();
void Up();
void Right();
void ExitGame();
int Scoreonly();
struct coordinate{
    int x;
    int y;
    int direction;
};
typedef struct coordinate coordinate;
coordinate head, bend[500],food,body[30];
int main()
{
    char key;
    Print();
    system("cls");
    load();
    length=5;
    head.x=25;
    head.y=20;
    head.direction=RIGHT;
    Boarder();
    Food(); //to generate food coordinates initially
    life=3; //number of extra lives
    bend[0]=head;
    Move();   //initialing initial bend coordinate
    return 0;
}

void Move()
{
    int a,i;
    do{
        Food();
        fflush(stdin);
        len=0;
        for(i=0;i<30;i++)
        {
            body[i].x=0;
            body[i].y=0;
            if(i==length)
            break;
        }
        Delay(length);
        Boarder();
        if(head.direction==RIGHT)
            Right();
        else if(head.direction==LEFT)
            Left();
        else if(head.direction==DOWN)
            Down();
        else if(head.direction==UP)
            Up();
        ExitGame();

    }while(!kbhit());
    a=getch();
    if(a==27)
    {
        system("cls");
        exit(0);
    }
    key=getch();
    if((key==RIGHT&&head.direction!=LEFT&&head.direction!=RIGHT)||(key==LEFT&&head.direction!=RIGHT&&head.direction!=LEFT)||(key==UP&&head.direction!=DOWN&&head.direction!=UP)||(key==DOWN&&head.direction!=UP&&head.direction!=DOWN))
    {
        bend_no++;
        bend[bend_no]=head;
        head.direction=key;
        if(key==UP)
            head.y--;
        if(key==DOWN)
            head.y++;
        if(key==RIGHT)
            head.x++;
        if(key==LEFT)
            head.x--;
        Move();

    }
    else if(key==27)
    {
        system("cls");
        exit(0);
    }
    else
    {
        printf("\a");
        Move();
    }
}
void gotoxy(int x, int y)
{
 COORD coord;
 coord.X = x;
 coord.Y = y;
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void GotoXY(int x, int y)
{
    HANDLE a;
    COORD b;
    fflush(stdout);
    b.X = x;
    b.Y = y;
    a = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(a,b);
 }
void load(){
    int row,col,r,c,q;
    gotoxy(36,14);
    printf("loading...");
    gotoxy(30,15);
    for(r=1;r<=20;r++){
    for(q=0;q<=100000000;q++);//to display the character slowly
    printf("%c",177);}
    getch();
}
void Down()
{
    int i;
    for(i=0;i<=(head.y-bend[bend_no].y)&&len<length;i++)
    {
        GotoXY(head.x,head.y-i);
        {
            if(len==0)
                printf("v");
            else
                printf("*");
        }
        body[len].x=head.x;
        body[len].y=head.y-i;
        len++;
    }
    Bend();
    if(!kbhit())
        head.y++;

}
void Delay(long double k)
{
    Score();
    long double i;
    for(i=0;i<=(10000000);i++);
}
void ExitGame()
{
    int i,check=0;
    for(i=4;i<length;i++)   //starts with 4 because it needs minimum 4 element to touch its own body
    {
        if(body[0].x==body[i].x&&body[0].y==body[i].y)
        {
            check++;    //check's value increases as the coordinates of head is equal to any other body coordinate
        }
        if(i==length||check!=0)
            break;
    }
    if(head.x<=10||head.x>=70||head.y<=10||head.y>=30||check!=0)
    {
        life--;
        if(life>=0)
        {
            head.x=25;
            head.y=20;
            bend_no=0;
            head.direction=RIGHT;
            Move();
        }
        else
        {
            system("cls");
            printf("All lives completed\nBetter Luck Next Time!!!\nPress any key to quit the game\n");
            record();
            exit(0);
        }
    }
}
void Food()
{
    if(head.x==food.x&&head.y==food.y)
    {
        length++;
        time_t a;
        a=time(0);
        srand(a);
        food.x=rand()%70;
        if(food.x<=10)
            food.x+=11;
        food.y=rand()%30;
        if(food.y<=10)
            food.y+=11;
    }
    else if(food.x==0)/*to create food for the first time coz global variable are initialized with 0*/
    {
        food.x=rand()%70;
        if(food.x<=10)
            food.x+=11;
        food.y=rand()%30;
        if(food.y<=10)
            food.y+=11;
    }

}
void Left()
{
    int i;
    for(i=0;i<=(bend[bend_no].x-head.x)&&len<length;i++)
    {
        GotoXY((head.x+i),head.y);
       {
                if(len==0)
                    printf("<");
                else
                    printf("*");
        }
        body[len].x=head.x+i;
        body[len].y=head.y;
        len++;
    }
    Bend();
    if(!kbhit())
        head.x--;

}
void Right()
{
    int i;
    for(i=0;i<=(head.x-bend[bend_no].x)&&len<length;i++)
    {
        //GotoXY((head.x-i),head.y);
        body[len].x=head.x-i;
        body[len].y=head.y;
        GotoXY(body[len].x,body[len].y);
        {
            if(len==0)
                printf(">");
            else
                printf("*");
        }
        /*body[len].x=head.x-i;
        body[len].y=head.y;*/
        len++;
    }
    Bend();
    if(!kbhit())
        head.x++;

}
void Bend()
{
    int i,j,diff;
    for(i=bend_no;i>=0&&len<length;i--)
    {
            if(bend[i].x==bend[i-1].x)
            {
                diff=bend[i].y-bend[i-1].y;
                if(diff<0)
                    for(j=1;j<=(-diff);j++)
                    {

                        body[len].x=bend[i].x;
                        body[len].y=bend[i].y+j;
                        GotoXY(body[len].x,body[len].y);
                        printf("*");
                        len++;
                        if(len==length)
                            break;
                    }
                else if(diff>0)
                    for(j=1;j<=diff;j++)
                    {
                        /*GotoXY(bend[i].x,(bend[i].y-j));
                        printf("*");*/
                        body[len].x=bend[i].x;
                        body[len].y=bend[i].y-j;
                        GotoXY(body[len].x,body[len].y);
                        printf("*");
                        len++;
                        if(len==length)
                            break;
                    }
            }
        else if(bend[i].y==bend[i-1].y)
        {
            diff=bend[i].x-bend[i-1].x;
            if(diff<0)
                for(j=1;j<=(-diff)&&len<length;j++)
                {
                    /*GotoXY((bend[i].x+j),bend[i].y);
                    printf("*");*/
                    body[len].x=bend[i].x+j;
                    body[len].y=bend[i].y;
                    GotoXY(body[len].x,body[len].y);
                        printf("*");
                    len++;
                    if(len==length)
                            break;
                }
            else if(diff>0)
                for(j=1;j<=diff&&len<length;j++)
                {
                    /*GotoXY((bend[i].x-j),bend[i].y);
                    printf("*");*/
                    body[len].x=bend[i].x-j;
                    body[len].y=bend[i].y;
                    GotoXY(body[len].x,body[len].y);
                        printf("*");
                    len++;
                    if(len==length)
                        break;
                }
        }
    }
}
void Boarder()
{
    system("cls");
    int i;
    GotoXY(food.x,food.y);   /*displaying food*/
        printf("F");
    for(i=10;i<71;i++)
    {
        GotoXY(i,10);
            printf("!");
        GotoXY(i,30);
            printf("!");
    }
    for(i=10;i<31;i++)
    {
        GotoXY(10,i);
            printf("!");
        GotoXY(70,i);
        printf("!");
    }
}
void Print()
{
    //GotoXY(10,12);
    printf("\tWelcome to the mini Snake game.(press any key to continue)\n");
   getch();
    system("cls");
    printf("\tGame instructions:\n");
    printf("\n-> Use arrow keys to move the snake.\n\n-> You will be provided foods at the several coordinates of the screen which you have to eat. Everytime you eat a food the length of the snake will be increased by 1 element and thus the score.\n\n-> Here you are provided with three lives. Your life will decrease as you hit the wall or snake's body.\n\n-> YOu can pause the game in its middle by pressing any key. To continue the paused game press any other key once again\n\n-> If you want to exit press esc. \n");
    printf("\n\nPress any key to play game...");
    if(getch()==27)
    exit(0);
}
void record(){
    char plname[20],nplname[20],cha,c;
    int i,j,px;
    FILE *info;
    info=fopen("record.txt","a+");
    getch();
    system("cls");
    printf("Enter your name\n");
    scanf("%[^\n]",plname);
    //************************
    for(j=0;plname[j]!='\0';j++){ //to convert the first letter after space to capital
    nplname[0]=toupper(plname[0]);
    if(plname[j-1]==' '){
    nplname[j]=toupper(plname[j]);
    nplname[j-1]=plname[j-1];}
    else nplname[j]=plname[j];
    }
    nplname[j]='\0';
    //*****************************
    //sdfprintf(info,"\t\t\tPlayers List\n");
    fprintf(info,"Player Name :%s\n",nplname);
     //for date and time
time_t mytime;
mytime = time(NULL);
fprintf(info,"Played Date:%s",ctime(&mytime));
      //**************************
      fprintf(info,"Score:%d\n",px=Scoreonly());//call score to display score
      //fprintf(info,"\nLevel:%d\n",10);//call level to display level
    for(i=0;i<=50;i++)
    fprintf(info,"%c",'_');
    fprintf(info,"\n");
    fclose(info);
    printf("wanna see past records press 'y'\n");
    cha=getch();
    system("cls");
    if(cha=='y'){
    info=fopen("record.txt","r");
    do{
        putchar(c=getc(info));
        }while(c!=EOF);}
      fclose(info);
}
int Score()
{
    int score;
    GotoXY(20,8);
    score=length-5;
    printf("SCORE : %d",(length-5));
    score=length-5;
    GotoXY(50,8);
    printf("Life : %d",life);
    return score;
}
int Scoreonly()
{
int score=Score();
system("cls");
return score;
}
void Up()
{
    int i;
    for(i=0;i<=(bend[bend_no].y-head.y)&&len<length;i++)
    {
        GotoXY(head.x,head.y+i);
        {
            if(len==0)
                printf("^");
            else
                printf("*");
        }
        body[len].x=head.x;
        body[len].y=head.y+i;
        len++;
    }
    Bend();
    if(!kbhit())
        head.y--;

}

C++ Project Bus Reservation System in Code

This project is console application without GUI. You can add many features in this project.Here data of bus information is not store in file so every run of program previous data is lost so you can implement the file handling to store all the bus details.
#include <conio.h>


#include <cstdio>


#include <iostream>


#include <string.h>


#include <cstdlib>


using namespace std;


static int p = 0;


class a


{


  char busn[5], driver[10], arrival[5], depart[5], from[10], to[10], seat[8][4][10];


public:


  void install();


  void allotment();


  void empty();


  void show();


  void avail();


  void position(int i);


}


bus[10];


void vline(char ch)


{


  for (int i=80;i>0;i--)


  cout<<ch;


}


void a::install()


{


  cout<<"Enter bus no: ";


  cin>>bus[p].busn;


  cout<<"\nEnter Driver's name: ";


  cin>>bus[p].driver;


  cout<<"\nArrival time: ";


  cin>>bus[p].arrival;


  cout<<"\nDeparture: ";


  cin>>bus[p].depart;


  cout<<"\nFrom: \t\t\t";


  cin>>bus[p].from;


  cout<<"\nTo: \t\t\t";


  cin>>bus[p].to;


  bus[p].empty();


  p++;


}


void a::allotment()


{


  int seat;


  char number[5];


  top:


  cout<<"Bus no: ";


  cin>>number;


  int n;


  for(n=0;n<=p;n++)


  {


    if(strcmp(bus[n].busn, number)==0)


    break;


  }


  while(n<=p)


  {


    cout<<"\nSeat Number: ";


    cin>>seat;


    if(seat>32)


    {


      cout<<"\nThere are only 32 seats available in this bus.";


    }


    else


    {


    if (strcmp(bus[n].seat[seat/4][(seat%4)-1], "Empty")==0)


      {


        cout<<"Enter passanger's name: ";


        cin>>bus[n].seat[seat/4][(seat%4)-1];


        break;


      }


    else


      cout<<"The seat no. is already reserved.\n";


      }


      }


    if(n>p)


    {


      cout<<"Enter correct bus no.\n";


      goto top;


    }


  }



void a::empty()


{


  for(int i=0; i<8;i++)


  {


    for(int j=0;j<4;j++)


    {


      strcpy(bus[p].seat[i][j], "Empty");


    }


  }


}


void a::show()


{


  int n;


  char number[5];


  cout<<"Enter bus no: ";


  cin>>number;


  for(n=0;n<=p;n++)


  {


    if(strcmp(bus[n].busn, number)==0)


    break;


  }


while(n<=p)


{


  vline('*');


  cout<<"Bus no: \t"<<bus[n].busn


  <<"\nDriver: \t"<<bus[n].driver<<"\t\tArrival time: \t"


  <<bus[n].arrival<<"\tDeparture time:"<<bus[n].depart


  <<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t"<<


  bus[n].to<<"\n";


  vline('*');


  bus[0].position(n);


  int a=1;


  for (int i=0; i<8; i++)


  {


    for(int j=0;j<4;j++)


    {


      a++;


      if(strcmp(bus[n].seat[i][j],"Empty")!=0)


      cout<<"\nThe seat no "<<(a-1)<<" is reserved for "<<bus[n].seat[i][j]<<".";


    }


  }


  break;


  }


  if(n>p)


    cout<<"Enter correct bus no: ";


}


void a::position(int l)


{


  int s=0;p=0;


  for (int i =0; i<8;i++)


  {


    cout<<"\n";


    for (int j = 0;j<4; j++)


    {


      s++;


      if(strcmp(bus[l].seat[i][j], "Empty")==0)


        {


          cout.width(5);


          cout.fill(' ');


          cout<<s<<".";


          cout.width(10);


          cout.fill(' ');


          cout<<bus[l].seat[i][j];


          p++;


        }


        else


        {


        cout.width(5);


        cout.fill(' ');


        cout<<s<<".";


        cout.width(10);


        cout.fill(' ');


        cout<<bus[l].seat[i][j];


        }


      }


    }


  cout<<"\n\nThere are "<<p<<" seats empty in Bus No: "<<bus[l].busn;


  }


void a::avail()


{



  for(int n=0;n<p;n++)


  {


    vline('*');


    cout<<"Bus no: \t"<<bus[n].busn<<"\nDriver: \t"<<bus[n].driver


    <<"\t\tArrival time: \t"<<bus[n].arrival<<"\tDeparture Time: \t"


    <<bus[n].depart<<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t\t"


    <<bus[n].to<<"\n";


    vline('*');


    vline('_');


  }


}


int main()


{


system("cls");


int w;


while(1)


{


    //system("cls");


  cout<<"\n\n\n\n\n";


  cout<<"\t\t\t1.Install\n\t\t\t"


  <<"2.Reservation\n\t\t\t"


  <<"3.Show\n\t\t\t"


  <<"4.Buses Available. \n\t\t\t"


  <<"5.Exit";


  cout<<"\n\t\t\tEnter your choice:-> ";


  cin>>w;


  switch(w)


  {


    case 1:  bus[p].install();


      break;


    case 2:  bus[p].allotment();


      break;


    case 3:  bus[0].show();


      break;


    case 4:  bus[0].avail();


      break;


    case 5:  exit(0);


  }


}


return 0;


}

Employee’s Management System Project in c++ with source

. It is console application without graphics. Whole project is completely based on file handling all the employee’s record are store in file. You learn how to store the data, editing data, searching data and deleting the data using file. Following features can be found in this project which is listed below.
1. Built The Employee table
2.List the employee table
3.Insert new entry
4.Delete an entry
5.Edit an entry
6.Search a record
7.Sort the table


#include<iostream>


#include<cstring>


#include<cstdlib>


#include<iomanip>


#include<windows.h>


//#include <ctime>


//#include <dos.h>


#include<dos.h>


#include<conio.h>


#include<cstdio>


#define max 20


using namespace std;


struct employee


{


 char name[20];


 long int code;


 char designation[20];


 int exp;


 int age;


};


int num;


employee emp[max],tempemp[max],sortemp[max],sortemp1[max];


int main()


{


 system("cls");


 void build();


 void list();


 void insert();


 void deletes();


 void edit();


 void search();


 void sort();


 char option;


 void menu();


 menu();


 while((option=cin.get())!='q')


 {


  switch(option)


  {


   case 'b':


         build();


         break;


   case 'l':


         list();


         break;


   case 'i':


         insert();


         break;


   case 'd':


         deletes();


         break;


   case 'e':


       edit();


        break;


   case 's':


        search();


        break;


   case 'n':


         sort();


         break;


  }


   menu();


  }


  return 0;


 }


 void menu()


 {


  system("cls");


 // highvideo();


cout<<"          ";


printf("\n*****  Employees Management System 1.0 ***** ");




//normvideo();


cout<<endl;


cout<<"             ";


cout<<"\n\t\t Press  b---->Built The Employee Table ";


cout<<"             ";


cout<<"\n\t\t Press  l---->List The Employee Table  ";


cout<<"             ";


cout<<"\n\t\t Press  i---->Insert New Entry        ";


cout<<"             ";


cout<<"\n\t\t Press  d---->Delete An Entry         ";


cout<<"             ";


cout<<"\n\t\t Press  e---->Edit An Entry           ";


cout<<"             ";


cout<<"\n\t\t Press  s---->Search Arecord          ";


cout<<"             ";


cout<<"\n\t\t Press  n---->Sort The Table          ";


cout<<"             ";


cout<<"\n\t\t Press  q---------->Quit Program              ";


cout<<"             ";


cout<<"\n\n \t\t Select Your Option Please ====> ";


}



void build()


{



 system("cls");


// highvideo();


 printf("Build The Table");


 cout<<endl;


 //normvideo();


 cout<<"maximum number of entries  -----  >  20"<<endl;


 cout<<"how many do you want    ----->";


 cin>>num;


 cout<<"Enter The Following Items"<<endl;


 for(int i=0;i<=num-1;i++)


 {


  cout<<" Name  ";


  cin>>emp[i].name;


  cout<<"Code  ";


  cin>>emp[i].code;


  cout<<"Designation  ";


  cin>>emp[i].designation;


  cout<<"Years of Experience  ";


  cin>>emp[i].exp;


  cout<<"Age  ";


  cin>>emp[i].age;


 }


  cout<<"going to main menu";


 Sleep(500);


}



void  list()


{


 system("cls");


// highvideo();


 printf("       ********List The Table********");


 cout<<endl;


 //normvideo();


 cout<<"     Name     Code     Designation     Years(EXP)     Age "<<endl;


 cout<<"    ------------------------------------------------------"<<endl;


 for(int i=0;i<=num-1;i++)


 {


  cout<<setw(13)<<emp[i].name;


  cout<<setw(6)<<emp[i].code;


  cout<<setw(15)<<emp[i].designation;


  cout<<setw(10)<<emp[i].exp;


  cout<<setw(15)<<emp[i].age;


  cout<<endl;


 }


  cout<<"going to main menu";


 getch();


  }


  void insert()


  {


  system("cls");


  int i=num;


  num+=1;


 // highvideo();


  printf("Insert New Record");


  cout<<endl;


  //normvideo();


  cout<<"Enter The Following Items"<<endl;


  cout<<"Name  ";


  cin>>emp[i].name;


  cout<<"Code  ";


  cin>>emp[i].code;


  cout<<"Designation  ";


  cin>>emp[i].designation;


  cout<<"Years of Experience  ";


  cin>>emp[i].exp;


  cout<<"Age  ";


  cin>>emp[i].age;


  cout<<endl<<endl;


  cout<<"going to main menu";


 Sleep(500);



  }




  void deletes()


  {


   system("cls");


  // highvideo();


   int code;


   int check;


   printf("Delete An Entry");


   //normvideo();


   cout<<endl;


   cout<<"Enter An JobCode To Delete That Entry  ";


   cin>>code;


   int i;


   for(i=0;i<=num-1;i++)


   {


    if(emp[i].code==code)


    {


      check=i;


    }


   }


   for(i=0;i<=num-1;i++)


   {


    if(i==check)


    {


    continue;


    }


    else


    {


    if(i>check)


    {


     tempemp[i-1]=emp[i];


    }


    else


    {


     tempemp[i]=emp[i];


    }


     }


   }


  num--;



  for(i=0;i<=num-1;i++)


  {


   emp[i]=tempemp[i];


  }


 }



void edit()


{


 system("cls");


 int jobcode;


// highvideo();


 printf("          Edit An Entry           ");


 cout<<endl;


 cout<<endl;


 int i;


 void editmenu();


 void editname(int);


 void editcode(int);


 void editdes(int);


 void editexp(int);


 void editage(int);


 char option;


 //normvideo();


 cout<<"Enter An jobcode To Edit An Entry----  ";


 cin>>jobcode;


  editmenu();


 for(i=0;i<=num-1;i++)


   {


    if(emp[i].code==jobcode)


    {



while((option=cin.get())!='q')


{


      switch(option)


      {


       case 'n':


            editname(i);


            break;


       case 'c':


            editcode(i);


            break;


       case 'd':


            editdes(i);


            break;


       case 'e':


            editexp(i);


            break;


       case 'a':


           editage(i);


           break;


     }


   editmenu();


    }


  }


  }


  }


  void editmenu()


  {


   system("cls");


   cout<<"        What Do You Want To edit";


   cout<<"          n--------->Name ";


   cout<<"          c--------->Code ";


   cout<<"          d--------->Designation";


   cout<<"          e--------->Experience ";


   cout<<"          a--------->Age        ";


   cout<<"              q----->QUIT                            ";


   cout<<"   Options Please ---->>>  ";


  }


  void editname(int i)


  {


     cout<<"Enter New Name----->  ";


     cin>>emp[i].name;


  }


  void editcode(int i)


  {


   cout<<"Enter New Job Code----->  ";


   cin>>emp[i].code;


  }


  void editdes(int i)


  {


   cout<<"enter new designation----->  ";


   cin>>emp[i].designation;


  }


  void editexp(int i)


  {


   cout<<"Enter new Years of Experience";


   cin>>emp[i].exp;


  }


  void editage(int i)


  {


   cout<<"Enter new Age ";


   cin>>emp[i].age;


  }



void search()


{


 system("cls");


 // highvideo();


  printf("Welcome To Search Of Employee Database ");


  //normvideo();


  cout<<endl;


  cout<<endl;


  int jobcode;


  cout<<"You Can Search Only By Jobcode Of An Employee";


  cout<<"Enter Code Of An Employee                    ";


 cin>>jobcode;


 for(int i=0;i<=num-1;i++)


   {


    if(emp[i].code==jobcode)


    {



    cout<<"     Name     Code     Designation     Years(EXP)     Age ";


 cout<<"     ------------------------------------------------------                                  ";


  cout<<setw(13)<<emp[i].name;


  cout<<setw(6)<<emp[i].code;


  cout<<setw(15)<<emp[i].designation;


  cout<<setw(10)<<emp[i].exp;


  cout<<setw(15)<<emp[i].age;


  cout<<endl;


 }



  }


    cout<<"going to main menu";


 getch();




}



void sort()


{


 system("cls");


// highvideo();


 printf("Sort The Databse By JobCode");


 //normvideo();


 void sortmenu();


 void sortname();


 void sortcode();


 void sortdes();


 void sortexp();


 char option;


 void sortage();



 cout<<endl;


 cout<<endl;


 sortmenu();


 while((option=cin.get())!='q')


 {


  switch(option)


  {


   case 'n':


          sortname();


          break;


   case 'c':


          sortcode();


          break;


   case 'd':


          sortdes();


          break;


   case 'e':


          sortexp();


          break;


   case 'a':


          sortage();


          break;


   }


   sortmenu();


  }


 }




 void sortmenu()


 {


    system("cls");


   cout<<"          What Do You Want To edit";


   cout<<"          n--------->Name         ";


   cout<<"          c--------->Code         ";


   cout<<"          d--------->Designation  ";


   cout<<"          e--------->Experience   ";


   cout<<"          a--------->Age          ";


   cout<<"                               q----->QUIT            ";


   cout<<"   Options Please ---->>>  ";  }





void sortname()


{


 system("cls");


 int i,j;


 struct employee temp[max];


 for(i=0;i<=num-1;i++)


 {


  sortemp1[i]=emp[i];


 }


 for(i=0;i<=num-1;i++)


  {


   for(j=0;j<=num-1;j++)


   {


    if(strcmp(sortemp1[i].name,sortemp1[j].name)<=0)


    {


     temp[i]=sortemp1[i];


     sortemp1[i]=sortemp1[j];


     sortemp1[j]=temp[i];


    }


   }


 }



 for( i=0;i<=num-1;i++)


   {



    cout<<"     Name     Code     Designation     Years(EXP)     Age ";


 cout<<"     ------------------------------------------------------                                  ";


 for( i=0;i<=num-1;i++)


 {


  cout<<setw(13)<<sortemp1[i].name;


  cout<<setw(6)<<sortemp1[i].code;


  cout<<setw(15)<<sortemp1[i].designation;


  cout<<setw(10)<<sortemp1[i].exp;


  cout<<setw(15)<<sortemp1[i].age;


  cout<<endl;


 }


  cout<<"Press Any Key To Go Back";


 getch();



} }



void sortcode()


{


 system("cls");


 int i,j;


 struct employee temp[max];


 for(i=0;i<=num-1;i++)


 {


  sortemp1[i]=emp[i];


 }


 for(i=0;i<=num-1;i++)


  {


   for(j=0;j<=num-1;j++)


   {


    if(sortemp1[i].code<sortemp1[j].code)


    {


     temp[i]=sortemp1[i];


     sortemp1[i]=sortemp1[j];


     sortemp1[j]=temp[i];


    }


   }


 }



 for( i=0;i<=num-1;i++)


   {



    cout<<"     Name     Code     Designation     Years(EXP)     Age ";


 cout<<"     ------------------------------------------------------                                  ";


 for( i=0;i<=num-1;i++)


 {


  cout<<setw(13)<<sortemp1[i].name;


  cout<<setw(6)<<sortemp1[i].code;


  cout<<setw(15)<<sortemp1[i].designation;


  cout<<setw(10)<<sortemp1[i].exp;


  cout<<setw(15)<<sortemp1[i].age;


  cout<<endl;


 }


  cout<<"Press Any Key To Go Back";


 getch();



} }




void sortdes()


{


 system("cls");


 int i,j;


 struct employee temp[max];


 for(i=0;i<=num-1;i++)


 {


  sortemp1[i]=emp[i];


 }


 for(i=0;i<=num-1;i++)


  {


   for(j=0;j<=num-1;j++)


   {


    if(strcmp(sortemp1[i].designation,sortemp1[j].designation)<=0)


    {


     temp[i]=sortemp1[i];


     sortemp1[i]=sortemp1[j];


     sortemp1[j]=temp[i];


    }


   }


 }



 for( i=0;i<=num-1;i++)


   {



    cout<<"     Name     Code     Designation     Years(EXP)     Age";


 cout<<"     ------------------------------------------------------                                 ";


 for( i=0;i<=num-1;i++)


 {


  cout<<setw(13)<<sortemp1[i].name;


  cout<<setw(6)<<sortemp1[i].code;


  cout<<setw(15)<<sortemp1[i].designation;


  cout<<setw(10)<<sortemp1[i].exp;


  cout<<setw(15)<<sortemp1[i].age;


  cout<<endl;


 }


  cout<<"Press Any Key To Go Back";


 getch();



} }



void sortage()


{


 system("cls");


 int i,j;


 struct employee temp[max];


 for(i=0;i<=num-1;i++)


 {


  sortemp1[i]=emp[i];


 }


 for(i=0;i<=num-1;i++)


  {


   for(j=0;j<=num-1;j++)


   {


    if(sortemp1[i].age<sortemp1[j].age)


    {


     temp[i]=sortemp1[i];


     sortemp1[i]=sortemp1[j];


     sortemp1[j]=temp[i];


    }


   }


 }



 for( i=0;i<=num-1;i++)


   {



    cout<<"     Name     Code     Designation     Years(EXP)     Age";


 cout<<"     ------------------------------------------------------                                 ";


 for( i=0;i<=num-1;i++)


 {


  cout<<setw(13)<<sortemp1[i].name;


  cout<<setw(6)<<sortemp1[i].code;


  cout<<setw(15)<<sortemp1[i].designation;


  cout<<setw(10)<<sortemp1[i].exp;


  cout<<setw(15)<<sortemp1[i].age;


  cout<<endl;


 }


  cout<<"Press Any Key To Go Back";


 getch();



} }




void sortexp()


{


 system("cls");


 int i,j;


 struct employee temp[max];


 for(i=0;i<=num-1;i++)


 {


  sortemp1[i]=emp[i];


 }


 for(i=0;i<=num-1;i++)


  {


   for(j=0;j<=num-1;j++)


   {


    if(sortemp1[i].exp<sortemp1[j].exp)


    {


     temp[i]=sortemp1[i];


     sortemp1[i]=sortemp1[j];


     sortemp1[j]=temp[i];


    }


   }


 }



 for( i=0;i<=num-1;i++)


   {



    cout<<"     Name     Code     Designation     Years(EXP)     Age ";


 cout<<"  ------------------------------------------------------ ";


 for( i=0;i<=num-1;i++)


 {


  cout<<setw(13)<<sortemp1[i].name;


  cout<<setw(6)<<sortemp1[i].code;


  cout<<setw(15)<<sortemp1[i].designation;


  cout<<setw(10)<<sortemp1[i].exp;


  cout<<setw(15)<<sortemp1[i].age;


  cout<<endl;


 }


  cout<<"Press Any Key To Go Back";


 getch();



} }



Mini project supermarket billing system in c++ source code download


//program for creating bill in a supermarket

#include<iostream>

#include<windows.h>

#include<conio.h>

#include<fstream>

#include<cstring>

#include<cstdio>

#include<cstdlib>

#include<iomanip>

using namespace std;

//global variable declaration

int k=7,r=0,flag=0;

COORD coord = {0, 0};



void gotoxy(int x, int y)

{

 COORD coord;

 coord.X = x;

 coord.Y = y;

 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

struct date

{int mm,dd,yy;};



ofstream fout;

ifstream fin;



class item

{

int itemno;

char name[25];

date d;

public:

void add()

{

cout<<"\n\n\tItem No: ";

cin>>itemno;

cout<<"\n\n\tName of the item: ";

cin>>name;

//gets(name);

cout<<"\n\n\tManufacturing Date(dd-mm-yy): ";

cin>>d.mm>>d.dd>>d.yy;

}

void show()

{

cout<<"\n\tItem No: ";

cout<<itemno;

cout<<"\n\n\tName of the item: ";

cout<<name;

cout<<"\n\n\tDate : ";

cout<<d.mm<<"-"<<d.dd<<"-"<<d.yy;

}

void report()

{

gotoxy(3,k);

cout<<itemno;

gotoxy(13,k);

puts(name);

}

int retno()

{

    return(itemno);



}



};



class amount: public item

{

float price,qty,tax,gross,dis,netamt;

public:

void add();

void show();

void report();

void calculate();

void pay();

float retnetamt()

{

    return(netamt);

}

}amt;



void amount::add()

{

item::add();

cout<<"\n\n\tPrice: ";

cin>>price;

cout<<"\n\n\tQuantity: ";

cin>>qty;

cout<<"\n\n\tTax percent: ";

cin>>tax;

cout<<"\n\n\tDiscount percent: ";

cin>>dis;

calculate();

fout.write((char *)&amt,sizeof(amt));

fout.close();

}

void amount::calculate()

{gross=price+(price*(tax/100));

netamt=qty*(gross-(gross*(dis/100)));

}

void amount::show()

{fin.open("itemstore.dat",ios::binary);

fin.read((char*)&amt,sizeof(amt));

item::show();

cout<<"\n\n\tNet amount: ";

cout<<netamt;

fin.close();

}



void amount::report()

{item::report();

gotoxy(23,k);

cout<<price;

gotoxy(33,k);

cout<<qty;

gotoxy(44,k);

cout<<tax;

gotoxy(52,k);

cout<<dis;

gotoxy(64,k);

cout<<netamt;

k=k+1;

if(k==50)

{gotoxy(25,50);

cout<<"PRESS ANY KEY TO CONTINUE...";

getch();

k=7;

system("cls");

gotoxy(30,3);

cout<<" ITEM DETAILS ";

gotoxy(3,5);

cout<<"NUMBER";

gotoxy(13,5);

cout<<"NAME";

gotoxy(23,5);

cout<<"PRICE";

gotoxy(33,5);

cout<<"QUANTITY";

gotoxy(44,5);

cout<<"TAX";

gotoxy(52,5);

cout<<"DEDUCTION";

gotoxy(64,5);

cout<<"NET AMOUNT";

}

}



void amount::pay()

{show();

cout<<"\n\n\n\t\t*********************************************";

cout<<"\n\t\t                 DETAILS                  ";

cout<<"\n\t\t*********************************************";

cout<<"\n\n\t\tPRICE                     :"<<price;

cout<<"\n\n\t\tQUANTITY                  :"<<qty;

cout<<"\n\t\tTAX PERCENTAGE              :"<<tax;

cout<<"\n\t\tDISCOUNT PERCENTAGE         :"<<dis;

cout<<"\n\n\n\t\tNET AMOUNT              :Rs."<<netamt;

cout<<"\n\t\t*********************************************";

}



int main()

{

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout<<setprecision(2);

fstream tmp("temp.dat",ios::binary|ios::out);

menu:

system("cls");

gotoxy(25,2);

cout<<"Super Market Billing ";

gotoxy(25,3);

cout<<"===========================\n\n";

cout<<"\n\t\t1.Bill Report\n\n";

cout<<"\t\t2.Add/Remove/Edit Item\n\n";

cout<<"\t\t3.Show Item Details\n\n";

cout<<"\t\t4.Exit\n\n";

cout<<"\t\tPlease Enter Required Option: ";

int ch,ff;

float gtotal;

cin>>ch;

switch(ch)

{case 1:ss:

system("cls");

gotoxy(25,2);

cout<<"Bill Details";

gotoxy(25,3);

cout<<"================\n\n";

cout<<"\n\t\t1.All Items\n\n";

cout<<"\t\t2.Back to Main menu\n\n";

cout<<"\t\tPlease Enter Required Option: ";

int cho;

cin>>cho;

if(cho==1)

{system("cls");

gotoxy(30,3);

cout<<" BILL DETAILS ";

gotoxy(3,5);

cout<<"ITEM NO";

gotoxy(13,5);

cout<<"NAME";

gotoxy(23,5);

cout<<"PRICE";

gotoxy(33,5);

cout<<"QUANTITY";

gotoxy(44,5);

cout<<"TAX %";

gotoxy(52,5);

cout<<"DISCOUNT %";

gotoxy(64,5);

cout<<"NET AMOUNT";

fin.open("itemstore.dat",ios::binary);

if(!fin)

{cout<<"\n\nFile Not Found...";

goto menu;}

fin.seekg(0);

gtotal=0;

while(!fin.eof())

{fin.read((char*)&amt,sizeof(amt));

if(!fin.eof())

{amt.report();

gtotal+=amt.retnetamt();

ff=0;}

if(ff!=0) gtotal=0;

}gotoxy(17,k);

cout<<"\n\n\n\t\t\tGrand Total="<<gtotal;

getch();

fin.close();

}

if(cho==2)

{goto menu;}

goto ss;

case 2:

db:

system("cls");

gotoxy(25,2);

cout<<"Bill Editor";

gotoxy(25,3);

cout<<"=================\n\n";

cout<<"\n\t\t1.Add Item Details\n\n";

cout<<"\t\t2.Edit Item Details\n\n";

cout<<"\t\t3.Delete Item Details\n\n";

cout<<"\t\t4.Back to Main Menu ";

int apc;

cin>>apc;

switch(apc)

{

case 1:fout.open("itemstore.dat",ios::binary|ios::app);

amt.add();

cout<<"\n\t\tItem Added Successfully!";

getch();

goto db;



case 2:

int ino;

flag=0;

cout<<"\n\n\tEnter Item Number to be Edited :";

cin>>ino;

fin.open("itemstore.dat",ios::binary);

fout.open("itemstore.dat",ios::binary|ios::app);

if(!fin)

{cout<<"\n\nFile Not Found...";

goto menu;

}

fin.seekg(0);

r=0;

while(!fin.eof())

{fin.read((char*)&amt,sizeof(amt));

if(!fin.eof())

{int x=amt.item::retno();

if(x==ino)

{flag=1;

fout.seekp(r*sizeof(amt));

system("cls");

cout<<"\n\t\tCurrent Details are\n";

amt.show();

cout<<"\n\n\t\tEnter New Details\n";

amt.add();

cout<<"\n\t\tItem Details editted";

}

}r++;

}

if(flag==0)

{cout<<"\n\t\tItem No does not exist...Please Retry!";

getch();

goto db;

}

fin.close();

getch();

goto db;



case 3:flag=0;

cout<<"\n\n\tEnter Item Number to be deleted :";

cin>>ino;

fin.open("itemstore.dat",ios::binary);

if(!fin)

{cout<<"\n\nFile Not Found...";

goto menu;

}

//fstream tmp("temp.dat",ios::binary|ios::out);

fin.seekg(0);

while(fin.read((char*)&amt, sizeof(amt)))

{int x=amt.item::retno();

if(x!=ino)

tmp.write((char*)&amt,sizeof(amt));

else

{flag=1;}

}

fin.close();

tmp.close();

fout.open("itemstore.dat",ios::trunc|ios::binary);

fout.seekp(0);

tmp.open("temp.dat",ios::binary|ios::in);

if(!tmp)

{cout<<"Error in File";

goto db;

}

while(tmp.read((char*)&amt,sizeof(amt)))

fout.write((char*)&amt,sizeof(amt));

tmp.close();

fout.close();

if(flag==1)

cout<<"\n\t\tItem Succesfully Deleted";

else if (flag==0)

cout<<"\n\t\tItem does not Exist! Please Retry";

getch();

goto db;

case 4:

goto menu;

default: cout<<"\n\n\t\tWrong Choice!!! Retry";

getch();

goto db;

}

case 3:system("cls");

flag=0;

int ino;

cout<<"\n\n\t\tEnter Item Number :";

cin>>ino;

fin.open("itemstore.dat",ios::binary);

if(!fin)

{cout<<"\n\nFile Not Found...\nProgram Terminated!";

goto menu;

}

fin.seekg(0);

while(fin.read((char*)&amt,sizeof(amt)))

{int x=amt.item::retno();

if(x==ino)

{amt.pay();

flag=1;

break;

}

}

if(flag==0)

cout<<"\n\t\tItem does not exist....Please Retry!";

getch();

fin.close();

goto menu;

case 4:system("cls");

gotoxy(20,20);

cout<<"ARE YOU SURE, YOU WANT TO EXIT (Y/N)?";

char yn;

cin>>yn;

if((yn=='Y')||(yn=='y'))

{gotoxy(12,20);

system("cls");

cout<<"************************** THANKS **************************************";

getch();

exit(0);

}

else if((yn=='N')||(yn=='n'))

goto menu;

else{goto menu;}

default:cout<<"\n\n\t\tWrong Choice....Please Retry!";

getch();

goto menu;

}

return 0;

}