You are on page 1of 17

Assignment No 5

Submitted By:
Name: QuratulAin Javed
Reg# : SP21-BSE-067
Course Name: Programming Fundamentals
Submitted To: Ms. Ramsha Ahmad
Date: 13 October, 2021
TASK #5
Question # 1
Write a C++ program to check whether a character is alphabet or not.

ANSWER # 1
#include<iostream>
using namespace std;
int main(){
//Question#1
char ch;
cout<<"Enter an character to check it is alphabat or not: ";
cin>>ch;
if(ch>='a' && ch<='z' || ch>='A' && ch<='Z'){
cout<<"The character "<<ch<<" is an alphabat";
}
else
cout<<"The character"<<ch<<" is not an alphabat";
return 0;
}
The output #1(Alphabat):

The output #2(NOT Alphabat):


Question # 2
Write a C++ program to input angles of a triangle and check whether
triangle is valid or not.

ANSWER # 2
#include<iostream>
using namespace std;
int main(){
//Question#2
int a, b, c;
cout<<"Enter three angles of triangle to check it is valid or not:
"<<endl;
cin>>a>>b>>c;
if(a+b+c<=180)
{
cout<<"a = "<<a<<", b = "<<b<<", c = "<<c<<endl;
cout<<"This tiangle is valid"<<endl;
}
else if(a+b+c>180)
{
cout<<"a = "<<a<<", b = "<<b<<", c"<<c<<endl;
cout<<"This Triangle is not valid"<<endl;
}
return 0;
}
The output #1(Valid triangle):

The output #2(NOT valid triangle):

Question # 3
Write a C++ program to check whether a character is vowel or
consonant.

ANSWER # 3
#include<iostream>
using namespace std;

int main(){
//Question#3
char ch;
cout<<"Enter an alphabat to check vowel or consonent:
"<<endl;
cin>>ch;
if(ch=='a' && 'e' && 'i' && 'o' && 'u'){
cout<<"The alphabat '"<<ch<<"' is vowel
character"<<endl;

}
else
{
cout<<"The alphabat '"<<ch<<"' is consonent"<<endl;

}
return 0;
}
The output #1(Vowel):

The output #2(Consonent):


Question # 4
Write a menu driven C++ program for simple calculator using if-else.

ANSWER # 4
#include<iostream>
#include<cmath>
using namespace std;

int main(){
//Question#4
double add1, add2, sub1, sub2, multi1, multi2, a;
double div1, div2;
cout<<"Select the number to use calculator \n";
cout<<" 1. Addition \n 2. Substraction \n 3. Division \n 4.
Multiplication \n";
cin>> a;
if(a==1){
cout<<"Enter Two Numbers To Add: ";
cin>>add1>>add2;
cout<<"After Adding your numbers Result is "<<add1+add2;
}
else if(a==2){
cout<<"Enter two Number to substract: ";
cin>>sub1>>sub2;
cout<<"After Substracting your numbers Result is
"<<sub1-sub2;
}
else if(a==3){
cout<<"Enter two Number to Divide: ";
cin>>div1>>div2;
cout<<"After Divide your numbers Result is
"<<div1/div2;
}
else if(a==4){
cout<<"Enter two Number to multiply: ";
cin>>multi1>>multi2;
cout<<"After multiplying your numbers Result is
"<<multi1*multi2;
}
else
{
cout<<"You Entered invalid Number";
}
return 0;
}
Q#4 is Simple calculator function if you want to multiply , divide , add ,
subt you have to select its series number and put your value they gives
you your output Quickly see below how to put number and select
series number
The output #1(Add):
Question # 5
Write a program to input three numbers and find maximum between all.

ANSWER # 5
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
//Question#5
int a, b, c;
cout<<"Enter three numbers to check which is maximum: "<<endl;
cin>>a>>b>>c;
switch(a>b and a>c){
case 1:
cout<<"The number is "<<a<<" is greater";
break;
}
switch(b>a and b>c){
case 1:
cout<<"The number is "<<b<<" is greater";
break;
}
switch(c>b and c>a){
case 1:
cout<<"The number is "<<c<<" is greater";
break;
}
switch(a==b and b==c){
cout<<"All numbers are equal";
break;
}
getch();
return 0;
}
The output #1(Maximum number):

Question # 6
Write a C++ program that tells the user that the number entered is less
than, greater than or equal to 10?

ANSWER # 6
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
//Question#6
int a;
cout<<"Enter a number to check it greater less or equal to
10:"<<endl;
cin>>a;
switch(a>10){
case 1:
cout<<"The number "<<a<<" is greater then
10"<<endl;
break;
}
switch(a<10){

case 1:
cout<<"The number "<<a<<" is less than 10"<<endl;
break;
}
switch(a==10){
case 1:
cout<<"The number "<<a<<" is equal to 10"<<endl;
break;
}
getch();
return 0;
}

The output #1(greater):


The output #2(Less):

The output #3(Equal):

Question # 7
Write a C++ program that tells the user that the number entered is even
or odd?

ANSWER # 7
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
//Question#7
int a, t;
cout<<"Enter a number to check even or odd: "<<endl;
cin>>a;
t = a%2;
switch(t){
case 0:
cout<<"The number "<<a<<" is even"<<endl;
break;
case 1:
cout<<"The number "<<a<<" is odd"<<endl;
break;
}
getch();
return 0;
}
The output #1(Even):

The output #2(Odd):

Question # 8
Write a menu driven C++ program that ask the user to choose the type
in which he wants the output?
Either he wants to convert the entered Celsius temperature in to
Fahrenheit or Kelvin?

ANSWER # 8
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
//Question#8
double C, K, F, a, CF, CK;
cout<<"Choose one number you wants: "<<endl;
cout<<"1. Celceus to Fahrenhiet \n2. Celceus to Kalvin \n";
cin>>a;
switch(a==1){
case 1:
cout<<"Enter Temprature in Celceus to convert into Fahrenhiet: ";
cin>>C;
CF=(C*1.8)+32;
cout<<"The temprature in fahrenhiet is "<<CF;
break;
}
switch(a==2){
case 1:
cout<<"Enter Temprature in Celceus to convert into Kalvin:
";
cin>>C;
CK=C+273.15;
cout<<"The temprature in kalvin is "<<CK;
break;

}
getch();
return 0;
}
The output #1(Celcius to Farenheit):

The output #2(Celcius to Kelvin):

Question # 9
According to your grading system mark the user entered percentage as
Grade A, B, C, D, F?
Percentage >=90 A grade
Percentage >=80 B grade
Percentage >=70 C grade
Percentage >=60 D grade
Percentage >=40 E grade
Percentage <40 F grade
ANSWER # 9
#include<iostream>
#include<conio.h>
using namespace std;

int main(){
//Question#9
int m;
cout<<"Enter your obtained marks: \n";
cin>>m;
cout<<"Total marks = 1100 \n";
switch(m >= 880){
case 1:
cout<<"Your marks are "<<m<<endl;
cout<<"Your marks percentage is above 80 % \n";
cout<<"Your marks grade is A+ \n";
break;
}
switch(m < 880 && m >= 770){
case 1:
cout<<"Your marks are "<<m<<endl;
cout<<"Your marks percentage is above 70 % \n";
cout<<"Your marks grade is A \n";
break;
}
switch(m < 770 && m >= 660){
case 1:
cout<<"Your marks are "<<m<<endl;
cout<<"Your marks percentage is above 60 % \n";
cout<<"Your marks grade is B \n";
break;
}
switch(m < 650 && m >= 550){
case 1:
cout<<"Your marks are "<<m<<endl;
cout<<"Your marks percentage is above 50 % \n";
cout<<"Your marks grade is C \n";
break;
}
switch(m < 550 && m >= 440){
case 1:
cout<<"Your marks are "<<m<<endl;
cout<<"Your marks percentage is above 40 % \n";
cout<<"Your marks grade is D \n";
break;
}
switch(m < 440 && m >= 256){
case 1:
cout<<"Your marks are "<<m<<endl;
cout<<"Your marks percentage is above 33 % \n";
cout<<"Your marks grade is E \n";
break;
}
switch(m<220){
case 1:
cout<<"Your marks are below 33 % so you are fail";
break;
}
getch();
return 0;
}
Q#9 is grading system if you want to show your grade then enter your
Obtained marks then you show your grade easily see below how to use
this program
The output #1(Grading system):

___________________________________________________________
___

You might also like