0% found this document useful (0 votes)
3 views47 pages

Computer Science Assignment

assignment for class 12 cs

Uploaded by

harsh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views47 pages

Computer Science Assignment

assignment for class 12 cs

Uploaded by

harsh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

COMPUTER

SCIENCE
ASSIGNMENT

By Tanmay Gupta

Class: XII-L | Roll No.: 36


Computer
Science
Assignment
List 1
/*
Program No: 1
Developed By : Ark, Harsh Mittal
Date: 18 April 2017
*/
#include<iostream.h>
#include<conio.h>
void Series1();
void Series2();
void Series3();
void main()
{
clrscr();
int n;
do
{
cout<<"1. For X + X^2 + X^3 +....N terms \n";
cout<<"2. For U+U^2/2!+ U^3/3!+....N terms \n";
cout<<"3. For 2+(2+4)+(2+4+6)+....N terms \n";
cout<<"4. For exit \n";
cout<<"Enter your choice: \n";
cin>>n;
switch(n)
{
case 1: Series1();break;
case 2: Series2();break;
case 3: Series3();break;
default: cout<<"Thank You";
}
}
while(n!=4);
getch();
}
void Series1()
{
int a,x,pro=1,sum=0;
cout<<"Enter the value for X \n";
cin>>x;
cout<<"Enter the value for N \n";
cin>>a;
for(int i=1;i<=a;i++)
{
pro*=x;
sum+=pro;
}
cout<<"Sum of series: "<<sum<<endl<<endl;
}
void Series2()
{
float u,a,pro=1,fact=1,sum=0;
cout<<"Enter the value for U: ";
cin>>u;
cout<<"Enter the value for N: ";
cin>>a;
for(int i=1;i<=a;i++)
{
pro*=u;
fact*=i;
sum+=pro/fact;
}
cout<<"Sum of series: "<<sum<<endl<<endl;
}
void Series3()
{
int a,subsum=0,sum=0;
cout<<"Enter the value for N: ";
cin>>a;
for(int i=1;i<=a;i++)
{
subsum+=i*2;
sum+=subsum;
}
cout<<"Sum of series: "<<sum<<endl<<endl;
}
/*
OUTPUT:
1. For X + X^2 + X^3 +....N terms
2. For U+U^2/2!+ U^3/3!+....N terms
3. For 2+(2+4)+(2+4+6)+....N terms
4. For exit
Enter your choice:
1
Enter the value for X
5
Enter the value for N
3
Sum of series: 155

1. For X + X^2 + X^3 +....N terms


2. For U+U^2/2!+ U^3/3!+....N terms
3. For 2+(2+4)+(2+4+6)+....N terms
4. For exit
Enter your choice:
4
Thank You
*/
/*
Program No: 2
Developed By : Ark, Harsh Mittal
Date: 18 April 2017
*/
#include<iostream.h>
#include<conio.h>
int Prime(int);
int Palindrome(int);
int Even(int);
void main()
{
clrscr();
int n,N;
do
{
cout<<"Enter a number: ";cin>>N;
cout<<"Choose an option to check for: \n";
cout<<"1. Prime Number \n";
cout<<"2. Palindrome \n";
cout<<"3. Even Number \n";
cout<<"4. For exit \n";
cin>>n;
switch(n)
{
case 1: if(Prime(N)==1)
cout<<"Yes, it is a Prime Number. \n";
else
cout<<"No, it is not a Prime Number. \n";
break;
case 2: if(Palindrome(N)==1)
cout<<"Yes, it is a Palindrome. \n";
else
cout<<"No, it is not a Palindrome \n";
break;
case 3: if(Even(N)==1)
cout<<"Yes, it is an Even Number. \n";
else
cout<<"No, it is not an Even Number. \n";
break;
default: cout<<"Thank You";
}
}
while(n!=4);
getch();
}
int Prime(int N)
{
int count=0;
for(int i=2;i<=N/2 && count==0;i++)
if(N%i==0)
count++;
if(count==0)
return 1;
else
return 0;
}
int Palindrome(int N)
{
int r=0,t=N;
for(int i=1;t!=0;i++)
{
r+=(t%10);
r*=10;
t/=10;
}
r=r/10;
if(N=r)
return 1;
else
return 0;
}
int Even(int N)
{
if(N%2==0)
return 1;
else
return 0;
}
/*
OUTPUT:

Enter a number: 1221


Choose an option to check for:
1. Prime Number
2. Palindrome
3. Even Number
4. For exit
2
Yes, it is a Palindrome.
Enter a number: 3
Choose an option to check for:
1. Prime Number
2. Palindrome
3. Even Number
4. For exit
4
Thank You
*/
/*
Program No: 3
Developed By : Ark, Harsh Mittal
Date: 18 April 2017
*/
#include<iostream.h>
#include<conio.h>
void Enter(int [],int);
void Display(int [],int);
void Sort(int [],int);
void Search(int [],int);
void main()
{
clrscr();
int A[50],N,n;
cout<<"Enter the number of elements: ";cin>>N;
do
{
cout<<"Choose an option: \n";
cout<<"1. Enter the contents of the array. \n";
cout<<"2. Display the contents of the array. \n";
cout<<"3. Sort the array. \n";
cout<<"4. Search for an integer. \n";
cout<<"5. Exit \n";
cout<<"Enter your choice: ";cin>>n;
switch(n)
{
case 1: Enter(A,N);break;
case 2: Display(A,N);break;
case 3: Sort(A,N);break;
case 4: Search(A,N);break;
default: cout<<"Thank You";
}
}
while(n!=5);
getch();
}
void Enter(int A[],int N)
{
cout<<endl;
cout<<"Enter the contents of the array: \n";
for(int i=0;i<N;i++)
{
cout<<"Enter Element "<<i+1<<" : ";cin>>A[i];
}
cout<<endl;
}
void Display(int A[],int N)
{
cout<<endl;
for(int i=0;i<N;i++)
{
cout<<"Element "<<i+1<<" : "<<A[i]<<endl;
}
cout<<endl;
}
void Sort(int A[],int N)
{
int i,key,j;
for (i=1;i<N;i++)
{
key = A[i];
j = i-1;
while (j>=0 && A[j]>key)
{
A[j+1] = A[j];
j=j-1;
}
A[j+1]=key;
}
}
void Search(int A[],int N)
{
cout<<endl;
int X,count=0;
cout<<"What value do you want to search? ";cin>>X;
for(int i=0;i<N;i++)
{
if(A[i]==X)
count++;
}
if(count>0)
cout<<"The value exists "<<count<<" times.";
else
cout<<"The Value doesn't exixst.";
cout<<endl;
}
/*
OUTPUT:
Enter the number of elements: 3
Choose an option:
1. Enter the contents of the array.
2. Display the contents of the array.
3. Sort the array.
4. Search for an integer.
5. Exit
Enter your choice: 1

Enter the contents of the array:


Enter Element 1 : 23
Enter Element 2 : 69
Enter Element 3 : 23

Choose an option:
1. Enter the contents of the array.
2. Display the contents of the array.
3. Sort the array.
4. Search for an integer.
5. Exit
Enter your choice: 5
Thank You
*/

/*
Program No: 4
Developed By : Ark, Harsh Mittal
Date: 19 April 2017
*/
#include<iostream.h>
#include<conio.h>
void Enter(int [],int);
void Display(int [],int);
void Sort(int [],int);
void Search(int [],int);
void main()
{
clrscr();
int A[50],N,n;
cout<<"Enter the number of elements: ";cin>>N;
do
{
cout<<"Choose an option: \n";
cout<<"1. Enter the contents of the array. \n";
cout<<"2. Display the contents of the array. \n";
cout<<"3. Sort the array. \n";
cout<<"4. Search for an integer. \n";
cout<<"5. Exit \n";
cout<<"Enter your choice: ";cin>>n;
switch(n)
{
case 1: Enter(A,N);break;
case 2: Display(A,N);break;
case 3: Sort(A,N);break;
case 4: Search(A,N);break;
default: cout<<"Thank You";
}
}
while(n!=5);
getch();
}
void Enter(int A[],int N)
{
cout<<endl;
cout<<"Enter the contents of the array: \n";
for(int i=0;i<N;i++)
{
cout<<"Enter Element "<<i+1<<" : ";cin>>A[i];
}
cout<<endl;
}
void Display(int A[],int N)
{
cout<<endl;
for(int i=0;i<N;i++)
{
cout<<"Element "<<i+1<<" : "<<A[i]<<endl;
}
cout<<endl;
}
void Sort(int A[],int N)
{
cout<<endl;
int i,j,t;
for(i=0;i<N;i++)
{
for(j=i+1;j<N;j++)
{
if(A[j]<A[i])
{
t=A[i];
A[i]=A[j];
A[j]=t;
}
}
}
cout<<endl;
}
void Search(int A[],int N)
{
int i,beg,mid,end,pos,X;
cout<<endl;
cout<<"Enter the value to be searched: ";cin>>X;
beg=0;
end=i-1;
mid=(beg+end)/2;
do
{
if(A[mid]==X)
{
pos=mid;
cout<<"The value is at "<<++pos<<" position \n";
}
else
{
if(A[mid]<X)
{
beg=mid+1;
mid=(beg+end)/2;
}
}
}
while(0);
}

/*
OUTPUT:
Enter the number of elements: 3
Choose an option:
1. Enter the contents of the array.
2. Display the contents of the array.
3. Sort the array.
4. Search for an integer.
5. Exit
Enter your choice: 1

Enter the contents of the array:


Enter Element 1 : 23
Enter Element 2 : 69
Enter Element 3 : 23

Choose an option:
1. Enter the contents of the array.
2. Display the contents of the array.
3. Sort the array.
4. Search for an integer.
5. Exit
Enter your choice: 5
Thank You
*/
/*
Program No: 5
Developed By : Ark, Harsh Mittal
Date: 25 April 2017
*/
#include<iostream.h>
#include<conio.h>
void Enter(int [50][50],int,int);
void Display(int [50][50],int,int);
void Add(int [50][50],int [50][50],int,int);
void Sub(int [50][50],int [50][50],int,int);
void main()
{
clrscr();
int R,C,A[50][50],B[50][50],n;
cout<<"Enter number of rows: ";cin>>R;
cout<<"Enter number of columns: ";cin>>C;
do
{
cout<<"Choose an option: \n";
cout<<"1. Enter the contents of first array. \n";
cout<<"2. Enter the contents of second array. \n";
cout<<"3. Display the contents of first array. \n";
cout<<"4. Display the contents of second array. \n";
cout<<"5. Add two arrays. \n";
cout<<"6. Subtract two arrays. \n";
cout<<"7. Exit. \n";
cout<<"Enter your choice: ";cin>>n;
switch(n)
{
case 1: Enter(A,R,C);break;
case 2: Enter(B,R,C);break;
case 3: Display(A,R,C);break;
case 4: Display(B,R,C);break;
case 5: Add(A,B,R,C);break;
case 6: Sub(A,B,R,C);break;
default: cout<<"Thank You";
}
}
while(n!=7);
getch();
}
void Enter(int A[50][50],int R,int C)
{
cout<<endl;
cout<<"Enter the contents of the array: \n";
for(int i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
cout<<"Enter Element "<<i+1<<","<<j+1<<" : ";cin>>A[i][j];
}
}
}
void Display(int A[50][50],int R,int C)
{
cout<<endl;
for(int i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
cout<<"Element "<<i+1<<","<<j+1<<" : "<<A[i][j]<<" ";
}
}
cout<<endl;
}
void Add(int A[50][50],int B[50][50],int R,int C)
{
int c[50][50];
for(int i=0;i<R;i++)
for(int j=0;j<C;j++)
{
c[i][j]= A[i][j]+B[i][j];
}
Display(c,R,C);
}
void Sub(int A[50][50],int B[50][50],int R,int C)
{
int c[50][50];
for(int i=0;i<R;i++)
for(int j=0;j<C;j++)
{
c[i][j]= A[i][j]-B[i][j];
}
Display(c,R,C);
}
/*
OUTPUT:
Enter the number of rows: 2
Enter the number of columns: 2
Choose an option:
1. Enter the contents of first array.
2. Enter the contents of second array.
3. Display the contents of first array.
4. Display the contents of second array.
5. Add two arrays.
6. Subtract two arrays.
7. Exit.
Enter your choice: 1
Enter the contents of the array:
Enter Element 1,1 : 1
Enter Element 1,2 : 2
Enter Element 2,1 : 3
Enter Element 2,2 : 4
Choose an option:
1. Enter the contents of first array.
2. Enter the contents of second array.
3. Display the contents of first array.
4. Display the contents of second array.
5. Add two arrays.
6. Subtract two arrays.
7. Exit.
Enter your choice: 2

Enter the contents of the array:


Enter Element 1,1 : 5
Enter Element 1,2 : 6
Enter Element 2,1 : 7
Enter Element 2,2 : 8
Choose an option:
1. Enter the contents of first array.
2. Enter the contents of second array.
3. Display the contents of first array.
4. Display the contents of second array.
5. Add two arrays.
6. Subtract two arrays.
7. Exit.
Enter your choice: 5

Element 1,1 : 6 Element 1,2 : 8 Element 2,1 : 10 Element 2,2 : 12


Choose an option:
1. Enter the contents of first array.
2. Enter the contents of second array.
3. Display the contents of first array.
4. Display the contents of second array.
5. Add two arrays.
6. Subtract two arrays.
7. Exit.
Enter your choice: 7
Thank You
*/
/*
Program No: 6
Developed By : Ark, Harsh Mittal
Date: 25 April 2017
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void main()
{
clrscr();
char str[40];
int vowels=0,digit=0,cons=0,space=0;
cout<<"Enter the string: ";
gets(str);
for(int i=0;i<strlen(str);i++)
if(tolower(str[i])=='a'|| tolower(str[i])=='e' || tolower(str[i])=='i'||
tolower(str[i])=='o'|| tolower(str[i])=='u')
vowels++;
else if(str[i]>=48 && str[i]<=57)
digit++;
else if(str[i]==32)
space++;
else
cons++;
cout<<"Number of Vowels: "<<vowels<<endl;
cout<<"Number of Consonants: "<<cons<<endl;
cout<<"Number of Digits: "<<digit<<endl;
cout<<"Number of Space: "<<space<<endl<<endl;
cout<<"The reverse string is: "<<strrev(str);
getch();
}
/*
OUTPUT:

Enter the string: DPS RKP Sec12 New Delhi


Number of Vowels: 4
Number of Consonants: 13
Number of Digits: 2
Number of Space: 4

The reverse string is: ihleD weN 21ceS PKR SPD


*/
/*
Program No: 7
Developed By : Ark, Harsh Mittal
Date: 26 April 2017
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void Enter(char[][50],int);
void Display(char[][50],int);
void Sort(char[][50],int);
void Search(char[][50],int);

void main()
{
clrscr();
int n,N;
char A[50][50];
cout<<"Enter Number of Countries: ";cin>>N;
do
{
cout<<"1. Enter the names of the countries. \n";
cout<<"2. Display the names of the countries. \n";
cout<<"3. Sort the names of the countries. \n";
cout<<"4. Search for the name of a country. \n";
cout<<"5. Exit. \n";
cin>>n;
switch(n)
{
case 1: Enter(A,N);break;
case 2: Display(A,N);break;
case 3: Sort(A,N);break;
case 4: Search(A,N);break;
default: cout<<"Thank You..!";
}
}
while(n!=5);
getch();
}
void Enter(char A[50][50],int N)
{
for(int i=0;i<N;i++)
{
cout<<"Enter Country "<<i+1<<" : ";
gets(A[i]);
}
}
void Display(char A[][50],int N)
{
for(int i=0;i<N;i++)
puts(A[i]);

}
void Sort(char A[][50],int N)
{
char Z[50];
for(int i=0;i<N;i++)
for(int j=0;j<N-1;j++)
if(strcmpi(A[j],A[j+1])<0)
{
strcpy(Z,A[j+1]);
strcpy(A[j+1],A[j+2]);
strcpy(A[j+2],Z);
}
for(int j=0;j<N;j++)
cout<<A[j]<<endl;
}
void Search(char A[][50],int N)
{
int count=0;
char S[50];
cout<<"Enter the value to be searched: ";gets(S);
for(int i=0;i<N;i++)
if(strcmpi(S,A[i])==0)
count++;
if(count>0)
cout<<"Value Exists.";
else
cout<<"Value doesn't exists.";
}
/*
OUTPUT:
Enter the Number of Countries: 3
1. Enter the names of the countries.
2. Display the names of the countries.
3. Sort the names of the countries.
4. Search for the name of a country.
5. Exit.
1
Enter Country 1 : India
Enter Country 2 : United States
Enter Country 3 : Czech Republic
1. Enter the names of the countries.
2. Display the names of the countries.
3. Sort the names of the countries.
4. Search for the name of a country.
5. Exit.
3
Czech Republic
India
United States
1. Enter the names of the countries.
2. Display the names of the countries.
3. Sort the names of the countries.
4. Search for the name of a country.
5. Exit.
5
Thank You..!
*/
Computer
Science
Assignment
List 2
/*
Program No: 8
Developed By: Harsh Mittal
Date: 13 May 2017
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct BOOK
{
int Bno;
char Bname[20],Author[20];
float Price;
};
void Enter(BOOK [],int);
void Display(BOOK [],int);
void Search(BOOK [],int);
void main()
{
clrscr();
BOOK B[20];
int N,n;
cout<<"Enter the number of Books: ";cin>>N;
do
{
cout<<"Select an option: \n";
cout<<"1. Enter the details of the books.\n";
cout<<"2. Displaying the details of the books. \n";
cout<<"3. Search for a book. \n";
cout<<"4. Exit. \n";
cout<<"Choose an option: ";cin>>n;
switch(n)
{
case 1: Enter(B,N);break;
case 2: Display(B,N);break;
case 3: Search(B,N);break;
default: cout<<"Exiting...";
}
}
while(n!=4);
getch();
}
void Enter(BOOK B[],int N)
{
cout<<"\nEnter the details of the books: \n";
for(int i=0;i<N;i++)
{
cout<<"BookNumber of Book "<<i+1<<" : ";cin>>B[i].Bno;
cout<<"Name of Book "<<i+1<<" : ";gets(B[i].Bname);
cout<<"Author of Book "<<i+1<<" : ";gets(B[i].Author);
cout<<"Price of Book "<<i+1<<" : ";cin>>B[i].Price;
}
}
void Display(BOOK B[],int N)
{
for(int i=0;i<N;i++)
{
cout<<"BookNumber of Book "<<i+1<<" : ";cout<<B[i].Bno<<endl;
cout<<"Namee of Book "<<i+1<<" : ";puts(B[i].Bname);
cout<<"Author of Book "<<i+1<<" : ";puts(B[i].Author);
cout<<"Price of Book "<<i+1<<" : ";cout<<B[i].Price<<endl;
}
}
void Search(BOOK B[],int N)
{
int n;
cout<<"Select an option to search: \n";
cout<<"1. Search by BookNumber \n";
cout<<"2. Search by BookName \n";
cout<<"Choose an option: ";cin>>n;
if(n==1)
{
int no,Found=0;
cout<<"Enter the BookNumber to be searched: ";cin>>no;
for(int i=0;i<N;i++)
{
if(no==B[i].Bno)
{
cout<<"BookNumber of Book "<<" : ";cout<<B[i].Bno<<endl;
cout<<"Name of Book "<<" : ";puts(B[i].Bname);
cout<<"Author of Book "<<" : ";puts(B[i].Author);
cout<<"Price of Book "<<" : ";cout<<B[i].Price<<endl;
Found++;
}
}
if(Found==0)
cout<<"Book doesn't exist.\n";

}
else
{
char bookname[40];
int found=0;
cout<<"Enter the name of the book to be searched: ";gets(bookname);
for(int i=0;i<N;i++)
{
if(strcmpi(bookname,B[i].Bname)==0)
{
cout<<"BookNumber of Book "<<" : ";cout<<B[i].Bno<<endl;
cout<<"Name of Book "<<" : ";puts(B[i].Bname);
cout<<"Author of Book "<<" : ";puts(B[i].Author);
cout<<"Price of Book "<<" : ";cout<<B[i].Price<<endl;
found++;
}
}
if(found==0)
cout<<"Book doesn't exist.\n";
}
}

/*
OUTPUT:
Enter the number of Books: 2
Select an option:
1. Enter the details of the books.
2. Displaying the details of the books.
3. Search for a book.
4. Exit.
Choose an option: 1

Enter the details of the books:


BookNumber of Book 1 : 123
Name of Book 1 : Percy Jackson
Author of Book 1 : Rick Riordan
Price of Book 1 : 299
BookNumber of Book 2 : 234
Name of Book 2 : The Hunger Games
Author of Book 2 : Suzanne Collins
Price of Book 2 : 599
Select an option:
1. Enter the details of the books.
2. Displaying the details of the books.
3. Search for a book.
4. Exit.
Choose an option: 3
Select an option to search:
1. Search by BookNumber
2. Search by BookName
Choose an option: 2
Enter the name of the book to be searched: Percy Jackson
BookNumber of Book : 123
Name of Book : Percy Jackson
Author of Book: Rick Riordan
Price of Book : 299
Select an option:
1. Enter the details of the books.
2. Displaying the details of the books.
3. Search for a book.
4. Exit.
Choose an option: 4
Exiting...

*/

/*
Program No. : 9
Developed By : Harsh Mittal
Date: 10 May 2017
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct CANDIDATE
{
int Cno,Score;
char Cname[20];
};
void Enter(int,CANDIDATE []);
void Display(int,CANDIDATE []);
void Sort(int,CANDIDATE []);
void main()
{
clrscr();
int N,n;
CANDIDATE C[20];
cout<<"Enter the number of candidates: ";cin>>N;
do
{
cout<<"Select an option: \n";
cout<<"1. Enter data of candidates. \n";
cout<<"2. Display data of candidates. \n";
cout<<"3. Sort and Display data of candidates. \n";
cout<<"4. Exit \n";
cout<<"Choose an option: ";cin>>n;
cout<<endl;
switch(n)
{
case 1: Enter(N,C);break;
case 2: Display(N,C);break;
case 3: Sort(N,C);break;
default: cout<<"Exiting...";
}
}
while(n!=4);
getch();
}
void Enter(int N,CANDIDATE C[])
{
for(int i=0;i<N;i++)
{
cout<<"Enter the details of candidate "<<i+1<<" : \n";
cout<<"Candidate Number: ";cin>>C[i].Cno;
cout<<"Name: ";gets(C[i].Cname);
cout<<"Score: ";cin>>C[i].Score;
cout<<endl;
}
}
void Display(int N,CANDIDATE C[])
{
for(int i=0;i<N;i++)
{
cout<<"Details of Candidate "<<i+1<<" : \n";
cout<<"Candidate Number: "<<C[i].Cno;
cout<<endl;
cout<<"Name: ";puts(C[i].Cname);
cout<<"Score: "<<C[i].Score;
cout<<endl;
}
}
void Sort(int N,CANDIDATE C[])
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<N-1;j++)
if(C[j].Score>C[j+1].Score)
{
CANDIDATE T=C[j];
C[j]=C[j+1];
C[j+1]=T;
}
for(i=0;i<N;i++)
{
cout<<"Details of Candidate "<<i+1<<" : \n";
cout<<"Candidate Number: "<<C[i].Cno;
cout<<endl;
cout<<"Name: ";puts(C[i].Cname);
cout<<"Score: "<<C[i].Score;
cout<<endl;
}
}
/*
OUTPUT:
Enter the number of candidates: 3
Select an option:
1. Enter data of candidates.
2. Display data of candidates.
3. Sort and Display data of candidates.
4. Exit
Choose an option: 1

Enter the details of candidate 1 :


Candidate Number: 112233
Name: John Smith
Score: 87

Enter the details of candidate 2 :


Candidate Number: 696969
Name: Ronald McDonald
Score: 19

Enter the details of candidate 3 :


Candidate Number: 000001
Name: Harsh Mittal
Score: 100

Select an option:
1. Enter data of candidates.
2. Display data of candidates.
3. Sort and Display data of candidates.
4. Exit
Choose an option: 3

Details of Candidate 1 :
Candidate Number: 112233
Name: Ronald McDonald
Score: 19
Details of Candidate 2 :
Candidate Number: 696969
Name: John smSmith
Score: 87
Details of Candidate 3 :
Candidate Number: 000001
Name: Harsh Mittal
Score: 100

Select an option:
1. Enter data of candidates.
2. Display data of candidates.
3. Sort and Display data of candidates.
4. Exit
Choose an option: 4

Exiting...
*/
/*
Program No. : 10
Developed By : Harsh Mittal
Date: 10 May 2017
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct ACCOUNT
{
int Acno;
float Balance;
char Name[20];
};
void Enter(int,ACCOUNT []);
void Display1(int,ACCOUNT []);
void Display2(int,ACCOUNT []);
void main()
{
clrscr();
int N,n;
ACCOUNT A[20];
cout<<"Enter the number of Bank Accounts: ";cin>>N;
do
{
cout<<"Select an option: \n";
cout<<"1. Enter data of Bank Accounts. \n";
cout<<"2. Display data of Bank Accounts. \n";
cout<<"3. Display data of Bank Accounts which have balance>100000. \n";
cout<<"4. Exit \n";
cout<<"Choose an option: ";cin>>n;
cout<<endl;
switch(n)
{
case 1: Enter(N,A);break;
case 2: Display1(N,A);break;
case 3: Display2(N,A);break;
default: cout<<"Exiting...";
}
}
while(n!=4);
getch();
}
void Enter(int N,ACCOUNT A[])
{
for(int i=0;i<N;i++)
{
cout<<"Enter the details of Bank Account: "<<i+1<<" : \n";
cout<<"Account Number: ";cin>>A[i].Acno;
cout<<"Name: ";gets(A[i].Name);
cout<<"Balance: ";cin>>A[i].Balance;
cout<<endl;
}
}
void Display1(int N,ACCOUNT A[])
{
for(int i=0;i<N;i++)
{
cout<<"Details of Bank Account "<<i+1<<": \n";
cout<<"Account Number: "<<A[i].Acno;
cout<<endl;
cout<<"Name: ";puts(A[i].Name);
cout<<"Balance: "<<A[i].Balance;
cout<<endl;
cout<<endl;
}
}
void Display2(int N,ACCOUNT A[])
{
for(int i=0;i<N;i++)
{
if(A[i].Balance>100000)
{
cout<<"Details of Bank Account "<<i+1<<": \n";
cout<<"Account Number: "<<A[i].Acno;
cout<<endl;
cout<<"Name: ";puts(A[i].Name);
cout<<"Balance: "<<A[i].Balance;
cout<<endl;
cout<<endl;
}
}
}
/*
OUTPUT:
Enter the number of Bank Accounts: 3
Select an option:
1. Enter data of Bank Accounts.
2. Display data of Bank Accounts.
3. Display data of Bank Accounts which have balance>100000.
4. Exit
Choose an option: 1

Enter the details of Bank Account 1:


Account Number: 1234
Name: Harsh Mittal
Balance: 10999

Enter the details of Bank Account 2:


Account Number: 5678
Name: Ark
Balance: 99999999.99

Enter the details of Bank Account 3:


Account Number: 9012
Name: Harsh mittal
Balance: 506969.66

Select an option:
1. Enter data of Bank Accounts.
2. Display data of Bank Accounts.
3. Display data of Bank Accounts which have balance>100000.
4. Exit
Choose an option: 3

Details of Bank Account 2:


Account Number: 5678
Name: Ark
Balance: 99999999.99

Details of Bank Account: 3 :


Account Number: 9012
Name: Harsh mittal
Balance: 506969.65625

Select an option:
1. Enter data of Bank Accounts.
2. Display data of Bank Accounts.
3. Display data of Bank Accounts which have balance>100000.
4. Exit
Choose an option: 4

Exiting...
*/
/*
Program No: 11
Developed By: Harsh Mittal
Date: 13 May 2017
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct FLIGHT
{
int Flno;
char DepTime[20],ArrTime[20];
float Fare;
};
void Enter(FLIGHT [],int);
void Display(FLIGHT [],int);
void Low(FLIGHT [],int);
void main()
{
clrscr();
FLIGHT B[20];
int N,n;
cout<<"Enter the number of Flight: ";cin>>N;
do
{
cout<<"Select an option: \n";
cout<<"1. Enter the details of the flight\n";
cout<<"2. Displaying the details of the flight. \n";
cout<<"3. Displaying the flight with lowest fares\n";
cout<<"4. Exit. \n";
cout<<"Choose an option: ";cin>>n;
switch(n)
{
case 1: Enter(B,N);break;
case 2: Display(B,N);break;
case 3: Low(B,N);break;
default: cout<<"Exiting...";
}
}
while(n!=4);
getch();
}
void Enter(FLIGHT B[],int N)
{
cout<<"\nEnter the details of the flight: \n";
for(int i=0;i<N;i++)
{
cout<<"Flight no. of flight "<<i+1<<" : ";cin>>B[i].Flno;
cout<<"Departure time of flight "<<i+1<<" : ";gets(B[i].DepTime);
cout<<"Arrival time of flight "<<i+1<<" : ";gets(B[i].ArrTime);
cout<<"Fare of flight "<<i+1<<" : ";cin>>B[i].Fare;
}
}
void Display(FLIGHT B[],int N)
{
for(int i=0;i<N;i++)
{
cout<<"Flight no. of flight "<<i+1<<" : ";cout<<B[i].Flno<<endl;
cout<<"Departure time of flight "<<i+1<<" : ";puts(B[i].DepTime);
cout<<"Arrival time of flight "<<i+1<<" : ";puts(B[i].ArrTime);
cout<<"Fare of flight "<<i+1<<" : ";cout<<B[i].Fare<<endl;
}
}
void Low(FLIGHT B[],int N)
{
float a;
for(int i=0;i<N;i++)
if(B[i].Fare>B[i+1].Fare)
{
a=B[i].Fare;
B[i].Fare=B[i+1].Fare;
B[i+1].Fare=a;
}
cout<<"Details of Flight with Lowest Fare: "<<endl;
cout<<"Flight Number of Lowest Flight: "<<B[0].Flno<<endl;
cout<<"Departure Time of Lowest Flight: "<<B[0].DepTime<<endl;
cout<<"Arrival Time of Lowest Flight: "<<B[0].ArrTime<<endl;
cout<<"Fare of Lowest Flight: "<<B[0].Fare<<endl;
}
/*
OUTPUT
Enter the number of Flight: 2
Select an option:
1. Enter the details of the flight
2. Displaying the details of the flight.
3. Displaying the flight with lowest fares
4. Exit.
Choose an option: 1

Enter the details of the flight:


Flight no. of flight 1 : 9999
Departure time of flight 1 : 07:30
Arrival time of flight 1 : 10:45
Fare of flight 1 : 7500
Flight no. of flight 2 : 9990
Departure time of flight 2 : 12:00
Arrival time of flight 2 : 15:00
Fare of flight 2 : 8500
Select an option:
1. Enter the details of the flight
2. Displaying the details of the flight.
3. Displaying the flight with lowest fares
4. Exit.
Choose an option: 3
Details of Flight with Lowest Fare:
Flight Number of Lowest Flight: 9999
Departure Time of Lowest Flight: 07:30
Arrival Time of Lowest Flight: 10:45
Fare of Lowest Flight: 7500
Select an option:
1. Enter the details of the flight
2. Displaying the details of the flight.
3. Displaying the flight with lowest fares
4. Exit.
Choose an option: 4
Exiting...

*/
/*
Program No: 12
Developed By: Harsh Mittal
Date: 20 May 2017
*/
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct DATE
{
int Day,Month,Year;
};
struct STUDENT
{
int Admno;
char Sname[20];
DATE DOB;
};
void Enter(STUDENT [],int);
void Display(STUDENT [],int);
void Display2(STUDENT [],int);
void main()
{
clrscr();
int N,n;
STUDENT S[50];
cout<<"Enter the number of students: ";cin>>N;
do
{
cout<<"Choose an option: \n";
cout<<"1. Enter details of students. \n";
cout<<"2. Display the details of all students. \n";
cout<<"3. Display details of students born b/w [1.1.1990] & [31.12.1990]. \n";
cout<<"4. Exit \n";
cout<<"Enter your choice: ";cin>>n;
switch(n)
{
case 1: Enter(S,N);break;
case 2: Display(S,N);break;
case 3: Display2(S,N);break;
default: cout<<"Exiting...";
}
}
while(n!=4);
getch();
}
void Enter(STUDENT S[],int N)
{
cout<<"Enter the details of all students: \n";
for(int i=0;i<N;i++)
{
cout<<"Enter Admission No. of Student "<<i+1<<" : ";cin>>S[i].Admno;
cout<<"Enter the Name of Student "<<i+1<<" : ";gets(S[i].Sname);
cout<<"Enter DOB of Student "<<i+1<<" Format: [DD(Enter)MM(Enter)YYYY(Enter)]
\n"<<"{ex: Nov 8 1999 -> [08(Enter)11(Enter)1999(Enter)]} :
";cin>>S[i].[Link]>>S[i].[Link]>>S[i].[Link];
cout<<endl;
}
}
void Display(STUDENT S[],int N)
{
cout<<"The details of all Students: \n";
for(int i=0;i<N;i++)
{
cout<<"Admission No. of Student "<<i+1<<" : ";cout<<S[i].Admno<<endl;
cout<<"Name of Student"<<i+1<< " : ";puts(S[i].Sname);
cout<<"DOB of Studnet "<<i+1<<" ([Link]) :
";cout<<S[i].[Link]<<"."<<S[i].[Link]<<"."<<S[i].[Link]<<endl;
cout<<endl;
}
}
void Display2(STUDENT S[],int N)
{
int found=0;
cout<<"The details of all Students born b/w [1.1.1990] & [31.12.1990]: \n";
for(int i=0;i<N;i++)
if(S[i].[Link]==1990)
{
cout<<"Admission No. of Student"<<i+1<<" : ";cout<<S[i].Admno<<endl;
cout<<"Name of Student"<<i+1<<" : ";puts(S[i].Sname);
cout<<"DOB of Studnet "<<i+1<<" ([Link]) :
";cout<<S[i].[Link]<<"."<<S[i].[Link]<<"."<<S[i].[Link]<<endl;
cout<<endl;
found++;
}
if (found==0)
cout<<"No data exisits.";
}
/*

OUTPUT:

Enter the number of Students: 3


Choose an option:
1. Enter details of students.
2. Display the details of all students.
3. Display details of students born b/w [1.1.1990] & [31.12.1990].
4. Exit
Enter your choice: 1
Enter Admission No. of Student1 : 123
Enter the Name of Student1 : Tanmay
Enter DOB of Student 1 Format: [DD(Enter)MM(Enter)YYYY(Enter)]
{ex: Nov 8 1999 -> [08(Enter)11(Enter)1999(Enter)]} : 29 02 1996

Enter Admission No. of Student2 : 456


Enter the Name of Student2 : Ritik
Enter DOB of Student 2 Format: [DD(Enter)MM(Enter)YYYY(Enter)]
{ex: Nov 8 1999 -> [08(Enter)11(Enter)1999(Enter)]} : 31 12 2000

Enter Admission No. of Student3 : 007


Enter the Name of Student3 : Peter
Enter DOB of Student 3 Format: [DD(Enter)MM(Enter)YYYY(Enter)]
{ex: Nov 8 1999 -> [08(Enter)11(Enter)1999(Enter)]} : 27 07 1990

Choose an option:
1. Enter details of students.
2. Display the details of all students.
3. Display details of students born b/w [1.1.1990] & [31.12.1990].
4. Exit
Enter your choice: 3

The details of all Students born b/w [1.1.1990] & [31.12.1990]:


Admission No. of Student: 007
Name of Student: Peter
DOB of Student ([Link]) : 27.7.1990

Choose an option:
1. Enter details of students.
2. Display the details of all students.
3. Display details of students born b/w [1.1.1990] & [31.12.1990].
4. Exit
Enter your choice: 4
Exiting...

*/
Computer
Science
Assignment
List 3
/*
Program No: 13
Developed By: Harsh Mittal
Date: 11 July 2017
*/
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
class BOOK
{
int Bno;
char Bname[20], Author[20];
float Price;
public:
void Enter()
{
cout<<"Enter Book No: ";
cin>>Bno;
cout<<"Enter Book Name: ";
gets(Bname);
cout<<"Enter Author: ";
gets(Author);
cout<<"Enter Price: ";
cin>>Price;
}
void Display()
{
cout<<"Book No: "<<Bno<<", Book Name: "<<Bname<<endl;
cout<<"Author: :"<<Author<<", Price: "<<Price;
}
int RBno() {return Bno;}
char* RBname() {return Bname;}
};
void Input(BOOK [], int);
void Output(BOOK);
void SearchBno(BOOK [], int, int);
void SearchBname(BOOK [], int, char []);
void main()
{
clrscr();
int N, reply;
BOOK B[100];
do
{
cout<<endl<<"1. Enter Book Array\n2. Display Book Details";
cout<<"\n3. Search Bno\n4. Search Bname\n5. Exit"<<endl;
cin>>reply;
if(reply==1)
{
cout<<"Enter the number of books: ";
cin>>N;
Input(B,N);
}
else if(reply==2)
{
int sub;
cout<<"Enter the book subscript number: ";
cin>>sub;
Output(B[sub]);
}
else if(reply==3)
{
int Sbno;
cout<<"Enter the book no. to be searched: ";
cin>>Sbno;
SearchBno(B,N,Sbno);
}
else if(reply==4)
{
char Sbname[20];
cout<<"Enter the name to be searched: ";
gets(Sbname);
SearchBname(B,N,Sbname);
}
} while(reply!=5);
getch();
}
void Input(BOOK B[], int N)
{
for(int i=0; i<N; i++)
B[i].Enter();
}
void Output(BOOK C)
{
[Link]();
}
void SearchBno(BOOK B[],int N,int Sbno)
{
int found =0;
for(int i=0; i<N; i++)
{
if(B[i].RBno()==Sbno)
{
found++
cout<<"BOOK FOUND!"<<endl;
B[i].Display();
}
}
if(found==0) cout<<"BOOK NOT FOUND!";
}
void SearchBname(BOOK B[],int N, char Sbname[])
{
int found =0;
for(int i=0; i<N; i++)
{
if(strcmpi(B[i].RBname(),Sbname)==0)
{
found++
cout<<"BOOK FOUND!"<<endl;
B[i].Display();
}
}
if(found==0) cout<<"BOOK NOT FOUND!";
}
/*
OUTPUT:

1. Enter Book Array


2. Display Book Details
3. Search Bno
4. Search Bname
5. Exit
1
Enter the number of books: 2
Enter Book No: 1
Enter Book Name: Harry Potter
Enter Author: JK Rowling
Enter Price: 599
Enter Book No: 2
Enter Book Name: Borne
Enter Author: Jeff VanderMeer
Enter Price: 999
1. Enter Book Array
2. Display Book Details
3. Search Bno
4. Search Bname
5. Exit
2
Enter the book subscript number: 0
Book No: 1, Book Name: Harry Potter
Author: :JK Rowling, Price: 599
1. Enter Book Array
2. Display Book Details
3. Search Bno
4. Search Bname
5. Exit
3
Enter the book no. to be searched: 2
BOOK FOUND!
Book No: 2, Book Name: Borne
Author: :Jeff VanderMeer, Price: 999
1. Enter Book Array
2. Display Book Details
3. Search Bno
4. Search Bname
5. Exit
4
Enter the name to be searched: Harry Potter
BOOK FOUND!
Book No: 1, Book Name: Harry Potter
Author: :JK Rowling, Price: 599
1. Enter Book Array
2. Display Book Details
3. Search Bno
4. Search Bname
5. Exit
5
*/

/*
Program No: 14
Developed By: Harsh Mittal
Date: 12 July 2017
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct DATE
{
int Day, Month, Year;
};

class STUDENT
{
int Admno;
char Sname[20];
DATE DOB;
public:
void Input()
{
cout<<"Enter Admission No: ";
cin>>Admno;
cout<<"Enter Name: ";
gets(Sname);
cout<<"Enter DOB: ";
cin>>[Link]>>[Link]>>[Link];
}
void Show()
{
cout<<"Admission No: "<<Admno<<", Name: "<<Sname;
cout<<endl<<"DOB: "<<[Link]<<" "<<[Link]<<" "<<[Link];
}
DATE RDOB() {return DOB;}
};
void Enter(STUDENT [], int &);
void Output(STUDENT [], int);
void Search(STUDENT [], int);
void main()
{
clrscr();
STUDENT A[100];
int N, opt;
do
{
cout<<"\nPlease select the option: "<<endl;
cout<<"1. Input Array"<<endl;
cout<<"2. Display Array"<<endl;
cout<<"3. Search"<<endl;
cout<<"4. Exit"<<endl;
cin>>opt;
if(opt==1)
Enter(A,N);
else if(opt==2)
{
int X;
cout<<"Enter the subscript number of the student: ";
cin>>X;
Output(A,X);
}
else if(opt==3)
Search(A,N);
} while(opt!=4);
getch();
}
void Enter(STUDENT A[], int &N)
{
cout<<"Enter the number of students: ";
cin>>N;
for(int i=0; i<N; i++)
A[i].Input();
}
void Output(STUDENT A[], int X)
{
A[X].Show();
}
void Search(STUDENT A[], int N)
{
int found=0;
for(int i=0; i<N; i++)
{
if(A[i].RDOB().Year==1990 && A[i].RDOB().Day==A[i].RDOB().Month)
{
cout<<"FOUND!"<<endl;
found++;
A[i].Show();
}
}
if(found==0) cout<<"NOT FOUND!";
}
/* OUTPUT:

Please select the option:


1. Input Array
2. Display Array
3. Search
4. Exit
1
Enter the number of students: 2
Enter Admission No: 1234
Enter Name: Tanmay Gupta
Enter DOB: 08 11 1999
Enter Admission No: 5678
Enter Name: Peter
Enter DOB: 2 2 1990
Please select the option:
1. Input Array
2. Display Array
3. Search
4. Exit
2
Enter the subscript number of the student: 0
Admission No: 1234, Name: Tanmay Gupta
DOB: 8 11 1999
Please select the option:
1. Input Array
2. Display Array
3. Search
4. Exit
3
FOUND!
Admission No: 5678, Name: Peter
DOB: 2 2 1990
Please select the option:
1. Input Array
2. Display Array
3. Search
4. Exit
4
*/

/*
Program No: 15
Developed By: Harsh Mittal
Date: 18 July 2017
*/
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void Intext();
void Outtext();
void main()
{
clrscr();
Intext();
cout<<"THIS IS WHAT IS STORED IN THE FILE: "<<endl;
Outtext();
getch();
}
void Intext()
{
fstream fil;
[Link]("[Link]", ios::app);
char Lin[80], reply;
do
{
cout<<"Enter text: ";
gets(Lin);
fil<<Lin<<endl;
cout<<"Enter more? (Y/N): ";
cin>>reply;
} while(tolower(reply)=='y');
[Link]();
}
void Outtext()
{
fstream fil;
[Link]("[Link]", ios::in);
char word[40];
while(![Link]())
{
fil>>word;
cout<<word<<endl;
}
[Link]();
}
/* OUTPUT:

Enter text: Once Upon


Enter more? (Y/N): Y
Enter text: a Time
Enter more? (Y/N): N
THIS IS WHAT IS STORED IN THE FILE:
Once
Upon
a
Time
*/

/*
Program No: 16
Developed By: Harsh Mittal
Date: 19 July 2017
*/
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void Intext();
void CountAVD();
void main()
{
clrscr();
Intext();
CountAVD();
getch();
}
void Intext()
{
fstream fil;
[Link]("[Link]", ios::out);
char Lin[80], reply;
do
{
cout<<"Enter text: ";
gets(Lin);
fil<<Lin<<endl;
cout<<"Enter more? (Y/N): ";
cin>>reply;
} while(tolower(reply)=='y');
[Link]();
}
void CountAVD()
{
int alph=0, vow=0, digit=0;
fstream fil;
[Link]("[Link]", ios::in);
char ch;
while(![Link]())
{
[Link](ch);
ch=tolower(ch);
if(isdigit(ch))
digit++;
if(isalpha(ch))
alph++;
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
vow++;
}
cout<<"ALPHABETS: "<<alph<<"\nVOWELS: "<<vow<<"\nDIGITS: "<<digit;
[Link]();
}
/*
Enter text: hello090
Enter more? (Y/N): Y
Enter text: hielo
Enter more? (Y/N): n
ALPHABETS: 10
VOWELS: 5
DIGITS: 3
*/

/*
Program No: 17
Developed By: Harsh Mittal
Date: 25 July 2017
*/
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void Intext();
void RevT();
void main()
{
clrscr();
Intext();
cout<<"REVERSE OF LINES STARTING WITH 'T': "<<endl;
RevT();
getch();
}
void Intext()
{
fstream fil;
[Link]("[Link]", ios::out);
char Lin[80], reply;
do
{
cout<<"Enter text: ";
gets(Lin);
fil<<Lin<<endl;
cout<<"Enter more? (Y/N): ";
cin>>reply;
} while(tolower(reply)=='y');
[Link]();
}
void RevT()
{
fstream fil;
[Link]("[Link]", ios::in);
char Lin[80];
while([Link](Lin,80))
{
if(Lin[0]=='T' || Lin[0]=='t')
{
for(int i=strlen(Lin)-1; i>=0; i--)
cout<<Lin[i];
cout<<endl;
}
}
[Link]();
}
/*
Enter text: Hello
Enter more? (Y/N): Y
Enter text: That day I went
Enter more? (Y/N): Y
Enter text: To my school
Enter more? (Y/N): Y
Enter text: DPS RKP
Enter more? (Y/N): Y
Enter text: Too Good
Enter more? (Y/N): Y
Enter text: End
Enter more? (Y/N): N
REVERSE OF LINES STARTING WITH 'T':
tnew I yad tahT
loohcs ym oT
dooG ooT
*/

/*
Program No: 18
Developed By: Harsh Mittal
Date: 26 July 2017
*/
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
class CANDIDATE
{
int Cno;
char Cname[20];
int Score;
public:
void Enter()
{
cout<<"Enter CNo: ";
cin>>Cno;
cout<<"Enter Name: ";
gets(Cname);
cout<<"Enter Score: ";
cin>>Score;
}
void Display()
{
cout<<"CNo: "<<Cno<<", Name: "<<Cname<<", Score: "<<Score;
}
int RScore()
{
return Score;
}
};
void Enrol();
void GetPass();
void main()
{
clrscr();
Enrol();
cout<<"THE STUDENTS WHO HAVE PASSED: "<<endl;
GetPass();
getch();
}
void Enrol()
{
fstream fil;
[Link]("[Link]", ios::app | ios::binary);
CANDIDATE C;
char reply;
do
{
[Link]();
[Link]((char*)&C, sizeof(C));
cout<<"More records? (Y/N): ";
cin>>reply;
} while(tolower(reply)=='y');
[Link]();
}
void GetPass()
{
fstream fil;
[Link]("[Link]", ios::in | ios::binary);
CANDIDATE C;
while([Link]((char*)&C, sizeof(C)))
{
if([Link]()>=33)
[Link]();
cout<<endl;
}
[Link]();
}
/*Enter CNo: 1
Enter Name: Harsh Mittal
Enter Score: 100
More records? (Y/N): Y
Enter CNo: 2
Enter Name: Ark
Enter Score: 31
More records? (Y/N): Y
Enter CNo: 3
Enter Name: Anirudh
Enter Score: 33
More records? (Y/N): N
THE STUDENTS WHO HAVE PASSED:
CNo: 1, Name: Harsh Mittal, Score: 99

CNo: 3, Name: Anirudh, Score: 33


*/

You might also like