Can you please help me? I'm not allowed to define any functions or use void which is why the entire code should only work inside int main(). I need help putting the codes in the functions int nDays (int monthNo, int year), string getNameOfMonth(int monthNo), and void displayCalendar(int yr, int start_day) inside int main() #include #include using namespace std; int nDays (int monthNo, int year) { switch(monthNo) { case 0: return (31); break; case 1: if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { return (29); break; } else { return (28); break; } case 2: return (31); break; case 3: return (30); break; case 4: return (31); break; case 5: return (30); break; case 6: return (31); break; case 7: return (31); break; case 8: return (30); break; case 9: return (31); break; case 10: return (30); break; case 11: return (31); break; } } string getNameOfMonth(int monthNo) { string monthSet[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; return (monthSet[monthNo]); } void displayCalendar(int yr, int start_day) { cout<<" Calendar - "< 6) { k = 0; cout<<"\n"; } } if (k) cout<<"\n"; start_day = k; } return; } int main() // need help putting the codes in three functions inside int main() { int yr, start_day; cout <<"Enter a calendar year to display? "; cin>>yr; cout <<" what is the new year's day? "; cin>>start_day; displayCalendar(yr, start_day); return 0; }
A bartleby expert gave me the code below but I need help putting everything inside int main() because I told them there can't be anything before int main().
Can you please help me? I'm not allowed to define any functions or use void which is why the entire code should only work inside int main().
I need help putting the codes in the functions int nDays (int monthNo, int year), string getNameOfMonth(int monthNo), and void displayCalendar(int yr, int start_day) inside int main()
#include<iostream>
#include<iomanip>
using namespace std;
int nDays (int monthNo, int year)
{
switch(monthNo)
{
case 0:
return (31);
break;
case 1:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
return (29);
break;
}
else
{
return (28);
break;
}
case 2:
return (31);
break;
case 3:
return (30);
break;
case 4:
return (31);
break;
case 5:
return (30);
break;
case 6:
return (31);
break;
case 7:
return (31);
break;
case 8:
return (30);
break;
case 9:
return (31);
break;
case 10:
return (30);
break;
case 11:
return (31);
break;
}
}
string getNameOfMonth(int monthNo)
{
string monthSet[] = {"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"
};
return (monthSet[monthNo]);
}
void displayCalendar(int yr, int start_day)
{
cout<<" Calendar - "<<yr<<"\n\n";
int theDays;
for (int i = 0; i < 12; i++)
{
theDays = nDays (i, yr);
cout<<"\n ------------"<<getNameOfMonth (i).c_str()<<"-------------\n";
cout<<" Sun Mon Tue Wed Thu Fri Sat\n";
int k;
for (k = 0; k < start_day; k++)
cout<<" ";
for (int j = 1; j <= theDays; j++)
{
cout<<setw(5)<<j;
if (++k > 6)
{
k = 0;
cout<<"\n";
}
}
if (k)
cout<<"\n";
start_day = k;
}
return;
}
int main() // need help putting the codes in three functions inside int main()
{
int yr, start_day;
cout <<"Enter a calendar year to display? ";
cin>>yr;
cout <<" what is the new year's day? ";
cin>>start_day;
displayCalendar(yr, start_day);
return 0;
}
Program description :
The functions,int nDays (int monthNo, int year), string getNameOfMonth(int monthNo), and void displayCalendar(int yr, int start_day) are removed from the given c++ program.
The main.cpp C++ program objective is to remove all the functions from the given program and write all the code inside the main function.
The program prompts to enter the year value and starting day of the year as integer values and then print the year calendar on the c++ console window.
Step by step
Solved in 3 steps with 3 images