I need to convert the integer to a string. The integer is a most_occurred_number and I cannot figure out which integer to plug into the code. I have put most_occurred_number as the integer but nothing is changing in the cout. I tried putting month1[i] but it is coming out with an error of an undeclared identifier even though it is in the code.
#include <string>
#include <algorithm>
#include <map>
#include <array>
#include <iomanip>
using namespace std;
int dayofweek(int d, int m, int y)
{
static int t[] = { 0, 3, 2, 5, 0, 3,
5, 1, 4, 6, 2, 4 };
y -= m < 3;
return ( y + y / 4 - y / 100 +
y / 400 + t[m - 1] + d) % 7;
}
std::string to_date_string1(int most_occurred_number1)
{
switch(most_occurred_number1)
{
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
return "Saturday";
case 7:
return "Sunday";
}
}
std::string to_date_string2(int most_occurred_number2)
{
switch(most_occurred_number2)
{
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
return "Saturday";
case 7:
return "Sunday";
}
}
void most_occurred_number1(int month1[], int size1)
{
int max_count1 = 0;
cout << "\nMost occurred number: ";
for (int i=0; i<size1; i++)
{
int count1=1;
for (int j=i+1;j<size1;j++)
if (month1[i]==month1[j])
count1++;
if (count1>max_count1)
max_count1 = count1;
}
for (int i=0;i<size1;i++)
{
int count1=1;
for (int j=i+1;j<size1;j++)
if (month1[i]==month1[j])
count1++;
if (count1==max_count1)
cout << month1[i] << endl;
}
}
void most_occurred_number2(int month2[], int size2)
{
int max_count2 = 0;
cout << "\nMost occurred number: ";
for (int i=0; i<size2; i++)
{
int count2=1;
for (int j=i+1;j<size2;j++)
if (month2[i]==month2[j])
count2++;
if (count2>max_count2)
max_count2 = count2;
}
for (int i=0;i<size2;i++)
{
int count2=1;
for (int j=i+1;j<size2;j++)
if (month2[i]==month2[j])
count2++;
if (count2==max_count2)
cout << month2[i] << endl;
}
}
int main()
{
int day1 = dayofweek(03, 02, 2020); //month 1 days
int day2 = dayofweek(04, 02, 2020);
int day3 = dayofweek(04, 02, 2020);
int day4 = dayofweek(05, 02, 2020);
int day5 = dayofweek(11, 02, 2020);
int day6 = dayofweek(12, 02, 2020);
int day7 = dayofweek(13, 02, 2020);
int day8 = dayofweek(20, 02, 2020);
int day9 = dayofweek(21, 02, 2020);
int day10 = dayofweek(27, 02, 2020);
int day11 = dayofweek(02, 03, 2020); //month 2 days
int day12 = dayofweek(02, 03, 2020);
int day13 = dayofweek(05, 03, 2020);
int day14 = dayofweek(10, 03, 2020);
int day15 = dayofweek(11, 03, 2020);
int day16 = dayofweek(11, 03, 2020);
int day17 = dayofweek(17, 03, 2020);
int day18 = dayofweek(19, 03, 2020);
int day19 = dayofweek(24, 03, 2020);
int day20 = dayofweek(25, 03, 2020);
int month1 [] = {day1, day2, day3, day4, day5, day6, day7, day8, day9, day10};
int n1 = sizeof(month1)/sizeof(month1[0]);
cout << "Original array: ";
for (int i=0; i < n1; i++)
cout << month1[i] <<" ";
most_occurred_number1(month1, n1);
int month2 [] = {day11, day12, day13, day14, day15, day16, day17, day18, day19, day20};
int n2 = sizeof(month2)/sizeof(month2[0]);
cout << "Original array: ";
for (int i=0; i < n2; i++)
cout << month2[i] <<" ";
most_occurred_number2(month2, n2);
}```