Popular Posts

6/25/2012

Student Management in C Programming

Download Here
Code Here :
============================================

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<process.h>
char menu1[6][30]={"Add","Show & Edit","Sort","Search","Delete"};
struct student{ char id[20];
char name[20];
char sex;
char birth[20];
char phonenum[20];
char room[20];
char department[50];
char fathername[50];
char fatherjob[50];
char mothername[50];
char motherjob[50];
char highschool[50];
char graduateyear[20];
char graduatelevel;
char placebirth[50];
char homeaddress[50];
     }stu[50]={NULL},temp,temp1[50];
char move='s';
int y=2,x=3,n=0,countstudent=0;
void menu();
void menu2();
void add();
void show();
void edit(int );
void search1(int );
void showlist(int);
void listsearch(int,int);
void temp1show(int );
void load();
void del();
void sort();
void bordersearch(int ,int );
void border(int );
void search();
void main()
{ menu();
}

void menu()
{
clrscr();
load();
do
{       cancel:
clrscr();
switch(tolower(move))
{
case 's': y++;
break;
case 'w': y--;
break;
case 13:        if(y==0)
add();
if(y==1)
show();
if(y==4)
del();
if(y==2)
sort();
if(y==3)
search();
clrscr();
break;
}
if(y>=5)
y=0;
if(y<0)
y=4;
for(int i=0;i<6;i++)
{ if(i==y)
{ gotoxy(x,i+2);
textcolor(RED);
cprintf("%s",menu1[i]);
}
else
{
gotoxy(x,i+2);
textcolor(WHITE);
cprintf("%s",menu1[i]);
}
gotoxy(20,20);
textcolor(WHITE);
FILE *daro1;
daro1=fopen("countstu.txt","r");
/* if(daro1==NULL)
{
puts("Can't open file");
exit(1);
}
*/  //It run this first if we run this "r" can't open. If we have delete the file countstu.txt.
fscanf(daro1," %d ",&countstudent);
gotoxy(2,29);
textcolor(YELLOW);
cprintf("Number of students=%d",countstudent);
fclose(daro1);
}
gotoxy(2,31);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,33);
textcolor(YELLOW);
cprintf("ESC=exit");
move=getch();
}while(move!=27);
clrscr();
gotoxy(10,10);
textcolor(YELLOW);
cprintf("Do you want to exit ?");
gotoxy(2,31);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
char exit[2][10]={"Yes","No"};
int x1=0,y1=12;
char ch='d';
do
{ switch(tolower(ch))
{ case 'a': x1--;
 break;
case 'd': x1++;
 break;
case 13:  if(x1==1)
 goto cancel;
 if(x1==0)
 goto exit;
}
if(x1>1)
x1=0;
if(x1<0)
x1=1;
int x2=12;
for(int i=0;i<2;i++)
{
if(i==x1)
{       gotoxy(x2,y1);
textcolor(RED);
cprintf("%s",exit[i]);
}
else
{ gotoxy(x2,y1);
textcolor(WHITE);
cprintf("%s",exit[i]);
}
x2=x2+5;
}
ch=getch();
}while(1);
exit:
}
void add()
{
clrscr();
textcolor(WHITE);
cprintf("Enter number of added students:");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
printf("%d",i+1);
printf("\tPlease fill all the information below");
printf("\tId=");
fflush(stdin);
gets(stu[i].id);
if(strcmp(stu[i].id,NULL)==0)
strcpy(stu[i].id,".");
printf("\tName=");
fflush(stdin);
gets(stu[i].name);
if(strcmp(stu[i].name,NULL)==0)
strcpy(stu[i].name,".");

printf("\tSex=");
fflush(stdin);
scanf("%c",&stu[i].sex);
if(stu[i].sex==NULL)
stu[i].sex='.';
printf("\tBirthday=");
fflush(stdin);
gets(stu[i].birth);
if(strcmp(stu[i].birth,NULL)==0)
strcpy(stu[i].birth,".");
printf("\tPhone number=");
fflush(stdin);
gets(stu[i].phonenum);
if(strcmp(stu[i].phonenum,NULL)==0)
strcpy(stu[i].phonenum,".");
printf("\tRoom=");
fflush(stdin);
gets(stu[i].room);
if(strcmp(stu[i].room,NULL)==0)
strcpy(stu[i].room,".");
printf("\tDepartment=");
fflush(stdin);
gets(stu[i].department);
if(strcmp(stu[i].department,NULL)==0)
strcpy(stu[i].department,".");
printf("\tFather's name=");
fflush(stdin);
gets(stu[i].fathername);
if(strcmp(stu[i].fathername,NULL)==0)
strcpy(stu[i].fathername,".");
printf("\tFather's job=");
fflush(stdin);
gets(stu[i].fatherjob);
if(strcmp(stu[i].fatherjob,NULL)==0)
strcpy(stu[i].fatherjob,".");
printf("\tMother's name=");
fflush(stdin);
gets(stu[i].mothername);
if(strcmp(stu[i].mothername,NULL)==0)
strcpy(stu[i].mothername,".");
printf("\tMother's job=");
fflush(stdin);
gets(stu[i].motherjob);
if(strcmp(stu[i].motherjob,NULL)==0)
strcpy(stu[i].motherjob,".");
printf("\tGraduated School=");
fflush(stdin);
gets(stu[i].highschool);
if(strcmp(stu[i].highschool,NULL)==0)
strcpy(stu[i].highschool,".");
printf("\tGraduated Level=");
fflush(stdin);
scanf("%c",&stu[i].graduatelevel);
if(stu[i].graduatelevel==NULL)
stu[i].graduatelevel='.';
printf("\tGraduated Year=");
fflush(stdin);
gets(stu[i].graduateyear);
if(strcmp(stu[i].graduateyear,NULL)==0)
strcpy(stu[i].graduateyear,".");
printf("\tPlace of birth:");
fflush(stdin);
gets(stu[i].placebirth);
if(strcmp(stu[i].placebirth,NULL)==0)
strcpy(stu[i].placebirth,".");
printf("\tHome address:");
fflush(stdin);
gets(stu[i].homeaddress);
if(strcmp(stu[i].homeaddress,NULL)==0)
strcpy(stu[i].homeaddress,".");
}
countstudent=countstudent+n;
FILE *daro,*daro1;
daro=fopen("123.txt","a");
daro1=fopen("countstu.txt","w");
if(daro==NULL||daro1==NULL)
{ puts("Can't open file");
getch();
exit(1);
}
fprintf(daro1," %d ",countstudent);
for(i=0;i<n;i++)
fprintf(daro," %s %s %c %s %s %s %s %s %s %s %s %s %c %s %s %s ",stu[i].id,stu[i].name,stu[i].sex,stu[i].birth,stu[i].phonenum,stu[i].room,stu[i].department,stu[i].fathername,stu[i].fatherjob,stu[i].mothername,stu[i].motherjob,stu[i].highschool,stu[i].graduatelevel,stu[i].graduateyear,stu[i].placebirth,stu[i].homeaddress);
fclose(daro);
fclose(daro1);

}
void show()
{       clrscr();
load();
char move='s';
int x,y;
do{
switch(tolower(move))
{ case 's':y++;
break;
case 'w':y--;
break;
case 13: edit(y);
break;
}
if(y>=countstudent)
y=0;
if(y<0)
y=countstudent-1;
clrscr();
menu2();
for(int i=0;i<countstudent;i++)
{
if(i==y)
{       gotoxy(1,(i+1)*2);
textcolor(RED);
showlist(i);
border(i);
}
else
{       gotoxy(1,(i+1)*2);
textcolor(WHITE);
showlist(i);
border(i);
}
}
gotoxy(2,48);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
move=getch();
}while(move!=27);
exit:
}
void load()
{ clrscr();
int i=0;
FILE *daro;
daro=fopen("123.txt","r");
menu2();
while(fscanf(daro," %s %s %c %s %s %s %s %s %s %s %s %s %c %s %s %s ",stu[i].id,stu[i].name,&stu[i].sex,stu[i].birth,stu[i].phonenum,stu[i].room,stu[i].department,stu[i].fathername,stu[i].fatherjob,stu[i].mothername,stu[i].motherjob,stu[i].highschool,&stu[i].graduatelevel,stu[i].graduateyear,stu[i].placebirth,stu[i].homeaddress)!=EOF)
i++;
fclose(daro);

}
void del()
{ int x1=1,y1=0 ;
char ch1='s';
clrscr();
do
{ clrscr();
textcolor(WHITE);
fflush(stdin);
menu2();
load();
switch(tolower(ch1))
{ case 'w': y1--;
 break;
case 's': y1++;
 break;
case 13:   clrscr();
 menu2();
 for(int i=y1;i<countstudent;i++)
 stu[i]=stu[i+1];
 countstudent--;
 FILE *daro1,*daro;
 daro=fopen("123.txt","w");
 daro1=fopen("countstu.txt","w");
 if(daro==NULL||daro1==NULL)
 { puts("Can't open file");
exit(1);
 }
 fprintf(daro1," %d ",countstudent);
 for(i=0;i<countstudent;i++)
 fprintf(daro," %s %s %c %s %s %s %s %s %s %s %s %s %c %s %s %s ",stu[i].id,stu[i].name,stu[i].sex,stu[i].birth,stu[i].phonenum,stu[i].room,stu[i].department,stu[i].fathername,stu[i].fatherjob,stu[i].mothername,stu[i].motherjob,stu[i].highschool,stu[i].graduatelevel,stu[i].graduateyear,stu[i].placebirth,stu[i].homeaddress);
 fclose(daro);
 fclose(daro1);
 break;

}
if(y1>=countstudent)
y1=0;
if(y1<0)
y1=countstudent-1;
if(x1>=7)
x1=0;
if(x1<0)
x1=6;
for(int i=0;i<countstudent;i++)
{       fflush(stdin);
if(i==y1)
{ textcolor(RED);
showlist(i);
border(i);
}
else
{
textcolor(WHITE);
showlist(i);
border(i);
}
}
gotoxy(2,44);
textcolor(YELLOW);
cprintf("ENTER=To delete file");
gotoxy(2,48);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
ch1=getch();
}while(ch1!=27);
exit:
}
void menu2()
{       textcolor(GREEN);
gotoxy(3,2);
cprintf("ID");
gotoxy(9,2);
cprintf("Name");
gotoxy(20,2);
cprintf("Sex");
gotoxy(27,2);
cprintf("Birthday");
gotoxy(40,2);
cprintf("Phone");
gotoxy(53,2);
cprintf("Room");
gotoxy(61,2);
cprintf("Department");

}
void showlist(int i)
{
gotoxy(3,(i+2)*2);
cprintf("%s",stu[i].id);
gotoxy(9,(i+2)*2);
cprintf("%s",stu[i].name);
gotoxy(20,(i+2)*2);
cprintf("%c",stu[i].sex);
gotoxy(27,(i+2)*2);
cprintf("%s",stu[i].birth);
gotoxy(40,(i+2)*2);
cprintf("%s",stu[i].phonenum);
gotoxy(53,(i+2)*2);
cprintf("%s",stu[i].room);
gotoxy(61,(i+2)*2);
cprintf("%s",stu[i].department);
}
void border(int i)
{       textcolor(BLUE);
gotoxy(2,2);
cprintf("³");
gotoxy(2,3);
cprintf("³");
gotoxy(2,1);
cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");
gotoxy(72,2);
cprintf("³");
gotoxy(72,3);
cprintf("³");

gotoxy(2,((i+2)*2)-1);
cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");

gotoxy(2,((i+2)*2)-1);
cprintf("³");
gotoxy(2,(i+2)*2);
cprintf("³");
gotoxy(2,((i+2)*2)+1);
cprintf("³");

gotoxy(8,2);
cprintf("³");
gotoxy(8,3);
cprintf("³");
gotoxy(8,((i+2)*2)-1);
cprintf("³");
gotoxy(8,(i+2)*2);
cprintf("³");
gotoxy(8,((i+2)*2)+1);
cprintf("³");

gotoxy(19,2);
cprintf("³");
gotoxy(19,3);
cprintf("³");
gotoxy(19,((i+2)*2)-1);
cprintf("³");
gotoxy(19,(i+2)*2);
cprintf("³");
gotoxy(19,((i+2)*2)+1);
cprintf("³");

gotoxy(26,2);
cprintf("³");
gotoxy(26,3);
cprintf("³");
gotoxy(26,((i+2)*2)-1);
cprintf("³");
gotoxy(26,(i+2)*2);
cprintf("³");
gotoxy(26,((i+2)*2)+1);
cprintf("³");

gotoxy(39,2);
cprintf("³");
gotoxy(39,3);
cprintf("³");
gotoxy(39,((i+2)*2)-1);
cprintf("³");
gotoxy(39,(i+2)*2);
cprintf("³");
gotoxy(39,((i+2)*2)+1);
cprintf("³");

gotoxy(52,2);
cprintf("³");
gotoxy(52,3);
cprintf("³");
gotoxy(52,((i+2)*2)-1);
cprintf("³");
gotoxy(52,(i+2)*2);
cprintf("³");
gotoxy(52,((i+2)*2)+1);
cprintf("³");

gotoxy(60,2);
cprintf("³");
gotoxy(60,3);
cprintf("³");
gotoxy(60,((i+2)*2)-1);
cprintf("³");
gotoxy(60,(i+2)*2);
cprintf("³");
gotoxy(60,((i+2)*2)+1);
cprintf("³");

gotoxy(72,((i+2)*2)-1);
cprintf("³");
gotoxy(72,(i+2)*2);
cprintf("³");
gotoxy(72,((i+2)*2)+1);
cprintf("³");

if(i==countstudent-1)
{ gotoxy(2,((i+2)*2)+1);
cprintf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");

}

}
void bordersearch(int i,int n)
{       textcolor(BLUE);
gotoxy(2,2);
cprintf("³");
gotoxy(2,3);
cprintf("³");
gotoxy(2,1);
cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");
gotoxy(72,2);
cprintf("³");
gotoxy(72,3);
cprintf("³");

gotoxy(2,((i+2)*2)-1);
cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");

gotoxy(2,((i+2)*2)-1);
cprintf("³");
gotoxy(2,(i+2)*2);
cprintf("³");
gotoxy(2,((i+2)*2)+1);
cprintf("³");

gotoxy(8,2);
cprintf("³");
gotoxy(8,3);
cprintf("³");
gotoxy(8,((i+2)*2)-1);
cprintf("³");
gotoxy(8,(i+2)*2);
cprintf("³");
gotoxy(8,((i+2)*2)+1);
cprintf("³");

gotoxy(19,2);
cprintf("³");
gotoxy(19,3);
cprintf("³");
gotoxy(19,((i+2)*2)-1);
cprintf("³");
gotoxy(19,(i+2)*2);
cprintf("³");
gotoxy(19,((i+2)*2)+1);
cprintf("³");

gotoxy(26,2);
cprintf("³");
gotoxy(26,3);
cprintf("³");
gotoxy(26,((i+2)*2)-1);
cprintf("³");
gotoxy(26,(i+2)*2);
cprintf("³");
gotoxy(26,((i+2)*2)+1);
cprintf("³");

gotoxy(39,2);
cprintf("³");
gotoxy(39,3);
cprintf("³");
gotoxy(39,((i+2)*2)-1);
cprintf("³");
gotoxy(39,(i+2)*2);
cprintf("³");
gotoxy(39,((i+2)*2)+1);
cprintf("³");

gotoxy(52,2);
cprintf("³");
gotoxy(52,3);
cprintf("³");
gotoxy(52,((i+2)*2)-1);
cprintf("³");
gotoxy(52,(i+2)*2);
cprintf("³");
gotoxy(52,((i+2)*2)+1);
cprintf("³");

gotoxy(60,2);
cprintf("³");
gotoxy(60,3);
cprintf("³");
gotoxy(60,((i+2)*2)-1);
cprintf("³");
gotoxy(60,(i+2)*2);
cprintf("³");
gotoxy(60,((i+2)*2)+1);
cprintf("³");

gotoxy(72,((i+2)*2)-1);
cprintf("³");
gotoxy(72,(i+2)*2);
cprintf("³");
gotoxy(72,((i+2)*2)+1);
cprintf("³");

if(i==n)
{ gotoxy(2,((i+2)*2)+1);
cprintf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");

}

}
void temp1show(int i)
{
gotoxy(3,(i+2)*2);
cprintf("%s",temp1[i].id);
gotoxy(9,(i+2)*2);
cprintf("%s",temp1[i].name);
gotoxy(20,(i+2)*2);
cprintf("%c",temp1[i].sex);
gotoxy(27,(i+2)*2);
cprintf("%s",temp1[i].birth);
gotoxy(40,(i+2)*2);
cprintf("%s",temp1[i].phonenum);
gotoxy(53,(i+2)*2);
cprintf("%s",temp1[i].room);
gotoxy(61,(i+2)*2);
cprintf("%s",temp1[i].department);
}

void listsearch(int i,int y)
{
gotoxy(3,(y+2)*2);
cprintf("%s",stu[i].id);
gotoxy(9,(y+2)*2);
cprintf("%s",stu[i].name);
gotoxy(20,(y+2)*2);
cprintf("%c",stu[i].sex);
gotoxy(27,(y+2)*2);
cprintf("%s",stu[i].birth);
gotoxy(40,(y+2)*2);
cprintf("%s",stu[i].phonenum);
gotoxy(53,(y+2)*2);
cprintf("%s",stu[i].room);
gotoxy(61,(y+2)*2);
cprintf("%s",stu[i].department);


}
void search()
{ clrscr();
char search[5][40]={"Search by Id","Search by Name","Search by phone number","Search by Department","Search by room"};
int x=11,y=0,i;
char ch='s',choice;
do
{
switch(tolower(ch))
{ case 'w': y--;
 break;
case 's': y++;
 break;
case 13:  clrscr();
 char search[20];
 load();
 clrscr();
 if(y==0)
 { printf("\n\nPlease enter 'Id' that you want to search:");
gets(search);
clrscr();

menu2();
int y2=0;
for(i=0;i<countstudent;i++)
if(strcmp(stu[i].id,search)==0)
{ listsearch(i,y2);
temp1[y2]=stu[i];
y2++;
getch();

}
search1(y2);

 }
 else if(y==1)
 { printf("\n\nPlease enter 'Name' that you want to search:");
gets(search);
clrscr();
menu2();
int y2=0;
for(i=0;i<countstudent;i++)
if(strcmp(stu[i].name,search)==0)
{ listsearch(i,y2);
temp1[y2]=stu[i];
y2++;

}
search1(y2);

 }
 else if(y==2)
 { printf("\n\nPlease enter 'Phone number' that you want to search:");
gets(search);
clrscr();
menu2();
int y2=0;
for(i=0;i<countstudent;i++)
if(strcmp(stu[i].phonenum,search)==0)
{ listsearch(i,y2);
temp1[y2]=stu[i];
y2++;

}
search1(y2);
 }
 else if(y==3)
 { printf("\n\nPlease enter 'Department' that you want to search:");
gets(search);
clrscr();
menu2();
int y2=0;
for(i=0;i<countstudent;i++)
if(strcmp(stu[i].department,search)==0)
{ listsearch(i,y2);
temp1[y2]=stu[i];
y2++;


}
search1(y2);
 }
 else
 { printf("\n\nPlease enter 'Room' that you want to search:");
gets(search);
clrscr();
menu2();
int y2=0;
for(i=0;i<countstudent;i++)
if(strcmp(stu[i].room,search)==0)
{ listsearch(i,y2);
temp1[y2]=stu[i];
y2++;

}
search1(y2);
 }

 clrscr();
 break;
}

if(y>=5)
y=0;
if(y<0)
y=4;
for(int  i=0;i<5;i++)

{
if(i==y)
{       gotoxy(x,(i+5)*2);
textcolor(RED);
cprintf("%s",search[i]);
}
else
{ gotoxy(x,(i+5)*2);
textcolor(WHITE);
cprintf("%s",search[i]);
}
}
gotoxy(2,48);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
ch=getch();
}while(ch!=27);

}
void sort()
{ clrscr();
char sort[5][40]={"Sort by Id","Sort by Name","Sort by phone number","Sort by Department","Sort by room"};
int x=11,y=0;
char ch='s',choice;
do
{
switch(tolower(ch))
{ case 'w': y--;
 break;
case 's': y++;
 break;
case 13:  gotoxy(2,20);
 textcolor(YELLOW);
 cprintf("Press 'A' to sort A->Z");
 gotoxy(2,22);
 textcolor(YELLOW);
 cprintf("Press 'Z' to sort Z->A");
 choice=getch();
 for(int i=0;i<countstudent;i++)
for(int j=i+1;j<countstudent;j++)
switch(tolower(choice))
{
 case 'a': switch(y)
{ case 0: if(strcmp(stu[i].id,stu[j].id)>0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 1: if(strcmp(stu[i].name,stu[j].name)>0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 2: if(atoi(stu[i].phonenum)>atoi(stu[j].phonenum))
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 3: if(strcmp(stu[i].department,stu[j].department)>0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 4: if(strcmp(stu[i].room,stu[j].room)>0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
}
break;
 case 'z': switch(y)
{ case 0: if(strcmp(stu[i].id,stu[j].id)<0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 1: if(strcmp(stu[i].name,stu[j].name)<0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 2: if(atoi(stu[i].phonenum)<atoi(stu[j].phonenum))
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 3: if(strcmp(stu[i].department,stu[j].department)<0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 4: if(strcmp(stu[i].room,stu[j].room)<0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
}
break;
}

FILE *daro;
daro=fopen("123.txt","w");
if(daro==NULL)
{
puts("Can't open file");
exit(1);
}
for(i=0;i<countstudent;i++)
fprintf(daro," %s %s %c %s %s %s %s %s %s %s %s %s %c %s %s %s ",stu[i].id,stu[i].name,stu[i].sex,stu[i].birth,stu[i].phonenum,stu[i].room,stu[i].department,stu[i].fathername,stu[i].fatherjob,stu[i].mothername,stu[i].motherjob,stu[i].highschool,stu[i].graduatelevel,stu[i].graduateyear,stu[i].placebirth,stu[i].homeaddress);
fclose(daro);
gotoxy(30,25);
textcolor(BLUE);
cprintf("Sorted has been completed.");
getch();
clrscr();
break;

}

if(y>=5)
y=0;
if(y<0)
y=4;
for(int  i=0;i<5;i++)

{
if(i==y)
{       gotoxy(x,(i+5)*2);
textcolor(RED);
cprintf("%s",sort[i]);
}
else
{ gotoxy(x,(i+5)*2);
textcolor(WHITE);
cprintf("%s",sort[i]);
}
}
gotoxy(2,48);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
ch=getch();
}while(ch!=27);
exit:
}
void search1(int y2)
{ char c='s';
int y1=0;
clrscr();
do{ switch(tolower(c))
{ case 'w': y1--;break;
case 's': y1++;break;
case 13: clrscr();
textcolor(WHITE);
cprintf("          Transcribe view");
cprintf("\n\n\r\rID:%s",temp1[y1].id);
cprintf("\n\n\r\rName:%s",temp1[y1].name);
cprintf("\n\n\r\rSex:%c",temp1[y1].sex);
cprintf("\n\n\r\rBirthday:%s",temp1[y1].birth);
cprintf("\n\n\r\rPhone number:%s",temp1[y1].phonenum);
cprintf("\n\n\r\rRoom:%s",temp1[y1].room);
cprintf("\n\n\r\rDepartment:%s",temp1[y1].department);
cprintf("\n\n\r\rFather's name:%s",temp1[y1].fathername);
cprintf("\n\n\r\rFather's job:%s",temp1[y1].fatherjob);
cprintf("\n\n\r\rMother's name:%s",temp1[y1].mothername);
cprintf("\n\n\r\rMother's job:%s",temp1[y1].motherjob);
cprintf("\n\n\r\rGraduated School:%s",temp1[y1].highschool);
cprintf("\n\n\r\rGraduated Level:%c",temp1[y1].graduatelevel);
cprintf("\n\n\r\rGraduated year:%s",temp1[y1].graduateyear);
cprintf("\n\n\r\rPlace of birth:%s",temp1[y1].placebirth);
cprintf("\n\n\r\rHome address:%s",temp1[y1].homeaddress);
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
getch();

clrscr();


break;



}
if(y1>=y2)
y1=0;
if(y1<0)
y1=y2-1;
menu2();
for(int k=0;k<=y2;k++)
{
if(y1==k)
{
textcolor(RED);
temp1show(k);
}
else
{
textcolor(WHITE);
temp1show(k);
}
bordersearch(k,y2);
gotoxy(2,48);
}

textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
c=getch();
clrscr();
}while(c!=27);

}
void edit(int y1)
{
clrscr();
char edit[16][50]={"Id:","Name:","Sex:","Birthday:","Phone number:","Room:","Department:","Father's name:","Father's job:","Mother's name:","Mother's job:","Graduated school:","Graduated level:","Graduated year:","Place of birth:","Home address:"};
char ch='s';
int y=0,i=0;
do
{
switch(ch)
{ case 'w': y--;
break;
case 's': y++;
break;
case 13:        clrscr();
for(int j=0;j<16;j++)
{ if(j==y)
{       gotoxy(2,(j+1)*2);
textcolor(RED);
cprintf("%s",edit[j]);
}
else
{       gotoxy(2,(j+1)*2);
textcolor(WHITE);
cprintf("%s",edit[j]);
}
if(j==0)
cprintf("%s",stu[y1].id);
if(j==1)
cprintf("%s",stu[y1].name);
if(j==2)
cprintf("%c",stu[y1].sex);
if(j==3)
cprintf("%s",stu[y1].birth);
if(j==4)
cprintf("%s",stu[y1].phonenum);
if(j==5)
cprintf("%s",stu[y1].room);
if(j==6)
cprintf("%s",stu[y1].department);
if(j==7)
cprintf("%s",stu[y1].fathername);
if(j==8)
cprintf("%s",stu[y1].fatherjob);
if(j==9)
cprintf("%s",stu[y1].mothername);
if(j==10)
cprintf("%s",stu[y1].motherjob);
if(j==11)
cprintf("%s",stu[y1].highschool);
if(j==12)
cprintf("%s",stu[y1].graduateyear);
if(j==13)
cprintf("%c",stu[y1].graduatelevel);
if(j==14)
cprintf("%s",stu[y1].placebirth);
if(j==15)
cprintf("%s",stu[y1].homeaddress);
}
gotoxy(2,(y+1)*2);
textcolor(WHITE);
cprintf("%s",edit[y]);
textcolor(RED);
if(y==0)
gets(stu[y1].id);
else if(y==1)
gets(stu[y1].name);
else if(y==2)
scanf("%c",&stu[y1].sex);
else if(y==3)
gets(stu[y1].birth);
else if(y==4)
gets(stu[y1].phonenum);
else if(y==5)
gets(stu[y1].room);
else if(y==6)
gets(stu[y1].department);
else if(y==7)
gets(stu[y1].fathername);
else if(y==8)
gets(stu[y1].fatherjob);
else if(y==9)
gets(stu[y1].mothername);
else if(y==10)
gets(stu[y1].motherjob);
else if(y==11)
gets(stu[y1].highschool);
else if(y==12)
gets(stu[y1].graduateyear);
else if(y==13)
scanf("%c",&stu[y1].graduatelevel);
else if(y==14)
gets(stu[y1].placebirth);
else//if(y==15)
gets(stu[y1].homeaddress);

FILE *daro;
daro=fopen("123.txt","w");
if(daro==NULL)
{ puts("Can't open file");
exit(1);
}
for(j=0;j<countstudent;j++)
fprintf(daro," %s %s %c %s %s %s %s %s %s %s %s %s %c %s %s %s ",stu[j].id,stu[j].name,stu[j].sex,stu[j].birth,stu[j].phonenum,stu[j].room,stu[j].department,stu[j].fathername,stu[j].fatherjob,stu[j].mothername,stu[j].motherjob,stu[j].highschool,stu[j].graduatelevel,stu[j].graduateyear,stu[j].placebirth,stu[j].homeaddress);
fclose(daro);

break;
}
if(y>=16)
y=0;
if(y<0)
y=15;
textcolor(WHITE);
gotoxy(10,1);
cprintf("Transcribe view");
for(i=0;i<16;i++)
{ if(i==y)
{       gotoxy(2,(i+1)*2);
textcolor(RED);
cprintf("%s",edit[i]);
}
else
{       gotoxy(2,(i+1)*2);
textcolor(WHITE);
cprintf("%s",edit[i]);
}
if(i==0)
cprintf("%s",stu[y1].id);
if(i==1)
cprintf("%s",stu[y1].name);
if(i==2)
cprintf("%c",stu[y1].sex);
if(i==3)
cprintf("%s",stu[y1].birth);
if(i==4)
cprintf("%s",stu[y1].phonenum);
if(i==5)
cprintf("%s",stu[y1].room);
if(i==6)
cprintf("%s",stu[y1].department);
if(i==7)
cprintf("%s",stu[y1].fathername);
if(i==8)
cprintf("%s",stu[y1].fatherjob);
if(i==9)
cprintf("%s",stu[y1].mothername);
if(i==10)
cprintf("%s",stu[y1].motherjob);
if(i==11)
cprintf("%s",stu[y1].highschool);
if(i==12)
cprintf("%s",stu[y1].graduateyear);
if(i==13)
cprintf("%c",stu[y1].graduatelevel);
if(i==14)
cprintf("%s",stu[y1].placebirth);
if(i==15)
cprintf("%s",stu[y1].homeaddress);

}
gotoxy(2,44);
textcolor(YELLOW);
cprintf("ENTER=To rename");
gotoxy(2,48);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
ch=getch();
clrscr();
}while(ch!=27);



}

// Don't forget to shared it to your friends ..!

Sample Worker Hours in C++


Code :
========================

#include<iostream.h>
#include<string.h>
class Worker{
  private:
char name[20];
int hour;
float rate;
  public:
Worker();
Worker(char *na,int h,float r);
void input();
void output();
float income();
char *getname(){return name;}
};

Worker::Worker(char *na,int h,float r){
strcpy(name,na);
hour=h;
rate=r;
}
Worker::Worker(){
strcpy(name,"No Name");
hour=0;
rate=0;
}
void Worker::input()
{
cout<<"Input Name:";cin.clear();cin.seekg(0);cin.get(name,20);
cout<<"Input hour:";cin>>hour;
cout<<"Input rate:";cin>>rate;
}
void Worker::output(){
cout<<name<<"\t"<<hour<<"\t"<<rate<<"\t"<<hour<<"\t"<<income()<<endl;
}
float Worker::income(){
return rate*hour;}
float total(Worker a[],int n)
{ float s=0;
for(int i=0;i<n;i++)
s=s+a[i].income();
return s;
}
Worker *maxincome(Worker a[],int n)
{
Worker *p;
p=&a[0];
for(int i=1;i<n;i++)
if (p->income()<a[i].income())
p=&a[i];
return p;
}
void main(){int i,n;
Worker a[3]={Worker("sok",56,3.5),Worker("San",85,3.5),Worker("Lyva",98,3.5)};
cout<<"Constructer name:"<<endl;
for(i=0;i<3;i++)
a[i].output();
cout<<"Input n:";cin>>n;
Worker *p=new Worker [n];
for(i=0;i<n;i++)
p[i].input();
cout<<"All Worker "<<endl;
for(i=0;i<n;i++)
p[i].output();
float s1=total(p,n);
cout<<"Sum of income: "<<s1<<endl;
Worker *ptr;
ptr=maxincome(p,n);
cout<<"The max worker income: "<<ptr->getname()<<endl;
delete[] p;
}
//Share it to your friends ..!


Sample Math C++


The following code :
===================================

#include<iostream.h>
#include<conio.h>
class Number{
private:
int x,y;
public:
void input(){
cout<<"Input X:";cin>>x;
cout<<"Input Y:";cin>>y;
}
void display(){
cout<<x<<"\t"<<y<<"\t"<<sum()<<"\t"<<pgcd()<<"\t"<<max()<<endl;
}
Number(){x=100;y=200;}
Number(int x1,int y1){
x=x1;
y=y1;
}
int sum(){
return (x+y);
}
  /* int pgcd(){
if(x==y)
return x;
else if(x>y){
x=x-y;
return pgcd();
}
else{
y=y-x;
return pgcd();
}
}*/
int pgcd(){
int a,b;
a=x; b=y;
while(a!=b){
if(a>b) a=a-b;
else b=b-a;
}
return a;
}
int max(){
if(x>y) return x;
else return y;
}
};
void sort(Number a[],int n){
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(a[i].sum()>a[j].sum()){
Number t=a[i];a[i]=a[j];a[j]=t;
}
}
Number *maxsum(Number a[],int n){
Number *p; p=&a[0];
for(int i=1;i<n;i++)
if(p->sum()<a[i].sum()) p=&a[i];
return p;
}
void main(){
int n,i;
Number a[6]={Number(1,2),Number(2,4),
Number(3,6),Number(4,8),
Number(5,10),Number(6,36)};
cout<<"============================================"<<endl;
cout<<"Initialization of Oject:\n";
cout<<"X"<<"\t"<<"Y"<<"\t"<<"SUM"<<"\t"<<"PGCD"<<"\t"<<"Max"<<endl;
for(i=0;i<6;i++)
a[i].display();
cout<<"============================================"<<endl;
cout<<"Input N Value:";cin>>n;
Number *b=new Number[n];
cout<<"Default Data:"<<endl;
cout<<"X"<<"\t"<<"Y"<<"\t"<<"SUM"<<"\t"<<"PGCD"<<"\t"<<"Max"<<endl;
for(i=0;i<n;i++)
b[i].display();
cout<<"============================================"<<endl;
cout<<"Input Data from Keyboard"<<endl ;
for(i=0;i<n;i++)
b[i].input();
cout<<"============================================"<<endl;
cout<<"Data Before sort:"<<endl;
cout<<"X"<<"\t"<<"Y"<<"\t"<<"SUM"<<"\t"<<"PGCD"<<"\t"<<"Max"<<endl;
for(i=0;i<n;i++)
b[i].display();
cout<<"============================================"<<endl;
cout<<"Data After sort:"<<endl;
sort(b,n);
cout<<"X"<<"\t"<<"Y"<<"\t"<<"SUM"<<"\t"<<"PGCD"<<"\t"<<"Max"<<endl;
for(i=0;i<n;i++)
b[i].display();
cout<<"============================================"<<endl;
Number *Ptr;
Ptr=maxsum(b,n);
cout<<"PGCD of MaxSum Data = "<<Ptr->pgcd()<<endl;  
}

6/24/2012

Sample Send Product C++



The following code :
=====================

#include<iostream.h>
#include<conio.h>
class SendProduct{
private:
float weight;
char location;
public:
void input(){
cout<<"Input Weight:";cin>>weight;
cout<<"Input Location(A,B,C):";cin>>location;
}
void display(){
cout<<weight<<"\t\t"<<location<<"\t\t"<<payment()<<"$"<<endl;
}
  float payment(){
if(location=='A'||location=='a')
return (weight*35/65);
else if(location=='B'||location=='b')
return (weight*25/90);
else
return (weight*45/20);
}
/*float payment(){
float s;
switch(location){
case 'A':
case 'a': s=(weight*35/65);break;
case 'B':
case 'b':   s=(weight*25/90);break;
case 'C':
case 'c':   s=(weight*45/20);break;
default :
cout<<"Input Location only A,B,C other Invalide"<<endl;
}
return s;
}*/
SendProduct(){weight=90;location='B';}
SendProduct(float w,char l){
weight=w;
location=l;}
SendProduct(SendProduct&send){
weight=send.weight;
location=send.location;
}
float getweight(){
return weight;
}
};
void sort(SendProduct a[],int n){
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(a[i].payment()>a[j].payment()){
SendProduct t=a[i];a[i]=a[j];a[j]=t;
}
}
void sort1(SendProduct a[],int n){
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(a[i].getweight()>a[j].getweight()){
SendProduct t=a[i];a[i]=a[j];a[j]=t;
}
}
SendProduct *max(SendProduct a[],int n){
SendProduct *P;
P=&a[0];
for(int i=1;i<n;i++)
if(P->payment()<a[i].payment())
P=&a[i];
return P;
}
SendProduct *min(SendProduct a[],int n){
SendProduct *P1;
P1=&a[0];
for(int i=1;i<n;i++)
if(P1->payment()>a[i].payment())
P1=&a[i];
return P1;
}
void main(){
int n,i;
SendProduct a[5]={SendProduct(10,'A'),SendProduct(20,'B'),
SendProduct(30,'C'),SendProduct(40,'A'),SendProduct(50,'C')};
cout<<"============================================"<<endl;
cout<<"Initialization of Oject:\n";
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
for(i=0;i<5;i++)
a[i].display();
cout<<"============================================"<<endl;
SendProduct b[25],*p,*p1;
cout<<"Input Data from Keyboard"<<endl ;
cout<<"Input N Value:";cin>>n;
for(i=0;i<n;i++)
b[i].input();
cout<<"============================================"<<endl;
cout<<"Data Before sort:"<<endl;
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
for(i=0;i<n;i++)
b[i].display();
cout<<"============================================"<<endl;
cout<<"Data After sort Payment:"<<endl;
sort(b,n);
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
for(i=0;i<n;i++)
b[i].display();
cout<<"============================================"<<endl;
cout<<"Data After sort Weight:"<<endl;
sort1(b,n);
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
for(i=0;i<n;i++)
b[i].display();
cout<<"============================================"<<endl;
p=max(b,n);
cout<<"the Bigest Product:"<<endl;
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
p->display();
   cout<<"============================================"<<endl;
p1=min(b,n);
cout<<"the Smallest Product:"<<endl;
cout<<"Weight"<<"\t\t"<<"Location"<<"\t"<<"Payment"<<endl;
p1->display();
}

Sample Array in C++


The following code :
=====================

#include<iostream.h>
#include<conio.h>
void inputarray(int a[],int n){
for(int i=0;i<n;i++){
cout<<"Enter a["<<i<<"]= ";
cin>>a[i];
}
}
void display(int a[],int n){
for(int i=0;i<n;i++)
cout<<a[i]<<"\t";
cout<<endl;
}
int search(int a[],int n,int x){
int index=-1;
for(int i=0;i<n;i++)
if(x==a[i]){
index=i;
break;
}
return index;;
}
void sort(int a[],int n){
int i,j,t;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j]){
t=a[i];a[i]=a[j];a[j]=t;
}
}
void main(){
int a[40],n,x,pos;
do{
clrscr();
cout<<"Input N : ";cin>>n;
inputarray(a,n);
display(a,n);
cout<<"The Result After sort"<<endl;
sort(a,n);
display(a,n);
cout<<"Input Data to search : ";cin>>x;
pos=search(a,n,x);
if(pos==-1) cout<<"search not found"<<endl;
else cout<<"The Result Search in index : "<<pos<<endl;
   getch();
}while(1);

}

Sample Count Day in month C++

code :
================

#include<iostream.h>
void main()
{
int day,month,year;
cout<<"input month:";
cin>>month;
cout<<"input year:";
cin>>year;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:day =31;break;
case 4:
case 6:
case 9:
case 11:day=30;break;
case 2:if(year%4==0)day=29;
else day=28; break;

cout<<day;
cout<<"This month is:"<<day<<"day";
defaul:cout<<"Please Try Again";
}
if(month>=1&&month<=12)

cout<<day;
}

Sample Book Info in C++

the following code :
======================

#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<process.h>
class Book{
private:
int id;
char bookname[30];
char author[30];
float price;
public:
void input();
void output();
 friend void search_update(Book t[],int n);
Book();
Book(int i, char *n, char *a, float p);
char *getbookname(){
return bookname;
}
float getprice(){
return price;}
int getid(){
return id;
}


 // ~Book(){cout<<" Destructor Function "<<endl;}
};
Book::Book(){
id=0;
strcpy(bookname,"Unknow");
strcpy(author,"Unknown");
price=0.0;
}
Book::Book(int i, char *n, char *a, float p){
id=i;
strcpy(bookname,n);
strcpy(author,a);
price=p;
}


void Book::input(){
cout<<"Input id:";
cin>>id;
cout<<"Input Bookname:";
cin.clear();cin.seekg(0,ios::end);cin.get(bookname,30);
cout<<"Input Author:";
cin.clear();cin.seekg(0,ios::end);cin.get(author,30);
cout<<"Input Price:";
cin>>price;
}
void Book::output(){
cout<<getid()<<"\t"<<getbookname()<<"\t"<<author<<"\t"<<getprice()<<"$"<<endl;
}

void sort(Book a[],int n)
{
Book t;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(a[i].getprice()<a[j].getprice())
{
t=a[i];
a[j]=a[i];
a[i]=t;
}
}
float total(Book a[],int n)
{
float s;
for(int i=0;i<n;i++)
s=0;
s=s+a[i].getprice();
return s;
}
void search_update(Book t[],int n)
{ char search[20];
int choice=-1;
cout<<"\nEnter bookname you want to update:"<<endl;
cin.clear();
cin.seekg(0,ios::end);
cin.get(search,20);
for(int i=0;i<n;i++)
if(strcmp(search,t[i].bookname)==0)
{ cout<<"Press 1 to update id"<<endl;
cout<<"Press 2 to update bookname"<<endl;
cout<<"Press 3 to update author"<<endl;
cout<<"Press 4 to update price"<<endl;
cin>>choice;
switch(choice)
{ case 1: cout<<"Enter new ID:";
cin>>t[i].id;
break;
case 2: cout<<"Enter new bookname:";
cin.clear();
cin.seekg(0,ios::end);
cin.get(t[i].bookname,30);
break;
case 3: cout<<"Enter new Author:";
cin.clear();
cin.seekg(0,ios::end);
cin.get(t[i].author,20);
break;
case 4: cout<<"Enter new Price:";
cin>>t[i].price;
break;
}
}
if(choice==-1)
cout<<"Not Found !!"<<endl;
}
void main(){
int i,n;

Book a[3]={Book(1,"Grammar","Dara",3.0),Book(2,"Computer","Net",2.0),Book(3,"Conversation","Sok",1.0)};
cout<<"Data of Initialize"<<endl;
for(i=0;i<3;i++)
a[i].output();
cout<<"Input n:";
cin>>n;
cout<<"=================================="<<endl;
Book *p=new Book[n];
for(i=0;i<n;i++)
p[i].input();
cout<<"=================================="<<endl;
cout<<"Original Data"<<endl;
for(i=0;i<n;i++)
p[i].output();
char ch;
d:
do{
cout<<"Press 1 for Search and update "<<endl;
cout<<"Press 2 for Sort "<<endl;
cout<<"Press 3 Total of Book Price"<<endl;
cout<<"Press 4 for Exit"<<endl;
cout<<"Menu Choice: "<<endl;
cin>>ch;

switch(ch)
{


case '1':
clrscr();
cout<<"Please Type Bookname for search and update"<<endl;
//cout<<"\nID\tTitle\tAuthor\tPrice";
for(i=0;i<n;i++)
p[i].output();
search_update(p,n);
for(i=0;i<n;i++)
p[i].output();
break;

case '2':

clrscr();
cout<<"After sort By Price "<<endl;
sort(a,n);
for(i=0;i<n;i++)

p[i].output();
break;

case '3':
clrscr();
//cout<<"All Total Price:"<<total(a[i],n)<<endl;

break;
case '4':
clrscr();

break;
case 's':exit(0);break;
default : cout<<"Invalid key Press againt"<<endl;

}
}
while (ch=='y' || ch=='Y');goto d;

}



Sample Circle In C++


The following code :
=================================

#include<iostream.h>
class circle{
private:
int X,Y;
float R;
public:
void input();
void output();
float Area();
float Perimeter();
};
void circle::input(){
cout<<"X:";cin>>X;
cout<<"Y:";cin>>Y;
cout<<"radius:";cin>>R;
}
void circle::output(){
cout<<X<<"\t"<<Y<<"\t"<<R<<"\t"<<Area()<<"\t"<<Perimeter()<<endl;
}
float circle::Area(){
return R*R*3.14;
}
float circle::Perimeter(){
return 2*R*3.14;
}
void main()
{
circle c1,c2,c3, max;
cout<<"Input Data of C1:"<<endl;
c1.input();
cout<<"Input Data of C2:"<<endl;
c2.input();
cout<<"Input Data of C3:"<<endl;
c3.input();

max=c1;
if(max.Area()<c2.Area()) max=c2;
if(max.Area()<c3.Area()) max=c3;
max.output();
cout<<"data of 3 Circle:"<<endl;
cout<<"X\ty\tRadius\tArea\tPerimeter"<<endl;
c1.output();
c2.output();
c3.output();
}



Sample Banking In C++


The following code :
===========================

#include<iostream.h>
#include<string.h>
#include<conio.h>
class Banking{
private:
int id;
char name[20];
float amount;
public:
Banking(){
id=0;strcpy(name,"Unknown");amount=0.00;
}
Banking(int i,char *n,float a){
id=i;strcpy(name,n);amount=a;
}
int getid(){return id;}
void input(){
cout<<"Input Id : ";cin>>id;
cout<<"Input Name : ";cin.clear();cin.seekg(0,ios::end);cin.get(name,20);
cout<<"Input Amount : ";cin>>amount;
}
void output(){
cout<<id<<"\t"<<name<<"\t"<<amount<<endl;
}
void deposit(float m){
amount+=m;
}
void withdraw(float m){
if(amount==0) cout<<"Sorry You can't Withdraw Money"<<endl;
else if(amount<=m) amount=0;
else amount-=m;
}
};
int search(Banking a[],int n, int id){
int index=-1;
for(int i=0;i<n;i++)
if(a[i].getid()==id){index=i;break;}
return index;
}
void main(){
int i,n,pos,id;
float m;
char ch;
do{
cout<<"Input Customer : ";cin>>n;
Banking *p=new Banking[n];
for(i=0;i<n;i++)
p[i].input();
cout<<"****************************"<<endl;
cout<<"All Customer Data"<<endl;
cout<<"ID"<<"\t"<<"Name"<<"\t"<<"Amount"<<endl;
for(i=0;i<n;i++)
p[i].output();
cout<<"****************************"<<endl;
cout<<"Input Position of customer's deposit:";cin>>id;
pos=search(p,n,id);
if(pos==-1) cout<<"Search Not Found"<<endl;
else{
cout<<"Input Deposit Money:";cin>>m;
p[pos].deposit(m);
}
cout<<"****************************"<<endl;
cout<<"Input Position of customer's withdraw:";cin>>id;
pos=search(p,n,id);
   if(pos==-1) cout<<"Search Not Found"<<endl;
else{
cout<<"Input Withdraw Money:";cin>>m;
p[pos].withdraw(m);
}
cout<<"****************************"<<endl;
cout<<"All Customer Data"<<endl;
cout<<"ID"<<"\t"<<"Name"<<"\t"<<"Amount"<<endl;
for(i=0;i<n;i++)
p[i].output();

ch=getch();
}while(ch!=27);
}