0% found this document useful (0 votes)
44 views

PSCP Assignment

The document contains 10 C++ programs that demonstrate the use of control flow statements like if-else, switch case, for loops etc. The programs cover topics like calculating library fines based on return date, determining mode of transport and route taken to reach a destination, calculating faculty salary based on position and gender, determining substance from its boiling point, calculating parking charges based on vehicle type and time. The last program determines earthquake damage level based on Richter scale number using if-else-if ladder.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

PSCP Assignment

The document contains 10 C++ programs that demonstrate the use of control flow statements like if-else, switch case, for loops etc. The programs cover topics like calculating library fines based on return date, determining mode of transport and route taken to reach a destination, calculating faculty salary based on position and gender, determining substance from its boiling point, calculating parking charges based on vehicle type and time. The last program determines earthquake damage level based on Richter scale number using if-else-if ladder.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

PRGM-1)

#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int ed,em,ey,ad,am,ay;
float fine=0;
cout<<"Enter the expected date of return of the book(dd/mm/yyyy): ";
cin>>ed>>em>>ey;
cout<<"Enter the actual date of return of the book(dd/mm/yyyy): ";
cin>>ad>>am>>ay;

if(ad<=ed)
cout<<"\nNO Dues";
else if(ad>ed&&am==em&&ay==ey)
{
fine=15*(ad-ed);
cout<<"\nFine = "<<fine;
}
else if(am>em&&ay==ey)
{
fine=50*(am-em);
cout<<"\nFine = "<<fine;
}
else if(ay>ey)
cout<<"\nFine = 1000";
getch();
}

OUTPUT:
PRGM-2)
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
char c1,c2,c3,c4;
cout<<"Destination->HYD";
cout<<"\n1)Train(press 't')";
cout<<"\n2)Bus(press 'b')";
cout<<"\n3)Car(press 'c')";
cout<<"\nChoose Faculty position: ";
cin>>c1;
switch(c1)
{
case('b'):cout<<"BUS";
cout<<"\n1)Bike(press 'k')";
cout<<"\n2)Auto(press 'a')";
cout<<"\n**Got down at UPPAL**";
cout<<"\nChoose an option: ";
cin>>c2;
switch(c2)
{ case('k'):cout<<"\nDestination->HYD reached by bike";
break;
case('a'):cout<<"\nDestination->HYD reached by auto";
break; }
break;
case('c'):cout<<"CAR";
cout<<"\nDestination-HYD reached by Car ";
break;
case('t'):cout<<"TRAIN";
cout<<"\n1)Cab(press 'd')";
cout<<"\n2)Bike(press 'k')";
cout<<"\n3)Auto(press 'a')";
cout<<"\nChoose an option: ";
cin>>c3;
switch(c3)
{ case('b'):cout<<"\nDestination->HYD reached by Train and taking a bike";
break;
case('a'):cout<<"\nDestination->HYD reached by Train and taking an auto";
break;
case('d'): cout<<"You took Cab ";
cout<<"\nPress 'k' for bike to reach your destination: ";
cin>>c4;
switch(c4)
{ case('k'):cout<<"Destination->HYD reached by Train, cab and bike ";
break;
} break;
}
break;
}
getch();
}
OUTPUT:

PRGM-3)
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int a1,b1,a2,b2;
float sum,product;
char c;
cout<<"Enter fraction 1: ";
cin>>a1>>c>>b1;
cout<<"Enter fraction 2: ";
cin>>a2>>c>>b2;
sum=(a1*b2)+(a2*b1);
product=b1*b2;
cout<<"The sum of the 2 fractions = "<<sum<<c<<product;
getch();
}

OUTPUT:
PRGM-4)
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
float f1,f2,m1,m2,f_used,km_t,mil;
cout<<"Enter the miles travelled at the start of the journey: ";
cin>>m1;
cout<<"Enter the miles travelled at the end of the journey: ";
cin>>m2;
cout<<"Enter the fuel consumed at the start of the journey: ";
cin>>f1;
cout<<"Enter the fuel consumed at the end of the journey: ";
cin>>f2;
f_used=f1-f2;
km_t=m1-m2;
mil=km_t/f_used;
cout<<"\nFuel used = "<<f_used;
cout<<"\nKilometers travelled(1mile=1.6kilometers) = "<<(1.6*km_t) ;
cout<<"\nOverall fuel consumed = "<<mil;
getch();
}

OUTPUT:

PRGM-5) OUTPUT:
#include <iostream.h>
#include <conio.h>
void main()
{ clrscr();
int x,price=0;
for(int i=1;i<50;i++)
{
x=i+50;
if(x%2==0&&x%3==0&&(x-3)%5==0)
price=0.5*x; }
cout<<"Number of eggs present were "<<price/0.5;
cout<<"\nMahesh paid Rs"<<price<<" to Sridhar ";
getch();
}
PRGM-6)
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int age;
float fare=0,dist;
cout<<"Enter the age of the passenger: ";
cin>>age;
cout<<"Enter the distance travelled from the source station to the destination: ";
cin>>dist;
if(age<5)
cout<<"\nChildren below 5 years are exempted from paying the fare" ;
else if(age>=5&&age<=59)
{
fare=0.5*dist;
cout<<"\nPassenger between 5-59 years of age need to pay full fare";
cout<<"\nFare = "<<fare;
}
else if(age>=60)
{
fare=0.6*0.5*dist;
cout<<"\nPassenger above 60 years of age(Senior Citizens) are exempted from paying 40% of the fare";
cout<<"\nFare = "<<fare;
}
getch();
}
OUTPUT:
PRGM-7)

#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int bp;
cout<<"Enter the boiling point of the substance ";
cin>>bp;

switch(bp)
{
case 95 ... 105: cout<<"Water";
break;

case 2527 ... 2793: cout<<"Gold";


break;

case 339 ... 375: cout<<"Mercury";


break;

case 1128 ... 1246: cout<<"Copper";


break;

case 2083 ... 2302: cout<<"Silver";


break;
default: cout<<"Unknown Substance ";
break;
}
getch();
}

OUTPUT:
PRGM-8)
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
char type;
int hr;
cout<<"Motorbike(press 'm' or 'M')";
cout<<"\nCar(press 'c' or 'C')";
cout<<"\nBus(press 'b' or 'B')";
cout<<"\nSelect the type of vehicle: ";
cin>>type;
cout<<"Select the type of vehicle: ";
cin>>type;
cout<<"Enter the no of hours the vehicle spent in the parking lot: ";
cin>>hr;
switch(type)
{
case('M'):

case('m'):cout<<"Motorbike" ;
cout<<"\nParking charge =Rs"<<5*hr;
break;
case('C'):

case('c'):cout<<"Car" ;
cout<<"\nParking charge =Rs"<<10*hr;
break;
case('B'):

case('b'):cout<<"Bus" ;
cout<<"\nParking charge =Rs"<<50*hr;
break;
}
getch();
}

OUTPUT:
PRGM-9)
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
float basic=0,da,hra,ma,ta,gross=0;
int type;
char g;
cout<<"\n1)Professor ";
cout<<"\n2)Associate Professor ";
cout<<"\n3)Assisstant Professor";
cout<<"\nSelect the type of faculty: ";
cin>>type;
switch(type)
{
case(1):cout<<"PROFESSOR ";
basic=40000;
da=0.55*basic;
hra=0.3*basic;
ma=0.1*basic;
ta=0.05*basic;
gross=basic+da+hra+ma;
cout<<"Gender(g/l): ";
cin>>g;
switch(g)
{
case('l'):cout<<"Lady faculty" ;
gross=gross+ta;
cout<<"\nGross Salary = "<<gross;
break;
case('g'):cout<<"Gent faculty ";
cout<<"\nGross Salary = "<<gross;
break;
}
break;
case(2):cout<<"ASSOCIATE PROFESSOR ";
basic=30000;
da=0.5*basic;
hra=0.25*basic;
ma=0.1*basic;
ta=0.05*basic;
gross=basic+da+hra+ma;
cout<<"Gender(g/l): ";
cin>>g;
switch(g)
{
case('l'):cout<<"Lady faculty" ;
gross=gross+ta;
cout<<"\nGross Salary = "<<gross;
break;
case('g'):cout<<"Gent faculty ";
cout<<"\nGross Salary = "<<gross;
break;
}
break;

case(3):cout<<"ASSISSTANT PROFESSOR ";


basic=20000;
da=0.45*basic;
hra=0.2*basic;
ma=0.1*basic;
ta=0.05*basic;
gross=basic+da+hra+ma;
cout<<"Gender(g/l): ";
cin>>g;
switch(g)
{
case('l'):cout<<"Lady faculty" ;

gross=gross+ta;
cout<<"\nGross Salary = "<<gross;
break;

case('g'):cout<<"Gent faculty ";

cout<<"\nGross Salary = "<<gross;


break;
}
break;
}
getch();
}

OUTPUT:
PRGM-10)
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
float n;
cout<<"Enter the ritcher scale number: ";
cin>>n;
if(n<5.0)
cout<<"Little or no damage ";
else if(n>=5&&n<5.5)
cout<<"Some damage";
else if(n>=5.5&&n<6.5)
cout<<"Serious damage:walls may crack or fall ";
else if(n>=6.5&&n<7.5)
cout<<"Disaster:houses and buildings may collapse ";
else
cout<<"Catastrophe: most buildings destroyed";
getch();
}

OUTPUT:

Here, instead of using switch, we use if-else-if statements because the


given program involves the usage of decimal numbers for comparison
and decimal/fractional numbers can’t be entered in the case of switch.

You might also like