PROGRAMS BASED ON CONDITIONAL STATEMENTS
1) Write a program to accept the price of certain items and calculate the discount
and amount to be paid by the customer based on the given details:
Price Discount
Upto 5000 5%
5001 to 10000 10%
10001 to 15000 15%
Above 1500 20%
class Tax
void print(int pr)
if(pr<=5000)
double d1=pr*5/100; double
a1 = pr - d1;
[Link](“the amount is”+a1);
else if(pr>= 5001 && pr<=10000)
double d2=pr*10/100; double
a2=pr-d2;
[Link](“the amount is”+a2)
else if(pr>=10001 && pr<=15000)
double d3=pr*15/100; double
a3=pr-d3;
[Link](“the
amount is”+a3);
else if(pr>15000)
double d4=pr*20/100; double
a4=pr-d4;
[Link](“the amount is”+a4);
2) Write program to calculate the discount and amount based on the given details.
Display the discount and amount also.
Price Discount
Upto 10000 5%
10001 to 15000 15%
15001 to 20000 20%
Above 20000 25%
class Discount
void print(int pr)
if(pr<=10000)
double d1=pr*5/100; double
a1=pr-d1;
[Link](“the discount is”+d1);
[Link](“the amount is”+a1);
}
else if(pr>=10001 && pr<=15000)
double d2=pr*15/100; double
a2=pr-d2;
[Link](“the discount is”+d2);
[Link](“the amount is”+a2);
else if(pr>=15001 && pr<=20000)
double d3=pr*20/100; double
a3=pr-d3;
[Link](“the discount is”+d3);
[Link](“the amount is”+a3);
else if(pr>20000)
double d4=pr*25/100; double
a4=pr-d4;
[Link](“the discount is”+d4);
[Link](“the amount is”+a4);
3) Write a program to calculate discount and amount based on the given details.
Price Discount
Upto 20000 10%
20001 to 30000 15%
30001 to 40000 20%
Above 40000 25%
class shop
void calculate(int pr)
if(pr<=20000)
double d1=pr*10/100; double
a1=pr-d1;
[Link](“the amount is”+a1);
else if(pr>=20001 && pr<=30000)
double d2=pr*15/100; double
a2=pr-d2;
[Link](“the amount is”+a2);
else if(pr>=30001 && pr<=40000)
double d3=pr*20/100; double
a3=pr-d3;
[Link](“the amount is”+a3);
else if(pr>40000)
double d4=pr*25/100; double
a4= pr-d5;
[Link](“the amount is”+a4);
}
}
4) Write a program to calculate an electricity bill based on the details.
No. Of units Rate per unit
Upto 100 units No charge
101 to 200 units Rs. 0.80 per unit
201 to 300 units Rs. 1.50 per unit
Above 300 units Rs. 2.50 per unit
class Bill
void calculate (int u)
if(u<=100)
double c1=u*0;
[Link](“the bill is”+c1);
else if(u>=101 && u<=300)
double c2= u*0.80;
[Link](“the bill is”+c2);
else if(u>=200 && u<=300)
double c3=u*1.50;
[Link](“the bill is”+c3);
else if( u>300)
{
double c4=u*2.50;
[Link](“the bill is”+c4);
5) Write a program to calculate telephone bill based on the given details.
Number of calls Rate per call
Upto 100 calls Rs. 1.50/ call
101 to 200 calls Rs. 2.30/call
201 to 300 calls Rs. 3.00/call
Above 300 calls Rs. 3.50/call
class telephone
void print (int c)
If(c<=100)
double ch1= c*1.50;
[Link](“the rate is”+ ch1);
else if(c>=101 && c<=200)
double ch2= c*2.30;
[Link](“the rate is”+ ch2);
else if(c>=201 && c<=300)
double ch3= c*3.00;
[Link](“the rate is”+ ch3);
else if(c>300)
double ch4= c*3.50;
[Link](“the rate is”+ ch4);
5) Write a program to calculate water bill based on the given details.
No. Of Gallons Rate/gallon
Upto 200 gallons Rs. 100/gallon
201 to 400 gallons Rs. 300/gallon
401 to 800 gallons Rs. 500/gallon
Above 800 gallons Rs. 700/gallon
class water
void bill(int g)
if(g<=200)
double ch1=g*100;
[Link](“the charge is”+ch1);
else if(g<=201 && g>=400)
double ch2=g*300;
[Link](“the charge is”+ch2);
}
else if(g<=401 && g>=800)
double ch3=g*500;
[Link](“the charge is”+ch3);
else if(g>800)
double ch4=g*700;
[Link](“the charge is”+ch4);
7) Write a program to calculate telephone bill based on the given details.
No. Of calls Rate per calls
Upto 100 calls Rs. 1.80
For the next 200 calls Rs. 2.80
For the next 200 calls Rs. 3.80
class telephone
void charge(int c)
if(c<=100)
double r1=u*1.80;
[Link](“the rate is”+r1);
else if(c>100 && c<=300)
double r2=100*1.80+(c-100)*2.80;
[Link](“the rate is”+r2);
else if(c>300 && c<=500)
double r3=100*1.80+200*2.80+(c-300)*3.80;
[Link](“the rate is”+r3);
8) Write a program to calculate water bill based on the given details.
No. Of Gallons Rate per gallons
Upto 300 gallons Rs. 100/gallon
For the next 100 gallons Rs. 150/gallon
For the next 100 gallons Rs. 200/gallon
Above 500 gallons Rs. 250/gallon
class water
void find(int w)
if(w<=300)
double b1=w*100;
[Link](“the rate is”+b1);
else if(w>300 && w<=400)
double b2=300*100+(w-300)*150;
[Link](“the rate is”+b2);
}
else if(w>400 && w<=500)
double b3= 300*100+100*150(w-400)*200;
[Link](“the rate is”+b3);
else if(w>500)
double b4=300*100+100*150+100*200+(g-500)*250;
[Link](“the rate is”+b4);
9) Write a program to calculate security charges based on the given details.
No. Of hours Charge/hour
Upto 5 hours Rs. 10/hour
For the next 10 hours Rs. 20/hour
For the next 10 hours Rs. 30/hour
Above 25 hours Rs. 50/hour
class Charge
void print (int c)
if(c<=5)
double s1=c*10;
[Link](“the charge is”+s1);
else if(c>5 && c<=15)
{
double s2=5*10+(c-5)*20;
[Link](“the charge is”+s2);
else if(c>15 && c<=25)
double s3=5*10+10*20+(c-15)*30;
[Link](“the charge is”+s3);
else if(c>25)
double s4= 5*10+10*20+10*30+(c-25)*50;
[Link](“the charge is”+s4);
10) Write a program to calculate income tax based on the given details.
Income Tax
Upto 200000 No tax
More than 200000 and less 5% of the income exceeding 200000
than or equal to 250000
More than 250000 and less 10% of the income exceeding 250000
than or equal to 300000
More than 300000 15% of the income exceeding 300000
class Tax
void print(int Ic)
if(Ic<=200000)
double t1= 0.0;
[Link](“No tax”);
else if(Ic>200000 && Ic<=250000)
double t2=(Ic-200000)*5/100;
[Link](“the tax is”+t2);
else if(Ic>250000 && Ic<=300000)
double t3=(Ic-250000)*10/100;
[Link](“the tax is”+t3);
else if(Ic>300000)
double t4=(Ic-300000)*15/100;
[Link](“the tax is”+t4);
}
11) Write a program to calculate income tax based on the given details.
Income Tax
Upto 300000 No tax
More than 300000 and less than or 10% of the income
equal to 350000 exceeding 300000
More than 350000 and less than or 15% of the income
equal to 400000 exceeding
Above 400000 20% of the income
exceeding 400000
class Income
void accept(int Ic)
if(Ic<=300000)
double t1= 0.0;
[Link](“No tax”);
else if(Ic>300000 && Ic<=350000)
double t2=(Ic-300000)*10/100;
[Link](“the tax is”+t2);
else if(Ic>350000 && Ic<=400000)
double t3=(Ic-350000)*15/100;
[Link](“the tax is”+t3);
else if(Ic>400000)
{
double t4=(Ic-400000)*20/100;
[Link](“the tax is”+t4);
12) Write a program to calculate income tax based on the given details.
Income Tax
Upto 450000 No tax
More than 450000 and less than or Rs. 5000+10% of the income
equal to 600000 exceeding 450000
More than 450000 and less than or Rs. 10000+20% of the income
equal to 800000 exceeding 600000
Above 800000 Rs. 15000+25% of the income
exceeding 800000
class Detail
void print(int Ic)
double t1=0.0;
[Link](“No tax”);
else if(Ic>450000 && Ic<=600000)
double t2=5000+(Ic-450000)*10/100;
[Link](“the tax is”+t2);
else if(Ic>600000 && Ic<=800000)
double t3=10000+(Ic-600000)*20/100;
[Link](“the tax is”+t3);
}
else if(Ic>800000)
double t4=15000+(Ic-800000)*25/100;
[Link](“the tax is”+t4);
PROGRAMS BASED ON THE SWITCH CASE STATEMENTS
1)Write a program to accept three sides of a triangle and check whether it is
equilateral, isosceles, scalene triangle using switch case.
class equilateral
void print(int a, int b, char ch)
switch(ch)
case ‘E’:if((a==b) && (b== c) && (c==a))
[Link](“It is equilateral”);
break;
case ‘I’: if((a==b) || (b==c) || (c==a))
[Link](“It is isosceles”);
break;
default: [Link](“invalid”);
}
2) Write a program to calculate the rate of interest for general category(G) and rate
of interest for senior citizens(S) using switch case by accepting deposit amount
from the user and the switch case choice variable.
Term Rate of interest(G) Rate of Interest (S)
Upto 1 year 7.5% 8.0%
Upto 2 years 8.5% 9.0%
Upto 3 years 9.5% 10.0%
More than 3 years 10.0% 11.0%
class Senior
void print(int d, char ch, int y);
switch(ch)
case ‘A’: if(y<=1)
double y1=(d*7.5*y)/100;
double r1=d+y1;
[Link](“the interest rate is”+r1);
else if(y<=2)
double y2=(d*8.5*y)/100; double
r2=d+y2;
[Link](“the interest rate is”+r2);
else if(y<=3)
double y3=(d*9.5*y)/100; double
r3=d+y3;
[Link](“the interest rate is”+r3);
else if(y>3)
double y4=(d*10.0*y)/100; double
r4=d+y4;
[Link](“the interest rate is”+r4);
break; case
‘S’:if(y<=1)
double y1=(d*8.0*y)/100;
double r1=d+y1;
[Link](“the interest rate is”+r1);
else if(y<=2)
double y2=(d*9.0*y)/100; double
r2=d+y2;
[Link](“the interest rate is”+r2);
else if(y<=3)
double y3=(d*10*y)/100;
double r3=d+y3;
[Link](“the interest rate is”+r3);
else if(y>3)
{
double y4=(d*11.0*y)/100; double
r4=d+y4;
[Link](“the interest rate is”+r4);
break;
3) Write a program to calculate the discount and amount based on the given details
using switch case by accepting price of the items and the switch case variable.
Price OLED (Tv) AMOLED(Tv)
Upto 60000 10% 15%
60001 to 80000 15% 20%
80001 to 120000 20% 25%
Above 120000 25% 30%
class Tv
void verify(int pr,char ch)
switch(ch)
case ‘A’:if(pr<=60000)
double d1=(pr*10)/100; double
a1=pr-d1;
[Link](“the amount is”+a1);
}
else if(pr>=60001 && pr<=80000)
double d2=(pr*15)/100; double
a2=pr-d2;
[Link](“the amount is”+a2);
else if(pr>=80001 && pr<=120000)
double d3=(pr*20)/100; double
a3=pr-d3;
[Link](“the amount is”+a3);
else if(pr>120000)
double d4=(pr*25)/100; double
a4=pr-d4;
[Link](“the amount is”+a4);
break; case
‘A’:if(pr<=60000)
double d1=(pr*15)/100; double
a1=pr-d1;
[Link](“the amount is”+a1); }
else if(pr>=60001 && pr<=80000)
double d2=(pr*20)/100; double
a2=pr-d2;
[Link](“the amount is”+a2);
else if(pr>=80001 && pr<=120000)
double d3=(pr*25)/100; double
a3=pr-d3;
[Link](“the amount is”+a3);
else if(pr>120000)
double d4=(pr*30)/100; double
a4=pr-d4;
[Link](“the amount is”+a4);
break;
************