Lab 44
Lab 44
TASK-01
code:
//muhammad abubakar rashid
//459565
#include<iostream>
using namespace std;
int main(){
int a,b,c,d,e;
//taking input from the user
cout << "Enter a three digit number : ";
cin >> a;
//to get the first digit of thegiven number we use this formula
b = a % 10;
//to get second number we use the given formula
c = (a / 10) % 10;
d = a / 100;
//now adding the cubes of each to check whether it is armstrong or not
e = b*b*b + c*c*c + d*d*d;
//using this condition to verify that whether input is 3 digit number or
not
if (a > 99 && a < 1000){
//if the number is armstrong then it is equal to its input
if (e == a){
cout << "Entered number is armstrong";
}
else{
cout << "Entered number is not armtrong ";
}
}
else{
cout << "Enter a three digit number";
}
return 0;
output:
and:
task-02:
code:
//muhammad abubakar rashid
//459565
#include<iostream>
using namespace std;
int main(){
int a,b,c,d,e;
cin >> a;
if (a > 999 && a < 10000){
//first calculating the digits seprately in a sequence
b = a % 10;
c = (a / 10) % 10;
d = (a / 10) / 10 % 10;
e = a / 1000;
//using this in a sequence to verify that whether a function is
decreasing or increasing
if (b <= c &&c<=d && d<= e){
cout << "The given number is decreasing";
}
else if (b>=c && c>=d && d>=e){
cout << "The given number is increasing";
}
else{
cout << "The given number is bouncy";
}
}
else{
cout << "enter of four digit number";
}
return 0;
}
output:
task-03:
code:
//muhammad abubakar rashid
//459565
#include<iostream>
using namespace std;
int main(){
char a, b, c, d, e;
int f, g;
cin >> a;
//using (int)variable syntax to determine the ASCII code of the given
value and then comparing it with if else.
if ((int)a >= 65 && (int)a <= 90){
cout << "The given value is capital alphabet";
}
else if ((int)a >= 97 && (int)a <= 122)
{
cout << "the given value is small alphabet";
}
else if ((int)a >= 48 && (int)a <= 57){
cout << "the given value is a number";
}
else{
if ((int)a < 128){
cout << "given valuse is a speacial character";
}
else{
cout << "input is wrong";
}
}
return 0;
}
Output:
task-04
code:
#include<iostream>
using namespace std;
int main(){
double a, b, c, e;
//simply sing cout to display
cout << "Enter your weight in kilograms" << endl;
cin >> a;
cout << endl;
cout << "Enter your height in meters " << endl;
cin >> b;
c = a / (b*b);
cout << "Your BMI value is" << c << endl;
cout << "BMI values:" << endl << "underweight : less than 18.5" << endl
<< "normal : between 18.5 and 24.9" << endl << "overweight : between 25 and
29.9" << endl << "obese : 30 or greater" << endl;
return 0;
}
output:
task-05
code:
//muhammad abubakar rashid
//459565
#include<iostream>
using namespace std;
int main(){
int a, b, c, d;
cout << "Enter the day number : " << endl;
cin >> a;
//declaring variables and then using if else to verify integer input
if (a >= 1 && a <= 7){
//switch case statemnet to print the weekend name and number on
using the input number
switch (a){
case 1:
cout <<"Weekend 1: Saturday";
break;
case 2:
cout <<"Weekend 2: Sunday";
break;
case 3:
cout << "Weekend 3: Monday";
break;
case 4:
cout <<"Weekend 4: Tuesday";
break;
case 5:
cout <<"Weekend 5: Wednesday";
break;
case 6:
cout <<"Weekend 6: Thursday";
break;
default :
cout << "Weekend 7: Frieday";
break;
}
}
else{
cout <<"Weekend"<<a<< ": error";
}
return 0;
}
:
Task-06
code:
//muhammad abubakar rashid
//459565
#include<iostream>
using namespace std;
int main(){
int a, b, c, d;
//taking input from the user
cout << "Enter your current earth weight";
cin >> a;
cout << "I have information for the following planets :" << endl;
cout << "1. Mercury 2.Venus 3.Earth" << endl << "4.Moon 5. Mars
6. Jupiter " << endl << "7. Saturn 8. Uranus 9.Neptune" << endl;
cout << "which planet are you visiting?";
cin >> b;
cout << endl;
//using switch to select certain cases
if (b >= 1 && b <= 9){
switch (b){
case 1:
cout << "Your weight would be " << (a * 378) / 1000 << "
kilograms on that planet";
break;
case 2:
cout << "your weight would be " << (a * 907) / 1000 << "
kilograms on that planet";
break;
case 3:
cout << "your weight would be " << a << " kilograms on that
planet ";
break;
case 4:
cout << "your weight would be " << (a * 165) / 1000 << "
kilograms on that planet";
break;
case 5:
cout << "your weight would be " << (a * 377) / 1000 << "
kilograms on that planet";
break;
case 6:
cout << "your weight would be " << (a * 2364) / 1000 << "
kilograms on that planet";
break;
case 7:
cout << "your weight would be " << (a * 910) / 1000 << "
kilograms on that planet ";
break;
case 8:
cout << "your weight would be " << (a * 889) / 1000 << "
kilograms on that planet";
break;
default:
cout << "your weight would be " << (a * 1125) / 1000 << "
kilograms on that planet";
break;
}
}
else{
cout << "invalid input";
}
return 0;
}
Output:
Task-07:
code:
//muhammad abubakar abubakar
//459565
#include<iostream>
#include<string>
using namespace std;
int main(){
int age, pizza, d, e;
char exer;
//taking input from the user
cout << "Please enter the age of the person (years) : " << endl;
cin >> age;
cout << "Please enter how many pizzas he eat per week : " << endl;
cin >> pizza;
cout << "Please mention whether he exercises daily in the
morning(y/n) :" << endl;
cin >> exer;
//using if statement and first using age para meter
//then using pizzas and age to sort out which statement is going to be
executed
if ((age <= 25 && exer == 'y')){
if (pizza <= 4){
cout << "You are Fit";
}
else {
cout << "you are unfit";
}
}
else if (age <= 25 && exer == 'n'){
if (pizza <= 3){
cout << "you are fit";
}
else{
cout << "you are unfit";
}
}
else if (25<age<35 && exer == 'y'){
cout << "you are Fit";
}
else if (25<age&&age<35 && exer == 'n'){
if (pizza<3){
cout << "you are fit";
}
else{
cout << "you are UNFIT";
}
}
else if (35<age&& age<40){
if ((exer == 'y'&& pizza <= 3)){
cout << "you are fit";
}
else{
cout << "you are UNFIT";
}
}
else{
if (41<age){
if (exer == 'n'){
cout << "you are unfit";
exit(0);
}
if (pizza <= 1 && exer == 'y'){
cout << "you are fit";
exit(0);
}
else{
cout << "you are unfit";
}
}
else{
cout << "you are unfit";
}
}
return 0;
OUTPUT: