SRM ELAB SOLUTIONS OOPS


 I/O Operations 2

  • Play with XOR
  • Professor Omkar  
  • Swim               
  • Sachin and his Pills                                   
  • Print Floyd's   



Play with XOR

#include <iostream>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int a[n], c1 = 0c0 = 0;
        for (int i = 0i < ni++)
        {
            cin >> a[i];
            if (a[i] == 1)
                c1++;
        }
        c0 = n - c1;
        if (c1 % 2 == 0)
        {
            cout << c0 << endl;
        }
        if (c1 % 2 != 0)
        {
            cout << c1 << endl;
        }
    }
    return 0;
}





Professor Omkar

#include <iostream>
using namespace std;
int main()
{
    int abc;
    float d;
    cin >> a >> b >> c;
    d = (a * (c - b)) * 4184;
    cout << "The energy needed is " << d;
    return 0;
}




swim

#include <iostream>
using namespace std;
int main()
{
    int abcs;
    cin >> a >> b;
    c = 3.14 * a * a;
    s = b * b;
    if (c > s)
        cout << "I prefer centre 1";
    else
        cout << "I prefer centre 2";
    return 0;
}





Sachin and his Pills    

#include <iostream>
using namespace std;
class Month
{
    int days;

public:
    Month(intint);
    bool leapYear(int);
    int getDays();
};
Month::Month(int numberint year)
{
    if (number < 8)
        (number % 2 == 1) ? (days = 31) : (days = 30);
    else
        (number % 2 == 0) ? (days = 31) : (days = 30);
    if (number == 2)
    {
        if (leapYear(year) == 1)
            days = 29;
        else
            days = 28;
    }
}
bool Month::leapYear(int year)
{
    if (year % 400 == 0)
        return 1;
    if (year % 100 == 0)
        return 0;
    if (year % 4 == 0)
        return 1;
    return 0;
}
int Month::getDays()
{
    return days;
}
int pillDays(int dayint monthint yearint count = 0)
{
    Month M(monthyear);
    int monthDays = M.getDays(), i;
    for (i = dayi <= monthDaysi++)
        if (i % 2 == 1)
            count++;
    if (monthDays % 2 == 0)
    {
        pillDays(1month + 1, (month == 12) ? (year + 1) : (year), count);
    }
    else
        return count;
}
int main()
{
    int ijndaymonthyeardate[10];
    char temp[10];
    //char date[10];
    cin >> n;
    for (i = 0i < ni++)
    {
        cin >> temp;
        for (j = 0j < 10j++)
            date[j] = temp[j] - 48;
        day = date[8] * 10 + date[9];
        month = date[5] * 10 + date[6];
        year = date[0] * 1000 + date[1] * 100 + date[2] * 10 + date[3];
        cout << pillDays(daymonthyear<< endl;
    }
    return 0;
}






Print Floyd's   

#include <iostream>
using namespace std;
int main()
{
    int nkij;
    cin >> n;
    k = 1;
    for (i = 1i <= ni++)
    {
        for (j = 1j <= ij++, k++)
        {
            cout << k;
        }
        cout << endl;
    }

    return 0;