You are on page 1of 20

Name:

Taimoor Malik
Registration no:
SP23-BCS-009
Submitted to:
Maam samia raiz

Department of computer science


QUESTION:01:
SOLUTION:
#include<iostream>

using namespace std;

int main()

char ch;

cout<<"Enter a character:"<<endl;

cin>>ch;

if(int(ch)>=97&&int(ch)<=122)

cout<<"The entered character is a lowercase character"<<endl;

else if(ch >= 'A' && ch <='Z')

cout<<"Entered character is not a lowercase letter"<<endl;

else

cout << "Invalid Input";

QUESTION:2:
#include<iostream>

using namespace std;

int main()

char ch;
cout<<"Enter status of a salesperson:"<<endl;

cin>>ch;

if(ch=='j'||ch=='J')

cout<<"Junier salesperson salary: Rs.275 a week"<<endl;

else if(ch=='s'||ch=='S')

cout<<"Senior salesperson salary: Rs.400 a week"<<endl;

else

cout<<"Error";

QUESTION:03:
#include<iostream>

using namespace std;

int main()

int a,b,c;

cout<<"Enter 3 integers:"<<endl;

cin>>a>>b>>c;

if(a!=0)

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

cout<<a<<" is a common divisor for "<<b<<" and "<<c<<endl;

}
else

cout<<a<<" is not a common divisor for "<<b<<" and "<<c<<endl;

QUESTION:04:
#include<iostream>

using namespace std;

int main()

char ch;

float h,b,x;

cout<<"Enter side of a square:"<<endl;

cin>>x;

cout<<"Enter base and height of a triangle:"<<endl;

cin>>b>>h;

cout<<"Enter a character:"<<endl;

cin>>ch;

if(ch=='S')

cout<<"Area of square is:"<<x*x<<endl;

else if(ch=='T')

cout<<"Area of triangle is:"<<.5*b*h<<endl;

else
cout<<"invalid input";

QUESTION:05:
#include<iostream>

using namespace std;

int main()

int x;

char ch;

cout<<"Enter a character:"<<endl;

cin>>ch;

if (ch=='f')

cout<<"Enter the temperature in Fahrenheit:";

cin>>x;

cout<<endl<<"The temperature in celsius is:"<< (x-32)*5/9<<endl;

else if(ch=='c')

cout<<"Enter the temperature in celsius:";

cin>>x;

cout<<endl<<"The temperature in Fahrenhiet is:"<<(x*9/5)+32<<endl;


}

else

cout<<"invalid input";

QUESTION:06:
#include<iostream>

using namespace std;

int main()

int x;
cout<<"Enter the code number of disk drive manufacture from 1-5:";

cin>>x;

switch (x)

case 1:

cout<<endl<<"Western Digital";

break;

case 2:

cout<<endl<<"3M Corporation";

break;

case 3:

cout<<endl<<"Maxell Corporation";

break;

case 4:

cout<<endl<<"Sony Corporation";

break;

case 5:

cout<<endl<<"Verbatim Corporation";

break;

default:

cout<<endl<<"Invalid input";

break;

QUESTION:07:
SOLUTION:
#include<iostream>

using namespace std;

int main()

char ch;

cout<<"A for Adventure Movies"<<endl<<"C for Comedy Movies"<<endl<<"F for Family


Movies"<<endl<<"H for Horror Movies"<<endl<<"S for Science Fiction Movies";

cout<<endl<<"Enter your choice:"<<endl;

cin>>ch;

switch (ch)

case 'A':

cout<<"Adventure Movies"<<endl;

break;

case 'C':

cout<<"Comedy Movies"<<endl;

break;

case 'F':

cout<<"Family Movies"<<endl;

break;

case 'H':

cout<<"Horror Movies"<<endl;

break;

case 'S':

cout<<"Science Fiction Movies"<<endl;

break;

default:

cout<<"Invalid input";

}
}

QUESTION:08:
#include<iostream>

using namespace std;

int main()

float x;

char ch;

cout<<"Enter an integer for conversion:";

cin>>x;

cout<<endl<<"inches to centimeter:a \ngallons to litres:b \nmiles to kilometers:c \npounds


to kilograms:d";

cout<<endl<<"Enter your choice of conversion:";

cin>>ch;

switch (ch)

case'a':

cout<<x<<" inches="<<x*2.54<<" cm"<<endl;

break;
case'b':

cout<<x<<" gallons="<<x*3.785<<" litres"<<endl;

break;

case'c':

cout<<x<<" miles="<<x*1.609<<" km"<<endl;

break;

case'd':

cout<<x<<" pounds="<<x*.4536<<" kg"<<endl;

break;

default:

cout<<"Invalid input";

QUESTION:10:
#include <iostream>

using namespace std;

int main()

{
float temp;

cout<<"Enter temperature in degree celsius:";

cin>>temp;

if (temp>35)

cout<<"Hot day"<<endl;

else if(temp>=25&&temp<=35)

cout<<"Pleasant day"<<endl;

else

cout<<"Cool day";

QUESTION:11:
#include<iostream>

using namespace std;

int main()

float num,per;

cout<<"Enter obtained marks:"<<endl;

cin>>num;

per=(num*100)/1100;

cout<<per<<"%"<<endl;

if(per>=80&&per<=100)

cout<<"A+"<<endl;

else if(per>=70&&per<80)
cout<<"A"<<endl;

else if(per>=60&&per<70)

cout<<"B"<<endl;

else if(per>=50&&per<60)

cout<<"C"<<endl;

else if(per>=40&&per<50)

cout<<"D"<<endl;

else if(per>=33&&per<40)

cout<<"E"<<endl;

else if(per>=0&&per<33)

cout<<"F"<<endl;

else

cout<<"Invalid input";

QUESTION:12:
#include<iostream>

using namespace std;

int main()

int hr,mins;

cout<<"Enter time in military format:"<<endl;

cout<<"Hours:";

cin>>hr;
cout<<"Minutes:";

cin>>mins;

if (hr>=0&&hr<=23&&mins>=0&&mins<=60)

if(hr>12)

cout<<"Standard Format:"<<hr-12<<":"<<mins<<endl;

else if(hr==0)

cout<<"standard Format:"<<hr+12<<":"<<mins<<endl;

else

cout<<"Standard Format:"<<hr<<":"<<mins<<endl;

else

cout<<"Invalid input";

QUESTION:14
#include<iostream>

using namespace std;

int main()

float x,s;

int tax;

cout<<"Enter salary of an employee:";

cin>>x;
if(x>30000)

tax=20;

s=(x*tax)/100;

cout<<"Salary:"<<x<<"\nTax:"<<tax<<"%"<<"\nNet salary:"<<s;

else if(x>=20000&&x<=30000)

tax=15;

s=(x*tax)/100;

cout<<"Salary:"<<x<<"\nTax:"<<tax<<"%"<<"\nNet salary:"<<s;

else if(x<20000)

tax=10;

s=(x*tax)/100;

cout<<"Salary:"<<x<<"\nTax:"<<tax<<"%"<<"\nNet salary:"<<s;

else

cout<<"invalid Input";

QUESTION:15
#include<iostream>
using namespace std;
int main()
{
int yr,m;
cout<<"Enter year and a month:"<<endl;
cout<<"Year:";
cin>>yr;
cout<<"Month:";
cin>>m;
switch(m)
{
case 1:
cout<<"January "<<yr<<" has 31 days."<<endl;
break;
case 2:
if((yr%4==0) && ((yr%400==0) || (yr%100!=0)))
{
cout<<"February "<<yr<<" has 29 days."<<endl;
}
else
{
cout<<"February "<<yr<<" has 28 days."<<endl;
}
break;
case 3:
cout<<"March "<<yr<<" has 31 days."<<endl;
break;
case 4:
cout<<"April "<<yr<<" has 30 days."<<endl;
break;
case 5:
cout<<"May "<<yr<<" has 31 days."<<endl;
break;
case 6:
cout<<"June "<<yr<<" has 30 days."<<endl;
break;
case 7:
cout<<"July "<<yr<<" has 31 days."<<endl;
break;
case 8:
cout<<"August "<<yr<<" has 31 days."<<endl;
break;
case 9:
cout<<"September "<<yr<<" has 30 days."<<endl;
break;
case 10:
cout<<"October "<<yr<<" has 31 days."<<endl;
break;
case 11:
cout<<"November "<<yr<<" has 30 days."<<endl;
break;
case 12:
cout<<"December "<<yr<<" has 31 days."<<endl;
break;
default:
cout<<"Invalid input";
}
}

QUESTION#9
#include<iostream>

using namespace std;

int main()

int x;

cout<<"Enter a year:"<<endl;

cin>>x;

if((x%4==0) && ((x%400==0) || (x%100!=0)))

cout<<"Leap year"<<endl;

else

cout<<"Not a leap year";

}
QUESTION#16:
#include <iostream>

using namespace std;

main()

char a;

int b;

cout<<" Menu for parking area : \n M = MOTORCYCLE (Rs 10 per day)\n C = CAR (Rs 20 per
day)\n B = BUS (Rs 30 per day)\n"<<endl;

cout<<endl;

cout<<"Enter your vehicle type : ";

cin>>a;

cout<<endl;

cout<<"Enter number of days you want to park your car : ";

cin>>b;

cout<<endl;

if(a == 'M')

cout<<"Parking for your Motorcycle will cost you : "<<10*b<<"Rs."<<endl;


}

else if(a == 'C')

cout<<"Parking for your Car will cost you : "<<20*b<<"Rs."<<endl;

else if(a == 'B')

cout<<"Parking for your Bus will cost you : "<<30*b<<"Rs."<<endl;

else

cout<<"Invalid input ";

QUESTION#17:
#include<iostream>
using namespace std;

int main()

float x;

char ch;

cout<<"Enter an integer for conversion:";

cin>>x;

cout<<endl<<"Centimeter to inches:a \nLitres to gallons :b \nKilometers to miles:c \


nKilograms to pounds:d"<<endl;

cout<<endl;

cout<<"Enter your choice of conversion :";

cin>>ch;

cout<<endl;switch (ch)

case'a':

cout<<x<<" cm="<<x*0.394<<" inches"<<endl;

break;

case'b':

cout<<x<<" litres="<<x*0.264 <<" gallons"<<endl;

break;

case'c':

cout<<x<<" km="<<x*0.622<<" miles"<<endl;

break;

case'd':

cout<<x<<" kg="<<x*2.2<<" pounds"<<endl;

break;

default:

cout<<"Invalid input";

}
}

You might also like