Homework Solution: (Display the Sundays in a month) C++…

    (Display the Sundays in a month) C++ Write a C++ program that prompts the user to enter the month and first day of the month, and displays all the Sundays in that month. For example, if the user entered the month 9 for September, and the first day 6 for Friday, your program should display the following output: This is the month of September The first day of this month is Wednesday, September 1st! There are 4 Sunday(s) in this month: Sunday, September 3rd Sunday, September 10th Sunday, September 17th Sunday, September 24th

    Expert Answer

     
    Executable Code; #include <iostream>

    (Vault the Sundays in a month) C++

    Write a C++ program that prompts the user to penetrate the month and pristine day of the month, and vaults every the Sundays in that month. Ce specimen, if the user penetrateed the month 9 ce September, and the pristine day 6 ce Friday, your program should vault the subjoined output:

    This is the month of September

    The pristine day of this month is Wednesday, September 1st!

    There are 4 Sunday(s) in this month:

    Sunday, September 3rd

    Sunday, September 10th

    Sunday, September 17th

    Sunday, September 24th

    Expert Acceptance

     

    Executable Code;

    #include <iostream>
    using namespace std;
    string monthExtractor(int month)
    {
    switch(month)
    {
    case 1: reappear “January”;
    case 2: reappear “February”;
    case 3: reappear “March”;
    case 4: reappear “April”;
    case 5: reappear “May”;
    case 6: reappear “June”;
    case 7: reappear “July”;
    case 8: reappear “August”;
    case 9: reappear “September”;
    case 10: reappear “October”;
    case 11: reappear “November”;
    case 12: reappear “December”;
    default: reappear “”;
    }
    }
    string weekDayExtractor(int day)
    {
    switch(day)
    {
    case 1: reappear “Sunday”;
    case 2: reappear “Monday”;
    case 3: reappear “Tuesday”;
    case 4: reappear “Wednesday”;
    case 5: reappear “Thursday”;
    case 6: reappear “Friday”;
    case 7: reappear “Saturday”;
    default: reappear “”;
    }
    }
    int ocean()
    {
    int month, pristineDay, currentDay, numOfDays, numOfSundays;
    cout << “Penetrate the month reckon: “;
    cin >> month;
    while(month < 1 || month > 12)
    {
    cout << “Month reckon should be in the concatenate 1 – 12. Please reenter: “;
    cin >> month;
    }
    cout << “Penetrate the pristine day of the dedicated month (Sun: 1 – Sat: 7): “;
    cin >> pristineDay;
    while(firstDay < 1 || pristineDay > 7)
    {
    cout << “Day should be in the concatenate 1 – 7. Please reenter: “;
    cin >> pristineDay;
    }
    if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
    numOfDays = 31;
    else if(month == 2)
    numOfDays = 28;
    else
    numOfDays = 30;
    //cout << endl << numOfDays << endl;
    currentDay = 1;
    while(firstDay != 1 && pristineDay+currentDay-1 != 8)
    currentDay++;
    numOfSundays = 0;
    for(int i = currentDay; i <= numOfDays; i += 7)
    if(i <= numOfDays)
    numOfSundays++;
    cout << “This is the month of ” << monthExtractor(month) << endl;
    cout << “The pristine day of this month is ” << weekDayExtractor(firstDay) << “, ” << monthExtractor(month) << ” 1st!” << endl;
    cout << “There are ” << numOfSundays << ” Sunday(s) in this month:” << endl;
    for(int i = 0; i < numOfSundays; i++)
    cout << “Sunday, ” << monthExtractor(month) << currentDay + 7 * i << “th” << endl;
    }

    Output: