228
BANASTHALI PUBLIC SCHOOL CERTIFICATE Student’s Name – ANUBHAV RAWAT STD - XI sci. ROLL NO. This is to certify that the programs in this file have been performed and completed by the student satisfactorily to the best of my knowledge. MADE BY | ISHAN POPLI

My Programs

Embed Size (px)

Citation preview

Page 1: My Programs

BANASTHALI PUBLIC SCHOOL

CERTIFICATEStudent’s Name – ANUBHAV RAWAT

STD - XI sci.

ROLL NO. –

This is to certify that the programs in this

file have been performed and completed by the student satisfactorily to the best of

my knowledge. …………….

| ISHAN POPLI

Page 2: My Programs

BANASTHALI PUBLIC SCHOOL

Signature

DATED-

ACKNOWLEDGMENTThis project file could not have been completed without my computer science teacher !!!!!!!

Ms. VARINDER KAUR who not only served as my supervisor but also encouraged and challenged

| ISHAN POPLI

Page 3: My Programs

BANASTHALI PUBLIC SCHOOL

me throughout my academic program. She and my classmates guided me through the whole project, never accepting less than my best efforts. I thank them all.

INTRODUCTIONThis project is a part of C++ final term exams of class Xi .In this project, there are lots of program based on our syllabus. All the programs are taken or are related to our ncert book “computer science” written by sumita arora.

| ISHAN POPLI

Page 4: My Programs

BANASTHALI PUBLIC SCHOOL

The project contains all the basic programs of using c++ such as arrays, calculator, conversions and many more.

In this file all the source codes are present that I was instructed to present .I hope the reader would like the format and presentation of this project file.

INDEXSR NO.

TOPIC DATE

1 Leap Year 14/7/20102 Multiplication Table 19/7/20103 Check for Odd or

Even 20/7/2010

4 Week Day 30/7/2010 | ISHAN POPLI

Page 5: My Programs

BANASTHALI PUBLIC SCHOOL

5 No. of Digits 31/7/20106 Greatest of 3 Nos. 01/8/20107 No. of Vowels,

Characters in a String

08/8/2010

8 Calculator 10/8/20109 Greatest of 3 Nos.

using Conditional 14/8/2010

10 Bonus, Commission And Gross Salary Of A Salesman

16/8/2010

11 Search ( Linear & Binary )

3/9/2010

12 Multiplication of Matrix

18/9/2010

13 No Days, Weeks in a Year

22/9/2010

14 Celsius To Fahrenheit

14/9/2010

15 Triangle Area 25/9/201016 Sqrt & Power 14/10/201

| ISHAN POPLI

Page 6: My Programs

BANASTHALI PUBLIC SCHOOL

017 Quotient &

Remainder 24/10/2010

18 Largest Element Of An Array

03/11/2010

19 Search (linear & binary)

09/11/2010

20 Array 18/11/2010

21 Fibonacci Series 19/11/2010

22 Print n Prime Nos. 23/11/2010

23 Armstrong Number 25/11/2010

24 No. of repetitions of a digit

27/11/2010

25 Insert & Delete from Array

02/12/2010

26 Palindrome Or Not 17/12/2010

| ISHAN POPLI

Page 7: My Programs

BANASTHALI PUBLIC SCHOOL

27 Sum Of First N Natural Numbers

29/12/2010

28 Telephone directory(using structure)

05/01\2011

29 Teachers Remarks 30 Bibliography

Print n Prime Nos.

#include<iostream.h> #include<conio.h> void main() { clrscr(); int n=0,i,l,j,k=2,a=0; cout<<"Enter Limit"<<endl; cin>>l; while(n<l) { j=2; a=0;

| ISHAN POPLI

Page 8: My Programs

BANASTHALI PUBLIC SCHOOL

while(j<=k/2) { if(k%j==0) a=a+1; j++; } if(a==0) { cout<<endl<<k<<endl; } else l++; n++; k++; } getch(); }

RESULTS

Enter Limit

10

THE N PRIME NOS ARE

2

3

5

7

| ISHAN POPLI

Page 9: My Programs

BANASTHALI PUBLIC SCHOOL

11

13

17

19

23

29

No. of repetitions of a digit

#include<iostream.h> #include<conio.h> #include<string.h> void main() { clrscr(); int i,j,c=1,l; char a[100]; cout<<"Enter Array"<<endl; cin.getline(a,100); l=strlen(a); for(i=0;i<l;i++)

| ISHAN POPLI

Page 10: My Programs

BANASTHALI PUBLIC SCHOOL

{ c=1; for(j=i+1;j<l;j++) { if(a[i]==a[j]) { c=c+1; a[j]=' '; } } if(a[i]!=' ') cout<<"Element"<<a[i]<<"is present"<<c<<"times"<<endl; } getch(); }

RESULTS

Enter Array

9227393662

Element9is present2times

Element2is present3times

Element7is present1times

Element3is present2times

Element6is present2times | ISHAN POPLI

Page 11: My Programs

BANASTHALI PUBLIC SCHOOL

Array

#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,n,g,j,a[100],b[100][100]; cout<<"Enter Limit"<<endl; cin>>n; cout<<"Enter "<<endl; for(g=0;g<n;g++) cin>>a[g]; for(i=0;i<n;i++) {

| ISHAN POPLI

Page 12: My Programs

BANASTHALI PUBLIC SCHOOL

for(j=n-1;j>=0;j--) { b[i][j]=a[j]; } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i>j) b[i][j]=0; } } for(i=0;i<n;i++) { cout<<endl; for(j=0;j<n;j++) { cout<<b[i][j]<<" "; } } getch(); }

RESULTS

Enter Limit

5

Enter

9

| ISHAN POPLI

Page 13: My Programs

BANASTHALI PUBLIC SCHOOL

8

7

6

5

9 8 7 6 5

0 8 7 6 5

0 0 7 6 5

0 0 0 6 5

0 0 0 0 5

Calculator

#include<iostream.h> #include<conio.h> void main() { int a,b,s,op; clrscr(); cout<<"\t\t\t\tCALCULATOR\n\t\t\tAll Rights Reserved\a\n"; cout<<"\t\tIllegal Copying is punishable\a\nEnter Number A\a :"; cin>>a; cout<<"\nEnter Number B\a :"; cin>>b; cout<<endl<<"\t\t1.Addition\n\t\t2.Subtraction\n\t\t"; cout<<"3.Division(Whole Numbers only)\n\t\t4.Multiplication\n\t\t";

| ISHAN POPLI

Page 14: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"5.Square of A\n\t\t6.Square of B\n\t\t"; cout<<"7.'A'square - 'B'square\n\t\t8.'A'square + 'B'square\n\t\t"; cout<<"9.'A'square * 'B'square\n\t\t10.'A'square / 'B'square(whole numbers only"; cout<<"\n\t\t11.'A'cube\n\t\t12.'B'cube"; cout<<endl<<" Enter Choice\a :"; cin>>op; switch(op) { case 1:s=a+b; cout<<"Sum = \a"<<s; break; case 2:s=a-b; cout<<"Difference =\a "<<s; break; case 3:s=a/b; cout<<"Quotient =\a "<<s; break; case 4:s=a*b; cout<<"Product =\a "<<s; break; case 5:s=a*a; cout<<"Square =\a "<<s; break; case 6:s=b*b; cout<<"Square =\a "<<s; break; case 7:s=(a*a)-(b*b); cout<<"Answer =\a "<<s; break; case 8:s=(a*a)+(b*b); cout<<"Answer =\a "<<s; break;

| ISHAN POPLI

Page 15: My Programs

BANASTHALI PUBLIC SCHOOL

case 9:s=(a*a)*(b*b); cout<<"Answer =\a "<<s; break; case 10:s=(a*a)/(b*b); cout<<"Answer =\a "<<s; break; case 11:s=a*a*a; cout<<"Answer =\a "<<s; break; case 12:s=b*b*b; cout<<"Answer =\a "<<s; break; default:cout<<"Invalid\a Choice\a"; } getch(); }

RESULTS

Enter Number A :23

Enter Number B :23

1.Addition

2.Subtraction

3.Division(Whole Numbers only)

4.Multiplication

| ISHAN POPLI

Page 16: My Programs

BANASTHALI PUBLIC SCHOOL

5.Square of A

6.Square of B

7.'A'square - 'B'square

8.'A'square + 'B'square

9.'A'square * 'B'square

10.'A'square / 'B'square(whole numbers only

11.'A'cube

12.'B'cube

Enter Choice :4

Product = 529

Prime Or Not

#include<iostream.h> #include<conio.h> void main() { clrscr(); int p=0,i,n; cout<<"Enter the no :"<<endl; cin>>n; for(i=2;i<=(n/2);i++) { if(n%i==0) p=1; }

| ISHAN POPLI

Page 17: My Programs

BANASTHALI PUBLIC SCHOOL

if(p==0) cout<<"Prime"; else if (p==1) cout<<"Not Prime"; getch(); }

RESULTS

Enter the no :

3

Prime

No. of Digits

#include<iostream.h> #include<conio.h> void main() { clrscr(); int s,n,i,d; cout<<"Enter a number"<<endl; cin>>n; for(i=0;n>0;i++) { n=n/10; }

| ISHAN POPLI

Page 18: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<i; getch(); }

RESULTS

Enter a number

223456

5

Greatest of 3 Nos.

#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,c,bi; cout<<"Enter 3 nos"<<endl; cin>>a>>b>>c; bi=a>b?(a>c?a:c):((b>c)?b:c); cout<<"Greatest = "<<bi; getch(); }

| ISHAN POPLI

Page 19: My Programs

BANASTHALI PUBLIC SCHOOL

RESULTS

Enter 3 nos

25

45

73

Greatest = 73

No Days, Weeks in a Year

#include<iostream.h> #include<conio.h> void main() { clrscr(); int d,y,w,da; cout<<"Enter the no of Days"<<endl; cin>>d; y=d/365; w=((y%365)/7); da=((y%365)%7); cout<<y<<"Yrs "<<w<<"Weeks"<<da<<"Days";

| ISHAN POPLI

Page 20: My Programs

BANASTHALI PUBLIC SCHOOL

getch(); }

RESULTS

Enter the no of Days

34653874

-40Yrs -5Weeks-5Days

Greatest of 3 Nos. using Conditional

#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,by; cout<<"Enter 2 nos"<<endl; cin>>a>>b; by=(a>b)?a:b; cout<<"Greatest = "<<by; getch(); }

| ISHAN POPLI

Page 21: My Programs

BANASTHALI PUBLIC SCHOOL

RESULTS

Enter 2 nos

14

23

Greatest = 23

Insert & Delete from Array

#include<iostream.h> #include<conio.h> void main() { clrscr(); int n,x,c=0,e,ch,i,a[50],j; cout<<"Enter Array lim"<<endl; cin>>n; cout<<"Enter array"<<endl; for(i=0;i<n;i++) cin>>a[i]; cout<<"Enter Choice 1:Deletion 2Insertion"<<endl; cin>>ch;

| ISHAN POPLI

Page 22: My Programs

BANASTHALI PUBLIC SCHOOL

switch(ch) { case 1: cout<<"Enter to be deleted"<<endl; cin>>x; for(i=0;i<n;i++) { if(a[i]==x) {c++; for(j=i;j<n;j++) { a[j]=a[j+1]; } } } if(c==0) cout<<"ENP"<<endl; for(i=0;i<n-c;i++) cout<<a[i]<<endl; break;

case 2: cout<<"Enter What & Where to be inserted"<<endl; cin>>e>>x; for(i=n;i>=x;i--) a[i]=a[i-1]; a[x-1]=e; for(i=0;i<=n;i++) cout<<a[i]<<endl; break; }

| ISHAN POPLI

Page 23: My Programs

BANASTHALI PUBLIC SCHOOL

getch(); }

RESULTS

Enter Array lim

5

Enter array

5

4

3

2

1

Enter Choice 1:Deletion 2Insertion

2

Enter What & Where to be inserted

6

3

5

4

| ISHAN POPLI

Page 24: My Programs

BANASTHALI PUBLIC SCHOOL

6

3

2

1

No. of Vowels, Characers in a String

#include<iostream.h> #include<conio.h> #include<ctype.h> #include<stdio.h> #include<string.h> void main() { int i,j=0,l=0,u,v=0,s=0; char st[50]; clrscr(); cout<<"Enter the string"<<endl; gets(st);

| ISHAN POPLI

Page 25: My Programs

BANASTHALI PUBLIC SCHOOL

l=strlen(st); for(j=0;j<l;j++) { if((st[j]== ' ')) s=s+1; if((st[j]=='a')||(st[j]=='e')||(st[j]=='o')||(st[j]=='i')||(st[j]=='u')||(st[j]=='A')||(st[j]=='E')||(st[j]=='O')||(st[j]=='I')||(st[j]=='U')) v=v+1; } cout<<"No of Words = "<<s+1<<endl<<"No Space = "<<s<<endl<<"No of Vowels ="<<v<<endl<<"No of Characters ="<<l-s; getch(); }

RESULTS

Enter the string

hello mam...! this project is made by ishan popli.

No of Words = 9

No Space = 8

No of Vowels =13

No of Characters =42

| ISHAN POPLI

Page 26: My Programs

BANASTHALI PUBLIC SCHOOL

Search ( Linear & Binary )

#include<iostream.h> #include<conio.h> void main() { clrscr(); int ch,l,u,mid,c=0,i,n,e,a[50]; cout<<"Enter the limit"<<endl; cin>>n; cout<<endl<<"Enter the elemnts"<<endl; for(i=0;i<n;i++) { cout<<endl; cin>>a[i];

| ISHAN POPLI

Page 27: My Programs

BANASTHALI PUBLIC SCHOOL

} cout<<"Enter the element to be searched for"<<endl; cin>>e; cout<<"Enter Your Choice 1:Linear 2:Binary Search"; cin>>ch; switch(ch) { case 1 : for(i=0;i<n;i++) { if(a[i]==e) cout<<endl<<"Element is at "<<i+1<<" Position"; c=c+1; } if (c==0) cout<<"Element Not Present"; break; case 2: c=0; l=0; u=n-1; while(l<u) { mid=(l+u)/2; if (a[mid]==e) { cout<<"Element is at "<<mid+1<<" Position "<<endl; c++; break; } if(e<a[mid]) u=mid-1;

| ISHAN POPLI

Page 28: My Programs

BANASTHALI PUBLIC SCHOOL

if (e>a[mid]) l=mid+1; } if (c==0) cout<<"Element not Present"<<endl; break; default : cout<<"Wrong Choice"<<endl; break; } getch(); }

RESULTS

Enter the limit

5

Enter the elemnts

4

7

| ISHAN POPLI

Page 29: My Programs

BANASTHALI PUBLIC SCHOOL

4

3

2

Enter the element to be searched for

2

Enter Your Choice 1:Linear 2:Binary Search1

Element is at 5 Position

Fibonacci Series

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long int i,x=0,y=1,s;

| ISHAN POPLI

Page 30: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<x<<endl<<y<<endl;

for(i=3;i<=10;i++)

{

s=x+y;

cout<<s<<endl;

x=y;

y=s;

}

getch();

}

RESULTS

0

1

1

2

3

5

8 | ISHAN POPLI

Page 31: My Programs

BANASTHALI PUBLIC SCHOOL

13

21

34

Sqrt & Power

#include<iostream.h> #include<math.h> #include<conio.h> void main() { clrscr(); int n,r; cout<<"Enter no"<<endl; cin>>n; if((n>0)&&(n%2==1)) r = sqrt (n); else if((n<0))

| ISHAN POPLI

Page 32: My Programs

BANASTHALI PUBLIC SCHOOL

r=pow(n,5); cout<<"Result ="<<r; getch(); }

RESULTS

Enter no

625

Result =25

Quotient & Remainder

#include<iostream.h> #include<conio.h> void main() { clrscr(); int q,r,a,b; cout<<"Enter 2 nos :"<<endl; cin>>a>>b; q=a/b; r=a%b; cout<<"Quotient = "<<q<<endl<<"Remainder = "<<r;

| ISHAN POPLI

Page 33: My Programs

BANASTHALI PUBLIC SCHOOL

getch(); }

RESULTS

Enter 2 nos :

1000

5

Quotient = 200

Remainder = 0

Multiplication Table

#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,n,a; cout<<"Enter the no upto which u want table"<<endl; cin>>a; for(i=1;i<=10;i++) cout<<i<<"x"<<a<<"="<<a*i<<endl;

| ISHAN POPLI

Page 34: My Programs

BANASTHALI PUBLIC SCHOOL

getch(); }

RESULTS

Enter the no upto which u want table

12

1x12=12

2x12=24

3x12=36

4x12=48

5x12=60

6x12=72

7x12=84

8x12=96

9x12=108

10x12=120

Check for Odd or Even

#include<iostream.h> #include<conio.h> void main() {

| ISHAN POPLI

Page 35: My Programs

BANASTHALI PUBLIC SCHOOL

clrscr(); int e; cout<<"Enter a no :"<<endl; cin>>e; if (e==0) cout<<"The no is neither even or odd "<<endl; if (e%2==0) cout<<"The no is even"<<endl; else cout<<"The no is odd "<<endl; getch(); }

RESULTS

Enter a no :

34

The no is even

Celcius To Farenheit

#include<iostream.h> #include<conio.h> void main() { clrscr(); float k,c; cout<<"Enter the temp in Celsius :"; cin>>c; k=(9/5)*c+32;

| ISHAN POPLI

Page 36: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"Temperature in Farenheit = "<<k; getch(); }

RESULTS

Enter the temp in Celsius :23

Temperature in Farenheit = 55

Triangle Area

#include<iostream.h> #include<conio.h> #include<math.h> void main() { clrscr(); float a,b,c,p,ar; cout<<"Enter 3 sides :"<<endl; cin>>a>>b>>c;

| ISHAN POPLI

Page 37: My Programs

BANASTHALI PUBLIC SCHOOL

p=a+b+c; ar=sqrt(p*(p-a)*(p-b)*(p-c)); cout<<"Area :"<<ar; getch(); }

RESULTS

Enter 3 sides :

12

23

34

Area :2516.372314

Palindrome Or Not

#include<iostream.h>#include<conio.h>void main(){int n, num, digit, rev=0;cout<<”\n input the no.(max.32767):”;cin>>num;n=num;do

| ISHAN POPLI

Page 38: My Programs

BANASTHALI PUBLIC SCHOOL

{digit=num%10;rev=(rev*10)+digit; num=num/10;}while(num!=0);cout<<”the reverse of the number is:”<<rev<<”\n”;if(n==rev)cout<<”the no is palindrome”;elsecout<<”\n the no. is not a palindrome”;getch();}RESULTS

input the no.(max.32767):12321

the reverse of the number is:12321

the no is palindrome

Multiplication of Matrix

#include<iostream.h> #include<conio.h> class matrix { int x[10][10]; int m,n; public: void input();

| ISHAN POPLI

Page 39: My Programs

BANASTHALI PUBLIC SCHOOL

void output(); void multiply(matrix,matrix); }; void matrix::input() { cout<<"Enter Row"<<endl; cin>>m; cout<<"Enter Column"<<endl; cin>>n; cout<<"Matrix"<<endl; for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { cin>>x[i][j]; } } } void matrix :: output() { for(int i=0;i<m;i++) { cout<<endl; for(int j=0;j<n;j++) { cout<<x[i][j]<<" "; } } }

void matrix :: multiply(matrix m1, matrix m2) {

| ISHAN POPLI

Page 40: My Programs

BANASTHALI PUBLIC SCHOOL

for(int i=0;i<m1.m;i++) { for(int j=0;j<m2.n;j++) { x[i][j]=0; for(int k=0;k<m1.n;k++) { x[i][j]=x[i][j] +( m1.x[i][k] * m2.x[k][j]); m=m1.m; n=m2.n; } } } } void main() { clrscr(); matrix m1,m2,m3; m1.input(); m2.input(); m3.multiply(m1,m2); m3.output(); getch(); }

RESULTS

Enter Row2Enter Column2Matrix122334

| ISHAN POPLI

Page 41: My Programs

BANASTHALI PUBLIC SCHOOL

45Enter Row2Enter Column2Matrix123445561179 16962433 3676

Largest Element Of An Array

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

{clrscr(); | ISHAN POPLI

Page 42: My Programs

BANASTHALI PUBLIC SCHOOL

int array[10]={1,0,6,4,-5,3,-1,3,9,8};

cout<<"\n The contents of the array are : "<<endl;

cout<<"\n Elements :"<<"\t\t Value:"<<endl;

for(int count_1=0;count_1<10;count_1++)

{

cout<<"\t"<<" array ["<<count_1<<"]"<<"\t\t"<<array[count_1]

<<endl;

}

int largest_number=array[0];

for(int count_2=0;count_2<10;count_2++)

{

if(array[count_2]>largest_number)

largest_number=array[count_2];

}cout<<"\n The largest number of the array is = "<<largest_number<<endl;

getch();

}

RESULTS

The contents of the array are :

Elements : Value: | ISHAN POPLI

Page 43: My Programs

BANASTHALI PUBLIC SCHOOL

array [0] 1

array [1] 0

array [2] 6

array [3] 4

array [4] -5

array [5] 3

array [6] -1

array [7] 3

array [8] 9

array [9] 8

The largest number of the array is = 9

Armstrong Number

# include <iostream.h>

# include <conio.h>

# include <math.h>

void main ()

{ clrscr();

| ISHAN POPLI

Page 44: My Programs

BANASTHALI PUBLIC SCHOOL

int a,b=0,sum=0;

long int n;

cout<<"ENter the NO. : ";

cin>>n;

for(;n>0;)

//counts the digits

{ a=n%10;

n=n/10;

b++;

}

for(;n>0;)

{ a=n%10;

sum=sum+pow(a,b);

n=n/10;

}

if(sum==n)

{ cout<<"IT IS AN ARMSTRONG NUMBER...";

getch();

} | ISHAN POPLI

Page 45: My Programs

BANASTHALI PUBLIC SCHOOL

else

{ cout<<"IT IS NOT AN ARMSTRONG NUMBER...";

getch();

}

}

RESULTS

ENter the NO. : 23

IT IS AN ARMSTRONG NUMBER...

Leap Year

#include<iostream.h>

#include<conio.h>

int year;

void main()

{

cout << "Please enter the current year: ";

| ISHAN POPLI

Page 46: My Programs

BANASTHALI PUBLIC SCHOOL

cin >> year;

switch (year % 4)

{

case 0:

if (year % 100 == 0)

{

cout << "\"Century\" years aren't leap years.";

if (year % 400 == 0)

{

cout << "..unless divisible by 400.\n";

cout << year << "'s a leap year!" << endl;

}

else

cout << " " << year << " isn't a leap year." << endl;

}

else

cout << year << " is a leap year!" << endl;

break;

case 3: | ISHAN POPLI

Page 47: My Programs

BANASTHALI PUBLIC SCHOOL

cout << "Next year is a leap year. "; // Fall through...

default:

cout << year << " isn't a leap year." << endl;

break;

}

getch();

}

RESULTS

Please enter the current year: 2011

Next year is a leap year. 2011 isn't a leap year.

Sum Of First N Natural Numbers

#include<iostream.h>

#include<stdio.h>

#include<conio.h>

void main()

{

int s=0,i=1,n;

clrscr();

printf("Enter a value ");

| ISHAN POPLI

Page 48: My Programs

BANASTHALI PUBLIC SCHOOL

scanf("%d",&n);

while(i <= n)

{

s=s+i;

i=i+1;

}

printf("Sum of first %d natural numbers is %d",n,s);

getch();

}

RESULTS

Enter a value 23

Sum of first 23 natural numbers is 276

Bonus, Commission And Gross Salary Of A Salesman

#include<stdio.h>

#include<conio.h>

#define BASE_SALARY 1500.00

#define BONUS_RATE 200.00

#define COMMISSION 0.02

void main() | ISHAN POPLI

Page 49: My Programs

BANASTHALI PUBLIC SCHOOL

{

int quantity;

float gross_salary,price;

float bonus,commission;

clrscr();

printf("Input number sold and price\n");

scanf("%d %f",&quantity,&price);

bonus = BONUS_RATE * quantity;

commission = COMMISSION * quantity * price;

gross_salary = BASE_SALARY + bonus + commission;

printf("\n");

printf("Bonus = %6.2f\n",bonus);

printf("Commission = %6.2f\n",commission);

printf("Gross-slary = %6.2f\n",gross_salary);

| ISHAN POPLI

Page 50: My Programs

BANASTHALI PUBLIC SCHOOL

getch();

}

RESULTS

Input number sold and price

2559

2345

Bonus = 511800.00

Commission = 120017.10

Gross-slary = 633317.12

Week Day

#include<iostream.h>

#include<conio.h>void main(){int iDay;cout<<"Enter the day of the week:";cin>>iDay;switch(iDay){case 1:{cout<<"The day is Sunday"<<endl; //The value in variable iDay is one

| ISHAN POPLI

Page 51: My Programs

BANASTHALI PUBLIC SCHOOL

break;}case 2:{cout<<"The day is Monday"<<endl; //The value in variable iDay is Twobreak;}case 3:{cout<<"The day is Tuesday"<<endl; //The value in variable iDay is threebreak;}case 4:{cout<<"The day is Wednesday"<<endl; //The value in variable iDay is fourbreak;}case 5:{cout<<"The day is Thrusday"<<endl; //The value in variable iDay is fivebreak;}case 6:{cout<<"The day is Friday"<<endl; //The value in variable iDay is sixbreak;}case 7:{cout<<"The day is Saturday"<<endl; //The value in variable iDay is sevenbreak;}

| ISHAN POPLI

Page 52: My Programs

BANASTHALI PUBLIC SCHOOL

default:{cout<<"You have entered the wrong day"<<endl;break;}}

Getch(); }

RESULTS

Enter the day of the week:5

The day is Thrusday

Telephone directory(using structure) #include<iostream.h>#include<conio.h>

struct name{char first[50],mid[50],last[50];};

struct phone{char area[50],exch[50];long no;};

class rec{name n;phone p;

| ISHAN POPLI

Page 53: My Programs

BANASTHALI PUBLIC SCHOOL

public :void reci();void disp();};

void rec::reci(){clrscr();cout<<"Enter First Name :";cin>>n.first;cout<<endl;cout<<"Enter Mid Name :";cin>>n.mid;cout<<endl;cout<<"Enter Last Name :";cin>>n.last;cout<<endl;cout<<"Enter Area :";cin>>p.area;cout<<endl;cout<<"Enter Exchange :";cin>>p.exch;cout<<endl;cout<<"Enter No :";cin>>p.no;}

void rec::disp(){clrscr();cout<<endl;cout<<endl;

| ISHAN POPLI

Page 54: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"First Name :";cout<<n.first;cout<<endl;cout<<endl;cout<<"Mid Name :";cout<<n.mid;cout<<endl;cout<<endl;cout<<"Last Name :";cout<<n.last;cout<<endl;cout<<endl;cout<<"Area :";cout<<p.area;cout<<endl;cout<<endl;cout<<"Exchange :";cout<<p.exch;cout<<endl;cout<<endl;cout<<"No :";cout<<p.no;cout<<endl;cout<<endl;getch();}void main(){rec t;t.reci();t.disp();getch();

| ISHAN POPLI

Page 55: My Programs

BANASTHALI PUBLIC SCHOOL

}

RESULTS

First Name :PRIYANKA

Mid Name :P

Last Name :RAI

Area :C31,SILICON

Exchange :VALLEY

No :7

//prg to conv decimal to binary & binary to decimal//Downloaded From www.c4cpp.co.nr. (C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<math.h>void main(){clrscr();int a,g,h,s=0,i=0,d,b,ch;cout<<endl<<"Enter the choice - "<<endl<<"1:Binary to Decimal"<<endl<<"2:Decimal to Binary"<<endl;cin>>ch;switch(ch){

| ISHAN POPLI

Page 56: My Programs

BANASTHALI PUBLIC SCHOOL

case 1:

cout<<"Enter the Binary Digit"<<endl;cin>>b;while(b>0){a=b%10;s=s+a*(pow(2,i));i=i+1;b=b/10;}cout<<"Answer ="<<s<<endl;break;

case 2:cout<<"Enter the Decimal"<<endl;cin>>d;while(d>0){a=d%2;a=a*pow(10,i);s=s+a;i=i+1;d=d/2;}cout<<"Answer ="<<s<<endl;break;

default:cout<<"Wrong choice"<<endl;break;}

| ISHAN POPLI

Page 57: My Programs

BANASTHALI PUBLIC SCHOOL

getch();

}

//prg to display diamond and pascals triangle//Downloaded From www.c4cpp.co.nr. (C)2009.All rights reserved.#include<iostream.h>#include<conio.h>void main(){clrscr();int x,i,f,r,b,g,c,h,v=1,q,j,n,p,k=1;int ch;cout<<"Enter choice 1:STARS"<<endl;cout<<" 2:NUMBERS"<<endl;cin>>ch;switch(ch){//WITH STARcase 1:v=2;char a2[100][100];cout<<"Enter Limit : "<<endl;cin>>n;p=n-1;//INPUTTINGfor(i=0;i<=(2*n)-2;i++) { for(j=0;j<=(2*n)-2;j++) {

a2[i][j]= ' '; }

| ISHAN POPLI

Page 58: My Programs

BANASTHALI PUBLIC SCHOOL

}//STARTINGfor(i=0;i<=(2*n)-2;i++) { for(j=0;j<=(2*n)-2;j++) {

if(((i+j)==p)&&(i<n)) { for(c=0;c<k;c++) { a2[i][j]='*'; j=j+v; } k++; j=(2*n)-2; r=c-1; } if(((i+j)==(p+2))&&(i>=n)) { for(h=r;h>0;h--) { a2[i][j]='*'; j=j+v; } p=p+2; r--; j=(2*n)-2; } } }

for(i=0;i<=(2*n)-2;i++){

| ISHAN POPLI

Page 59: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<endl;for(j=0;j<=(2*n)-2;j++){cout<<a2[i][j];}}break;

//CASE TWO WITH NUMBERScase 2:int a[100][100];cout<<"Enter Limit : "<<endl;cin>>n;p=n-1;for(i=0;i<=(2*n)-2;i++){for(j=0;j<=(2*n)-2;j++){a[i][j]=0;}}

for(i=0;i<=(2*n)-2;i++){for(j=0;j<=(2*n)-2;j++){if(((i+j)==p)&&(i<n)){b=1;for(c=0;c<k;c++){

| ISHAN POPLI

Page 60: My Programs

BANASTHALI PUBLIC SCHOOL

if(j<=(n-1)){a[i][j]=b;j=j+v;b++;r=b-2;}if(j>(n-1)){a[i][j]=r;j=j+v;r--;}}k=k+2;j=(2*n)-2;r=c-2;}if(((i+j)==p+2)&&(i>=n)){f=1;for(h=r;h>0;h--){if(j<=(n-1)){a[i][j]=f;j=j+v;f++;x=f-2;}if(j>(n-1)){

| ISHAN POPLI

Page 61: My Programs

BANASTHALI PUBLIC SCHOOL

a[i][j]=x;j=j+v;x--;}}r=r-2;p=p+2;j=(2*n)-2;}}}for(i=0;i<=(2*n)-2;i++){cout<<endl;for(j=0;j<=(2*n)-2;j++){if(a[i][j]!=0)cout<<a[i][j];elsecout<<" ";}}break;

default:cout<<"Wrong choice"<<endl;break;

}getch();

| ISHAN POPLI

Page 62: My Programs

BANASTHALI PUBLIC SCHOOL

}#include<fstream.h>#include<iostream.h>#include<conio.h>#include<ctype.h>#include<process.h>#include<iomanip.h>#include<stdio.h>#include<string.h>#include<stdlib.h>void welcome_screen();void welcome_screen() {

clrscr();gotoxy(20,10);cputs("**************** W E L C O M E *********************** ");gotoxy(25,12);cputs("*** C A M P I O N S C H O O L *** " );gotoxy(20,14);textcolor(WHITE);cputs(" T E L E P H O N E M A N A G E M E N T S O F T W A R E ");gotoxy(38,16);textcolor(WHITE);cputs(" D O N E B Y : ");gotoxy(50,18);cputs(" Navi Arora ");gotoxy(50,20);cputs("");

textcolor(WHITE+BLINK);gotoxy(40,30);cputs(" *** PRESS ANY KEY TO CONTINUE***");

| ISHAN POPLI

Page 63: My Programs

BANASTHALI PUBLIC SCHOOL

getch();return;

}class directory { public:

int record; long pn1; char pn2[10]; int age; char address1[50]; char address2[50]; char occupation[20]; char name[20]; char emailadd[25]; char internetadd[25]; void modification(); void addition(); void deleate(); void menu(); void search(); void view1(); void init(); void display(); void view(); char check(char *); int test(); }obj;

void directory::addition() //ADDING INFORMATION { ofstream fout; fout.open("heera",ios::out|ios::app);

| ISHAN POPLI

Page 64: My Programs

BANASTHALI PUBLIC SCHOOL

init(); fout.write((char*)&obj,sizeof(obj)); fout.close(); }int directory::test() //FIND NO. OF RECORDS { ifstream fin; fin.open("heera"); fin.seekg(0,ios::end); int n; n=fin.tellg()/sizeof(obj); cout<<" \n NUMBER OF RECORDS = "<<n ; return n ; }void directory::search() //SEARCHING FOR A PARTICULAR NUMBER { ifstream fin; fin.open("heera"); if(fin.fail())

{ cout<<" \n FILE NOT FOUND "; getch(); return;}

clrscr(); textcolor(BLACK+BLINK); gotoxy(30,1); cprintf(" [SEARCHING] "); cout<<" \n ENTER PHONE NUMBER TO BE SEARCHED : "; long pn; cin>>pn; int n;

| ISHAN POPLI

Page 65: My Programs

BANASTHALI PUBLIC SCHOOL

n=test(); for(int i=0;i<n;i++)

{ fin.read((char*)&obj,sizeof(obj)); if(pn==pn1) { view1(); return; }}

if(fin.eof()){ cout<<" \n RECORD NOT FOUND ";}

}void directory::init() // ENTERING THE DETAILS {

clrscr(); char ch; textcolor(BLACK+BLINK); gotoxy(30,1); cprintf(" [ADDITION] "); textcolor(BLACK); cout<<" \n ENTER HOUSE PHONE NUMBER : "; cin>>pn1; cout<<" \n ENTER OFFICE PHONE NUMBER : "; cin>>pn2; // ch=cin.get(); cin.get(ch); cout<<" \n ENTER NAME : "; cin.getline(name,20,'\n');

| ISHAN POPLI

Page 66: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<" \n ENTER THE OCCUPATION : "; cin.getline(occupation,20,'\n'); cout<<" \n ENTER HOUSE ADDRESS : "; cin.getline(address1,50,'\n'); cout<<" \n ENTER OFFICE ADDRESS : "; cin.getline(address2,50,'\n'); cout<<" \n ENTER EMAIL ADDRESS : "; cin.getline(emailadd,25,'\n'); cout<<" \n ENTER INTERNET ADDRESS : "; cin.getline(internetadd,25,'\n'); }

void directory::view1() //TO DISPLAY ALL THE RECORDS { cout<<"\n"; cout<<" PHONE NUMBER1 : "<<obj.pn1<<"\n"; cout<<" PHONE NUMBER2 : "<<obj.pn2<<"\n"; cout<<" NAME : "<<obj.name<<"\n"; cout<<" HOUSE ADDRESS : "<<obj.address1<<"\n"; cout<<" OCCUPATION : "<<obj.occupation<<"\n"; cout<<" OFFICE ADDRESS : "<<obj.address2<<"\n"; cout<<" EMAIL ADDRESS : "<<obj.emailadd<<"\n"; cout<<" INTERNET ADDRESS : "<<obj.internetadd<<"\n"; getch(); }void directory::modification() //TO MODIFY ANY DATA IN THE RECORD IF NECESSARY { clrscr(); textcolor(BLACK+BLINK); gotoxy(30,1); cprintf(" [ MODIFICATION ] ");

| ISHAN POPLI

Page 67: My Programs

BANASTHALI PUBLIC SCHOOL

textcolor(BLACK); long pn; int n,i; ifstream fin; ofstream fout; fin.open("heera"); if(fin.fail()) {

cout<<"\n FILE NOT FOUND !"; fout.close(); exit(-1);

} fout.open("new"); n=test(); if(n==0) {

cout<<"\n FILE IS EMPTY ! ";getch();return;

} while(fin.good()) {

fin.read((char*)&obj,sizeof(obj));fout.write((char*)&obj,sizeof(obj));

} fin.close(); fout.close(); fout.open("heera",ios::trunc); fin.open("new"); if(fin.fail()) { cout<<"\n FILE NOT FOUND !";

| ISHAN POPLI

Page 68: My Programs

BANASTHALI PUBLIC SCHOOL

exit(-1); } char ch; cout<<"\n ENTER PHONE NUMBER :"; cin>>pn; ch=cin.get();// cin.get(ch); for(i=0;i<n;i++)

{ fin.read((char*)&obj,sizeof(obj)); char d; if(pn==pn1) {

view1();d=check("HOUSE PHONE NUMBER ");if((d=='y') || (d=='Y')) { cout<<"\n ENTER NEW PHONE NUMBER :"; cin>>pn1; ch=cin.get(); // cin.get(ch); }if(check("OFFICE PHONE NUMBER ")=='Y') { cout<<"\n ENTER NEW PHONE NUMBER :"; cin>>pn2; ch=cin.get(); // cin.get(ch); }if(check("NAME")=='y') { cout<<"\n ENTER NEW NAME : ";

| ISHAN POPLI

Page 69: My Programs

BANASTHALI PUBLIC SCHOOL

cin.getline(name,20,'\n'); }if(check("HOME ADDRESS")=='y') { cout<<"\n ENTER NEW ADDRESS :"; cin.getline(address1,50,'\n'); }if(check("OFFICE ADDRESS")=='y') { cout<<"\n ENTER NEW ADDRESS :"; cin.getline(address2,50,'\n'); }if(check("EMAIL ADDRESS:")=='y') { cout<<"\n ENTER NEW MAIL ADDRESS :"; cin.getline(emailadd,25,'\n'); }if(check("INTERNET ADDRESS")=='y') { cout<<"\n ENTER NEW INTERNET ADDRESS :"; cin.getline(internetadd,25,'\n'); }

} fout.write((char*)&obj,sizeof(obj));}

fout.close(); fin.close(); }char directory::check(char *s) { cout<<"\n MODIFY \t "<<s<<"\t"<<"Y/N"; char ch;

| ISHAN POPLI

Page 70: My Programs

BANASTHALI PUBLIC SCHOOL

ch =getch(); //cin.get(ch); if((ch=='y')||(ch=='Y'))

return 'y'; else

return 'n'; }void directory::deleate() { clrscr(); window(1,1,80,25); textcolor(BLACK+BLINK); gotoxy(30,1); cprintf("[DELETION]"); long pn; int n,i; ifstream fin; ofstream fout; fin.open("heera"); if(fin.fail())

{ cout<<"\n FILE NOT FOUND ! "; getch(); return;}

fout.open("new"); n=test(); if(n==0)

{ cout<<"\n FILE IS EMPTY ! "; getch(); return;

| ISHAN POPLI

Page 71: My Programs

BANASTHALI PUBLIC SCHOOL

} for(i=0;i<n;i++)

{ fin.read((char*)&obj,sizeof(obj)); fout.write((char*)&obj,sizeof(obj));}

fin.close(); fout.close(); fout.open("meera",ios::trunc); fin.open("new"); if(fin.fail())

{ cout<<"\n FILE NOT FOUND ! "; getch(); return;}

cout<<"\n ENTER PHONE NUMBER :"; cin>>pn; for(i=0;i<n;i++) {

fin.read((char*)&obj,sizeof(obj)); if(pn!=pn1) fout.write((char*)&obj,sizeof(obj));

} fout.close(); fin.close();

} void directory::view() { ifstream fin; int n,j;

| ISHAN POPLI

Page 72: My Programs

BANASTHALI PUBLIC SCHOOL

fin.open("heera"); if(fin.fail()||fin.bad()) {

cout<<"\n FILE NOT FOUND ! "; getch(); return;

} clrscr(); int i=0; n=test(); for(j=0;j<n;j++) {

cout<<"\n RECORD "<<i+1<<"\n"; fin.read((char*)&obj,sizeof(obj)); cout<<"\n PHONE NUMBER1 :"<<obj.pn1<<"\n"; cout<<"\n PHONE NUMBER2 :"<<obj.pn2<<"\n"; cout<<"\n NAME :"<<obj.name<<"\n"; cout<<"\n HOUSE ADDRESS :"<<obj.address1<<"\n"; cout<<"\n OCCUPATION :"<<obj.occupation<<"\n"; cout<<"\n OFFICE ADDRESS :"<<obj.address2<<"\n"; cout<<"\n INTERNET ADDRESS :"<<obj.internetadd<<"\n"; cout<<"\n EMAIL ADDRESS : "<<obj.emailadd<<"\n"; i+=1;

} fin.close(); getch();

}

void directory::menu() { char ch;

| ISHAN POPLI

Page 73: My Programs

BANASTHALI PUBLIC SCHOOL

clrscr(); textbackground(WHITE); textcolor(BLACK); gotoxy(30,8); cprintf(" A:ADDITION "); gotoxy(30,9); cprintf(" D: DELETION \n \r "); gotoxy(30,10); cprintf(" M:MODIFICATION \n \r "); gotoxy(30,11); cprintf(" V:VIEW \n \r "); gotoxy(30,12); cprintf(" S:SEARCH \n \r "); gotoxy(30,13); cprintf(" E:EXIT \n \r "); ch=getch();

switch(ch) { case 'a': case 'A':

addition();break;

case 'd' : case 'D' :

deleate();break;

case 'm': case 'M':

modification();break;

case 'v':

| ISHAN POPLI

Page 74: My Programs

BANASTHALI PUBLIC SCHOOL

case 'V':view();break;

case 's': case 'S':

search();break;

case 'e': case 'E':

system("cls");exit(0);

}}int main() { welcome_screen(); for(;;) obj.menu(); return 0; }

/*4 3 2 10 3 2 10 0 2 10 0 0 1*/

//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.

#include<iostream.h>

| ISHAN POPLI

Page 75: My Programs

BANASTHALI PUBLIC SCHOOL

#include<conio.h>void main(){clrscr();int i,n,g,j,a[100],b[100][100];cout<<"Enter Limit"<<endl;cin>>n;cout<<"Enter "<<endl;for(g=0;g<n;g++)cin>>a[g];

for(i=0;i<n;i++){for(j=n-1;j>=0;j--){b[i][j]=a[j];}}for(i=0;i<n;i++){for(j=0;j<n;j++){if(i>j)b[i][j]=0;}}for(i=0;i<n;i++){cout<<endl;for(j=0;j<n;j++){cout<<b[i][j]<<" ";

| ISHAN POPLI

Page 76: My Programs

BANASTHALI PUBLIC SCHOOL

}}

getch();}//program for creating bill in a supermarket.#include<iostream.h>#include<conio.h>#include<fstream.h>#include<string.h>#include<stdio.h>#include<stdlib.h>#include<iomanip.h>

//global variable declarationint k=7,r=0,flag=0;

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: ";

| ISHAN POPLI

Page 77: My Programs

BANASTHALI PUBLIC SCHOOL

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);}

| ISHAN POPLI

Page 78: My Programs

BANASTHALI PUBLIC SCHOOL

}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);

| ISHAN POPLI

Page 79: My Programs

BANASTHALI PUBLIC SCHOOL

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; clrscr(); 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";

| ISHAN POPLI

Page 80: My Programs

BANASTHALI PUBLIC SCHOOL

}}

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*********************************************";}

void main(){cout.setf(ios::fixed); cout.setf(ios::showpoint); cout<<setprecision(2); menu: clrscr(); 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;

| ISHAN POPLI

Page 81: My Programs

BANASTHALI PUBLIC SCHOOL

float gtotal; cin>>ch; switch(ch) {case 1:ss:

clrscr(); 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) {clrscr(); 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";

| ISHAN POPLI

Page 82: My Programs

BANASTHALI PUBLIC SCHOOL

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:clrscr();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 ";

| ISHAN POPLI

Page 83: My Programs

BANASTHALI PUBLIC SCHOOL

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)); clrscr(); cout<<"\n\t\tCurrent Details are\n"; amt.show();

| ISHAN POPLI

Page 84: My Programs

BANASTHALI PUBLIC SCHOOL

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;}}

| ISHAN POPLI

Page 85: My Programs

BANASTHALI PUBLIC SCHOOL

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:clrscr(); 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!";

| ISHAN POPLI

Page 86: My Programs

BANASTHALI PUBLIC SCHOOL

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:clrscr(); 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);

cout<<"SPECIAL THANKS TO RESHMI MISS FOR GIVING US THE GUIDING LIGHT";

getch();clrscr();gotoxy(15,20);cout<<"THANKS TO ALL THOSE WHO HELPED US TO MAKE THIS

PROJECT";getch();clrscr();

| ISHAN POPLI

Page 87: My Programs

BANASTHALI PUBLIC SCHOOL

gotoxy(12,20);cout<<"CREATED BY ROSHAN MARTIN , JYOTHIS PAUL , ARUN BABU";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;}}

//prg to conv decimal to binary & binary to decimal//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<math.h>#include<process.h>void main(){clrscr();int aa,g,h,s=0,ii=0,dd,b,ch;men :cout<<endl<<"Enter the choice - "<<endl<<endl<<"1:Binary to Decimal"<<endl<<endl<<"2:Decimal to Binary"<<endl;cout<<endl<<"3:Binary to Octal"<<endl<<endl<<"4:Octal to Binary"<<endl<<endl<<"5:exit"<<endl<<endl;;cin>>ch;

| ISHAN POPLI

Page 88: My Programs

BANASTHALI PUBLIC SCHOOL

switch(ch){case 1:s=0;ii=0;cout<<"Enter the Binary Digit"<<endl;cin>>b;

while(b>0){aa=b%10;s=s+aa*(pow(2,ii));ii=ii+1;b=b/10;}cout<<"Answer ="<<s<<endl;goto men;

case 2:s=0;ii=0;cout<<"Enter the Decimal"<<endl;cin>>dd;while(dd>0){aa=dd%2;aa=aa*pow(10,ii);s=s+aa;ii=ii+1;dd=dd/2;}cout<<"Answer ="<<s<<endl;

| ISHAN POPLI

Page 89: My Programs

BANASTHALI PUBLIC SCHOOL

goto men;

case 3:int oc,sum,p,r,n,a,i=0,x=0,d=0,j,o;cout<<"ENTER THE BINARY DIGIT :"<<endl;cin>>b;while(b>0){a=b%1000;j=0;d=0;while(a>0){n=(a%10);d=d+(n*pow(2,j));j=j+1;a=a/10;}x=x+(d*pow(10,i));i=i+1;b=b/1000;}cout<<"Answer ="<<x;goto men;

case 4:cout<<"Enter the Octel"<<endl;cin>>oc;i=0;j=0;

| ISHAN POPLI

Page 90: My Programs

BANASTHALI PUBLIC SCHOOL

sum=0;s=0;

while(oc>0){p=oc%1000;while(p>0){r=p%2;s=s+r*pow(10,j);j++;p=p/2;}sum=sum+(s*pow(1000,i));i++;oc=oc/10;j=0;}cout<<"Binary ="<<sum;goto men;

case 5:exit(0);

default:cout<<"Wrong choice"<<endl;

}getch();

}

| ISHAN POPLI

Page 91: My Programs

BANASTHALI PUBLIC SCHOOL

//BUBBLE SELECTION SORT//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<process.h>void main(){clrscr();int ch;int i,j,x,k,z,l,m,n,o,p,a[50],small;q :cout<<"Enter the choice 1:Selection 2:Bubble 3:Exchange Selection 4:Insertion 5:Exit"<<endl;cin>>ch;switch(ch){case 1:cout<<"Enter the limit "<<endl;cin>>n;cout<<endl;cout<<"Enter the elements"<<endl;

for(i=0;i<n;i++) { cin>>a[i]; cout<<endl; }

for(j=0;j<n;j++) { small=a[j];

| ISHAN POPLI

Page 92: My Programs

BANASTHALI PUBLIC SCHOOL

p=j; for(i=j;i<n;i++) { if(small>a[i]) { small=a[i]; p=i; } } for(k=p;k>j;k--) { a[k]=a[k-1]; } a[j]=small; }cout<<"Result"<<endl; for(z=0;z<n;z++) { cout<<a[z]; cout<<endl; } goto q; case 2:cout<<"Enter the limit"<<endl;cin>>n;cout<<"Enter the elements"<<endl; for(i=0;i<n;i++) cin>>a[i];for(j=0;j<n;j++) { for(i=0;i<n-1;i++) {

| ISHAN POPLI

Page 93: My Programs

BANASTHALI PUBLIC SCHOOL

if (a[i]>a[i+1]) { x=a[i+1]; a[i+1]=a[i]; a[i]=x; } } }cout<<"Result"<<endl; for (i=0;i<n;i++) { cout<<a[i]; cout<<endl; } break; case 3 :cout<<"Enter the limit "<<endl;cin>>n;cout<<endl;cout<<"Enter the elements"<<endl;

for(i=0;i<n;i++) { cin>>a[i]; cout<<endl; }

for(j=0;j<n;j++) { small=a[j]; p=j; for(i=j;i<n;i++)

| ISHAN POPLI

Page 94: My Programs

BANASTHALI PUBLIC SCHOOL

{ if(small>a[i]) { small=a[i]; p=i; } } a[p]=a[j]; a[j]=small; }cout<<"Result"<<endl; for(z=0;z<n;z++) { cout<<a[z]; cout<<endl; } goto q;

case 4 : int m=-32767; cout<<"enter the no. of elements"<<endl; cin>>n; cout<<"enter the array"<<endl; for(i=1;i<=n;i++) {cin>>a[i];} a[0]=m; for(i=1;i<=n;i++) {for(j=0;j<i;j++) {if(a[i]<a[j]) {p=a[i]; for(k=i-1;k>=j;k--) {a[k+1]=a[k];}

| ISHAN POPLI

Page 95: My Programs

BANASTHALI PUBLIC SCHOOL

a[j]=p;}}} for(i=1;i<=n;i++) {cout<<a[i];} goto q;

case 5:exit(0);default:cout<<"Wrong choice";goto q;

}getch();}//SALARY ORDER//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.

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

struct employee{int eno;char name[25];float salary;}e[10];

void main()

| ISHAN POPLI

Page 96: My Programs

BANASTHALI PUBLIC SCHOOL

{clrscr();int n;void bubb(employee,int);cout<<"Enter No of Employees"<<endl;cin>>n;for(int i=0;i<n;i++){cout<<"Enter Employee Name :";gets(e[i].name);cout<<endl<<"Enter Employee Code :";cin>>e[i].eno;cout<<endl<<"Enter Employee Salary :";cin>>e[i].salary;}bubb(e[10],n);getch();}void bubb(employee e,int n){employee x;for(int j=0;j<n;j++){if(e[j].salary<e[j+1].salary){for(int i=j;i<n-1;i++){x=e[i];e[i]=e[i+1];e[i+1]=x;}}

| ISHAN POPLI

Page 97: My Programs

BANASTHALI PUBLIC SCHOOL

}for(int i=0;i<n;i++){cout<<endl;cout<<e[i].name<<endl<<e[i].salary<<endl<<e[i].eno;}}//Circular queue//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<process.h>

class queue {int data[10]; int front,rear; public: queue() {front=-1; rear=-1; } void add(); void remove(); void display(); };

void queue::add() {if((rear+1==front)||(rear==9&&front==0)) {cout<<"Overflow "; } else

| ISHAN POPLI

Page 98: My Programs

BANASTHALI PUBLIC SCHOOL

{if((rear==-1) &&(front==-1)){rear=0; front=0;}

else if(rear==9){rear=0;}

else{rear++;}

cout<<"Enter the element "; cin>>data[rear]; } }

void queue::remove() {if(front==-1&&rear==-1) {cout<<"Underflow "; } else {if(front==9) {front=0; } else if(front==rear) {front=-1;

rear=-1; } else {front++; } } }

| ISHAN POPLI

Page 99: My Programs

BANASTHALI PUBLIC SCHOOL

void queue::display() {int i=0,n=9; if(rear==-1) {cout<<"No elements.."<<endl; } else { if(rear>front) {for(i=0;i<front;i++)

{cout<<"_";}

for(i=front;i<=rear;i++){cout<<data[i];}

for(i=rear+1;i<n;i++){cout<<"_";}

} else {for(i=0;i<=rear;i++)

{cout<<data[i];}

for(i=rear+1;i<front;i++){cout<<"_";}

for(i=front;i<n;i++){cout<<data[i];}

} } }

void main()

| ISHAN POPLI

Page 100: My Programs

BANASTHALI PUBLIC SCHOOL

{clrscr(); int ch; queue queue; X: cout<<"\nEnter your choice\n1.Insert\n2.Delete\n3.Display\n4.Exit\n"; cin>>ch; switch(ch) {case 1:queue.add();

goto X; case 2:queue.remove();

goto X; case 3:queue.display();

goto X; case 4:exit(0); } getch(); }//program for creating pay slip of employees of a company#include<iostream.h>#include<conio.h>#include<fstream.h>#include<string.h>#include<stdio.h>#include<stdlib.h>#include<iomanip.h>

//global variable declarationint k=7,r=0,flag=0;

struct date{int mm,dd,yy;};

| ISHAN POPLI

Page 101: My Programs

BANASTHALI PUBLIC SCHOOL

ofstream fout;ifstream fin;

class employee{int empno,dept;char name[25];date d,j;public:void add(){cout<<"\n\n\tEmployee No: ";cin>>empno;cout<<"\n\n\tName of the Employee: ";gets(name);cout<<"\n\n\tDepartment: ";cin>>dept;cout<<"\n\n\tDate of Birth (dd-mm-yy): ";cin>>d.mm>>d.dd>>d.yy;cout<<"\n\n\tDate of Joining (dd-mm-yy): ";cin>>j.mm>>j.dd>>j.yy;}void show(){cout<<"\n\tEmployee No: ";cout<<empno;cout<<"\n\n\tName of the Employee: ";cout<<name;cout<<"\n\n\tDepartment: ";cout<<dept;cout<<"\n\n\tDate of Birth (dd-mm-yy): ";cout<<d.mm<<"-"<<d.dd<<"-"<<d.yy;cout<<"\n\n\tDate of Joining (dd-mm-yy): ";cout<<j.mm<<"-"<<j.dd<<"-"<<j.yy;}void report()

| ISHAN POPLI

Page 102: My Programs

BANASTHALI PUBLIC SCHOOL

{gotoxy(3,k);cout<<empno;gotoxy(10,k);puts(name);gotoxy(20,k);cout<<dept;}int retno(){return(empno);}int retd(){return(dept);}};

class Salary: public employee{float basic,gross,deduction,da,hra,ot,oth,pf,lic,fadv,coops,hdfc,netpay;int abdys;public:void add();void show();void report();void calculate();void pay();}sal;

void Salary::add(){employee::add();cout<<"\n\n\tBasic Pay: ";cin>>basic;cout<<"\n\n\tDays Absent: ";cin>>abdys;cout<<"\n\n\tOvertime Hours: ";cin>>oth;cout<<"\n\n\tLoans and Savings\n";

| ISHAN POPLI

Page 103: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"\n\n\tLIC: ";cin>>lic;cout<<"\n\n\tHDFC: ";cin>>hdfc;cout<<"\n\n\tCo Operative Society: ";cin>>coops;calculate();fout.write((char *)&sal,sizeof(sal));fout.close();}void Salary::calculate(){hra=basic*0.1;da=basic*0.225;ot=oth*700;pf=basic*0.1275;fadv=100;gross=basic+hra+da+ot;deduction=pf+lic+fadv+coops+hdfc;netpay=gross-deduction;}

void Salary::show(){fin.open("database.dat",ios::binary);fin.read((char*)&sal,sizeof(sal));employee::show();cout<<"\n\n\tNet pay: ";cout<<netpay;fin.close();}

void Salary::report(){employee::report();

| ISHAN POPLI

Page 104: My Programs

BANASTHALI PUBLIC SCHOOL

gotoxy(30,k);cout<<basic;gotoxy(42,k);cout<<gross;gotoxy(52,k);cout<<deduction;gotoxy(67,k);cout<<netpay;k=k+1;if(k==50){gotoxy(25,50);cout<<"PRESS ANY KEY TO CONTINUE...";getch();k=7;clrscr();gotoxy(30,3);cout<<" EMPLOYEE DETAILS ";gotoxy(3,5);cout<<"CODE";gotoxy(10,5);cout<<"NAME";gotoxy(20,5);cout<<"DEPT";gotoxy(30,5);cout<<"BASIC";gotoxy(40,5);cout<<"GROSS PAY";gotoxy(52,5);cout<<"DEDUCTION";gotoxy(67,5);cout<<"NETPAY";}}

| ISHAN POPLI

Page 105: My Programs

BANASTHALI PUBLIC SCHOOL

void Salary::pay(){show();cout<<"\n\n\n\t\t*********************************************";cout<<"\n\t\t ENTERPRISES ";cout<<"\n\t\t*********************************************";cout<<"\n\n\t\tBASIC SALARY :"<<basic;cout<<"\n\t\tDEARNESS ALLOWANCE :"<<da;cout<<"\n\t\tHOUSE RENT ALLOWANCE :"<<hra;cout<<"\n\t\tOVER TIME HOURS :"<<oth;cout<<"\n\t\tOVER TIME WAGES :"<<ot;cout<<"\n\t\tGROSS PAY :"<<gross;cout<<"\n\n\n\n\n\n\t\tPROVIDENT FUND :"<<pf;cout<<"\n\t\tLIC :"<<lic;cout<<"\n\t\tFESTIVAL ADVANCE :"<<fadv;cout<<"\n\t\tHDFC :"<<hdfc;cout<<"\n\t\tCO-OP S :"<<coops;cout<<"\n\n\n\t\tNET PAY :Rs."<<netpay;cout<<"\n\t\t*********************************************";//earningsgotoxy(14,21);cout<<"E";gotoxy(14,22);cout<<"A";gotoxy(14,23);cout<<"R";gotoxy(14,24);cout<<"N";gotoxy(14,25);cout<<"I";gotoxy(14,26);cout<<"N";

| ISHAN POPLI

Page 106: My Programs

BANASTHALI PUBLIC SCHOOL

gotoxy(14,27);cout<<"G";gotoxy(14,28);cout<<"S";//deductionsgotoxy(14,31);cout<<"D";gotoxy(14,32);cout<<"E";gotoxy(14,33);cout<<"D";gotoxy(14,34);cout<<"U";gotoxy(14,35);cout<<"C";gotoxy(14,36);cout<<"T";gotoxy(14,37);cout<<"I";gotoxy(14,38);cout<<"O";gotoxy(14,39);cout<<"N";gotoxy(14,40);cout<<"S";}

void main(){cout.setf(ios::fixed);cout.setf(ios::showpoint);cout<<setprecision(2);menu:

| ISHAN POPLI

Page 107: My Programs

BANASTHALI PUBLIC SCHOOL

clrscr();gotoxy(25,2);cout<<"Company Employee Management";gotoxy(25,3);cout<<"===========================\n\n";cout<<"\n\t\t1.Salary Report\n\n";cout<<"\t\t2.Edit Database\n\n";cout<<"\t\t3.Search\n\n";cout<<"\t\t4.Pay Slip\n\n";cout<<"\t\t5.Exit\n\n";cout<<"\t\tPlease Enter Required Option: ";int ch;cin>>ch;switch(ch){case 1:ss:

clrscr();gotoxy(25,2);cout<<"Salary Statement";gotoxy(25,3);cout<<"================\n\n";cout<<"\n\t\t1.All Employees\n\n";cout<<"\t\t2.Department wise\n\n";cout<<"\t\t3.Back to Main menu\n\n";cout<<"\t\tPlease Enter Required Option: ";int cho;cin>>cho;if(cho==1){clrscr();gotoxy(30,3);cout<<" EMPLOYEE DETAILS ";gotoxy(3,5);cout<<"CODE";

| ISHAN POPLI

Page 108: My Programs

BANASTHALI PUBLIC SCHOOL

gotoxy(10,5);cout<<"NAME";gotoxy(20,5);cout<<"DEPT";gotoxy(30,5);cout<<"BASIC";gotoxy(40,5);cout<<"GROSS PAY";gotoxy(52,5);cout<<"DEDUCTION";gotoxy(67,5);cout<<"NETPAY";fin.open("database.dat",ios::binary);if(!fin){cout<<"\n\nFile Not Found...";goto menu;}fin.seekg(0);while(!fin.eof()){fin.read((char*)&sal,sizeof(sal));if(!fin.eof())sal.report();}getch();fin.close();}if(cho==2){flag=0;cout<<"\n\t\tEnter Department: ";int de;cin>>de;clrscr();gotoxy(30,3);cout<<" EMPLOYEE DETAILS ";gotoxy(3,5);

| ISHAN POPLI

Page 109: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"CODE";gotoxy(10,5);cout<<"NAME";gotoxy(20,5);cout<<"DEPT";gotoxy(30,5);cout<<"BASIC";gotoxy(40,5);cout<<"GROSS PAY";gotoxy(52,5);cout<<"DEDUCTION";gotoxy(67,5);cout<<"NETPAY";fin.open("database.dat",ios::binary);if(!fin){cout<<"\n\nFile Not Found...";goto menu;}fin.seekg(0);while(!fin.eof()){fin.read((char*)&sal,sizeof(sal));if(!fin.eof()){int x=sal.employee::retd();if(x==de){flag=1;sal.report();}}}if(flag==0){cout<<"\n\n\n\t\tDepartment doesnot exist...";getch();fin.close();goto ss;}getch();fin.close();}

| ISHAN POPLI

Page 110: My Programs

BANASTHALI PUBLIC SCHOOL

if(cho==3){goto menu;}goto ss;

case 2:db:clrscr();gotoxy(25,2);cout<<"Employee Database";gotoxy(25,3);cout<<"=================\n\n";cout<<"\n\t\t1.Add Employee Details\n\n";cout<<"\t\t2.Edit Employee Details\n\n";cout<<"\t\t3.Delete Employee\n\n";cout<<"\t\t4.Back to Main Menu ";int apc;cin>>apc;

switch(apc){case 1:fout.open("database.dat",ios::binary|ios::app);sal.add();cout<<"\n\t\tEmployee Added Successfully!";getch();goto db;

case 2:int eno;flag=0;cout<<"\n\n\tEnter Employee Number to be Edited :";cin>>eno;fin.open("database.dat",ios::binary);fout.open("database.dat",ios::binary|ios::app);if(!fin){cout<<"\n\nFile Not Found...";

| ISHAN POPLI

Page 111: My Programs

BANASTHALI PUBLIC SCHOOL

goto menu;}fin.seekg(0);r=0;while(!fin.eof()){fin.read((char*)&sal,sizeof(sal));if(!fin.eof()){r++;int x=sal.employee::retno();if(x==eno){flag=1;fout.seekp((r-1)*sizeof(sal));clrscr();cout<<"\n\t\tCurrent Details are\n";sal.show();cout<<"\n\n\t\tEnter New Details\n";sal.add();cout<<"\n\t\tEmployee Details editted";}}}if(flag==0){cout<<"\n\t\tEmployee No does not exist...Please Retry!";getch();goto db;}fin.close();getch();goto db;

case 3:flag=0;cout<<"\n\n\tEnter Employee Number to be deleted :";cin>>eno;fin.open("database.dat",ios::binary);if(!fin){cout<<"\n\nFile Not Found...";

| ISHAN POPLI

Page 112: My Programs

BANASTHALI PUBLIC SCHOOL

goto menu;}fstream tmp("temp.dat",ios::binary|ios::out);fin.seekg(0);while(fin.read((char*)&sal, sizeof(sal))){int x=sal.employee::retno();if(x!=eno)tmp.write((char*)&sal,sizeof(sal));else{flag=1;}}fin.close();tmp.close();fout.open("database.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*)&sal,sizeof(sal)))fout.write((char*)&sal,sizeof(sal));tmp.close();fout.close();if(flag==1)cout<<"\n\t\tEmployee Succesfully Deleted";else if (flag==0)cout<<"\n\t\tEmployee does not Exist! Please Retry";getch();goto db;case 4: goto menu;default: cout<<"\n\n\t\tWrong Choice!!! Retry";getch();goto db;}

| ISHAN POPLI

Page 113: My Programs

BANASTHALI PUBLIC SCHOOL

case 3:clrscr();cout<<"\n\n\t\tEnter Employee Number to be found: ";

flag=0;int eno;cin>>eno;fin.open("database.dat",ios::binary);if(!fin){cout<<"\n\nFile Not Found...";goto menu;}fin.seekg(0);while(fin.read((char*)&sal, sizeof(sal))){int x=sal.employee::retno();if(x==eno){flag=1;cout<<"\n\n\t\tEmployee Details are \n";cout<<"\t\t====================\n";sal.show();}}fin.close();if(flag==0) cout<<"\n\t\tEmployee does not exist....Please Retry!";getch();goto menu;

case 4:clrscr();flag=0;cout<<"\n\n\t\tEnter Employee Number :";cin>>eno;fin.open("database.dat",ios::binary);if(!fin){cout<<"\n\nFile Not Found...\nProgram Terminated!";goto menu;}fin.seekg(0);while(fin.read((char*)&sal,sizeof(sal))){int x=sal.employee::retno();

| ISHAN POPLI

Page 114: My Programs

BANASTHALI PUBLIC SCHOOL

if(x==eno){sal.pay();flag=1;break;}}if(flag==0)cout<<"\n\t\tEmployee does not exist....Please Retry!";getch();fin.close();goto menu;

case 5:clrscr();gotoxy(20,20);cout<<"ARE YOU SURE, YOU WANT TO EXIT (Y/N)?";char yn;cin>>yn;if((yn=='Y')||(yn=='y')){gotoxy(17,20);cout<<"THANKS TO EVERYONE WHO CONTRIBUTED TO THIS PROGRAM";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;}}//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<dos.h>

| ISHAN POPLI

Page 115: My Programs

BANASTHALI PUBLIC SCHOOL

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

struct stud{char name[50];int rno;};

void main(){

clrscr();stud st;int i;ofstream gpj("abcabc.dat",ios::binary|ios::trunc);if(!gpj){cout<<"File Cannot Be Created"<<endl;}else{int n;

cout<<"How many Students U Want to Enter ???? "<<endl;cin>>n;for(i=0;i<n;i++){cout<<"Enter Name"<<endl;gets(st.name);cout<<"Enter Roll No"<<endl;

| ISHAN POPLI

Page 116: My Programs

BANASTHALI PUBLIC SCHOOL

cin>>st.rno;gpj.write((char*)&st,sizeof(st));}gpj.close();}int a=0;ifstream gp("abcabc.dat",ios::binary);if(!gp){cout<<"File Error"<<endl;}else{gp.seekg(0);while(gp.read((char*)&st,sizeof(st))){a++;}cout<<"No = "<<a;gp.close();}getch();

}//_*************_ CRUISE TRAVEL MANAGENMENT _*****************_/*A Project based on Cruise Travel Management */

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

| ISHAN POPLI

Page 117: My Programs

BANASTHALI PUBLIC SCHOOL

#include<stdlib.h>#include<iomanip.h>long int code;class persdetails //class for collecting the personal details{ int trvlcode; int age[20]; char name[20][20]; char add[50]; char phnum[15]; char sex[20]; char passnum[10][10]; char familyname[30]; int num; int numppl; public: void p_input(int); void p_output(); void givefam(); int givecode(); int give();}pob;int persdetails::give(){ return num;}void persdetails::givefam(){ cout<<familyname;}int persdetails::givecode(){

| ISHAN POPLI

Page 118: My Programs

BANASTHALI PUBLIC SCHOOL

return trvlcode;}void persdetails::p_input(int cd) //input func() of class1{ trvlcode=cd; num=0; clrscr(); cout<<"\n\n\t:::::::::::::::::::::: PERSONAL DETAILS ::::::::::::::::::::::\n"; cout<<"\t\t\t\t~~~~~~~~~~~~~~\n"; cout<<"\n\t\t* Please fill in the details:\n\n\n\t\t\t1.Family Name: "; gets(familyname); cout<<"\n\t\t\t2.Address: "; gets(add); cout<<"\n\t\t\t3.Contact Number(10 Digit Mobile Number) : "; gets(phnum); cout<<"\n\n\n\t\tEnter The No of People Travelling: "; cin>>numppl; clrscr(); if(numppl>0) { cout<<"\n\t\tPlease Enter The Details of each Member/Members: "<<endl; cout<<"\t\t________________________________________________\n"; for(int i=0;i<numppl;i++) { cout<<endl<<"\n\t\tMember "<<i+1; cout<<"\n\t\t~~~~~~~~"; cout<<"\n\n\t\tFirst Name: "; gets(name[i]); cout<<"\n\t\tAge: "; cin>>age[i]; cout<<"\n\t\tSex (M/F): "; cin>>sex[i];

| ISHAN POPLI

Page 119: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"\n\t\tPassport Number: "; gets(passnum[i]); if(age[i]>5) {

num++; //to calculate no of travellers below 5 yrs } } }}void persdetails::p_output() //output func() of class1{ clrscr(); cout<<"\n\n\t_********************_ PERSONAL DETAILS _********************_"<<endl; cout<<"\n\n\t\t\tFamily Name:\t "<<familyname<<endl; cout<<"\t\t\tAddress:\t "<<add<<endl; cout<<"\t\t\tPhone Number:\t "<<phnum<<endl; cout<<"\n\n\tName\t\tAge\t\tSex\t\tPassport Number\n"<<endl; for(int i=0;i<numppl;i++) { cout<<"\t"<<name[i]<<"\t\t"<<age[i]<<"\t\t"<<sex[i]<<"\t\t"<<passnum[i]<<endl; } getch();}class travdetails //class which holds the travel details{ int trvtcode; int day; int month; int year; int num1; int bdg_pt; int go_pt;

| ISHAN POPLI

Page 120: My Programs

BANASTHALI PUBLIC SCHOOL

int deck; int cabin; int pool; int gym; int sports; int salon; int spa; int theatre; public: void initial(); void t_input(int); void t_output(); void compute(); int gtcode(); void accept(int);}tob;void travdetails::initial(){ pool=gym=theatre=sports=salon=0;}void travdetails::accept(int c){ num1=c;}int travdetails::gtcode(){ return trvtcode;}void travdetails::t_input(int cd) //input func()-class2{ tob.initial(); trvtcode=cd;

| ISHAN POPLI

Page 121: My Programs

BANASTHALI PUBLIC SCHOOL

int i=1,opt; clrscr(); do { clrscr(); cout<<endl; cout<<"\n\n\t\t\t\t_||__TRAVEL DETAILS__"; cout<<"\n\t\t\t\t\\___________________/"; cout<<"\n\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~"; cout<<"\n\n\t\tPlease enter the following details for your journey:"; cout<<"\n\n\t\t*Note:Options marked with '*' are compulsory.\n\t\t\tPlease do select them."; cout<<"\n\n\n\t\t\t\t*1.Boarding Point\n\t\t\t\t*2.Destination\n\t\t\t\t*3.Date of Departure\n\t\t\t\t*4.Deck\n\t\t\t\t 5.Cabin\n\t\t\t\t 6.Swimming Pool\n\t\t\t\t 7.Gymnasuim\n\t\t\t\t 8.Sports\n\t\t\t\t 9.Salon\n\t\t\t\t 10.Spa\n\t\t\t\t 11.Theatre\n\t\t\t\t 12.Back\n\n\t\t\t\t_ "; cin>>opt; switch(opt) { case 1:clrscr();

cout<<"\n\n\n\t\t\tSelect Boarding point:\n\n\t\t\t1.Mumbai\n\n\t\t\t2.Cochin\n\n\t\t\t3.Chennai\n\n\t\t\t_ ";

cin>>bdg_pt; break;

case 2:clrscr(); cout<<"\n\n\t\t\t****** Select Destination ******\n\n\n"; cout<<"\t 1.New York\t\t6.Dubai\t\t\t11.Antananariv"; cout<<"\n\n\t 2.Miami\t\t7.Lisbon\t\t12.Cairo\n\n"; cout<<"\t 3.Rio De Janeiro\t8.London\t\t13.Perth"; cout<<"\n\n\t 4.Colombo\t\t9.Copenhagen\t\t14.Sydney"; cout<<"\n\n\t 5.Hong Kong\t\t10.Cape Town\t\t15.Wellington\n\n\n\n\n\t\t\t\t _ "; cin>>go_pt; break;

| ISHAN POPLI

Page 122: My Programs

BANASTHALI PUBLIC SCHOOL

case 3:clrscr(); cout<<"\n\n\t______________ Date of Departure ________________"; cout<<"\n\n * Note:Format for entering:Day(press enter)Month(press

enter)Year *"; cout<<"\n\n\t\tEnter your preferred date of departure: "; cin>>day; gotoxy(59,7); //to create a paricular format for entry cout<<"/"; cin>>month; gotoxy(62,7); cout<<"/"; cin>>year; break;

case 4:clrscr(); cout<<"\n\n\t\t\tEnter The Choice OF Deck\n\n\t\t\t1.Top Deck\n\n\t\t\t2.Middle

Decks\n\n\t\t\t3.Bottom Deck\n\n\t\t\t_ "; cin>>deck; break;

case 5:clrscr(); cout<<"\n\n\t\t\tEnter The Choice Of Cabin\n\n\t\t\t1.AC\n\n\t\t\t2.Non AC\n\n\t\t\

t_ "; cin>>cabin; break;

case 6:clrscr(); cout<<"\n\n\t\tDo You Like To Avail The Facility Of A Swimming Pool\n\n\t\t\

t1.No\n\n\t\t\t2.Yes\n\n\t\t\t_ "; cin>>pool; pool--; break;

case 7:clrscr(); cout<<"\n\n\t\tDo You Like To Avail The Facility Of A Gymnasium\n\n\t\t\t1.No\

n\n\t\t\t2.Yes\n\n\t\t\t_ ";

| ISHAN POPLI

Page 123: My Programs

BANASTHALI PUBLIC SCHOOL

cin>>gym; gym--; break;

case 8:clrscr(); cout<<"\n\n\t\tDo You Like To Avail The Sports Facilities Offered\n\n\t\t\t1.No\n\

n\t\t\t2.Yes\n\n\t\t\t_ "; cin>>sports; sports--; break;

case 9:clrscr(); cout<<"\n\n\t\tDo You Like To Avail The Facility Of Beauty Salon\n\n\t\t\t1.No\n\

n\t\t\t2.Yes\n\n\t\t\t_ "; cin>>salon; salon--; break;

case 10:clrscr(); cout<<"\n\n\tDo You Like To Avail The Facility Of Spa and Ayurvedic

Treatment\n\n\t\t\t1.No\n\n\t\t\t2.Yes\n\n\t\t\t_ "; cin>>spa; spa--; break;

case 11:clrscr(); cout<<"\n\n\t\tDo You Like To Avail The Facility Of Amphitheatre\n\n\t\t\t1.No\n\

n\t\t\t2.Yes\n\n\t\t\t_ "; cin>>theatre; theatre--; break;

case 12:i=0; break;

} }while(i==1);}

| ISHAN POPLI

Page 124: My Programs

BANASTHALI PUBLIC SCHOOL

void boardpt(int c) //for easy o/p{ if(c==1) cout<<"Mumbai\t"; if(c==2) cout<<"Cochin\t"; if(c==3) cout<<"Chennai\t";}void dest(int d) //for easy o/p{ switch(d) { case 1:cout<<"New York";

break; case 2:cout<<"Miami";

break; case 3:cout<<"Rio De Janero";

break; case 4:cout<<"Colombo";

break; case 5:cout<<"Hong Kong";

break; case 6:cout<<"Dubai";

break; case 7:cout<<"Lisbon";

break; case 8:cout<<"London";

break; case 9:cout<<"Copenhagen";

break; case 10:cout<<"Cape Town";

| ISHAN POPLI

Page 125: My Programs

BANASTHALI PUBLIC SCHOOL

break; case 11:cout<<"Antananriv";

break; case 12:cout<<"Cairo";

break; case 13:cout<<"Perth";

break; case 14:cout<<"Sydney";

break; case 15:cout<<"Willington";

break; }}void travdetails::t_output() //output func()-class2{ clrscr(); cout<<"\n\n\t_*******************_ TRAVEL DETAILS _*********************_"; cout<<"\n\n\t\tBoarding Point: "; boardpt(bdg_pt); cout<<"\n\n\t\tDestination: "; dest(go_pt); cout<<"\n\n\t\tDate of departure: "; cout<<day<<"/"<<month<<"/"<<year; cout<<"\n\n\t\tDeck: "; switch(deck) { case 1:cout<<"Top Deck";

break; case 2:cout<<"Middle Deck";

break; case 3:cout<<"Bottom Deck";

break;

| ISHAN POPLI

Page 126: My Programs

BANASTHALI PUBLIC SCHOOL

} cout<<"\n\n\t\tCabin: "; switch(cabin) { case 1:cout<<"AC cabin";

break; case 2:cout<<"Non-AC cabin";

break; } cout<<"\n\n\n\tFacilities availed for are:"; if(pool==1) cout<<"\n\t\t\t\t Swimming Pool"; if(gym==1) cout<<"\n\t\t\t\t Gymnasuim"; if(sports==1) cout<<"\n\t\t\t\t Sports Facilities"; if(spa==1) cout<<"\n\t\t\t\t Spa and Ayurvedic Treatment"; if(salon==1) cout<<"\n\t\t\t\t Beauty Salon"; if(theatre==1) cout<<"\n\t\t\t\t Theatre"; getch();}void family(int c,int&flag) //to display familyname+to check for record{ flag=0; clrscr(); ifstream ifl("PersonalDetails.txt",ios::binary); if(!ifl) cout<<"\nError"; ifl.read((char*)&pob,sizeof(pob));

| ISHAN POPLI

Page 127: My Programs

BANASTHALI PUBLIC SCHOOL

while(!ifl.eof()) { if(pob.givecode()==c) { flag=1; break; } ifl.read((char*)&pob,sizeof(pob)); } if(flag==1) { cout<<"\n\n\t\t ******_ "; pob.givefam(); cout<<"'s FAMILY DATABASE _******"; } else { cout<<"\nError in locating record!!"; } ifl.close();}void editp(int c) //to edit persdetails{ ofstream ofl2("temp1.txt",ios::binary); if(!ofl2) cout<<"Error While Opening File"; ifstream ifl4("PersonalDetails.txt",ios::binary); if(!ifl4) cout<<"Error While Opening File"; ifl4.read((char*)&pob,sizeof(pob)); while(!ifl4.eof()) {

| ISHAN POPLI

Page 128: My Programs

BANASTHALI PUBLIC SCHOOL

if(pob.givecode()==c) { clrscr(); cout<<"Please Enter the New details of the record"<<endl; pob.p_input(c); ofl2.write((char*)&pob,sizeof(pob)); cout<<"\n\t\t\tModification Succesful!!!"; ifl4.read((char*)&pob,sizeof(pob)); } else { ofl2.write((char*)&pob,sizeof(pob)); ifl4.read((char*)&pob,sizeof(pob)); } } remove("PersonalDetails.txt"); rename("temp1.txt","PersonalDetails.txt"); ifl4.close(); ofl2.close(); getch();}void editt(int c) //to edit travdetails{ ofstream ofl2("temp1.txt",ios::binary); if(!ofl2) cout<<"Error While Opening File"; ifstream ifl4("TravelDetails.txt",ios::binary); if(!ifl4) cout<<"Error While Opening File"; ifl4.read((char*)&tob,sizeof(tob)); while(!ifl4.eof()) {

| ISHAN POPLI

Page 129: My Programs

BANASTHALI PUBLIC SCHOOL

if(tob.gtcode()==c) { clrscr(); cout<<"Please Enter the New details of the record"<<endl; tob.t_input(c); ofl2.write((char*)&tob,sizeof(tob)); cout<<"\n\t\t\tModification Succesful!!!"; ifl4.read((char*)&tob,sizeof(tob)); } else { ofl2.write((char*)&tob,sizeof(tob)); ifl4.read((char*)&tob,sizeof(tob)); } } remove("TravelDetails.txt"); rename("temp1.txt","TravelDetails.txt"); ifl4.close(); ofl2.close(); getch();}void deletion(int c) //common delete func(){ ofstream ofl2("temp1.txt",ios::binary); if(!ofl2) cout<<"Error While Opening File"; ifstream ifl4("PersonalDetails.txt",ios::binary); if(!ifl4) cout<<"Error While Opening File"; ifl4.read((char*)&pob,sizeof(pob)); while(!ifl4.eof()) {

| ISHAN POPLI

Page 130: My Programs

BANASTHALI PUBLIC SCHOOL

if(pob.givecode()!=c) { ofl2.write((char*)&pob,sizeof(pob)); } ifl4.read((char*)&pob,sizeof(pob)); } remove("PersonalDetails.txt"); rename("temp1.txt","PersonalDetails.txt"); ofl2.close(); ifl4.close(); ofstream ofl3("temp2.txt",ios::binary); if(!ofl3) cout<<"\nError While Opening File"; ifstream ifl5("TravelDetails.txt",ios::binary); if(!ifl5) cout<<"\nError While Opening File"; ifl5.read((char*)&tob,sizeof(tob)); while(!ifl5.eof()) { if(tob.gtcode()!=c) { ofl3.write((char*)&tob,sizeof(tob)); } ifl5.read((char*)&tob,sizeof(tob)); } ofl3.close(); ifl5.close(); remove("TravelDetails.txt"); rename("temp1.txt","TravelDetails.txt"); cout<<"\n\n\t\tDeletion Completed!"; getch();}

| ISHAN POPLI

Page 131: My Programs

BANASTHALI PUBLIC SCHOOL

void travdetails::compute() //compution+bill generation{ long int gttl=0,hr,dcst,dck,cabn,swpool=5000,gm=2000,spfts=7500,slon=6000,sp=20000,ttr=500; switch(go_pt) { case 1:; case 2:; case 3:hr=30*24;

dcst=250000; break;

case 4:; case 5:; case 6:hr=7*24;

dcst=75000; break;

case 7:; case 8:; case 9:hr=24*24;

dcst=130000; break;

case 10:; case 11:; case 12:hr=15*24;

dcst=100000; break;

case 13:; case 14:; case 15:hr=12*24;

dcst=120000; break;

| ISHAN POPLI

Page 132: My Programs

BANASTHALI PUBLIC SCHOOL

} switch(deck) { case 1:dck=7500;

break; case 2:dck=5000;

break; case 3:dck=1000; } switch(cabin) { case 1:cabn=5000;

break; case 2:cabn=2000;

break; } clrscr(); cout<<"\n\n\t\t:::::::::::::::::::::: BILL ::::::::::::::::::::::::::"; cout<<"\n\n\t\tBoarding point:\t\t "; boardpt(bdg_pt); cout<<"\n\n\t\tDestination:\t\t "; dest(go_pt); cout<<"\n\n\t\tDate of Departure: "; cout<<day<<"/"<<month<<"/"<<year; hr=hr/24; //to calculate date of arrival day=day+hr; if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) { if(day>31) { month=month+1; day=day%31;

| ISHAN POPLI

Page 133: My Programs

BANASTHALI PUBLIC SCHOOL

} } if(month==4||month==6||month==9||month==11) { if(day>30) { month=month+1; day=day%30; } } if(month==2) { if(day>28) { month=month+1; day=day%28; } } if(month==13) { month=1; year++; } cout<<"\n\n\t\tDate of Arrival: "; cout<<day<<"/"<<month<<"/"<<year; cout<<"\n\n\t\tSubject\t\tCost(for 1)\tNo of ppl\tTotal"; cout<<"\n\n\t\tTravel\t\t"<<dcst<<"\t\t "<<num1<<"\t\t"<<num1*dcst; gttl+=num1*dcst; cout<<"\n\t\tDeck\t\t"<<dck<<"\t\t "<<num1<<"\t\t"<<dck*num1; gttl+=dck*num1; cout<<"\n\t\tCabin\t\t"<<cabn<<"\t\t "<<num1<<"\t\t"<<cabn*num1; gttl+=cabn*num1;

| ISHAN POPLI

Page 134: My Programs

BANASTHALI PUBLIC SCHOOL

if(pool==1) { cout<<"\n\t\tSwimming Pool\t"<<swpool<<"\t\t "<<num1<<"\t\t"<<swpool*num1; gttl+=swpool*num1; } if(gym==1) { cout<<"\n\t\tGym\t\t"<<gm<<"\t\t "<<num1<<"\t\t"<<gm*num1; gttl+=gm*num1; } if(sports==1) { cout<<"\n\t\tSports\t\t"<<spfts<<"\t\t "<<num1<<"\t\t"<<spfts*num1; gttl+=spfts*num1; } if(salon==1) { cout<<"\n\t\tSalon\t\t"<<slon<<"\t\t "<<num1<<"\t\t"<<slon*num1; gttl+=slon*num1; } if(spa==1) { cout<<"\n\t\tSpa\t\t"<<sp<<"\t\t "<<num1<<"\t\t"<<sp*num1; gttl+=dcst*num1; } if(theatre==1) { cout<<"\n\t\tTheatre\t\t"<<ttr<<"\t\t "<<num1<<"\t\t"<<ttr*num1; gttl+=ttr*num1; } cout<<"\n\n\n\t\t\t_ Grand Total:Rs "; if(gttl>100000) //to provide comma's for grandtotal

| ISHAN POPLI

Page 135: My Programs

BANASTHALI PUBLIC SCHOOL

{ cout<<gttl/100000<<","; gttl=gttl%100000; } if(gttl>1000) { cout<<gttl/1000<<","; gttl=gttl%1000; } cout<<gttl; if(gttl<10) cout<<"00"; cout<<" _"; cout<<"\n\n\t__! All Travellers below the age of 5 have not been charged !__"; getch();}void main(){ clrscr(); cout<<"\n\n\n\n\n"; //welcome screen cout<<" ___ ___ ______ ** ::::::: !!!!!!!! ___ ___ ______ \n"; cout<<" ___ _ ___ ______ ** :: !! !! __ _ _ __ ______ \n"; cout<<" ___ ___ ___ _ ** :: !! !! __ __ __ _ \n"; cout<<" ___ ___ ______ ****** ::::::: !!!!!!!! __ _ __ ______ \n"; cout<<"\n\n\n\n\n"; cout<<" ~ __ ~ __ ~ __ \n"; cout<<" |==| |==| |==| \n"; cout<<" __|__|__|__|__|__|_ \n"; cout<<" __|___________________|___ \n"; cout<<" __|__[]__[]__[]__[]__[]__[]__|___ CRUISE DATABASE MANAGEMENT\n"; cout<<" |............................o.../ \n";

| ISHAN POPLI

Page 136: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<" \\.............................../ \n"; cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; cout<<" ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \n"; cout<<" ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n"; cout<<" ~ ~ ~ ~ ~ ~ ~ ~ ~ \n"; cout<<" ~ ~ ~ ~ ~ ~ ~ ~\n"; ifstream fl("INITIALL.txt",ios::binary); //initialisation of code if(!fl) cout<<"\nError"; fl.read((char*)&code,sizeof(code)); fl.close(); int opt,opt1,opt2,opt3,opt4; int acceptcode,flag; getch(); clrscr(); do { clrscr(); cout<<"\n\n\t\t_________________________________________________\n"; cout<<"\t\t _....WELCOME TO THE CRUISE DATABASE SYSTEM...._\n"; cout<<"\t\t_________________________________________________\n\n\n"; cout<<"\t\t____________________ ____________________\n"; cout<<"\t\t___________________ MAIN MENU ___________________\n"; cout<<"\t\t____________________ ____________________\n\n"; cout<<"\n\t\t\tPlease select a kind of user:"; cout<<"\n\n\t\t\t\t1.New User\n\n\t\t\t\t2.Existing User\n\n\t\t\t\t3.Exit"; cout<<"\n\n\t\t\t\t_ "; cin>>opt; switch(opt) { case 1:do

{

| ISHAN POPLI

Page 137: My Programs

BANASTHALI PUBLIC SCHOOL

clrscr(); cout<<"\n\n\n\t\t\t\t NEW USER\n"; cout<<"\t\t\t\t ********\n\n"; cout<<"\n\n\t\t\tChoose the type of details you want to enter:"; cout<<"\n\n\t\t\t\t1.Personal Details\n\n\t\t\t\t2.Travel Details\n\n\t\t\t\t3.Back\n\n\

t\t\t\t_ "; cin>>opt1; switch(opt1) {

case 1:code++;pob.p_input(code);ofstream ofl("PersonalDetails.txt",ios::binary|ios::app);if(!ofl)cout<<"\n\n\t\tSorry.The File Cannot Be Opened For Writing"<<endl;ofl.write((char*)&pob,sizeof(pob));ofl.close();break;

case 2:tob.t_input(code);ofstream ofl1("TravelDetails.txt",ios::binary|ios::app);if(!ofl1)cout<<"\n\n\t\tSorry.The File Cannot Be Opened For Writing"<<endl;ofl1.write((char*)&tob,sizeof(tob));ofl1.close();clrscr();cout<<"\n\n\n\n!!!!!Your Details Have Been Registered.Please Make A

Note Of This Code: "<<code;cout<<"\n\n* For modifications,Please visit 'existing user' section in the

main screen";getch();break;

} }while(opt1!=3);

| ISHAN POPLI

Page 138: My Programs

BANASTHALI PUBLIC SCHOOL

break; case 2:clrscr();

cout<<"\n\n\t\t\t_***** EXISTING USER *****_\n\n\t\tPlease Enter The Travel Code That Was Given To You\n\n\t\t\t_ ";

cin>>acceptcode; if(acceptcode>code) { cout<<"\nNo such record has been created!"; break; } family(acceptcode,flag); cout<<endl<<endl<<"\t\t\t\tCode no:"<<acceptcode; getch(); if(flag==1) { do { clrscr(); cout<<"\n\n\t\t\t@@@@@@@@@ Information Centre

@@@@@@@@@"; cout<<"\n\t\t\t\t ~~~~~~~~~~~~~~~~~"; cout<<"\n\n\tPlease select the type of operation that you would like to

perform:"; cout<<"\n\n\t\t\t1.View Personal Details\n\n\t\t\t2.View Travel Details\n\n\t\t\

t3.Edit Details\n\n\t\t\t4.Compute Bill\n\n\t\t\t5.Back\n\n\t\t\t_ "; cin>>opt2; switch(opt2) {

case 1:ifstream ifl("PersonalDetails.txt",ios::binary);if(!ifl)cout<<"\nError";ifl.read((char*)&pob,sizeof(pob));

| ISHAN POPLI

Page 139: My Programs

BANASTHALI PUBLIC SCHOOL

while(!ifl.eof()){ if(pob.givecode()==acceptcode) { break; } ifl.read((char*)&pob,sizeof(pob));}pob.p_output();ifl.close();break;

case 2:ifstream ifl1("TravelDetails.txt",ios::binary);if(!ifl1)cout<<"\nError";ifl1.read((char*)&tob,sizeof(tob));while(!ifl1.eof()){ if(tob.gtcode()==acceptcode) { break; } ifl1.read((char*)&tob,sizeof(tob));}tob.t_output();ifl1.close();break;

case 3:do{ clrscr(); cout<<"\n\n\n\t_______________________ Edit Details

__________________________"; cout<<"\n\n\t\tPlease select from among the editing options:\n\n";

| ISHAN POPLI

Page 140: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"\t\t\t\t1.Modify\n\n\t\t\t\t2.Delete\n\n\t\t\t\t3.Back\n\n\t\t\t\t_ "; cin>>opt3; switch(opt3) { case 1:do

{ clrscr(); cout<<"\n\n\t\t______________ Modificaton

_______________\n"; cout<<"\t\t ~~~~~~~~~~~"; cout<<"\n\n\tChoose The Type Of Details You Want To

Modify:\n\n\t\t\t1.Personal Details\n\n\t\t\t2.Travel Details\n\n\t\t\t3.Back\n\n\t\t\t_ "; cin>>opt4; switch(opt4) { case 1:editp(acceptcode);

break; case 2:editt(acceptcode);

break; case 3:break; } }while(opt4!=3); break;

case 2:deletion(acceptcode); opt3=3; opt2=5; break;

case 3:break; }}while(opt3!=3);break;

case 4:ifstream ifl3("PersonalDetails.txt",ios::binary);

| ISHAN POPLI

Page 141: My Programs

BANASTHALI PUBLIC SCHOOL

if(!ifl3)cout<<"\nError";ifl3.read((char*)&pob,sizeof(pob));while(!ifl3.eof()){ if(pob.givecode()==acceptcode) { break; } ifl3.read((char*)&pob,sizeof(pob));}ifstream ifl2("TravelDetails.txt",ios::binary);if(!ifl2)cout<<"\nError";ifl2.read((char*)&tob,sizeof(tob));while(!ifl2.eof()){ if(tob.gtcode()==acceptcode) { break; } ifl2.read((char*)&tob,sizeof(tob));}tob.accept(pob.give());tob.compute();ifl2.close();break;

case 5:break; } }while(opt2!=5); } break;

| ISHAN POPLI

Page 142: My Programs

BANASTHALI PUBLIC SCHOOL

case 3:ofstream fil("INITIALL.txt",ios::binary); //storing code value if(!fil) cout<<"\nError"; fil.write((char*)&code,sizeof(code)); fil.close(); clrscr(); cout<<"\n\n"; cout<<" _/_/_/_/_/ _/ _/ \n"; cout<<" _/ _/_/_/ _/_/_/ _/_/_/ _/ _/ \n"; cout<<" _/ _/ _/ _/ _/ _/ _/ _/_/ \n"; cout<<" _/ _/ _/ _/ _/ _/ _/ _/ _/ \n"; cout<<" _/ _/ _/ _/_/_/ _/ _/ _/ _/ \n"; cout<<" \n"; cout<<" \n"; cout<<" \n"; cout<<" _/ _/ \n"; cout<<" _/ _/ _/_/ _/ _/ \n"; cout<<" _/ _/ _/ _/ _/ \n"; cout<<" _/ _/ _/ _/ _/ \n"; cout<<" _/ _/_/ _/_/_/ \n\n";

cout<<"\t |===| ~~\n"; cout<<" _| |____________________________________________|| ||___

"; cout<<"\t\t |_|_|_|_\__()____()____()______()______()_____()__||_||

__/"<<endl; cout<<"\t ̀ .==---------|_|----|_|-----|_|----|_|-----------------/"<<endl; cout<<"\t

.̀__________________________________________________/"<<endl;

cout<<"..........oOoOo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;

| ISHAN POPLI

Page 143: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<".........oOoOo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;

cout<<".........oooo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;

getch(); exit(0);

} getch(); }while(1); //infinite loop till exit selected}

//SUM OF BOTH DIAGONALS//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<process.h>

int sum1(int a[50][50],int r){int s=0; for(int i=0;i<r;i++) { s=s+a[i][i];} return(s);}

| ISHAN POPLI

Page 144: My Programs

BANASTHALI PUBLIC SCHOOL

int sum2(int a[50][50],int r){int s=0;int j;j=r-1;for(int i=0;i<r;i++)s=s+a[i][j--];return(s);}

void row(int a[50][50],int r){int s=0;for(int i=0;i<r;i++){s=0;for(int j=0;j<r;j++){s=s+a[i][j];

}cout<<"Sum of Row "<<i+1<<" = "<<s<<endl;}}

void col(int a[50][50],int r){ int s=0;for(int i=0;i<r;i++){

s=0;for(int j=0;j<r;j++)

| ISHAN POPLI

Page 145: My Programs

BANASTHALI PUBLIC SCHOOL

{s=s+a[j][i];

}cout<<"Sum of Column "<<i+1<<" = "<<s<<endl;}}

void main(){clrscr();int i,s,j,r,c,ch,a[50][50];x:cout<<"Entr Array Limit--(Enter only Row as R=C)"<<endl;cin>>r;

cout<<"Enter Array"<<endl; for(i=0;i<r;i++) { for(j=0;j<r;j++) { cin>>a[i][j]; } }y:cout<<endl<<endl<<" Enter Choice :"<<endl<<"Sum of---- 1:main 2:Secondary 3.Rows 4.Columns 5.Re-enter 6.Exit "<<endl;cin>>ch;switch(ch){case 1:s=sum1(a,r);

| ISHAN POPLI

Page 146: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"Sum = "<<s<<endl;goto y;

case 2 :s=sum2(a,r);cout<<"Sum = "<<s<<endl;goto y;

case 3:row(a,r);goto y;

case 4:col(a,r);goto y;

case 5:goto x;

case 6:exit(0);

default :cout<<"Wrong Choice"<<endl;break;

}getch();}

| ISHAN POPLI

Page 147: My Programs

BANASTHALI PUBLIC SCHOOL

//prg to merge arrays//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>int c[100],i,j,k;

class merged{int na,nb,a[50],b[50];public:void merge();void display();void input();}g;

void merged::merge(){int j=0;int i=na-1;while((i>0)&&(j<nb)){if (b[j]<a[i]){c[k]=a[i];i--;k++;}if (b[j]>a[i]){c[k]=b[j];j++;

| ISHAN POPLI

Page 148: My Programs

BANASTHALI PUBLIC SCHOOL

k++;}if (b[j]==a[i]){c[k]=b[j];j++;k++;c[k]=a[i];i--;k++;}}if(i==-1){while(j<nb){c[k]=b[j];j++;k++;}}if(j==nb){while(i>=0){c[k]=a[i];i--;k++;}}}

| ISHAN POPLI

Page 149: My Programs

BANASTHALI PUBLIC SCHOOL

void merged::display(){for(i=0;i<na+nb;i++)cout<<c[i];}

void merged::input(){cout<<"Enter A Lim"<<endl;cin>>na;cout<<"Enter B Limit"<<endl;cin>>nb;cout<<"Enter array A"<<endl;for(i=0;i<na;i++)cin>>a[i];cout<<"Enter Array B"<<endl;for(j=0;j<nb;j++)cin>>b[j];}

void main(){clrscr();g.input();g.merge();g.display();getch();}

//PROGRAM

| ISHAN POPLI

Page 150: My Programs

BANASTHALI PUBLIC SCHOOL

#include<iostream.h>#include<conio.h>#include<string.h>#include<stdlib.h>#include<stdio.h>

//classclass travelplan{long plancode; char place[10]; int noofpeople; int noofbus; public: travelplan(); void newplan(); void showplan(); }travel;void travelplan::travelplan(){cout<<"enter the plancode"<<endl; cin>>plancode; cout<<endl; cout<<"enter the place"<<endl; gets(place); cout<<endl; cout<<"enter the no of travellers"<<endl; cin>>noofpeople; cout<<endl; }

void travelplan::newplan(){if(noofpeople<20)

| ISHAN POPLI

Page 151: My Programs

BANASTHALI PUBLIC SCHOOL

{noofbus=1;} else if((noofpeople>=20)&&(noofpeople<40)) {noofbus=2;} else if(noofpeople>=40) {noofbus=3;} }void travelplan::showplan(){cout<<"Plan code : "<<plancode<<endl;cout<<"Place : "; puts(place); cout<<endl; cout<<"No of travellers : "<<noofpeople<<endl; cout<<"No of bus : "<<noofbus<<endl; }void main(){travel.newplan();travel.showplan();getch();}

//Prg to keep record of books & Audio Cassetes//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<process.h>#include<stdio.h>class publication {

char title[20];

| ISHAN POPLI

Page 152: My Programs

BANASTHALI PUBLIC SCHOOL

float price;public:

void getdata(){cout<<"Enter Title"<<endl;gets(title);cout<<"Enter Price"<<endl;cin>>price;}

void putdata(){cout<<"Title"<<endl;puts(title);cout<<"Price"<<endl;cout<<price;

}};

class book : protected publication{int pagecount;public:void putdata(){publication :: putdata();

| ISHAN POPLI

Page 153: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<endl<<"Pg Count"<<endl;cout<<pagecount;}void getdata(){publication::getdata();cout<<"Pg Count"<<endl;cin>>pagecount;}};

class tape : protected publication{float time;public:void getdata(){publication :: getdata();cout<<"Enter Time"<<endl;cin>>time;}void putdata(){publication :: putdata();cout<<endl<<"Time "<<endl;cout<<time;}};

| ISHAN POPLI

Page 154: My Programs

BANASTHALI PUBLIC SCHOOL

void main(){clrscr();book b;tape t;int ch;x:{cout<<endl<<"1. BOOK 2:Tape 3:Exit "<<endl;cin>>ch;switch(ch){case 1:b.getdata();b.putdata();goto x;case 2:t.getdata();t.putdata();goto x;case 3:exit(0);}}

getch();}

//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<process.h>

| ISHAN POPLI

Page 155: My Programs

BANASTHALI PUBLIC SCHOOL

void main(){clrscr();int ch,i,rear=-1,front=-1,queue[10];x:cout<<endl<<endl;cout<<"Enter Choice 1> Insert 2> Delete 3>exit "<<endl;cin>>ch;switch(ch){case 1:

if(front==-1){front=0;}rear++;if(rear<=9){cout<<"Enter The Element"<<endl;cin>>queue[rear];cout<<"Queue is"<<endl;for(i=0;i<=rear;i++){cout<<queue[i];}}else{cout<<"****************QUEUE OVERFLOW****************";}goto x;

case 2:if(rear==-1){rear=0;}

if(front==-1)

| ISHAN POPLI

Page 156: My Programs

BANASTHALI PUBLIC SCHOOL

{cout<<"*************** UNDER FLOW **********"<<endl;goto x;}elseif(rear==front){queue[front]='\o';front=-1;rear=-1;goto x;}else{queue[front]='\o';front++;}cout<<"Queue is"<<endl;for(i=0;i<=rear;i++){cout<<queue[i];}goto x;case 3:exit(0);

default :goto x;}}

//Queue as a linked list//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<process.h>#include<stdio.h>#include<string.h>

| ISHAN POPLI

Page 157: My Programs

BANASTHALI PUBLIC SCHOOL

struct node {char name[20]; int age; node *link; }*ptr=NULL,*save=NULL;class queue {node *rear,*front; public: queue() {rear=NULL; front=NULL; } void queins(); void quedel(); void display(); }q;

void queue::queins() {ptr=new node; if(ptr==NULL) {cout<<"Queue overflow "; } else {cout<<"Enter the name "; gets(ptr->name); cout<<"Enter the age "; cin>>ptr->age; ptr->link=NULL; if(rear==NULL)

{rear=ptr; front=ptr;

| ISHAN POPLI

Page 158: My Programs

BANASTHALI PUBLIC SCHOOL

} else

{rear->link=ptr; rear=ptr;}

} }

void queue::quedel() {if(rear==NULL) {cout<<"Queue underflow "; } else {if(front==rear) {save=front; front=NULL; rear=NULL; cout<<"Name "; puts(save->name); cout<<"Age "<<save->age; delete save; } else {save=front; front=front->link; cout<<"Name "; puts(save->name); cout<<"Age "<<save->age; delete save; } } }

| ISHAN POPLI

Page 159: My Programs

BANASTHALI PUBLIC SCHOOL

void queue::display() {if(rear==NULL) {cout<<"No elements "; } else {ptr=front; while(ptr!=NULL) {cout<<"Name ";

puts(ptr->name);cout<<"Age "<<ptr->age;ptr=ptr->link;

} } }

void main() {clrscr(); int ch;

X: cout<<"\nEnter your choice\n1.Insert\n2.Delete\n3.Display\n4.Exit\n"; cin>>ch; switch(ch) {case 1:q.queins();

goto X; case 2:q.quedel();

goto X; case 3:q.display();

goto X;

| ISHAN POPLI

Page 160: My Programs

BANASTHALI PUBLIC SCHOOL

case 4:exit(0);

default:cout<<"Wrong choice "; goto X;

} getch(); }//REVERSING EACH WORD SENTENCE//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<string.h>#include<ctype.h>#include<stdio.h>void main(){clrscr();int ch,i,j,k=0,p=0,l;char st[50],sr[50];cout<<"Enter Your Choice : "<<endl<<"1.Each Word Reversing"<<endl<<"2.Whole Sentence Reversing"<<endl;cin>>ch;switch(ch){case 1:cout<<"Enter the String"<<endl;gets(st);l=strlen(st); for(i=0;i<=l;i++) {

| ISHAN POPLI

Page 161: My Programs

BANASTHALI PUBLIC SCHOOL

if((st[i]==' ')||(st[i]=='\0')) { for(j=i-1;j>=p;j--) { sr[k]=st[j]; k++; } sr[k]=' '; k++; p=i+1; } } for(i=0;i<p;i++) cout<<sr[i];break;

case 2:cout<<"Enter the String"<<endl;gets(st);l=strlen(st);p=l-1; for(i=l-1;i>=-1;i--) { if((st[i]==' ')||(i == -1)) { for(j=i+1;j<=p;j++) { sr[k]=st[j]; k++; } sr[k]=' '; k++;

| ISHAN POPLI

Page 162: My Programs

BANASTHALI PUBLIC SCHOOL

p=i-1; } }for(i=0;i<=l;i++)cout<<sr[i];break;

default:cout<<"Wrong Choice"<<endl;break;

}

getch();}

//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<process.h>void main(){clrscr();int ch,i,top=-1,stack[5];x:cout<<endl<<endl;cout<<"Enter Choice 1> Insert 2> Delete 3>exit "<<endl;cin>>ch;switch(ch)

| ISHAN POPLI

Page 163: My Programs

BANASTHALI PUBLIC SCHOOL

{case 1:top++;if(top<=4){cout<<"Enter The Element"<<endl;cin>>stack[top];cout<<"The Stack is"<<endl;for(i=0;i<=top;i++)cout<<stack[i];goto x;}else{cout<<" ************* Stack OVERFLOW ********** "<<endl;goto x;}

case 2:if(top>=0){top--;cout<<"Stack is"<<endl;for(i=0;i<=top;i++)cout<<stack[i];goto x;}else{cout<<"************** Stack UNDER FLOW ***********"<<endl;goto x;}

| ISHAN POPLI

Page 164: My Programs

BANASTHALI PUBLIC SCHOOL

case 3:exit(0);default :cout<<"WRONG CHOICE !!!!!!!!!!! "<<endl;goto x;}}//Stack as a linked list//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<process.h>#include<stdio.h>

struct node {char name[20]; int age; node *link; }*ptr=NULL,*save=NULL;class stack {node *top; public: stack() {top=NULL; } void stackpush(); void stackpop(); void display(); }st;

| ISHAN POPLI

Page 165: My Programs

BANASTHALI PUBLIC SCHOOL

void stack::stackpush() {ptr=new node; if(ptr==NULL) {cout<<"Overflow "; } else {cout<<"Enter the name "; gets(ptr->name); cout<<"Enter the age "; cin>>ptr->age; ptr->link=NULL; if(top==NULL)

{top=ptr;}

else{ptr->link=top; top=ptr;}

} }

void stack::stackpop() {if(top==NULL) {cout<<"Underflow "; } else {save=top; top=top->link; cout<<"Name "; puts(save->name); cout<<"Age "<<save->age; delete save;

| ISHAN POPLI

Page 166: My Programs

BANASTHALI PUBLIC SCHOOL

} }

void stack::display() {if(top==NULL) {cout<<"No elements.."<<endl; } else {ptr=top; while(ptr!=NULL) {cout<<"\nName ";

puts(ptr->name);cout<<"Age "<<ptr->age;ptr=ptr->link;

} } }

void main() {clrscr(); int ch; X: cout<<"\nEnter your choice\n1.Insert\n2.Delete\n3.Display\n4.Exit\n"; cin>>ch; switch(ch) {case 1:st.stackpush();

goto X; case 2:st.stackpop();

goto X; case 3:st.display();

| ISHAN POPLI

Page 167: My Programs

BANASTHALI PUBLIC SCHOOL

goto X; default:cout<<"Wrong choice ";

goto X; case 4:exit(0); } getch(); }//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<dos.h>#include<stdio.h>#include<fstream.h>#include<stdlib.h>#include<string.h>#include<iomanip.h>#include<ctype.h>

void main()

{clrscr();int i,l;char st[50];

ofstream t1("lower.txt");ofstream t2("upper.txt");

if(t1&&t2){cout<<"ENTER "<<endl;

| ISHAN POPLI

Page 168: My Programs

BANASTHALI PUBLIC SCHOOL

gets(st);l=strlen(st);for(i=0;i<l;i++){if(islower(st[i]))t1<<st[i];if(isupper(st[i]))t2<<st[i];}}

getch();}//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>

struct name{char first[50],mid[50],last[50];};

struct phone{char area[50],exch[50];long no;};

class rec{name n;phone p;public :void reci();void disp();};

| ISHAN POPLI

Page 169: My Programs

BANASTHALI PUBLIC SCHOOL

void rec::reci(){clrscr();cout<<"Enter First Name :";cin>>n.first;cout<<endl;cout<<"Enter Mid Name :";cin>>n.mid;cout<<endl;cout<<"Enter Last Name :";cin>>n.last;cout<<endl;cout<<"Enter Area :";cin>>p.area;cout<<endl;cout<<"Enter Exchange :";cin>>p.exch;cout<<endl;cout<<"Enter No :";cin>>p.no;}

void rec::disp(){clrscr();cout<<endl;cout<<endl;cout<<"First Name :";cout<<n.first;cout<<endl;cout<<endl;

| ISHAN POPLI

Page 170: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"Mid Name :";cout<<n.mid;cout<<endl;cout<<endl;cout<<"Last Name :";cout<<n.last;cout<<endl;cout<<endl;cout<<"Area :";cout<<p.area;cout<<endl;cout<<endl;cout<<"Exchange :";cout<<p.exch;cout<<endl;cout<<endl;cout<<"No :";cout<<p.no;cout<<endl;cout<<endl;getch();}void main(){rec t;t.reci();t.disp();getch();}

| ISHAN POPLI

Page 171: My Programs

BANASTHALI PUBLIC SCHOOL

//Downloaded From www.c4cpp.co.nr//(C)2009.All rights reserved.#include<iostream.h>#include<conio.h>#include<dos.h>#include<stdio.h>#include<fstream.h>

struct stud{public:int rno;char name[50];int cls;float marks[5];};

struct res{int rnos;float total;char grade;float perc;};

void main(){clrscr();float tm;int i,ma;stud st;

| ISHAN POPLI

Page 172: My Programs

BANASTHALI PUBLIC SCHOOL

res rt;

ofstream gpj("stud.dat",ios::binary|ios::trunc);ofstream jpg("result.dat",ios::binary|ios::trunc);

if(!gpj||!jpg)cout<<"File Cannot Be Created"<<endl;int n;if(gpj&&jpg){cout<<"How mamy Students U Want to Enter ???? "<<endl;cin>>n;for(i=0;i<n;i++){cout<<"Enter Name"<<endl;gets(st.name);cout<<"Enter Roll No"<<endl;cin>>st.rno;cout<<"Enter Class"<<endl;cin>>st.cls;for(ma=0;ma<5;ma++){cout<<"Enter Marks in subj"<<ma+1<<endl;cin>>st.marks[ma];}

gpj.write((char*)&st,sizeof(st));

tm=st.marks[0]+st.marks[2]+st.marks[1]+st.marks[3]+st.marks[4];

rt.perc=tm/5;

| ISHAN POPLI

Page 173: My Programs

BANASTHALI PUBLIC SCHOOL

if(rt.perc>=75)rt.grade='A';if((rt.perc>=60)&&(rt.perc<75))rt.grade='B';if((rt.perc>=50)&&(rt.perc<60))rt.grade='C';if((rt.perc>=40)&&(rt.perc<50))rt.grade='D';if(rt.perc<40)rt.grade='F';rt.rnos=st.rno;

jpg.write((char*)&rt,sizeof(rt));

}}gpj.close();jpg.close();

int r,k=0;ifstream god("result.dat",ios::binary);if(!god){cout<<"File Erroe"<<endl;}else{god.seekg(0);cout<<endl<<"ENTER ROLL NO"<<endl;cin>>r;while(god.read((char*)&rt,sizeof(rt))){if(r==rt.rnos)

| ISHAN POPLI

Page 174: My Programs

BANASTHALI PUBLIC SCHOOL

{k++;cout<<" Roll no :"<<rt.rnos<<endl<<" Percentage :"<<rt.perc<<endl<<" Grade :"<<rt.grade;}}if(k==0)cout<<"Roll no not present"<<endl;god.close();}getch();}

BIBLIOGRAPH

Y1. Computer science (c++) –sumita arora

| ISHAN POPLI

Page 175: My Programs

BANASTHALI PUBLIC SCHOOL

2. Www.cplusplus.com

TEACHERS REMARKS

| ISHAN POPLI

Page 176: My Programs

BANASTHALI PUBLIC SCHOOL

You have scored_______ marks/grade

For a good attempt.

__________

Signature

STUDENTS REPORT CARD

//***************************************************************

| ISHAN POPLI

Page 177: My Programs

BANASTHALI PUBLIC SCHOOL

// HEADER FILE USED IN PROJECT//****************************************************************

#include<conio.h>#include<stdio.h>#include<process.h>#include<fstream.h>#include<iomanip.h>

//***************************************************************// CLASS USED IN PROJECT//****************************************************************

class student{ int rollno; char name[50]; int p_marks,c_marks,m_marks,e_marks,cs_marks; float per; char grade; int std; void calculate(){ per=(p_marks+c_marks+m_marks+e_marks+cs_marks)/5.0; if(per>=60) grade='A'; else if(per>=50 && per<60) grade='B'; else if(per>=33 && per<50) grade='C';else grade='F';

| ISHAN POPLI

Page 178: My Programs

BANASTHALI PUBLIC SCHOOL

} public:

void getdata(){ cout<<"\nEnter The roll number of student "; cin>>rollno; cout<<"\n\nEnter The Name of student "; gets(name); cout<<"\nEnter The marks in physics out of 100 : "; cin>>p_marks; cout<<"\nEnter The marks in chemistry out of 100 : "; cin>>c_marks; cout<<"\nEnter The marks in maths out of 100 : "; cin>>m_marks; cout<<"\nEnter The marks in english out of 100 : "; cin>>e_marks; cout<<"\nEnter The marks in computer science out of 100 : "; cin>>cs_marks;calculate(); }

void showdata(){ cout<<"\nRoll number of student : "<<rollno; cout<<"\nName of student : "<<name; cout<<"\nMarks in Physics : "<<p_marks; cout<<"\nMarks in Chemistry : "<<c_marks; cout<<"\nMarks in Maths : "<<m_marks; cout<<"\nMarks in English : "<<e_marks; cout<<"\nMarks in Computer Science :"<<cs_marks; cout<<"\nPercentage of student is :"<<setprecision(2)<<per; cout<<"\nGrade of student is :"<<grade;

| ISHAN POPLI

Page 179: My Programs

BANASTHALI PUBLIC SCHOOL

}

void show_tabular() {

cout<<rollno<<setw(12)<<name<<setw(10)<<p_marks<<setw(3)<<c_marks<<setw(3)<<m_marks<<setw(3)<<e_marks<<setw(3)<<cs_marks<<setw(6)<<setprecision(3)<<per<<" "<<grade<<endl;

}

int retrollno() {return rollno;}

}; //class ends here

//***************************************************************// global declaration for stream object, object//****************************************************************

fstream fp; student st;

//***************************************************************// function to write in file//****************************************************************

void write_student() { fp.open("student.dat",ios::out|ios::app); st.getdata();

| ISHAN POPLI

Page 180: My Programs

BANASTHALI PUBLIC SCHOOL

fp.write((char*)&st,sizeof(student)); fp.close(); cout<<"\n\nstudent record Has Been Created "; getch(); }

//***************************************************************// function to read all records from file//****************************************************************

void display_all(){ clrscr(); cout<<"\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n"; fp.open("student.dat",ios::in); while(fp.read((char*)&st,sizeof(student)))

{ st.showdata(); cout<<"\n\n====================================\n"; getch(); }

fp.close(); getch();}

//***************************************************************// function to read specific record from file//****************************************************************

| ISHAN POPLI

Page 181: My Programs

BANASTHALI PUBLIC SCHOOL

void display_sp(int n){ int flag=0; fp.open("student.dat",ios::in); while(fp.read((char*)&st,sizeof(student)))

{ if(st.retrollno()==n)

{ clrscr(); st.showdata(); flag=1;}

} fp.close();if(flag==0) cout<<"\n\nrecord not exist"; getch();}

//***************************************************************// function to modify record of file//****************************************************************

void modify_student(){ int no,found=0; clrscr(); cout<<"\n\n\tTo Modify "; cout<<"\n\n\tPlease Enter The roll number of student";

| ISHAN POPLI

Page 182: My Programs

BANASTHALI PUBLIC SCHOOL

cin>>no; fp.open("student.dat",ios::in|ios::out); while(fp.read((char*)&st,sizeof(student)) && found==0)

{ if(st.retrollno()==no)

{ st.showdata(); cout<<"\nPlease Enter The New Details of student"<<endl; st.getdata(); int pos=-1*sizeof(st); fp.seekp(pos,ios::cur); fp.write((char*)&st,sizeof(student)); cout<<"\n\n\t Record Updated"; found=1; }

} fp.close(); if(found==0) cout<<"\n\n Record Not Found "; getch();}

//***************************************************************// function to delete record of file//****************************************************************

void delete_student() { int no; clrscr();

| ISHAN POPLI

Page 183: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"\n\n\n\tDelete Record"; cout<<"\n\nPlease Enter The roll number of student You Want To Delete"; cin>>no; fp.open("student.dat",ios::in|ios::out); fstream fp2; fp2.open("Temp.dat",ios::out); fp.seekg(0,ios::beg); while(fp.read((char*)&st,sizeof(student)))

{ if(st.retrollno()!=no)

{ fp2.write((char*)&st,sizeof(student)); }

} fp2.close(); fp.close(); remove("student.dat"); rename("Temp.dat","student.dat"); cout<<"\n\n\tRecord Deleted .."; getch(); }

//***************************************************************// function to display all students grade report//****************************************************************

void class_result() { clrscr(); fp.open("student.dat",ios::in); if(!fp)

| ISHAN POPLI

Page 184: My Programs

BANASTHALI PUBLIC SCHOOL

{ cout<<"ERROR!!! FILE COULD NOT BE OPEN\n\n\n Go To Entry Menu to create File"; cout<<"\n\n\n Program is closing ...."; getch(); exit(0); }

cout<<"\n\n\t\tALL STUDENTS RESULT \n\n"; cout<<"====================================================\

n"; cout<<"Roll No. Name P C M E CS %age Grade\n"; cout<<"====================================================\

n";

while(fp.read((char*)&st,sizeof(student))) { st.show_tabular();}

fp.close(); getch();}

//***************************************************************// function to display result menu//****************************************************************

void result() {

| ISHAN POPLI

Page 185: My Programs

BANASTHALI PUBLIC SCHOOL

int ans,rno; char ch; clrscr(); cout<<"\n\n\nRESULT MENU"; cout<<"\n\n\n1. Class Result\n\n2. Student Report Card\n\n3.Back to Main Menu"; cout<<"\n\n\nEnter Choice (1/2)? "; cin>>ans; switch(ans) { case 1 : class_result();break; case 2 : {

do{clrscr();char ans;cout<<"\n\nEnter Roll Number Of Student : ";cin>>rno;display_sp(rno);cout<<"\n\nDo you want to See More Result (y/n)?";cin>>ans;}while(ans=='y'||ans=='Y');

break; }

case 3: break; default: cout<<"\a"; } }

//***************************************************************// INTRODUCTION FUNCTION//****************************************************************

| ISHAN POPLI

Page 186: My Programs

BANASTHALI PUBLIC SCHOOL

void intro(){ clrscr(); gotoxy(35,11); cout<<"STUDENT"; gotoxy(33,14); cout<<"REPORT CARD"; gotoxy(35,17); cout<<"PROJECT"; cout<<"\n\nMADE BY : SULABH AGRAWAL"; cout<<"\n\nSCHOOL : CAMBRIDGE SCHOOL"; getch();

}

//***************************************************************// ENTRY / EDIT MENU FUNCTION//****************************************************************void entry_menu(){ clrscr(); char ch2; cout<<"\n\n\n\tENTRY MENU"; cout<<"\n\n\t1.CREATE STUDENT RECORD"; cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORDS"; cout<<"\n\n\t3.SEARCH STUDENT RECORD "; cout<<"\n\n\t4.MODIFY STUDENT RECORD"; cout<<"\n\n\t5.DELETE STUDENT RECORD"; cout<<"\n\n\t6.BACK TO MAIN MENU";

| ISHAN POPLI

Page 187: My Programs

BANASTHALI PUBLIC SCHOOL

cout<<"\n\n\tPlease Enter Your Choice (1-6) "; ch2=getche(); switch(ch2) { case '1': clrscr();

write_student(); break;

case '2': display_all();break; case '3':

int num; clrscr(); cout<<"\n\n\tPlease Enter The roll number "; cin>>num; display_sp(num); break;

case '4': modify_student();break; case '5': delete_student();break; case '6': break; default:cout<<"\a";entry_menu(); }}

//***************************************************************// THE MAIN FUNCTION OF PROGRAM//****************************************************************

void main(){ char ch; intro();

| ISHAN POPLI

Page 188: My Programs

BANASTHALI PUBLIC SCHOOL

do {

clrscr(); cout<<"\n\n\n\tMAIN MENU"; cout<<"\n\n\t01. RESULT MENU"; cout<<"\n\n\t02. ENTRY/EDIT MENU"; cout<<"\n\n\t03. EXIT"; cout<<"\n\n\tPlease Select Your Option (1-3) "; ch=getche(); switch(ch) {

case '1': clrscr(); result(); break;

case '2': entry_menu(); break;

case '3':exit(0); default :cout<<"\a";

} }while(ch!='3');}

//***************************************************************// END OF PROJECT//***************************************************************

| ISHAN POPLI