Vous êtes sur la page 1sur 6

PROGRAMMING FUNDAMENTAL

LAB

ASSIGMENT 1

Student Name Muhammad Abdullah


Roll Number Bcsm-F19-371

Question 1

“ ALL DATA TYPE ”


#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
int main() {
int a=7;
short int sh= 70;
long int lm= 20;
float f=6.6;
double yt= 2.988;
char alpha='j';
bool b = false;
string s = "hello";
cout << "data type is :" << a<<"\n";
cout << "data type is :" << f<<"\n";
cout << "data type is :" << alpha<<"\n";
cout << "data type is :" << b<<"\n";
cout << "data types is :" << s<<"\n";
cout << "data type is :" << sh << "\n";
cout << "data type is:" << lm << "\n";
cout << "data type is:" << yt << "\n";

QUESTION 2

“SWAP TO NUMBERS WITHOUT THIRD NUMBER”


#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int a = 2;
int b = 3;
cout << "before swap a= " << a<<endl;
cout << "b=" << b << endl;
a = a + b;
b = a - b;
a = a - b;
cout << "after swap without third variable a=" << a << endl;
cout << "after swap without third variable b=" << b << endl;
}
QUESTION 2

“SWAP WITH THRID VARIABLE”

#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int a = 5;
int b = 6;
int c = 7;
cout << "swapping";
cout << "x=";
cout << a;
cout << "y=";
cout << b;
c = a;
a = b;
b = c;
cout << "swapping";
cout << "x=";
cout << a;
cout << "y=";
cout << b;
}

QUESTION 3

“SUM OF TWO NUMBERS”

#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int a, b,c;
cout << "enter first number";
cin >> a;
cout << "engter second number";
cin >> b;
c = a + b;
cout << c;
}
QUESTION 4

“GREATEST AND SMALLEST”

#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int x, y, z;
cout << "enter three numbers";
cin >> x >> y >> z;
cout << x << "\n" << y << "\n" << z << "\n";
{
if (x > y&& x > z) {
cout << "it is the greater of the two";
cout << x;
}
else if (y > x&& y > z) {
cout << "it is the greater of the two";
cout << y;
}
else if (z > x&& z > y) {
cout << "it is the greater of the two";
cout << z;
}
else
cout << "all are equal";
}
{
if (x < y && x < z) {
cout << "it is the smallest of the three" << "\n";
cout << x;
}
else if (y < x && y < z) {
cout << "it is the samllest of the three" << "\n";
cout << y;
}
else if (z < x && z < y) {
cout << "it is the smallest of the three" << "\n";
cout << z;
}
else
cout << "all are equal";
}
}
QUESTION 4

“ASCENDING ORDER”

#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int x, y, z;
cin >> x >> y >> z;
if (x < y && y < z)
cout << x << "<" << y << "<" << z;
else if (x < z && z < y)
cout << x << "<" << z << "<" << y;
else if (y < x && x < z)
cout << y << "<" << x << "<" << z;
else if (y < z && z < x)
cout << y << "<" << z << "<" << x;
else if (z < x && x < y)
cout << z << "<" << x << "<" << y;
else
cout << z << "<" << y << "<" << x;
}

ASSIGMENT 2
QUESTION 1

AREA OF RECTANLGE

#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int a, b, r;
cout << "enter number";
cin >> a;
cin >> b;
if (a > 0 && b > 0) {
r = a * b;
cout << "area of rectangle";
cout << r;
}
else
cout << "number is negative";
}
QUESTION 2

CALCULATOR

#include<iostream>
#include<conio.h>
using namespace std;
int main() {
char op;
float f, s;
cout << "enter operator";
cin >> op;
cout << "Enter two operands=";
cin >> f >> s;
switch(op){
case '+':
cout << "addition"<< f + s;
break;
case '-':
cout << "subtraction"<< f - s;
break;
case '*':
cout << "multiplication"<< f * s;
break;
case '/':
cout << "division"<< f / s;
break;
default:
cout << "invalid operand";
}
}

QUESTION 3

PROFIT AND LOSS

#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int cost, sale, r;
cout << "enter cost price";
cin >> cost;
cout << "enter sale price";
cin >> sale;
r = cost - sale;
r = sale - cost;
if (r > 0)
cout << "profit is=" << r;
else if (r < 0)
cout << "loss=" << r;
else
cout << "no profit no loss";
}
QUESTION 4

TAKING DAYS AND CHANGE IT INTO YEARS AND MONTHS

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int days, years,rem1,rem2, months, remdays;
cout << "Enter days ";
cin >> days;
years = days / 365;

rem1 = 365 * years;


rem2 = days - rem1;

months = rem2 / 30;


remdays = rem2 % 30;

cout << "Years = " << years << endl;


cout << "Months = " << months << endl;
cout << "Days = " << remdays << endl;
}

Vous aimerez peut-être aussi