Assignment M.shehzad.....
Assignment M.shehzad.....
Name M.SHEHZAD
class Bs(it)
25-05-2023 Page 1
(OOP)
Program No 1:
Q1: Write a C++ program that take input from user in mile
and convert it into kilometers by using a class named
conversion? (Remember: 1 mile = 1.6 kilometers ) .
#include <iostream>
class Conversion
public:
};
int main()
float miles;
Conversion converter;
25-05-2023 Page 2
(OOP)
cout << miles << " miles is equal to " << kilometers << " kilometers." << endl;
return 0;
Output :
--------------------------------
25-05-2023 Page 3
(OOP)
Program No 2 :
#include<iostream>
#include<string>
class stringcomparator
public:
};
int main ()
string str1,str2;
25-05-2023 Page 4
(OOP)
cin>> str2;
stringcomparator comparator;
if (areEqual)
else
return 0;
Output :
--------------------------------
25-05-2023 Page 5
(OOP)
Program No 3 :
#include<iostream>
class date
int day;
25-05-2023 Page 6
(OOP)
int month;
int year;
public:
day = d;
month = m;
year = y;
void displaydate()
cout<<"Date"<<day<<"/"<<month<<"/"<<year<<"/"<<endl;
};
int main()
cout<<"Enter day";
cin>> day;
cout<<"Enter month";
cin>> month;
cout<<"Enter years";
cin>> year;
25-05-2023 Page 7
(OOP)
date date(day,month,year);
date.displaydate();
return 0;
Output :
Enter day 19
Enter month 06
Date19/6/2004/
--------------------------------
25-05-2023 Page 8
(OOP)
Program no 4 :
#include<iostream>
class NumberComparator
public:
if (num2>largest)
largest = num2;
if (num3>largest)
largest = num3;
return largest;
25-05-2023 Page 9
(OOP)
};
int main()
int num1;
int num2;
int num3;
cin>>num1;
cin>>num2;
cin>>num3;
NumberComparator comparator;
cout << "The largest number is: " << largestNumber << endl;
return 0;
25-05-2023 Page 10
(OOP)
Output:
--------------------------------
25-05-2023 Page 11
(OOP)
Program NO 5 :
#include<iostream>
class ZooAnimal
int weightDate;
public:
ZooAnimal(int weight)
weightDate = weight;
25-05-2023 Page 12
(OOP)
};
int main()
int weight;
cout<<"Enter weight";
cin>>weight;
ZooAnimal animal(400);
if (animal == weight)
else
return 0;
25-05-2023 Page 13
(OOP)
Output :
--------------------------------
Program no 6 :
25-05-2023 Page 14
(OOP)
#include<iostream>
num1 = num2;
num2 = temp;
int main()
int a;
int b;
cin>>a;
25-05-2023 Page 15
(OOP)
cin>>b;
swap(a,b);
return 0;
Output :
--------------------------------
25-05-2023 Page 16
(OOP)
25-05-2023 Page 17