0% found this document useful (0 votes)
26 views5 pages

20sema CS2311 Lab4 Sol

CS2311 Lab problems

Uploaded by

gwgcbg6q9z
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

20sema CS2311 Lab4 Sol

CS2311 Lab problems

Uploaded by

gwgcbg6q9z
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Question1

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double a, b, c;
cout << "Enter the value of A, B and C:" << endl;
cin>> a >> b >> c;
if (a <= 0 || b <= 0 || c <= 0 || a + b <= c || a + c <= b || b + c <= a) {
cout << "Impossible" << endl;
}
else if (a == b && b == c) {
cout << "Equilateral" << endl;
}
else if (a == b || b == c || a == c) {
cout << "Isosceles" << endl;
}
else cout << "Scalene" << endl;
return 0;

Question2
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int a;
cout << "Enter an Integer Number:" << endl;
cin >> a;
double three;
double five;
five = a % 5;
three = a % 3;
if (five == 0 && three == 0) {cout << a << " is divisible by 3 and 5." <<
endl;}
else if (five == 0 && three != 0) {cout << a << " is divisible by 5 only." <<
endl;}
else if (five != 0 && three == 0) { cout << a << " is divisible by 3 only." <<
endl; }
else { cout << a << " is not divisible by 3 or 5." << endl; }
return 0;

Question 3
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double a;
double b;
char op;
int answer;
cout << "Enter the equation : " << endl;
cin >> a >> op >> b;
if (cin.fail()) {
cout << "Invalid input." << endl;
}
else {
switch (op) {
case'+':
cout << a << op << b << "=" << a + b << endl;
break;
case'-':
cout << a << op << b << "=" << a - b << endl;
break;
case'*':
cout << a << op << b << "=" << a * b << endl;
break;
case'/':
cout << a << op << b << "=" << a / b << endl;
break;
case'<':
if (a < b) {
cout << a << "<" << b << "=T" << endl;
}
else cout << a << "<" << b << "=F" << endl;
break;
case'>':
if (a > b) {
cout << a << ">" << b << "=T" << endl;
}
else cout << a << ">" << b << "=F" << endl;
break;
case'=':
if (a == b) {
cout << "(" << a << "==" << b << ")=T" << endl;
}
else cout << "(" << a << "==" << b << ")=F" << endl;
break;
default:
cout << "Invalid operation." << endl;
}
return 0;
}
}

Question 4
#include <iostream>
#include <iomanip>
using namespace std;

int main() {

int cyear, cmonth, cage, bmonth, wyear, wmonth;


int ayear, amonth;
cout << "Enter the current year:" << endl;
cin >> cyear;
cout << "Enter the current month:" << endl;
cin >> cmonth;
if (cmonth <= 0 || cmonth >= 13) { cout << "Invalid Month Input!" << endl; }
else {
cout << "Enter your current age in years:" << endl;
cin >> cage;
if (cage < 0) { cout << "The value for age cannot be a negative
integer!" << endl; }
else if (cage > 200) { cout << "Sorry, people may be dead by this age!"
<< endl; }
else {
cout << "Enter the month in which you were born:" << endl;
cin >> bmonth;
if (bmonth <= 0 || bmonth >= 13) { cout << "Invalid Month Input!"
<< endl; }
else {
cout << "Enter the year for which you wish to know your
age:" << endl;
cin >> wyear;
cout << "Enter the month in the year for which you wish to
know your age:" << endl;
cin >> wmonth;
if (wmonth >= bmonth) {
if (wyear < (cyear - cage)) { cout << "You were not
born!" << endl; }
else if((wyear == (cyear - cage))&&wmonth<bmonth)
{ cout << "You were not born!" << endl; }
else if (((wyear)-(cyear - cage) == (1||0)) &&
((wmonth - bmonth) == (1||0))) {
cout << "Your age in " << wyear << "/" <<
wmonth << ":" << endl;
cout << (wyear)-(cyear - cage) << " year and
" << (wmonth - bmonth) << " month" << endl;
ayear = (wyear)-(cyear - cage);
amonth = (wmonth - bmonth);
if (ayear % 2 == 0 && amonth % 2 == 0) { cout
<< "Both of " << ayear << " and " << amonth << " are not odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 == 0)
{ cout << ayear << " is odd!" << endl; }
else if (ayear % 2 == 0 && amonth % 2 != 0)
{ cout << amonth << " is odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 != 0)
{ cout << "Both of " << ayear << " and " << amonth << " are odd!" << endl; }
}
else if (((wyear)-(cyear - cage) == (1||0)) &&
((wmonth - bmonth) != (1||0))) {
cout << "Your age in " << wyear << "/" <<
wmonth << ":" << endl;
cout << (wyear)-(cyear - cage) << " year and
" << (wmonth - bmonth) << " months" << endl;
ayear = (wyear)-(cyear - cage);
amonth = (wmonth - bmonth);
if (ayear % 2 == 0 && amonth % 2 == 0) { cout
<< "Both of " << ayear << " and " << amonth << " are not odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 == 0)
{ cout << ayear << " is odd!" << endl; }
else if (ayear % 2 == 0 && amonth % 2 != 0)
{ cout << amonth << " is odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 != 0)
{ cout << "Both of " << ayear << " and " << amonth << " are odd!" << endl; }
}
else if (((wyear)-(cyear - cage) != (1||0)) &&
((wmonth - bmonth) == (1||0))) {
cout << "Your age in " << wyear << "/" <<
wmonth << ":" << endl;
cout << (wyear)-(cyear - cage) << " years and
" << (wmonth - bmonth) << " month" << endl;
ayear = (wyear)-(cyear - cage);
amonth = (wmonth - bmonth);
if (ayear % 2 == 0 && amonth % 2 == 0) { cout
<< "Both of " << ayear << " and " << amonth << " are not odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 == 0)
{ cout << ayear << " is odd!" << endl; }
else if (ayear % 2 == 0 && amonth % 2 != 0)
{ cout << amonth << " is odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 != 0)
{ cout << "Both of " << ayear << " and " << amonth << " are odd!" << endl; }
}
else if (((wyear)-(cyear - cage) != (1||0)) &&
((cmonth - wmonth) != (1||0))) {
cout << "Your age in " << wyear << "/" <<
wmonth << ":" << endl;
cout << (wyear)-(cyear - cage) << " years and
" << (wmonth - bmonth) << " months" << endl;
ayear = (wyear)-(cyear - cage);
amonth = (wmonth - bmonth);
if (ayear % 2 == 0 && amonth % 2 == 0) { cout
<< "Both of " << ayear << " and " << amonth << " are not odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 == 0)
{ cout << ayear << " is odd!" << endl; }
else if (ayear % 2 == 0 && amonth % 2 != 0)
{ cout << amonth << " is odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 != 0)
{ cout << "Both of " << ayear << " and " << amonth << " are odd!" << endl; }

}
}

if (bmonth > cmonth) {


cout << "You were not born!" << endl;
if (wyear <= (cyear - cage)) { cout << "You were
not born!" << endl; }
else if (((wyear)-(cyear - cage) - 1) == 1||
((wyear)-(cyear - cage) - 1) == 0) {
cout << "Your age in " << wyear << "/" <<
wmonth << ":" << endl;
cout << (wyear)-(cyear - cage - 1) << "year
and " << (12 - wmonth) + bmonth << " months" << endl;
ayear = (wyear)-(cyear - cage - 1);
amonth = (12 - wmonth) + bmonth;
if (ayear % 2 == 0 && amonth % 2 == 0) { cout
<< "Both of " << ayear << " and " << amonth << " are not odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 == 0)
{ cout << ayear << " is odd!" << endl; }
else if (ayear % 2 == 0 && amonth % 2 != 0)
{ cout << amonth << " is odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 != 0)
{ cout << "Both of " << ayear << " and " << amonth << " are odd!" << endl; }
}
else if (((wyear)-(cyear - cage) - 1) != 1||
((wyear)-(cyear - cage) - 1) != 0) {
cout << "Your age in " << wyear << "/" <<
wmonth << ":" << endl;
cout << (wyear)-(cyear - cage - 1) << "years
and " << (12 - wmonth) + bmonth << " months" << endl;
ayear = (wyear)-(cyear - cage - 1);
amonth = (12 - wmonth) + bmonth;
if (ayear % 2 == 0 && amonth % 2 == 0) { cout
<< "Both of " << ayear << " and " << amonth << " are not odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 == 0)
{ cout << ayear << " is odd!" << endl; }
else if (ayear % 2 == 0 && amonth % 2 != 0)
{ cout << amonth << " is odd!" << endl; }
else if (ayear % 2 != 0 && amonth % 2 != 0)
{ cout << "Both of " << ayear << " and " << amonth << " are odd!" << endl; }
}
}

}
return 0;
}

You might also like