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

#include<iostream> #include<iomanip> using namespace std; void set(char[][4], ch

ID: 3641969 • Letter: #

Question

#include<iostream>
#include<iomanip>
using namespace std;
void set(char[][4], char[][4], char);
void output(char[][4], string);
void individual(char[][4], char[][4]);
void group(char[][4], char[][4]);
void getinfo(int&, int&, int&);

int main()
{
char jeff[4][4], anna[4][4];
int i, j, choice=0;

for(j=0; j<4; j++)
{
anna[i][j]=' ';
jeff[i][j]=' ';
}
while(choice!=6)
{
cout << "Choose what you would like to do " << endl;
cout << "1 Mark time slotbusy " << endl;
cout << "2 Mark time slotfree " << endl;
cout << "3 output timeschedule " << endl;
cout << "4 output timeslots forindividual lessons " << endl;
cout << "5 output timeslots forgroup lessons " << endl;
cout << "6 Exit " << endl;
cin >> choice;

switch(choice)
{ case 1: set(anna,jeff,'X');
break;
case 2: set(anna,jeff,' ');
break;
case 3: output(anna,"ANNA");
output(jeff,"JEFF");
break;
case 4: individual(anna,jeff);
break;
case 5: group(anna,jeff);
break;
case 6: return 0;
default: cout << "Illegal input: TryAgain " << endl;
}
}
system("pause");

return 0;
}

void getinfo(int& who, int& day, int& slot)
{
cout << "Enter 1 for Anna, 2 for Jeff: " << endl;
cin >> who;

while(who<1||who>2)
{
cout << "invalid entry-re try ";
cout << "Enter 1 for Anna, 2 for Jeff: ";
cin >> who;
}
slot=5;

while(slot<0||slot>3)
{
cout << "Enter timeslot: " << endl;
cout << "0 for 11-12 " << endl;
cout << "1 for 12-1 " << endl;
cout << "2 for 1-2 " << endl;
cout << "3 for 2-3 " << endl;
cin >> slot;

if(slot<0||slot>3)
{
cout << "Invalidentry " << endl;
}
}
day=5;

while(day < 0 || day > 3)
{
cout << "Enter day: " << endl;
cout << "0 for Monday " << endl;
cout << "1 for Tuesday " << endl;
cout << "2 for Wednesday " << endl;
cout << "3 for Thursday " << endl;
cin >> day;

if(day<0||day>3)
cout<<"Invalidentry ";
}
}

void set(char a[][4],char j[][4],char what)
{
int who,day,slot;
getinfo(who,day,slot);

if(who==1)
{
a[slot][day]=what;
}
else
{
j[slot][day]=what;
}
}

void output(char p[][4], string name)
{
int i,j;

cout << endl << setw(10) << name << " Monday Tuesday Wednesday Thursday ";

for (i=0;i<4;i++)
{
cout << setw(2) << (i-1+11)%12+1 << "-" << (i-1+12)%12+1;

for(j=0; j<4; j++)
cout << setw(11) << p[i][j];
cout << endl;
}
cout << endl;
}

void individual(char a[][4],char je[][4])
{
char free[4][4];
int i,j;
for(j=0;j<4;j++)
if(a[i][j]==' '||je[i][j]==' ')
{
free[i][j]='X';
}
else
{
free[i][j]=' ';
}
output(free,"Available");
}

void group(char a[][4], char je[][4])
{
char free[4][4];
int i,j;

for(j=0;j<4;j++)
{
if(a[i][j]==' '&&je[i][j]==' ')
{
free[i][j]='X';
}
else
{
free[i][j]=' ';
}
}
output(free,"Available");
}



What is wrong with this program that I need to fix. Please help.

Explanation / Answer

I made your code runnable (debugged compile errors)

#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

void set(char[][4], char[][4], char);
void output(char[][4], string);
void individual(char[][4], char[][4]);
void group(char[][4], char[][4]);
void getinfo(int&, int&, int&);

int main()
{
   char jeff[4][4], anna[4][4];
   int i, j, choice=0;

   for (i=0; i<4; i++)
   {
      for(j=0; j<4; j++)
      {
         anna[i][j]=' ';
         jeff[i][j]=' ';
      }
   }
   while(choice!=6)
   {
      cout << "Choose what you would like to do " << endl;
      cout << "1 Mark time slot busy " << endl;
      cout << "2 Mark time slot free " << endl;
      cout << "3 output time schedule " << endl;
      cout << "4 output time slots for individual lessons " << endl;
      cout << "5 output time slots for group lessons " << endl;
      cout << "6 Exit " << endl;
      cin >> choice;

      switch(choice)
      {
         case 1:
            set(anna,jeff,'X');
            break;
         case 2:
            set(anna,jeff,' ');
            break;
         case 3:
            output(anna,"ANNA");
            output(jeff,"JEFF");
            break;
         case 4:
            individual(anna,jeff);
            break;
         case 5:
            group(anna,jeff);
            break;
         case 6:
            return 0;
         default:
            cout << "Illegal input: TryAgain " << endl;
            break;
      }
   }

   system("pause");

   return 0;
}


void getinfo(int& who, int& day, int& slot)
{
   cout << "Enter 1 for Anna, 2 for Jeff: " << endl;
   cin >> who;

   while(who<1||who>2)
   {
      cout << "invalid entry-re try ";
      cout << "Enter 1 for Anna, 2 for Jeff: ";
      cin >> who;
   }
   slot=5;

   while(slot<0||slot>3)
   {
      cout << "Enter timeslot: " << endl;
      cout << "0 for 11-12 " << endl;
      cout << "1 for 12-1 " << endl;
      cout << "2 for 1-2 " << endl;
      cout << "3 for 2-3 " << endl;
      cin >> slot;

      if(slot<0||slot>3)
      {
         cout << "Invalidentry " << endl;
      }
   }
   day=5;

   while(day < 0 || day > 3)
   {
      cout << "Enter day: " << endl;
      cout << "0 for Monday " << endl;
      cout << "1 for Tuesday " << endl;
      cout << "2 for Wednesday " << endl;
      cout << "3 for Thursday " << endl;
      cin >> day;

      if(day<0||day>3)
         cout<<"Invalidentry ";
   }
}

void set(char a[][4],char j[][4],char what)
{
   int who,day,slot;
   getinfo(who,day,slot);

   if(who==1)
   {
      a[slot][day]=what;
   }
   else
   {
      j[slot][day]=what;
   }
}

void output(char p[][4], string name)
{
   int i,j;

   cout << endl << setw(10) << name << " Monday Tuesday Wednesday Thursday ";

   for (i=0;i<4;i++)
   {
      cout << setw(2) << (i-1+11)%12+1 << "-" << (i-1+12)%12+1;

      for(j=0; j<4; j++)
         cout << setw(11) << p[i][j];
      cout << endl;
   }
   cout << endl;
}

void individual(char a[][4],char je[][4])
{
   char free[4][4];
   int i,j;
   for (i=0;i<4;i++)
   {
      for(j=0;j<4;j++)
      {
         if(a[i][j]==' '||je[i][j]==' ')
         {
            free[i][j]='X';
         }
         else
         {
            free[i][j]=' ';
         }
      }
   }
   output(free,"Available");
}

void group(char a[][4], char je[][4])
{
   char free[4][4];
   int i,j;

   for (i=0;i<4;i++)
   {
      for(j=0;j<4;j++)
      {
         if(a[i][j]==' '&&je[i][j]==' ')
         {
            free[i][j]='X';
         }
         else
         {
            free[i][j]=' ';
         }
      }
   }
   output(free,"Available");
}