Professional Documents
Culture Documents
20
PROG
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();
}
return l*h*w; }
cout<<Code:<<ICode;
cout<<\nName:<<Item;
cout<<\nPrice:<<Price;
cout<<\nQuantity<<<Qty;
cout<<\nDiscount percentage:<<Discount;
}};
{
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;
clrscr();
}
cout<<"Number of travellers:"<<Number_of_travellers<<endl;
cout<<"Number of buses:"<<Number_of_buses<<endl;
}};
Program 07:-
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();
}
{
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();
}
filout1.close();
filout2.close();
filout3.close();
getch();
}
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();
}
}
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();
}
i++;
len++;
}
*(str1+len) = '\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;
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;
}
}
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;
}
}
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();
}
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();
}
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;
}
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