Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.188.227.64
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/jdwaltersdorf/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jdwaltersdorf/caltest2.cpp
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
bool isLeapYear(int yr);
int getYear();
int getMonth();
int getNoOfDaysInMonth(int mo, int yr);
int getTotalNoOfDays(int mo, int yr);
string getMonthName(int mo);
string getStartDay(int TotDays);

int main()
{
    int mo;
    int numOfDays;
    int yr;
    int TotDays;
    string moName;
    string dname;
    // processing area
    mo=getMonth();
    yr=getYear();
    //leapYear = isLeapYear(yr);
    numOfDays = getNoOfDaysInMonth( mo, yr);
    moName = getMonthName(mo);
    TotDays = getTotalNoOfDays(mo,yr);
    dname = getStartDay(TotDays);
    
    cout <<"Name of month is = " << moName << '\n'; 
    cout <<"Number of Days = " << numOfDays << '\n';
    cout <<"Total number of days = " << TotDays <<'\n';
    cout <<"The first day in the month of " << moName << " is " << dname 
<< " . " << '\n' ;
    char c;
    cout << "Please press any key to continue." << '\n';
    cin >> c;

return 0;
}
bool isLeapYear(int yr)
{
    bool leapYear;
    leapYear = ((yr % 4 == 0) && (yr % 100 != 0)) || (yr % 400 == 0);
    return leapYear;
}

int getNoOfDaysInMonth(int mo, int yr)
{
    if (mo==1||mo==3||mo==5||mo==7|| 
        mo==8||mo==10||mo==12)
        return 31;
    if (mo==9||mo==4||mo==6||mo==11)
        return 30;
    if (isLeapYear(yr))
        return 29;
    else
        return 28;
}
int getYear()
{
    int yr;
    cout << "Plese enter a year." << '\n';
    cin >> yr;
    return yr;
}
int getMonth()
{
    int mo;
    cout << "Please enter a month." << '\n';
    cin >> mo;
    return mo;
}

int getTotalNoOfDays(int mo, int yr)
{
    int j;
    int totDays=0;
    for (j=1800; j <= yr; j++)
    {
        if (isLeapYear(yr))
            totDays = totDays + 366;
        else
            totDays = totDays + 365;
    }
    for (j=1; j <= mo; j++)
    {
        totDays = totDays + getNoOfDaysInMonth(mo,yr);
    }
    return totDays; 
}
string getMonthName(int mo)
{
    switch (mo)
    {
        case 1:
            return "January";
        case 2:
            return "February";
        case 3:
            return "March";
        case 4:
            return "April";
        case 5:
            return "May";
        case 6:
            return "June";
        case 7:
            return "July";
        case 8:
            return "August";
        case 9:
            return "September";
        case 10:
            return "October";
        case 11:
            return "November";
        case 12:
            return "December";
    }
    return "You must enter a number between 1 and 12.";
}
string getStartDay(int TotDays)
{
    int wday;
    string dname;

    wday = (TotDays + 3) % 7;
    if (wday == 2)
    {
        dname = "Sunday";
    }
    if (wday == 3)
    {
        dname = "Monday";
    }
    if (wday == 4)
    {
        dname = "Tuesday";
    }
    if (wday == 5)
    {
        dname = "Wednesday";
    }
    if (wday == 6)
    {
        dname = "Thursday";
    }
    if (wday == 0)
    {
        dname = "Friday";
    }
    if (wday == 1)
    {
        dname = "Saturday";
    }

    return dname ;
}

Stv3n404 - 2023