Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help finishing this c++ template/shell. I will paste the template and the .

ID: 3859863 • Letter: N

Question

Need help finishing this c++ template/shell. I will paste the template and the .txt information below. Using visual stuidos 2017. Thank you for your help.

Num File Name Description holidaysshl Holiday structure array - linear search Use the shell program in DL NOTES: - You will also need the file holidays.dat file in D2L Be sure and check for successful disk file open Holidays Description: Sometimes when searching for a particular item in an array, instead of returning the index of where the item was found in the (if found ), you can return the item itself in the function parameter that was passed by reference. Then the function itself ret bool true if the item was found; it return bool false if the item wasn't found. In this exercise you create a function that searches an array of structures for a specified date (month and day pair) and if fou copies the C++ string from the array of structures into the array of characters that is the last parameter. If the date is not found, 10' is placed in cell 0 of the parameter and a false is returned. The following is a list of the data in the file: 1 11 Hostos Day (Puerto Rico) 1 15 Martin Luther King JrDay 123 Handwriting Day 23 Setsubun (Bean-throwing festival in Japan) 25 Cham Cham Mapinduzi Day (Tanzania) 26 Babe Ruths Birthday 29 Feast of Saint Appolonia (patron saint of dentists) 2 10 Feast of StPaul's Shipwreck Malta) 3 31 Bunsen Buner Day 4 22 Earth Day

Explanation / Answer

I had to make few changes to the code you gave.

1. The values MAX_NAME_LEN and MAX_DATES were not defined in the code you pasted. So I #defined them to some arbitary values long enough to hold data. You can change it back to what ever your original code had.

2. Since the code did not compile because main had void return type, I changed it int return type and returned 1 when file did not open

3. The file name in the code had an extra space before it i.e rather than "holidays.txt" , it was " holidays.txt" (an extra space in before h). Because of this file would not load. So removed the extra space.

The modified code and output is given below. Please rate the answer if it helped. Thank you.

#include <iostream>
#include <fstream>
#include <cstring>
#define MAX_NAME_LEN 150
#define MAX_DATES 50
using namespace::std;


// Definition of DayData type
struct DayData
{
int month, // Month / day of holiday
day;
char holiday[MAX_NAME_LEN]; // Name of holiday
};

// Function prototype
void findHoliday ( const DayData holidayList[], int listLength,
int month, int day, char holidayCopy[] );

int main ()
{
DayData holidayList[MAX_DATES]; // List of holidays
int count = 0, // Number of holidays in list
searchMonth, // Input month / day
searchDay;
char holidayName[MAX_NAME_LEN]; // Name of selected holiday
  
// Open the designated file for input.
ifstream holidayFile("holidays.txt");
if (!holidayFile) {
cout << "Can NOT open file " << endl;
return 1;
}
  
// Read in the list of holidays.
while (holidayFile.good() && holidayFile >>
holidayList[count].month>> holidayList[count].day )
{
holidayFile.get(); // Remove blank after day from the stream
holidayFile.getline(holidayList[count].holiday,
MAX_NAME_LEN,' '); // Read holiday name
count++; // including spaces
}
  
// Close the file.
holidayFile.close();
  
// Prompt the user for the date of the desired hoilday.
cout << endl << "Enter the month and day for a holiday: ";
cin >> searchMonth >> searchDay;
  
// Display the holiday (if any) for the requested date.
findHoliday(holidayList,count,searchMonth,searchDay,holidayName);
if ( holidayName[0] != '' )
cout << holidayName << endl;
else
cout << "No holiday listed" << endl;
}

//--------------------------------------------------------------------
// Insert your findHoliday() function here.
//--------------------------------------------------------------------
void findHoliday (const DayData holidayList[],int listLength,
int month,int day,char holidayCopy[])
{
  
for(int i = 0 ;i < listLength; i++)
if(holidayList[i].month == month && holidayList[i].day == day )
{
strcpy(holidayCopy, holidayList[i].holiday );
return;
}
  
holidayCopy[0] = ''; //when not found and the function did not return from loop above
  
  
  
  
  
} // end findHoliday


/******** Sample Output

Enter the month and day for a holiday: 3 31
Bunsen Burner Day


Enter the month and day for a holiday: 2 4
No holiday listed


*/

output

$ ./a.out

Enter the month and day for a holiday: 3 31
Bunsen Burner Day
$ ./a.out

Enter the month and day for a holiday: 2 4
No holiday listed

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote