24EEB0B59 ass 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

PDS LAB ASSIGNMENT – 2

NAME: SIRIPIREDDY TANISHQ REDDY ROLL NO:24EEB0B59

1. Write a C++ program to input electricity unit charges and calculate the total electricity bill
according to the given condition: For the first 50 units Rs. 0.50/unit For the next 100 units
Rs. 0.75/unit For the next 100 units Rs. 1.20/unit For units above 250 Rs. 1.50/unit An
additional surcharge of 20% is added to the bill.

#include <iostream>
using namespace std;
int main()
{
float unit ,total;
cout<<"enter the number of units used"<<endl;
cin>>unit;
if(unit<=50)
total=0.5 * unit;
if (unit>50 && unit<=150)
total=(0.5*50) + (unit-50)*0.75;
if(unit>150 && unit<=250)
total=(0.5*50) + (100 * 0.75) + (unit-150) *1.2;
if (unit >250)
total=(0.5*50) + (100 * 0.75) + (100*1.2) + (unit-250) *1.5;
total=total*1.2;
cout<<"the total electric charge is ="<<total<<endl;

return 0;

}
2. Write a program that will take three numbers from the keyboard and find the maximum of
these numbers. Then check whether the maximum number is even or odd.
#include <iostream>
using namespace std;
int main()
{int a,b,c,big;int d;
cout<<"enter three numbers"<<endl;
cin>>a>>b>>c;
big=a;
if(b>big )
big=b;
if(c> big)
{

big =c;}
d=big % 2;
if(d==0)
cout<<"the number is even";
if(d==1)
cout<<"the number is odd";
return 0;

}
3. Write a program that determines a student’s grade. The program will read three types of
scores (quiz, mid-term, and final scores) and determine the grade basedon the following
rules: -if the average score =90% =>grade=A -if the average score >= 70% and grade=B -if the
average score>=50% and grade=C -if the average scoregrade=F

# include<iostream>
using namespace std;
int main()
{
int q,m,f;float a;
cout<<"enter the marks in quiz out of 100"<<endl;
cin>>q;
cout<<"enter the marks in mid exams out of 100"<<endl;
cin>>m;
cout<<"enter the marks out of 100 in final exams"<<endl;
cin>>f;
a=(q+m+f)/3;

if(a>=90)
cout<<"grade = A";
if(a>=70 && a<90)
cout<<"grade = B";
if(a>=50 && a<70)
cout<<"grade = C";
if(a<50)
cout<<"grade = F ";
return 0;
}
4. A university has the following rules for a student to qualify for a degree with A asthe main
subject and B as the subsidiary subject: a. He should get 55 percent or more in A and 45
percent or more in B. b. If he gets less than 55 percent in A he should get 55 percent or more
in B. However, he should get at least 45 percent in A. c. If he gets less than 45 percent in B
and 65 percent or more in A he is allowedto reappear in an examination in B to qualify. d. In
all other cases he is declared to have failed.

#include <iostream>

using namespace std;

int main()

int a,b;

cout<<"enter the percentage of marks obtained in A and B"<< endl;

cin>>a>>b;

if((a>=55) && (b>=45) || (45<=a && a<55) && (b>=55) )


cout<<"pass"<<endl;

else if(b<45 && a>=65)

cout <<"allowed to reappear the exam in B"<<endl;

else

cout<<"fail"<<endl;

return 0;

5. An insurance company insured their driver in the following case: - (i) Driver is married, (ii)
Driver is unmarried male and above 30 years (iii) Driver is unmarried female and above 25
years. In all other cases, the driver will not be insured. Write a program to check whether a
driver is insured or not based on marital status, sex, and age.

#include <iostream>

using namespace std;


int main()

{int age,m,g;

char a;

cout<<"if driver is married ,enter 1 or else enter 0"<<endl;

cin>>m;

cout<<"enter the gender,if male enter m,if female enter f"<<endl;

cin>>a;

g=a;

cout<<"enter age"<<endl;

cin>>age;

if (m==0)

if( (a=='m' && age>30) )

cout<<"driver is insured";

if (g=='f' && age>25)

cout<<"driver is insured";

else if( m==1 )

cout<<"the driver is insured"<<endl;

else

cout<<"the driver is not insured";

return 0;

}
6.

1. Write a program to check whether a entered character is lowercase ( a to z ) or uppercase ( A to Z


).

#include <iostream>

using namespace std;

int main()
{

char a;

int c;

cout<<"enter a character";

cin>>a;

c=a;

if(c>=97 && c<=122)

cout<<"lower case alphabet";

if(c>=65 && c<=90)

cout<<"upper case alphabet";

return 0;

}
2. An equation of the form ax^2+bx+c=0 is known as a quadratic equation. The

values of x that satisfy the equation are known as the roots of the equation.

Write a program to find out the roots of the quadratic equation.

#include <iostream>

#include <cmath>

using namespace std;

int main()

float x,y;

float a,b,c,d;

cout<<"enter the values of a,b,c in ax^2+bx+c=0"<<endl;

cin>>a>>b>>c;

if((b*b)-(4*a*c)>=0)

x=(b-sqrt((b*b)-(4*a*c)))/2*a;

y=(b+sqrt((b*b)-(4*a*c)))/2*a;

cout<<"the roots of the equation are"<<x <<"," << y;

}
if((b*b)-(4*a*c)==0)

{x=(b-sqrt(b*b-4*a*c))/(2*a);

y=(b+sqrt(b*b-4*a*c))/(2*a);

cout<<"the equal root is"<<x;

if((b*b)-(4*a*c)<0)

{d=abs((b*b)-(4*a*c));

cout<<"the roots are :"<<((-b)/(2*a))<<"+"<<(sqrt(d)/(2*a))<<"i"<<","<<((-b)/(2*a))<<"-


"<<(sqrt(d)/(2*a))<<endl;

return 0;

}
7 . In a company, worker efficiency is determined based on the time required for a

worker to complete a particular job. If the time taken by the worker is between

2 – 3 hours, then the worker is said to be highly efficient. If the time required by

the worker is between 3 – 4 hours, then the worker is ordered to improve

speed. If the time taken is between 4 – 5 hours, the worker is given training to
improve his speed, and if the time taken by the worker is more than 5 hours,

then the worker has to leave the company. Write a program that calculates the

efficiency of worker by taking the time taken by the worker from the console.

#include<iostream>

using namespace std;

int main()

float a;

cout<<"enter the time taken by worker to complete the job"<<endl;

cin>>a;

if(a>=2 && a<=3)

cout<<"worker is highly efficient";

if(a>3 && a<=4)

cout<<"the worker is ordered to improve";

if(a>4 && a<=5)

cout<<"the worker is given training to improve his speed";

if(a>5)

cout<<"the worker has to leave the company";

return 0;

}
8. Write a C++ Program to check whether the triangle is equilateral, isosceles or

scalene.

#include <iostream>

using namespace std;

int main()

float a,b,c;
cout<<"enter the value of first side"<<endl;

cin>>a;

cout<<"enter the value of second side"<<endl;

cin>>b;

cout<<"enter the value of third side"<<endl;

cin>>c;

if (a==b && a==c)

cout<<"the triangle is equilateral"<<endl;

if(a!=b && a!=c &&b!=c)

cout<<"the triangle is scalene"<<endl;

if((a==b && a!=c)||(a==c && a!=b) ||(b==c && b!=a))

cout<<"the triangle is isosceles";

return 0;

}
9. There are 5 types of tickets, each of which is denoted by a character (both

uppercase and lower case). Please find the equivalent strings for the characters.

E or e - Early Bird Ticket

D or d - Discount Ticket

V or v - VIP Ticket

S or s - Standard Ticket

C or c - Child Ticket

Write a program that takes the input of a character and prints the equivalent

string.

#include<iostream>

using namespace std;

int main()

char a;

cout<<"enter the type of ticket"<<endl;

cin>>a;

if(a=='E' || a=='e')
cout<<"early bird ticket";

if(a=='D'|| a=='d')

cout<<"discount ticket";

if (a=='V'||a=='v')

cout<<"VIP ticket";

if(a=='S'||a=='s')

cout<<"standard ticket";

if(a=='C'||a=='c')

cout<<"child ticket";

}
10. Write a C++ program to design a calculator with basic operations using switch

statement.

#include <iostream>

using namespace std;

int main()

char a;

int b,c,s,d,q,r,p;

cout<<"enter an arithmetic operator"<<endl;

cin>>a;

cout<<"enter the numbers"<<endl;

cin>>b>>c;

switch(a)

case '+':

s=b+c;

cout<<"the sum is"<<s;

break;
case '-':

d=b-c;

cout<<"the difference is "<<d;

break;

case'*':

p=b*c;

cout<<"the product is"<<p;

case '/':

q=b/c;

cout<<"the quotient is"<<q;

break;

case'%':

r=b%c;

cout<<"the remainder is"<<r;

break;

}return 0;

}
11. Write a menu-driven program (using a switch case) that computes the area of

geometrical shapes by getting the needed inputs from the user: 1. Area of the

circle; 2. Area of square; 3. Area of triangle. The program continues till the user

decides to exit.

#include <iostream>

#include <cmath>

using namespace std;


int main()

int a;float area;int v;char g;

g='a';

while( g!='e')

cout<< "enter the number of sides of the shape"<<endl;

cin>>a;

switch(a)

{case 0:

int r;cout<<"enter the radius of circle"<<endl;

cin>>r;

area=3.14*r*r;

cout<<"area of circle is"<<area<<endl;

break;

case 3:

int q,w,e;

cout<<"enter the sides of the triangle"<<endl;

cin>>q>>w>>e;

v=(q+w+e)/2;

area=sqrt(v*(v-w)*(v-e)*(v-q));

cout<<" the area of triangle"<<area<<endl;

break;

case 4:

int s;

cout<<"enter the side of the square"<<endl;

cin>>s;

area=s*s;
cout<<"enter the area of square"<<area<<endl;

break;

cout<<"enter e if u want to exit or enter any character if you want to


continue"<<endl;

cin>>g;

if(g=='e')

cout<<"program exited"<<endl;

return 0;

}
12. Write a program to accept three numbers and display the following menu

1. Product 2. Smallest number 3. Middle number 4. Biggest number. Accept

user choice and display the related output

#include <iostream>

using namespace std;

int main()

int d;int a,b,c;int p,s,bi,m;

cout<<"enter the value of a according to operation 1. Product, 2. Smallest number, 3.


Middle number, 4. Biggest number"<<endl;

cin>>d;

cout<<"enter three numbers to perform the calculations"<<endl;

cin>>b>>c>>a;

switch(d)

case 1:

p=a*b*c;

cout<<"the product of three numbers ="<<p<<endl;

break;

case 2:

if(a<b && a<c)

s=a;

if(b<c && b<a)

s=b;

if(c<a && c<b)

s=c;

cout<<"the smallest number is"<<s;

break;

case 3:

if(a<b && b<c)


m=b;

if(c<b && b<a)

m=b;

if(a<c && c<b)

m=c;

if(b<c && c<a)

m=c;

if(c<a && a<b)

m=a;

if(b<a && a<c)

m=a;

cout<<"the middle number is"<<m;

break;

case 4:

if(a>b && a>c)

bi=a;

if(c>b && c>a )

bi=c;

if(b>c && b>>a)

bi=b;

cout<<"the biggest number is"<<bi;

break;
}return 0;}

You might also like