Computer Science Practicle File Class 12
Computer Science Practicle File Class 12
PRACTICAL
FILE
NAME : ASHAR FATMI
CLASS : XII-A
BOARD ROLL NUMBER :
SCHOOL : BHATNAGAR
INTERNATIONAL
SCHOOL
INDEX
S.No
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
TOPIC
DATE
SIGNATURE/
REMARKS
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
#include<iostream.h>
#include<conio.h>
struct billing{
int customer_no[100];
int no_of_units_consumed[10000];
float bill[100]; };
billing bills;
void main()
{
clrscr();
int x;
cout<<"\n Enter Total No. customers:";
cin>>x;
for(int i=0;i<x;i++)
{
cout<<"\nEnter customer No.:";
Tarif
Rs. 0.40 per unit
Rs. 0.50 per unit
Rs. 1 per unit
Rs. 1.50 per unit
cin>>bills.customer_no[i];
cout<<"\n Enter no. of units consumed:";
cin>>bills.no_of_units_consumed[i];
if(bills.no_of_units_consumed[i]<=100)
{ bills.bill[i]=(bills.no_of_units_consumed[i]*.40); }
else
if(bills.no_of_units_consumed[i]>100&&bills.no_of_units_consumed[i]<=3
00)
{ bills.bill[i]=bills.no_of_units_consumed[i]*(.50); }
else
if(bills.no_of_units_consumed[i]>300&&bills.no_of_units_consumed[i]<=6
00)
{ bills.bill[i]=bills.no_of_units_consumed[i]*(.75); }
else
if(bills.no_of_units_consumed[i]>600&&bills.no_of_units_consumed[i]<=7
00)
{ bills.bill[i]=bills.no_of_units_consumed[i]*(1); }
else
if(bills.no_of_units_consumed[i]>1000)
{ bills.bill[i]
=bills.no_of_units_consumed[i]*(1.5); }
}
cout<<"\n\n Customers Directory:";
for(i=0;i<x;i++)
{ cout<<"\n\n Customer No. :"<<bills.customer_no[i]<<"\n\n Number of
Units consumed :"
<<bills.no_of_units_consumed[i]<<"\n\n the bill is :"<<bills.bill[i]; }
getch();
}
OUTPUT
#include<iostream.h>
#include<conio.h>
struct complex
{ float real1;
float imag1;
float real2;
float imag2;
};
complex cno;
void main()
{
clrscr();
cout<<"Enter First complex No.:";
cout<<"\nReal Part :";
cin>>cno.real1;
cout<<"\nImaginary part:"<<"i";
cin>>cno.imag1;
cout<<"\n\nEnter Second Complex no.:"<<"\n real part:";
cin>>cno.real2;
cout<<"\n Imaginary part:"<<"i";
cin>>cno.imag2;
cout<<"\n\n The sum of the entered complex nos. is:\t"
<<(cno.real1+cno.real2)<<"+i"<<(cno.imag1+cno.imag2);
cout<<"\n\n The difference b/w the entered complex nos. is\t"
<<(cno.real1-cno.real2)<<"+i"<<(cno.imag1-cno.imag2);
int x=(cno.real1*cno.real2);
int y=(cno.imag1*cno.imag2);
int p=(cno.real1*cno.imag2);
int q=(cno.real2*cno.imag1);
cout<<"\n\n The product of the entered complex nos. is \t"<<(x-y)<<"+i"
<<(p+q);
int r=cno.real2*cno.real2;
int s=cno.imag2*cno.imag2;
cout<<"\n\n The quotient of the two complex numbers
is:\t"<<(x+y)<<"+i"
<<cno.real1*-(cno.imag2)+(cno.imag1*cno.real2)<<"/"<<r+s;
getch();
}
OUTPUT
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct student
{
char name[20];
int tmarks;
};
student stu;
void main()
{
clrscr();
int max=0;
int y;
char name1;
char name2;
cout<<"Enter information of the students:";
cout<<"\n Enter Maximum marks:";
cin>>y;
int min = y;
for(int i=0;i<10;i++)
{
cout<<"\n\n Enter name of the student:"<<(i+1)<<":";
gets(stu.name);
cout<<"\t Enter total marks scored by the student:";
cin>>stu.tmarks;
if(stu.tmarks>max)
{
max=stu.tmarks;
strcpy("name1","stu.name");
}
if(stu.tmarks<min)
{
min=stu.tmarks;
strcpy("name2","stu.name");
}
}
cout<<"Students information:";
cout<<"\n\n Highest marks are:"<<max<<","<<"secured by:";
cout<<(name1);
cout<<"lowest marks are:"<<min<<","<<"secured by:";
cout<<(name2);
getch();
}
OUTPUT
4. A class Student has three data members and few member functions:
-Name
-Rollno
-Marks
Write a menu driven program:-To create a file
- To print the stream according to the total marks of the students:
96 or more
Computer Science
91-95
Electronics
86-90
Mechanical
81-85
Electrical
76-80
Chemical
71-75
Civil
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class student
{
char name[20][20];
int rno;
char sub[20];
int m1, m2, m3, m4, m5;
float per;
public:
float calcu()
{
float x=(m1+m2+m3+m4+m5)/5;
return(x);
}
void enter();
void display();
};
void student::enter()
{
cout<<"Enter Roll number:";
cin>>rno;
cout<<"Enter name:";
gets(name[30]);
cout<<"Enter marks for 5 subjects:"<<"\n";
cin>>m1>>m2>>m3>>m4>>m5;
per=calcu();
if(per>=96)
{strcpy(sub,"computer science");}
else
if(per>=91&&per<=95)
{strcpy(sub,"Electronics");}
else
if(per>=86&&per<=90)
{strcpy(sub,"Mechanics");}
else
if(per>=81&&per<=85)
{strcpy(sub,"Electrical");}
else
if(per>=76&&per<=80)
{strcpy(sub,"Chemical");}
else
if(per>=71&&per<=75)
{strcpy(sub,"Civil");}}
void student::display()
{
cout<<"Alotted Subject:"<<sub;
}
void main()
{
clrscr();
student stu;
stu.enter();
stu.display();
getch();
}
OUTPUT
OUTPUT
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
struct date
{
int dd,mm, yy;
};
class bis
{
private:
int adno, rno, classs;
char name[20], address[30], sec;
date dob;
public:
void accept(int r)
{
rno=r;
cout<<"\n Enter adno";
cin>>adno;
cout<<"\n Enter name";
gets(name);
cout<<"\n Enter class:";
cin>>classs;
cout<<"\n Enter section";
cin>>sec;
cout<<"\n Enter address";
gets(address);
cout<<"Enter date";
cin>>dob.dd>>dob.mm>>dob.yy;
}
void show()
{
cout<<"\n"<<rno<<"\t"<<name<<"\t"<<classs<<"\t"<<sec<<"\t";
}
void getrno()
{
return rno;
}
};
void addrecord()
{
fstream f;
int r;
bis s;
f.open("bis.dat", ios::binary|ios::in|ios::app);
f.seekg(0, ios::end);
f.seekg(f.tellg()-sizeof(s), ios::beg);
f.read((char*)&s, sizeof(s));
r=s.getrno()+1;
s.accept(r);
f.seekp(0, ios::end);
f.write((char*)&s, sizeof(s));
f.close();
}
void showallrecord()
{
ifstream f;
bis s;
f.open("bis.dat", ios::binary);
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n Sno\t\tName\t\tClass\t\tSection";
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
while(f.read((char*)&s, sizeof(s)))
{
s.show();
}
f.close();
}
void main()
{
clrscr();
int op;
do
{ clrscr();
cout<<"\n 1 add";
cout<<"\n 2 Show all";
cout<<"\n 0 Exit";
cout<<"\n Enter choice";
cin>>op;
switch(op)
{
case 1: addrecord();
break;
case 2: showallrecord();
break;
}
getch();
}
while(op!=0);}
OUTPUT
int I,J,Temp;
for(I=0;I<s-1;I++)
{
for(J=0;J<(s-1-I);J++)
if(Arr[J]>Arr[J+1])
{
Temp=Arr[J];
Arr[J]=Arr[J+1];
Arr[J+1]=Temp;
}
}
}
int bsearch(int Arr[],int s)
{
int lb,ub,mid,item;
lb=0;
ub=s-1;
cout<<"\nEnter the value of search:";
cin>>item;
while(lb<=ub)
{
mid=(lb+ub)/2;
if(Arr[mid]==item)
return(mid);
else if(Arr[mid]>item )
ub=mid-1;
else
lb=mid+1;
}
return(-1);
}
int main()
{
int a[20],i,n;
cout<<"\nEnter number of element :";
cin>>n;
cout<<"\nEnter an element of an array:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nBefore sorting:";
for(i=0;i<n;i++)
cout<<" "<<a[i];
bsort(a,n);
cout<<"\nAfter sorting";
for(i=0;i<n;i++)
cout<<" "<<a[i];
cout<<"search position:";
cout<<bsearch(a,n);
return 0;
}
OUTPUT
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void main()
{
clrscr();
int n,j;
fstream ofile,afile;
char str[100];
char ch,ch1;
do
{
cout<<"\n\t1.Create Text\n\t2.Read from File\n\t3.create another
file";
cout << "\n 4.Exit ";
cin>>ch;
switch(ch)
{
case '1' :
ofile.open("smp.txt",ios::out);
cout<<"\n Enter The Text ";
gets(str);
ofile<<str;
ofile.close();
break;
case '2' :
char tmp1;
afile.open("smp.txt",ios::in);
while(!afile.eof())
{
afile.get(tmp1);
if(isalpha(tmp1))
{
if (islower(tmp1))
{
if (tmp1=='a'||tmp1=='e'||tmp1=='i'||
tmp1=='o'||tmp1=='u')
cout << "\n Lower case vowel "<<tmp1;
else
ofile.open("smp.txt",ios::in);
afile.open("smp1.txt",ios::out);
char c;
while(ofile)
{
ofile.get(c);
c = tolower(c);
if (c=='a'||c=='i'||c=='e'||c=='o'||c=='u')
afile.put(c);
}
ofile.close();
afile.close();
case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
}while(ch1=='Y'||ch1=='y');
getch();
}
OUTPUT
#include<iostream.h>
#include<process.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
struct node
{
int regno;
char pat[20];
node*next;
} *start, *newptr, *save, *ptr, *rear, pn;
void display(node*);
void insert(node*);
void main()
{
clrscr();
start=rear=NULL;
int reg;
char name[20];
char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"Enter the information for a new patient:"<<"\n"<<"Enter
Registration no.";
cin>>pn.regno;
cout<<"\n"<<"Enter name:";
gets(pn.pat);
newptr=&pn;
insert(newptr);
cout<<"press Y to enter more node, N to exit";
cin>>ch;
}
cout<<"The list is now"<<"\n";
display(start);
char ans;
int rno;
char nm[20];
cout<<"Wabt to Update list:";
cin>>ans;
if(ans=='y'||ans=='Y')
{
cout<<"Enter reg. no. of patient:";
cin>>regno;
while(newptr!=NULL)
{
if(newptr->regno==rno)
{
cout<<"Enter new name:";
gets(nm);
strcpy(newptr->pat,nm);
newptr=newptr->next;
}
}
cout<<"Now the list is:";
display(start);
}
getch();
}
void insert(node*)
{
if(start==NULL)
{ start=rear=newptr;}
else
{ rear->next=newptr;
rear=newptr;
rear->next=NULL;
}
}
void display(node*np)
{
while(np!=NULL)
{
cout<<"\n"<<np->regno<<". ";
cout.write(np->pat,20);
np=np->next;
}
cout<<"!!!\n";
}
OUTPUT
10.
#include<iostream.h>
#include<stdlib.h>
#include<process.h>
struct node
{
int info;
node*next;
} *top, *newptr, *save, *ptr;
node *create_new_node(int);
void push(node*);
void display(node*);
void main()
{
clrscr();
int inf;
char ch='y';
top=NULL;
while(ch=='y'||ch=='Y')
{
cout<<"Enter the information for the new node";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{
cout<<"cannot create new node....aborting!!";exit(1);
}
push(newptr);
cout<<"now the linked stack is";
display(top);
cout<<"press Y to enter more node, N to exit";
cin>>ch;
}
getch();
}
node*create_new_node(int n)
{
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void push(node*np)
{
if(top==NULL)top=np;
else
{
save=top;
top=np;
np->next=save;
}
}
void display(node*np)
{
while(np!=NULL)
{
cout<<np->info<<"->";
np=np->next;
}
cout<<"!!!";
}
OUTPUT
11.
Create a linked queue and perform addition and deletion
operations.
#include<iostream.h>
#include<process.h>
struct node
{ int info;
node*next;
} *front, *newptr, *save, *ptr, *rear;
node*create_new_node(int);
void insert(node*);
void display(node*);
void delnode_q();
void main()
{
front=rear=NULL;
int inf;
char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"Enter the information for a new node";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{
cout<<"Cannot create new node....aborting!!";exit(1);}
insert(newptr);
cout<<"press Y to enter more node, N to exit";
cin>>ch;
}
}
system("cls")
do
{
cout<<"\n The linked queue is:";
display(front);
cout<<"Want to delete first node?(y/n)";
cin>>ch;
if(ch=='y'||ch=='Y')
delnode_q();
}
while(ch=='y'||ch=='Y');
}
node*create_new_node(int n)
{
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void insert(node*np)
{
if(front==NULL)
{front=rear=np;}
else
{
rear->next=np;
rear=np;
}
}
void delnode_q()
{
if(font==NULL)cout<<"Underflow!!!";
else
{
ptr=front;
front=front->next;
delete ptr;
}
}
void display(node*np)
{
while(np!=NULL)
{
cout<<np->info<<"->";
np=np->next;
}
cout<<"!!!";
}
OUTPUT
12.
-
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<iomanip.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
class telephone;
void display();
void append();
int main()
{
int x;
char ch='y';
while(ch=='y')
{
clrscr();
cout<<"....WELCOME TO THE MENU...";
cout<<"\nPress 1 to APPEND record :";
cout<<"\nPress 2 to DISPLAY record :";
cout<<"\nPress any key to EXIT :";
cin>>x;
switch(x)
{
case 1: append();
break;
case 2: display();
break;
default: cout<<"\n....SYSTEM EXITING....";
break;
}
cout<<"\nTo go to MAIN MENU, PRESS Y :";
cout<<"\nTo EXIT, Press any key :";
cin>>ch;
}
return 0;
}
class telephone
{
char name[50];
char address[50];
int tele;
public:
void getdata()
{
cout<<"\nPlease enter your NAME :";
gets(name);
cout<<"\nPlease enter your ADDRESS :";
gets(address);
cout<<"\nPlease enter your TELEPHONE NUMBER :";
cin>>tele;
}
void showdata()
{
cout<<"\nNAME :"<<name<<endl;
cout<<"\nADDRESS :"<<address<<endl;
cout<<"\nTELEPHONE NUMBER :"<<tele<<endl;
}
int gettele()
{
return tele;
}
};
void append()
{
clrscr();
telephone te;
ofstream file;
file.open("tele database", ios::binary|ios::app);
char ch='y';
while(ch=='y')
{
te.getdata();
file.write((char*)&te, sizeof(te));
cout<<"\nPress key Y to enter more data :";
cout<<"\nPress any other key to EXIT :";
cin>>ch;
}
file.close();
}
void display()
{
clrscr();
int x;
cin>>x;
char found='n';
telephone te;
ifstream file;
cout<<"\nPlease enter the TELEPHONE NUMBER :";
cin>>x;
file.open("tele databse", ios::in|ios::binary);
file.seekg(0);
while(!file.eof())
{
file.read((char*)&te, sizeof(te));
if(filee.eof())
{
break;
}
if((te.gettele())==x)
{
te.showdata();
found='y';
}
}
if(found=='n')
cout<<"\nFile not found :";
file.clear();
file.close();
}
OUTPUT
13.
Declare a class students having sno, sname, fees and required
functions. Write a ,menu driven program to:
- Append record in a file
- Delete record for given serial no.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdlib.h>
#include<stdio.h>
class student;
void append();
void dele();
int main()
{
int x;
char ch='y';
while(ch=='y')
{
cout<<"....WELCOME TO STUDENT DATABASE PROGRAM....";
cout<<"\nPress 1 to APPEND a record :";
cout<<"\nPress 2 to DELETE a record :";
cout<<"\nPress another to EXIT :";
cin>>x;
switch(x)
{
case 1: append();
break;
case 2: dele();
break;
default : cout<<"\n....SYSTEM EXITING....";
break;
}
cout<<"\nPress Y to go to MAIN MENU :";
cout<<"\nPress another key to EXIT :";
cin>>ch;
}
return 0;
}
class student
{
char sname[50];
int sno;
float fee;
public:
void getdata()
{
cout<<"\nPlease enter your ROLL NUMBER :";
cin>>sno;
cout<<"\nPlease enter your NAME :";
gets(sname);
cout<<"\nPlease enter student's FEES :";
cin>>fee;
}
void showdata()
{
cout<<"\nROLL NUMBER :"<<sno<<endl;
cout<<"\nNAME :"<<sname<<endl;
cout<<"\nFEES :"<<fee<<endl;
}
int getsno()
{
return sno;
}
};
void append()
{
student stu;
ofstream file;
file.open("Student database", ios::out|ios::app|ios::binary);
char ch='y';
while(ch=='y')
{
stu.getdata();
file.write((char*)&stu, sizeof(stu));
cin>>ch;
}
file.close();
}
void dele()
{
clrscr();
student stu;
int x;
cout<<"\nEnter the SNO to DELETE record";
cin>>x;
ifstream fin;
ofstream fout;
fin.open("Student database", ios::binary|ios::in);
fin.seekg(0);
fout.open("temp",ios::out|ios::binary);
fout.seekp(0);
char ch;
while(!fin.eof())
{
fin.read((char*)&stu, sizeof(stu));
if(fin.eof())
{
break;
}
if((stu.getsno())==x)
{
cout<<"\nRecord is found";
stu.showdata();
cout<<"\nPress Y to DELETE record :";
cin>>ch;
if(ch!='Y'&&ch!='y')
{
fout.write((char*)&stu, sizeof(stu));
}
found = 'y';
}
if((stu.getsno())!==x)
{
fout.write((char*)&stu, sizeof(stu));
}
}
if(found=='y')
cout<<"\nRecord is FOUND and DELETED";
else
cout<<"\nNO RECORD EXISTS";
fin.close();
fout.close();
remove("Student database");
rename("temp", "Student database");
}
OUTPUT
14.
-
Front is the first node of the queue and rear is the last node. Write a
menu driven program to:
-
#include<conio.h>
#include<iostream.h>
#include<process.h>
#include<malloc.h>
struct node
{
int Eno;
float salary;
struct node *next;
};
class queue
{
struct node *frnt,*rear;
public:
queue()
{
frnt=rear=NULL;
}
void insert();
void del();
void show();
};
void queue::insert()
{
int Emno,sal;
struct node *ptr;
cout<<"Enter new employee no: ";
cin>>Emno;
cout<<"Enter new employee salary: ";
cin>>sal;
ptr=new node;
ptr->Eno=Emno;
ptr->salary=sal;
ptr->next=NULL;
if(frnt==NULL)
frnt=ptr;
else
rear->next=ptr;
rear=ptr;
cout<<"\nNew employee no. and salary is inserted to the Queue!!!";
getch();
}
void queue::del()
{
if(frnt==NULL)
{
cout<<"\nQueue is empty!!";
getch();
return;
}
struct node *temp;
temp=frnt;
frnt=frnt->next;
cout<<"\nDeletion Operation........\nDeleted value is "<<temp>Eno<<endl;
delete temp;
getch();
}
void queue::show()
{
struct node *ptr1=frnt;
if(frnt==NULL)
{
cout<<"The Queue is empty!!";
getch();
return;
}
cout<<"\nThe Queue is:\n";
while(ptr1!=NULL)
{
cout<<"\nEmployee No: "<<ptr1->Eno<<endl;
cout<<"Salary: "<<ptr1->salary;
ptr1=ptr1->next;
}
getch();
}
// Main function
int main()
{
queue q;
int choice;
while(1)
{
cout<<"\n-----------------------------------------------------------";
cout<<"\n\t\tQUEUE USING LINKED LIST\n\n";
cout<<"1:INSERTION\n2:DELETION\n3:DISPLAY QUEUE\n4:EXIT";
cout<<"\nEnter your choice(1-4): ";
cin>>choice;
switch(choice)
{
case 1:
q.insert();
break;
case 2:
q.del();
break;
case 3:
q.show();
break;
case 4:
exit(0);
break;
default:
cout<<"Please enter correct choice(1-4)!!";
getch();
break;
}
}
return 0;
}
OUTPUT
15.
-
Pointer field
Top is the first node of the stack. Write a menu driven program to:
Push an element
Pop an element
#include<iostream.h>
#include<stdlib.h>
#include<malloc.h>
#include<conio.h>
struct node{
int rollno,age;
struct node *next;
};
class stack{
struct node *top;
public:
stack();
void push();
void pop();
void display();
};
stack::stack()
{
top = NULL;
}
void stack::push()
{
int rollnumber,age1;
struct node *p;
if((p=new node)==NULL)
{
cout<<"Memory Exhausted";
exit(0);
}
cout<<"Enter a roll Number to insert:";
cin>>rollnumber;
cout<<"\nEnter the age of the student:";
cin>>age1;
p = new node;
p->rollno = rollnumber;
p->age=age1;
p->next = NULL;
if(top!=NULL){
p->next = top;
}
top = p;
cout<<"\nNew roll number and age are inserted"<<endl;
}
void stack::pop()
{
struct node *temp;
if(top==NULL)
{
cout<<"\nThe stack is Empty"<<endl;
}
else
{
temp = top;
top = top->next;
cout<<"\nThe value popped is: "<<endl;
cout<<"Roll No: "<<temp->rollno<<endl;
cout<<"Age: "<<temp->age<<endl;
delete temp;
}
}
void stack::display()
{
struct node *p = top;
if(top==NULL)
{
cout<<"\nNothing to Display\n";
}
else
{
cout<<"\nThe contents of Stack\n";
while(p!=NULL){
cout<<"Roll No: "<<p->rollno<<endl;
cout<<"Age: "<<p->age<<endl<<endl;
p = p->next;
}
}
}
int main()
{
clrscr();
stack s;
int choice;
do{
cout<<"\nSTACK IMPLEMENTATION";
OUTPUT
16.
Write a program to accept a 2D array of integers and its size as
arguments and displays elements which are exactly two digit numbers.
#include<conio.h>
#include<iostream.h>
#include<process.h>
#include<conio.h>
int main()
{
clrscr();
int row,col,i,j;
int arr[2][2];
cout<<"ARRAY INPUT\n";
cout<< "enter the no. of row: \n ";
cin>>row;
cout<<"enter the no. of coloum: ";
cin>>col;
cout<<"enter the array elemet:\n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>arr[i][j];
}
}
cout<<"entered array is:\n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}
cout<<"element in array which are exactly 2 digit\n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(arr[i][j]>9 && arr[i][j]<100)
{
cout<<"\t"<<arr[i][j];
}
}
}
getch();
return 0;
}
OUTPUT
17.
Write a menu driven program to perform the following operations
on a string without using inbuilt functions:
- Find the length
- Compare two strings
- Concatenate two strings
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class string
{
private:
char a[40], b[40], c[80];
public:
void findlength();
void compare();
void concatenate();
};
void string::findlength()
{
cout<<"\n Enter string";
gets(a);
int i=0;
while(a[i]!='\0')
{
i++;
}
cout<<"the length of the given string is"<<i;
}
void string::concatenate()
{
cout<<"Enter first string:";
gets(a);
cout<<"\nEnter second string:";
gets(b);
int j=0;
for(int i=0;a[i]!='\0';++i)
{
c[j++]=a[i];
}
for(i=0;b[i]!='\0';++i)
{
c[j++]=b[i];
}
c[j]='\0';
cout<<"\nThe concatenate string is"<<c;
}
void string::compare()
{
int c, i=0;
cout<<"\n ENTER THE STRING 1:";
cin>>a;
cout<<"\n ENTER THE STRING 2:";
cin>>b;
while(a[i]!='\0'&&b[i]!='\0')
{
if(a[i]==b[i])
{
c=1;
}
else
{
c=0;
break;
}
i++;
}
if(c==1&&a[i]=='\0'&&b[i]=='\0')
{
cout<<"\n\n THE GIVEN TWO STRINGS ARE ONE & SAME";
}
else
{
cout<<"\n NOT SAME";
}
}
void main()
{ int op;
string s;
do
{ clrscr();
cout<<"\n 1 FIND LENGTH";
cout<<"\n 2 COMPARE";
cout<<"\n 3 CONCATENATE";
cout<<"\n 0 EXIT";
cout<<"\n ENTER";
cin>>op;
switch(op)
{
case 1: s.findlength();
break;
case 2: s.compare();
break;
case 3: s.concatenate();
break;
}
getch();
}while(op!=0);
}
OUTPUT
18.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void amount(float princ, int time, float rate)
{
cout<<"\nPrincipal Amount:"<<princ;
cout<<"\tTime:"<<time<<"years";
cout<<"\tRate:"<<rate;
cout<<"\nInterest Amount:"<<(princ*time*rate)<<"\n";
}
void amount(float princ, int time)
{
cout<<"\nPrincipal amount:"<<princ;
cout<<"\tTime:"<<time<<"years";
cout<<"\tRate : 0.08";
cout<<"\nInterest amount:"<<(princ*time*0.08)<<"\n";
}
void amount(float princ, float rate)
{ cout<<"\nPrincipal amount:"<<princ;
cout<<"\tTime : 2 years";
cout<<"\tRate:"<<rate;
cout<<"\nInterest amount:"<<(princ*2*rate)<<"\n";
}
void amount(int time, float rate)
{ cout<<"\nPrincipal amount : 2000";
cout<<"\tTime:"<<time<<"years";
cout<<"\tRate:"<<rate;
cout<<"\nInterest amount:"<<(2000*time*rate)<<"\n";
}
void amount(float princ)
{ cout<<"\nPrincipal amount:"<<princ;
cout<<"\tTime : 2 years";
cout<<"\tRate : 0.08";
cout<<"\nInterest amount:"<<(princ*2*0.08)<<"\n";
}
void main()
{ system("cls");
cout<<"case 1";
amount(2000.0F);
cout<<"case 2";
amount(2500.0F, 3);
cout<<"case 3";
amount(2300.0F, 3, 0.11F);
cout<<"case 4";
amount(2, 0.12F);
cout<<"case 5";
amount(6, 0.07F);
getch();
}
19.
-
OUTPUT
20.
-
THE END