0% found this document useful (0 votes)
82 views41 pages

Class 12 20 Progs

The document contains summaries of 8 C++ programs submitted by Sanuj Kumar for their class XII programming assignment. Program 1 calculates the area of circle, rectangle, and triangle using function overloading. Program 2 demonstrates the use of default arguments. Program 3 uses classes and objects to store and display stock inventory information. Program 4 assigns, updates, and displays bowler information using classes and objects. Program 5 models a real cricket match using constructors and destructors. Program 6 implements a travel planning program using constructors and destructors. Program 7 demonstrates inheritance by modeling current and savings bank accounts. Program 8 further explores inheritance by defining employee and manager classes.

Uploaded by

DARK
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)
82 views41 pages

Class 12 20 Progs

The document contains summaries of 8 C++ programs submitted by Sanuj Kumar for their class XII programming assignment. Program 1 calculates the area of circle, rectangle, and triangle using function overloading. Program 2 demonstrates the use of default arguments. Program 3 uses classes and objects to store and display stock inventory information. Program 4 assigns, updates, and displays bowler information using classes and objects. Program 5 models a real cricket match using constructors and destructors. Program 6 implements a travel planning program using constructors and destructors. Program 7 demonstrates inheritance by modeling current and savings bank accounts. Program 8 further explores inheritance by defining employee and manager classes.

Uploaded by

DARK
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
You are on page 1/ 41

C++ PROJECT

20
PROG

Submitted By:Sanuj Kumar


XII-D

Program 01:Calculates area of circle ,


rectangle and triangle using
function overloading
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#define pi 3.14
class fn
{
public:
void area(int); //circle
void area(int,int); //rectangle
void area(float ,int,int); //triangle
};
void fn::area(int a)
{
cout<<"Area of Circle:"<<pi*a*a;
}
void fn::area(int a,int b)
{
cout<<"Area of rectangle:"<<a*b;
}
void fn::area(float t,int a,int b)
{
cout<<"Area of triangle:"<<t*a*b;
}
void main()
{
int ch;

int a,b,r;
clrscr();
fn obj;
cout<<"\n\t\tFunction Overloading";
cout<<"\n1.Area of Circle\n2.Area of Rectangle\n3.Area of
Triangle\n4.Exit\n:;
cout<<Enter your Choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter Radious of the Circle:";
cin>>r;
obj.area(r);
break;
case 2:
cout<<"Enter Sides of the Rectangle:";
cin>>a>>b;
obj.area(a,b);
break;
case 3:
cout<<"Enter Sides of the Triangle:";
cin>>a>>b;
obj.area(0.5,a,b);
break;
case 4:
exit(0);
}
getch();
}

Program 02:Use of default argument


#include<iostream.h>
#include<conio.h>
int vol(int=1,int=2,int=3);
int main()
{
clrscr();
int length;
int width;
int height;
int volume;
cout<<"\n Enter the value of length = ";
cin>>length;
cout<<"\n Enter the value of width = ";
cin>>width;
cout<<"\n Enter the value of heigth = ";
cin>>height;
volume=vol();
cout<<"\n Volume with no argument passed = "<<volume<<endl;
volume=vol(length);
cout<<"\n Volume with one argument passed = "<<volume<<endl;
volume=vol(length,width);
cout<<"\n Volume with two argument passed = "<<volume<<endl;
volume=vol(length,width,height);
cout<<"\n Volume with all argument passed = "<<volume<<endl;
getch();
return 0;
}
{

return l*h*w; }

Program 03:Classes and objects - 01


#include<iostream.h>
#include<conio.h>
class STOCK
{
int ICode;
char Item[20];
float Price;
int Qty;
float Dicount;
void FindDisc()
{ if (Qty<= 50)
Discount=0;
else if (Qty<=100)
Dicount=5;
else Discount=10;
}
public:
void Buy()
{
cout<<Enter Item Code:;
cin>>ICode;
cout<<Enter Item Name:
gets(item);
cout<<Enter price of each item:;
cin>>Price;
cout<<Enter quantity of item in stock;
cin>>Qty;
FindDisc();
}
void Showall()
{

cout<<Code:<<ICode;
cout<<\nName:<<Item;
cout<<\nPrice:<<Price;
cout<<\nQuantity<<<Qty;
cout<<\nDiscount percentage:<<Discount;
}};

Program 04:Assign, Update And Display


information {Classes And
Objects - 02}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Bowlers{
char F_Name[30];
char L_Name[30];
int Overs_bowled,Maiden_overs,Runs_given,Wickets;
public:
void initial(){
cout<<endl<<"Enter First Name: ";
gets(F_Name);
cout<<endl<<"Enter Last Name: ";
gets(L_Name);
cout<<endl<<"Enter The Overs bowled: ";
cin>>Overs_bowled;
cout<<endl<<"Enter how many overs maden: ";
cin>>Maiden_overs;
cout<<endl<<"Enter how many runs given: ";
cin>>Runs_given;
cout<<endl<<"Enter how many wickets taken: ";
cin>>Wickets;
}
void update()
{
int new_over_bolwed,new_maiden_overs,new_runs_given,new_wickets;
cout<<endl<<"Enter new overs bowled: ";
cin>>new_over_bolwed;

cout<<endl<<"Enter new madden overs: ";


cin>>new_maden_overs;
cout<<endl<<"Enter new runs given: ";
cin>>new_runs_given;
cout<<endl<<"Enter new wickets taken: ";
cin>>new_wickets;
Overs_bowled=Overs_bowled+new_over_bolwed;
Maiden_overs=Maiden_overs+new_maiden_overs;
Runs_given=Runs_given+new_runs_given;
Wickets=Wickets+new_wickets;
display();
cout<<"Total overs bowled: "<<Overs_bowled<<endl;
cout<<"Total maidden overs: "<<Maiden_overs<<endl;
cout<<"Total runs given: "<<Runs_given<<endl;
cout<<"Total wickets taken: "<<Wickets<<endl;
}
void display(){
cout<<".....Bolwer's information....."<<endl;
cout<<"Name: "<<F_Name<<" "<<L_Name<<endl;
}
};
void main(){
clrscr();
Bowlers b1;
b1.initial();
b1.update();
getch();
}

Program 05:Real Life Cricket {Constructor


And Destructor - 01}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class batsman
{
public:
char name[20];
int run_score,indi_out;
char modeout[20];
void getdata()
{
cout<<".....Enter information for batsman......."<<endl;
cout<<"Enter batsman's name: ";
gets(name);
cout<<"Enter runs scored: ";
cin>>run_score;
cout<<"Enter 0 if NOT-OUT or 1 if OUT: ";
cin>>indi_out;
if(indi_out==1)
{
cout<<"Enter mode by which out: ";
gets(modeout);
}}
void putdata()
{
cout<<"......Batsman's Information........."<<endl;
cout<<"Batsman's name: "<<name<<endl;
cout<<"Runs scored: "<<run_score<<endl;
if(indi_out==1)

{
cout<<"OUT: "<<"Yes"<<endl;
cout<<"Mode by which out: "<<modeout<<endl;
}}
void update()
{
int new_run;
cout<<"Enter update for batsman"<<endl;
cout<<"Enter new run: ";
cin>>new_run;
putdata();
run_score=run_score+new_run;
cout<<"Updated run: "<<run_score; }
};
class bowler
{
public:
char bname[20];
int over_play,maiden_over,run_given,wicket;
void getinfo()
{
cout<<".....Enter information for bolwer......."<<endl;
cout<<"Enter bowler's name: ";
gets(bname);
cout<<"Enter overs played: ";
cin>>over_play;
cout<<"Enter maiden overs: ";
cin>>maiden_over;
cout<<"Enter runs given: ";
cin>>run_given;
cout<<"Enter wicket taken: ";
cin>>wicket;
}
void disp_info()
{
cout<<"......Bowler's Information........."<<endl;
cout<<"Bolwer's name: "<<bname<<endl;
cout<<"Overs played: "<<over_play<<endl;
cout<<"Maiden overs: "<<maiden_over<<endl;
cout<<"Runs given: "<<run_given<<endl;

cout<<"Wicket taken: "<<wicket<<endl;


}
void upd()
{
int new_over,new_maidover,new_run,new_wicket;
cout<<endl<<".....Enter update for bolwer....."<<endl;
cout<<"Enter new overs played: ";
cin>>new_over;
cout<<"Enter new maiden overs: ";
cin>>new_maidover;
cout<<"Enter new runs given: ";
cin>>new_run;
cout<<"Enter new wickets taken: ";
cin>>new_wicket;
disp_info();
over_play=over_play+new_over;
maiden_over=maiden_over+new_maidover;
run_given=run_given+new_run;
wicket=wicket+new_wicket;
cout<<"After update......."<<endl;
cout<<"Overs played: "<<over_play<<endl;
cout<<"Maiden overs: "<<maiden_over<<endl;
cout<<"Runs given: "<<run_given<<endl;
cout<<"Wicket taken: "<<wicket<<endl;
}};
void main()
{
clrscr();
int ch;
batsman b1;
bowler b2;
b1.getdata();
b2.getinfo();
b1.putdata();
b2.disp_info();
cout<<"Is ball thrown..?? (1-Yes or 0-NO) ";
cin>>ch;
if(ch==1)
{b1.update();
b2.upd();}

clrscr();
}

Program 06:Travel Plan {Constructor And


Destructor - 02}
class TravelPlan
{
long PlanCode;
char *Place;
int Number_of_travellers;
int Number_of_buses;
public:
TravelPlan()
{
PlanCode=1001;
strcpy(Place,"Agra");
Number_of_travellers=5;
Number_of_buses=1;
}
void NewPlan()
{ cout<<"Enter Travel code, Place and Number of travellers \n";
cin>>PlanCode;
gets(Place);
cin>>Number_of_travellers;
if(Number_of_travellers<20)
Number_of_buses=1;
else if(Number_of_travellers<40)
Number_of_buses=2;
else
Number_of_buses=3; }
void ShowPlan()
{
cout<<"Plan Code:"<<PlanCode<<endl;
cout<<"Place:"<<Place<<endl;

cout<<"Number of travellers:"<<Number_of_travellers<<endl;
cout<<"Number of buses:"<<Number_of_buses<<endl;
}};

Program 07:-

Current Account And Saving


Account {Inheritance - 01}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
int const min=500;
class Account
{ char name[20];
long ano;
public:
void getdata()
{ cout<<"Enter customer name: ";
gets(name);
cout<<"Enter account no.: ";
cin>>ano;
cout<<"Enter opening balace: ";
cin>>balance;
}
void display()
{ cout<<"Customer name: "<<name<<endl;
cout<<"Account no: "<<ano<<endl;
cout<<"Balance :"<<balance;
}
};
class Current:public Account
{ float depo,with,pen;
public:
void deposit()
{ cout<<endl<<"Enter money to deposit: ";

cin>>depo;
display();
balance=balance+depo;
cout<<endl<<"After deposit main balance is: "<<balance<<endl;
}
void withdraw()
{ cout<<endl<<"Enter money to withdraw: ";
cin>>with;
if(with<balance)
{ display();
balance=balance-with;
cout<<endl<<"After withdraw main balance is: "<<balance<<endl;
}
else
{ cout<<endl<<"You cannot withdraw money....."<<endl;
}
}
void check_bal()
{ if(balance<min)
{ cout<<"Opening balance should not be less than 500...."<<endl;
balance=balance-150;
cout<<endl<<"After penalty main balance is: "<<balance<<endl;
}
}
};
class Savings:public Account
{ float depo,with,intr;
public:
void deposit()
{ cout<<endl<<"Enter money to deposit: ";
cin>>depo;
display();
balance=balance+depo;
cout<<endl<<"After deposit main balance is: "<<balance<<endl;
}
void withdraw()
{ cout<<endl<<"Enter money to withdraw: ";
cin>>with;
if(with<balance)
{ display();

balance=balance-with;
cout<<endl<<"After withdraw main balance is: "<<balance<<endl;
}
else
{ cout<<"You cannot withdraw money....."<<endl;
}
}
void cal_intr()
{ intr=(balance*2)/100;
balance=balance+intr;
cout<<endl<<"After calculating interest balance is: "<<balance;
} };
void main()
{ clrscr();
Current c;
Savings s;
char ch;
int choice,ch2;
cout<<"Enter 'S' for saving and 'C' for current: ";
cin>>ch;
if(ch=='C'||ch=='c') { c.getdata();
c.check_bal();
l2:cout<<"\n 1. Display \n 2.Deposit \n 3.Withdraw \n 4. Exit \n";
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1: c.display();
goto l2;
break;
case 2: c.deposit();
goto l2;
break;
case 3: c.withdraw();
goto l2;
break;
case 4: exit(0);
}
}
else if(ch=='S'||ch=='s')

{ s.getdata();
l1:cout<<"\n 1. Display \n 2.Deposit \n 3.Withdraw \n 4.Calculate
iterest \n 5. Exit \n";
cout<<"Enter your choice: ";
cin>>ch2;
switch(ch2)
{
case 1: s.display();
goto l1;
break;
case 2: s.deposit();
goto l1;
break;
case 3: s.withdraw();
goto l1;
break;
case 4: s.cal_intr();
goto l1;
break;
case 5: exit(0);
}
}
else
cout<<"Wrong choice"<<endl;
getch();
}

Program 08:Employees And Managers


{Inheritance 02}
#include<iostream.h>
#include<conio.h>
class employee
{
public:
int num,house ;
char city[20], state[20], name[20],depart[20];
public:
void input()
{
cout<<"Enter the employe's name";
cin>>name;
cout<<"Enter the employe number";
cin>>num;
cout<<"Enter the address including house number ,city ,state";
cin>>house>>city>>state;
cout<<"enter the department";
cin>>depart;
}
void output()
{
cout<<"\nemploye's infomation:";
cout<<"\n"<<name<<"\n"<<num<<"\n"<<"address -:" <<"\n"<<house<<"
"<<city<<"\n"<<state;
cout<<"\n"<<depart; };
class manager: public employee

{
char name[20];
int n ,i;
public:
void getdata()
{
cout<<"Enter the manager's name";
cin>>name;
cout<<"enter the total number of employe's working under him";
cin>>n;
}
void info();
};
void manager::info()
{
getdata();
for(i=1;i<=n;i++)
{
input();
}
cout<<name;
cout<<"\nemploye's are-:n" ;
for(i=1;i<=n;i++)
{
cout<<i<<" employe-:" ;
output();
}
}
void main()
{
class manager M;
clrscr();
M.info();
getch();
}

Program 09:Upper Case And Lower Case


{Data File Handling - 01}
#include<iostream.h>
#include <ctype.h>
#include<conio.h>
#include <stdio.h>
#include<fstream.h>
void main(){
char c,fname[10];
ofstream filout1,filout2,filout3;
filout1.open("UPPER.txt");
filout2.open("LOWER.txt");
filout3.open("OTHER.txt");
cout<<"Enter contents to store in file (Enter # to stop):\n";
while((c=getchar())!='#')
{
if(isupper(c))
{
filout1<<c;
}
else if(islower(c))
{
filout2<<c;
}
else
{
filout3<<c;
}
}

filout1.close();
filout2.close();
filout3.close();
getch();
}

Program 10:Multiple insertion {Data File


Handling - 02}
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<fstream.h>
void main()
{
clrscr();
ofstream fout;
fout.open("Studnms",ios::out);
fout<<"Mohan \n"<<"Rohan \n"<<"Dev"<<"abhyansi\n ";
fout.close();
fout.open("Stumarks",ios::out);
fout<<"60 \n"<<"70 \n"<<"100 \n"<<"99 \n";
fout.close();
char line[80];
ifstream fin;
fin.open("Studnms",ios::in);
cout<<"Records of file Student Names "<<endl;
fin.getline(line,80);
cout<<line<<endl;
fin.getline(line,80);
cout<<line<<endl;
fin.getline(line,80);
cout<<line<<endl;
fin.getline(line,80);

cout<<line<<endl;
fin.close();
fin.open("Stumarks",ios::in);
cout<<"Records of file Student Marks "<<endl;
fin.getline(line,80);
cout<<line<<endl;
fin.getline(line,80);
cout<<line<<endl;
fin.getline(line,80);
cout<<line<<endl;
fin.getline(line,80);
cout<<line<<endl;
fin.close();
getch();
}

Program 11:Bubble Sort {Arrays -01}


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,a[5];
void bub(int []);
cout<<"Enter the 5 elements of the array: "<<endl;
for(i=0;i<5;i++)
{
cin>>a[i];}
bub(a);
getch();
}
void bub(int a[])
{
int tempo,i,j;
for(i=0;i<5;i++)
{
for(j=0;j<4-i;j++)
{
tempo=a[j];
if(a[j]>a[j+1])
{a[j]=a[j+1];
a[j+1]=tempo;}
}
}

cout<<"The sorted array is: "<<endl<<"==> ";


for(int k=0;k<5;k++)
{cout<<a[k]<<" , ";}
}

Program 12:Transpose Of An Array {Array 02}


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr1[10][10],arr2[10][10],i,j,x,y;
cout<<"Enter row and column of your matrix"<<endl;
cin>>x>>y;
cout<<"Enter matrix"<<endl;
for(i=0;i<x;i++)
{for(j=0;j<y;j++)
cin>>arr1[i][j];
}
cout<<"Your matrix is :-"<<endl;
for(i=0;i<x;i++)
{cout<<"\n";
for(j=0;j<y;j++)
cout<<" "<<arr1[i][j];
}
for(i=0;i<y;i++)
{
for(j=0;j<x;j++)
arr2[i][j]=arr1[j][i];

}
cout<<"\n The Tranposed Matrix is: \n";
for(i=0;i<y;i++)
{cout<<"\n";
for(j=0;j<x;j++)
{cout<<" "<<arr2[i][j];
}}
getch();
}

Program 13:Concatenation Of Strings


{Pointers 01}
#include<iostream.h>
void stcat(char *str1, char *str2);
void main()
{
char *str1, *str2;
clrscr();
cout<<"\n\n\t ENTER THE FIRST STRING: ";
gets(str1);
cout<<"\n\n\t ENTER THE FIRST STRING: ";
gets(str2);
stcat(str1,str2);
cout<<"\n\t THE CONCATENATED STRING IS: ";
puts(str1);
getch();
}
void stcat (char *str1, char *str2)
{
int i = 0,len = 0;
while(*(str1+len)!='\0')
len++;
while(*(str2+i)!='\0')
{
*(str1+len) = *(str2+i);

i++;
len++;
}
*(str1+len) = '\0';

Program 14:Publication of books or audio


cassettes {Pointers - 02}
#include<iostream.h>
#include<string.h>
class Publication
{
private:
char title[20];
float price;
public:
void getName()
{
cout<<"Enter Title: "; cin>>title;
cout<<"Enter Price: $"; cin>>price;
}
void putName()
{
cout<<"\nTitle: "<<title;
cout<<", Price: $"<<price;
}
virtual void getData() = 0;

};
class Book : public Publication
{
private:
int pages; public:
void getData()
{
Publication::getName();
cout<<"Enter Pages: "; cin>>pages;
}
void putData()
{
Publication::putName();
cout<<", Pages: "<<pages<<endl;
}
};
class Tape : public Publication
{
private:
float minutes;
public:
void getData()
{
Publication::getName();
cout<<"Enter Minutes: "; cin>>minutes;
}
void putData()
{
Publication::putName();
cout<<", Minutes: "<<minutes<<endl;
}
};
int main()
{
Publication* ptrPub[100];
int n = 0;
char choice;
do
{
cout<<"Book or Tape? (b/t): "; cin>>choice;

if(choice == 'b')
{ ptrPub[n] = new Book; ptrPub[n]->getData(); }
else
{ ptrPub[n] = new Tape; ptrPub[n]->getData(); }
n++; cout<<"Enter another? (y/n): "; cin>>choice;
} while(choice == 'y');
for(int i=0; i<n; i++)
ptrPub[i]->putName();
cout<<endl;
return 0;

Program 15:Delete an element in a


dynamically allocating Queue
containing nodes {Linked Lists,
Stacks, Queues - 01}
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
struct Node
{
int itemno;
char Itemname[20] ;
Node *Link ;
};
class Queue
{
Node *front,*rear;

public:
Queue( )
{
front=rear=NULL; }
void Insert( );
void Delete( );
void Display( );
};
void Queue::Delete( )
{
Node *Temp;
if(front= =NULL)
cout<<Queue Underflow. No element to delete;
else
{
cout<<\n The item number for the element to delete.<<front->CNo;
cout<<\n The item name for the element to delete<<front->CName;
Temp=front;
front = front->Link;
delete Temp;
}
}

Program 16:Infix to Postfix Conversion using


stacks { Linked Lists, Stacks,
Queues - 02}
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int size = 50;
char infix[size], postfix[size], Stack[size];
int top=-1;
int precedence(char,ch);
char Pop();
char Topelement;
void Push(char ch);
int braces(char *);
int main()
{ char ele, elem, st[2];
int prep, pre, popped, j=0,chk=0;

strcpy(postfix, );
clrscr();
cout<<ASSUMPTION: The infix expression contains single letter variables
\n\t<<\t and single digit constants only.\n\n;
cout<<\n Enter Infix Expression..\n;
gets(infix);
chk=braces(infix);
if (chk!=0)
{ cout<<Unbalanced no. of braces.\n Extra;
cout<<(chk==1? right braces : left braces)<<endl;
exit(1);
}
for(int i=0;infix[i]!=\0;i++)
{ if (infix[i]!=(&&infix[i]!)&& infix[i]!=^&& infix[i]!=*
&& infix[i]!=/ && infix[i]!=+&& infix[i]!==-)
postfix[j++] = infix[i];
else if (infix[i]==()
{elem = infix[i];
Push(elem);
}
else if (infix[i]==)
{while((popped = Pop()) !=()
{ postfix[j++]=popped;}
}
else
{ elem = infix[i];
pre = precedence(elem);
ele = Topelement();
prep = precendence(ele);
if (pre > prep) Push(elem);
else
{
while ( prep>=pre)
{
if(ele==#) break;
Popped = Pop();
ele = Topelement();
postfix[j++] = popped;
prep = precedence(ele);
}
Push(elem);
}}

}}
while((popped = Pop())! = #)
postfix[j]=\0;
cout<<\n Post fix : <<postfix<<endl;
return 0;
}
Int precedence( char ch)
{ switch(ch)
{ case^: return 5;
case/: return 4;
case*: return 3;
case+: return 3;
case-: return 0;
}
}
char Pop()
{ char ret;
if (top!= -1)
{ ret= Stack[top];
top--;
return ret;
}
else
return#;
}
char Topelement()
ping
{
char ch;
if ( top!= -1) ch = Stack[top];
else ch = #;
return ch;
}
void Push( char ch )
{ if (top! = size - 1)
{ top++;
Stack[top]=ch;
}
}
int braces( char = s)
{
int leftbr, rightbr;

leftbr = rightbr = 0;
for( int i=0;s[i];i++)
{ if (s[i] = = () leftbr++;
else if ( s[i] = =)) rightbr++;
}
if ( leftbr = = rightbr) return 0;
else if ( leftbr< rightbr ) return 1;
else return-1;
}

Program 17:Seperating Even And Odd


Numbers From Array(Arrays
03)
#include<conio.h>
#include<iostream.h>
void Get1From2(int ALL[], int len)
{
int *EVEN,*ODD,i;
if(len%2==0)
{
EVEN=new int[len];
ODD=new int[len];
}
else
{
EVEN=new int[(len/2)+1];
ODD=new int[(len/2)];

}
for(int I=0;I<len; I++)
{
if (I%2==0)
{
EVEN[I]=ALL[I]; }
else
{
ODD[I]=ALL[I];
}
}
cout<<"Even Array contains\n";
for(i=0;i<len;i++)
{
if (i%2==0)
{
cout<<EVEN[i]<<", ";
}
}
cout<<"\nOdd Array contains\n";
for(i=0;i<len;i++)
{
if (i%2!=0)
{
cout<<ODD[i]<<", ";
}
}
}
void main()
{
clrscr();
int a[8]={12,34,56,67,89,90};
int ALLlen=sizeof a/sizeof(int); // get the length of Array a
clrscr();
Get1From2(a,ALLlen);
getch();
}

Program 18:Upper Case And Lower Case


{Arrays - 04}
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
char line[80];
int number_of_vowels,uc,lc,uv,lv;
uc=lc=uv=lv=0;
cout << "Enter your sentence : " << endl;
cin.getline(line,80);
for(int x=0; line[x]!='\0';x++)
{

if(line[x]=='A'||line[x]=='E'||line[x]=='I'||line[x]=='O'||line[x]=='U')
uv++;
else if(line[x]=='a'||line[x]=='e'||line[x]=='i'||line[x]=='o'||line[x]=='u')
lv++;
else if(line[x]>+65&&line[x]<=90)
uc++;
else if (line[x]>=97&&line[x]<=122)
lc++;
}
cout << "Uppercase Consonants = " << uc << "." << endl;
cout << "Lowercase Consonants = " << lc << "." << endl;
cout << "Uppercase Vowels = " << uv << "." << endl;
cout << "Lowercase Vowels = " << lv << "." << endl;
number_of_vowels=uv+lv;
cout << "Number of vowels = " << number_of_vowels << endl;
getch();
}

Program 19:Program to display all lines


starting with a particular letter
(Here D And M) { Linked Lists,
Stacks, Queues - 03}
#include<fstream.h>
#include<conio.h>
int main()
{
ifstream fin;
fin.open("out.txt");
char str[80]; int count=0;
clrscr();

while(!fin.eof())
{
fin.getline(str,80);
if(str[0]=='D' || str[0]=='M')
{
cout<<str<<endl;
}
count++;
} cout<<"Number of lines in file is "<<count;
fin.close();
getch();
return 0;
}

Program 20:Implementation Of Circular


Queue Using Arrays {Linked
Lists, Stacks And Queues 04}
#include<iostream.h>
#include<conio.h>
const int MAX = 5;
class cqueue
{
int a[MAX],front,rear;
public :

cqueue()
{
front=rear=-1;
}
void insert(int );
int deletion();
void display();
};
void cqueue :: insert(int val)
{
if((front==0 && rear==MAX-1) || (rear+1==front))
cout<<" Circular Queue is Full
";
else
{
if(rear==MAX-1)
rear=0;
else
rear++;
a[rear]=val;
}
if(front==-1)
front=0;
}
int cqueue :: deletion()
{
int k;
if(front==-1)
cout<<"Circular Queue is Empty
";
else
{
k=a[front];
if(front==rear)
front=rear=-1;
else
{
if(front==MAX-1)
front=0;

else
front++;
}
}
return k;
}
void cqueue :: display()
{
int i;
if(front==-1)
cout<<"Circular Queue is Empty
";
else
{
if(rear < front)
{
for(i=front;i<=MAX-1;i++)
cout<<a[i]<<" ";
for(i=0;i<=rear;i++)
cout<<a[i]<<" ";
}
else
{
for(i=front;i<=rear;i++)
cout<<a[i]<<" ";
cout<<endl;
}}}
void main()
{
cqueue c1;
int ch,val;
char op;
do
{
clrscr();
cout<<"-----------Menu------------";
cout<<"1.Insertion

2.Deletion
3.Display
4.Exit
";
cout<<"Enter Your Choice <1..4> ?";
cin>>ch;
switch(ch)
{
case 1 : cout<<"Enter Element to Insert ?";
cin>>val;
c1.insert(val);
break;
case 2 : val=c1.deletion();
cout<<"Deleted Element :"<<val<<endl;
break;
case 3 : c1.display();
break;
}
cout<<"Do you want to continue<Y/N> ?";
cin>>op;
}while(op=='Y' || op=='y');
getch();
}

THE END

You might also like