You are on page 1of 17

Program - 1

Write a c++ program that sorts an array of number sort function


to be overloaded to support both integer array and float array.

Template<class T>
Class sort
{
T a[10];
Public:
Void insert()
{
For(i=0;i<10;i++)
{
Cout<<”enter value”;
Cin>>a[i];
}
Void sort
{
T temp;
For(i=0;i<=n-1;i++)
{
For(j=1;j<=n-I;j++)
{
If (a[j]>a[j+1])
{
Temp=a[j]
A[j]=a[j+1]
A[j+1]=temp
}
}
}
}
Main()
{
Sort<int>s1;
S1.insert();
S1.sort();
Sort<float>s2;
S2.sort();
}
Program – 2

An electricity board charge following rate for domestic user to


discharge large cunsesion of
For first 100 units 60 per unit
For next 200 units 80 per unit
Beyond 300 units 90 per unit
All users are charge minimum of rupees 50 all the total amount
if more than rupees 300 than additional charge 15% it added
write a program to read the name of users and number of unit
consume and print out the charge with name.

Class ele-bill
{
Char name[10];
Int unit;
Float bill;
Public:
Void getdetail()
{
Cout<<”enter person details”;
Cin>>name>>unit;
If(unit<=100)
{
Bill=unit*60;
If(bill<50)
{
Bill=50;
}
}
Else if (unit>101 && unit<=300)
{
Bill=unit*80;
}
Else
{
Bill=unit*90;
If(bill>300)
{
Bill=bill+bill*0.15;
}
Void putdata()
{
Cout<<name<<bill;
}
};
Main()
{
Ele-bill p1,p2;
P1.getdata();
P1.getdata();
}
Program – 3

Write a function power to raise a number of M to N power


to function take a double value for M integer value for N
and return the result correctly use a default value of 2 for
N to make function to calculate squre when this argument
is omitted write a name function that gets values of M and
N from the users to test the function

#include<math.h>
Power(double M,int n=2)
{
Return= power(m,n);
}
Main()
{
Cout<<”enter value of m,n”;
Cin>>m>>n;
Power(m,n);
}
Program – 4

make display_area as a virtual function & redefine this function


in derived class to suit the requirements.Using these three
classess design a program that will accept dimention of a
triangle or a retangle interactively & display the area.
Remember the two value given as input will be treated as
lengths of two side of the case of rectangles & as base & height
in the case of triangles & used as follows:=>
Area of rectangle = x*y
Area of triangle =1/2* x*y

#include<iostream.h>
#include<conio.h>
class staff
{
public:
int code;
char *name;
void gets()
{
cout <<"ENTER THE NAME AND CODE OF
STAFF:";
cin >> code >> name;
}
};
class teacher : public staff
{
public:
char *sub,*pub;
void gett()
{
cout <<"ENTER THE DETAILS OF TEACHER:";
cin >>sub >>pub;
}
void displayt()
{
cout << "THE DETAILS OF A TEACHER IS:";
cout << sub <<endl <<pub;
}
};
class typist : public staff
{
public:
int speed;
void gett1()
{
cout << "ENTER SPEED:";
cin >>speed;
}

};
class regular : public typist
{
public:
int mw;
void getr()
{
cout << "ENTER THE MONTHLY
WAGES:";
cin >> mw;
}
void displayr()
{
cout << "THE MONTHLY WAGES IS:";
cout << mw <<endl;
}
};
class casual : public typist
{ public:
int dw;
void getc()
{
cout << "ENTER THE DAILY WAGES:";
cin >> dw;
}
void displayc()
{
cout << "THE DAILY WAGES IS:";
cout << dw <<endl;
}
};
class other:public staff
{
public:
int grade;
void geto()
{
cout << "ENTER THE GRADE:";
cin >> grade;
}
void displayo()
{
cout << "THE GRADE IS:";
cout << grade <<endl;
}
};

void main()
{
clrscr();
int n;
cout << "ENTER CODE:";
cout <<"1.TEACHER\n" <<"2.TYPIST\n"
<<"3.OTHERS\n";
teacher t;
t.gets();
if(t.code == 1)
{
t.gett();
t.displayt();
}
else if(t.code == 2)
{
typist t1;
t1.gett1();
cout << "1.regular and 2.casual:\n";
if(t1.speed == 1)
{
regular r;
r.getr();
r.displayr();
}
if(t1.speed == 2)
{
casual c;
c.getc();
c.displayc();
}
}
else if(t.code == 3)
{
other o;
o.geto();
o.displayo();
}
else
{
cout << "INVALID CHOICE:";
}
getch();
}
Program – 5

Assume that a bank maintains two kinds of accounts for


customers, one called as savings account and the other as
current account.The savings account provides compound
interest and withdrawal facilities
but no cheque book facility. The current account provides
cheque book facility but no interest. Current account holders
should also maintain a minimum balance of Rs. 500 and if the
balance falls below this level , a 11% service charged is
imposed. Create a class account that stores a customer name,
account number and type
of account. From this derive the classes current_acc and
savings_acc to make them more specific to their requirements.
Include necessary member functions in order to achieve the
following tasks.
a) Accept deposit from the customer and update the balance.
b) Display the balance.
c) Compute and deposit the interest.
d) Permit withdrawal and update the balance.
e) Check for the minimum balance, impose penalty,
necessary, and update the balance.
Do not use constructors. Use member functions to initialize the
class members.

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

class account
{
public:
char cust_name[10];
int accno;
int typeofac;

void getaccount()
{
cout<<"Enter customer name";
cin>>cust_name;
cout<<endl<<"Enter account number";
cin>>accno;

void displayaccount()
{
cout<<cust_name<<endl<<accno<<endl;
if (typeofac ==1)
cout<<"Savings";
else
cout<<"Current";
}

};

class savings:public account


{
public:
int interest;
int with_amt;
int balance;
int depo_amt;

void basicbalance()
{
cout<<endl<<"Enter the balance";
cin>>balance;
int i;
do
{
cout<<endl;
cout<<endl<<"1. Deposit amt";
cout<<endl<<"2. Withdraw amt";
cout<<endl<<"3. Calculate interest";
cout<<endl<<"4. Show balance";
cout<<endl<<"5. Exit";
cin>>i;

switch(i)
{
case 1:
depositamt();
break;
case 2:
withdrawal();
break;
case 3:
calculateinterest();
break;
case 4:
showbalance();
break;
case 5:
exit(0);
}
}while(i!=5);

}
void depositamt()
{
cout<<endl<<"Enter the amount to be
deposited";
cin>>depo_amt;

balance = balance + depo_amt;


}

void showbalance()
{
cout<<"The balanace is "<<balance;
}

void calculateinterest()
{
interest = balance * 0.10;
cout<<endl<<"The interest is "<<interest;

balance = balance + interest;

void withdrawal()
{
cout<<endl<<"Enter the withdrawal
amount";
cin>>with_amt;

balance = balance - with_amt;

};

class current:public account


{
public:
int chequeno;
char bankname[10];
int balance;
int depo_amt;
int with_amt;

void basicbalance()
{
cout<<endl<<"Enter the balance";
cin>>balance;
int i;
do
{
cout<<endl;
cout<<endl<<"1. Deposit amt";
cout<<endl<<"2. Withdraw amt";
cout<<endl<<"3. Show balance";
cout<<endl<<"4. Exit";
cin>>i;

switch(i)
{
case 1:
depositamt();
break;
case 2:
withdrawal();
break;
case 3:
showbalance();
break;
case 4:
exit(0);
}
}while(i!=4);

void depositamt()
{
cout<<endl<<"Enter the cheque no";
cin>>chequeno;
cout<<endl<<"Enter the bank name";
cin>>bankname;
cout<<endl<<"Enter the amount to be
deposited";
cin>>depo_amt;

balance = balance + depo_amt;


}

void showbalance()
{
cout<<"The balanace is "<<balance;
}

void withdrawal()
{
cout<<endl<<"Enter the withdrawal
amount";
cin>>with_amt;

balance = balance - with_amt;

if (balance <= 500)


{
int charge;
charge = (500-balance) * 0.11;
cout<<endl<<"The service charge is
"<<charge;
cout<<endl<<"As balance is less than
500";
balance = balance - charge;
}

};

void main()
{
clrscr();
savings s;
s.getaccount();
cout<<endl<<"Enter the type of account";
cout<<"1. Savings";
cout<<"2. Current";
cin>>s.typeofac;
s.displayaccount();
if (s.typeofac == 1)
s.basicbalance();
else
{
current c;
c.basicbalance();
}
getch();
}
Program – 6

Write a program to input string from user & print the following
types of triangle depend on input.
e.x if user input “program” then
Pr
Pro
Prog
Progr
Progra
Program

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[10];
int i,j,n;
clrscr();
cout<<endl<<"Enter string :=> ";
cin>>a;
n=strlen(a);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
cout<<a[j];
}
cout<<endl;
}
getch();
}

You might also like