[nfbcs] C++ Assignment Help

Lanie Molinar laniemolinar91 at gmail.com
Fri Oct 27 06:34:01 UTC 2017


Hi, everyone. Thanks for trying to help me a couple days ago. I still 
didn't understand what I needed to do after you tried to help, but not 
long after that, I was able to find a tutor, and she helped me a lot. 
Now, I have a question about another assignment, and I think this one 
even has my tutor stuck. I'm working on a program that prompts a user 
for the number of days in the month and the offset from Monday for that 
month, and then displays a calendar table. It's a lot like the calendar 
I wrote the pseudocode for in the assignment before this. It's almost 
complete, but the spacing of the numbers in the first row is off by 4, 
and I don't know how to fix it. I've tried several things, and my tutor 
has suggested some things, too, but nothing fixes it. My professor says 
this is probably the hardest assignment of the semester, and I can 
definitely see why. Can you please take a look at my work and let me 
know if you have any suggestions? I'm attaching my work, my log from 
PuTTY that shows the expected output, and the assignment instructions. 
Thanks.
-------------- next part --------------
/***********************************************************************
* Program:
*    Assignment 25, Loop Design
*    Sister Unsicker, CS124
* Author:
*    Lanie Molinar
* Summary: 
*    This program displays a calendar using input from the user.
*
*    Estimated:  1.0 hrs   
*    Actual:     0.0 hrs
*      Please describe briefly what was the most difficult part.
************************************************************************/

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

/***********************************************************************
* This function displays the calendar as a table.
***********************************************************************/
void displayTable(int numDays, int offset)
{
   cout << "  Su  Mo  Tu  We  Th  Fr  Sa\n";
   int count = 1;
   for (int day = 1; day <= numDays; )
   {
      if (offset > 0)
      {
         cout << "    ";
         offset--;
      }
      else if (offset == 0)
      {
         cout << setw(4) << day;
         day++;
      }
      count++;
      if ((count % 7 == 0) && (day != (numDays + 1)))
         cout << endl;
      if (day > numDays)
         cout << endl;
   }
}

/**********************************************************************
*    The main function tells a program where to start.
***********************************************************************/
int main()
{
   
   int numDays;
   int offset;
   cout << "Number of days: ";
   cin >> numDays;
   cout << "Offset: ";
   cin >> offset;
   displayTable(numDays, offset);
   return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nfbnet.org/pipermail/nfbcs_nfbnet.org/attachments/20171027/b9fff13a/attachment.html>
-------------- next part --------------
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2017.10.26 23:57:14 =~=~=~=~=~=~=~=~=~=~=~=
Using username "living4god1991".
living4god1991 at 157.201.194.201's password: 
Last login: Thu Oct 26 22:56:46 2017 from 67.44.193.75

[living4god1991 at LinuxLab01 ~]$ exittestBed cs124/assign25 assignment25.cpp

a.out:

------------------------------------------------------------
Starting Test 1

This first test is the simplest case. Here the offset from Monday
is zero so we start on Monday

   > Number of days: 28
   > Offset: 0
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >    1   2   3   4   5   6\n    
Exp:        1   2   3   4   5   6\n
   >    7   8   9  10  11  12  13
   >   14  15  16  17  18  19  20
   >   21  22  23  24  25  26  27
   >   28

Test 1 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 2

This is another simple case. The offset from Monday is 3 so
the first day of the month must be Thursday.

   > Number of days: 30
   > Offset: 3
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >                1   2   3\n    
Exp:                    1   2   3\n
   >    4   5   6   7   8   9  10
   >   11  12  13  14  15  16  17
   >   18  19  20  21  22  23  24
   >   25  26  27  28  29  30

Test 2 failed.
------------------------------------------------------------

Here we will be testing the case when the offset is 6. A common
mistake is to have a blank line at the beginning of the calendar.
In order to get around this, you need a special condition (an IF statement)
that checks for offset == 6 and handle that case.

------------------------------------------------------------
Starting Test 3

   > Number of days: 31
   > Offset: 6
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >                         \n    
Exp:    1   2   3   4   5   6   7\n
   >    1   2   3   4   5   6   7\n
Exp:    8   9  10  11  12  13  14\n
   >    8   9  10  11  12  13  14\n
Exp:   15  16  17  18  19  20  21\n
   >   15  16  17  18  19  20  21\n
Exp:   22  23  24  25  26  27  28\n
   >   22  23  24  25  26  27  28\n
Exp:   29  30  31\n
   >   29  30  31\n
Exp: No output

Test 3 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 4

Here is another special case. Since the last day of the month also happens
to be the last day of the week, it is a common case to put an extra blank
line in the output. In other words, you put a newline in the output when
the day of the week is Saturday, and you put a newline in the output when
we get to the end of the month. You will need a special condition to check
that you are not on a Saturday when you display the end of the month newline

   > Number of days: 30
   > Offset: 4
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >                    1   2\n    
Exp:                        1   2\n
   >    3   4   5   6   7   8   9
   >   10  11  12  13  14  15  16
   >   17  18  19  20  21  22  23
   >   24  25  26  27  28  29  30

Test 4 failed.
------------------------------------------------------------


============================================================
Failed 4/4 tests.
============================================================

[living4god1991 at LinuxLab01 ~]$ testBed cs124/assign25 assignment25.cpp

a.out:

------------------------------------------------------------
Starting Test 1

This first test is the simplest case. Here the offset from Monday
is zero so we start on Monday

   > Number of days: 28
   > Offset: 0
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >    1   2   3   4   5   6\n    
Exp:        1   2   3   4   5   6\n
   >    7   8   9  10  11  12  13
   >   14  15  16  17  18  19  20
   >   21  22  23  24  25  26  27
   >   28

Test 1 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 2

This is another simple case. The offset from Monday is 3 so
the first day of the month must be Thursday.

   > Number of days: 30
   > Offset: 3
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >                1   2   3\n    
Exp:                    1   2   3\n
   >    4   5   6   7   8   9  10
   >   11  12  13  14  15  16  17
   >   18  19  20  21  22  23  24
   >   25  26  27  28  29  30

Test 2 failed.
------------------------------------------------------------

Here we will be testing the case when the offset is 6. A common
mistake is to have a blank line at the beginning of the calendar.
In order to get around this, you need a special condition (an IF statement)
that checks for offset == 6 and handle that case.

------------------------------------------------------------
Starting Test 3

   > Number of days: 31
   > Offset: 6
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >                         \n    
Exp:    1   2   3   4   5   6   7\n
   >    1   2   3   4   5   6   7\n
Exp:    8   9  10  11  12  13  14\n
   >    8   9  10  11  12  13  14\n
Exp:   15  16  17  18  19  20  21\n
   >   15  16  17  18  19  20  21\n
Exp:   22  23  24  25  26  27  28\n
   >   22  23  24  25  26  27  28\n
Exp:   29  30  31\n
   >   29  30  31\n
Exp: No output

Test 3 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 4

Here is another special case. Since the last day of the month also happens
to be the last day of the week, it is a common case to put an extra blank
line in the output. In other words, you put a newline in the output when
the day of the week is Saturday, and you put a newline in the output when
we get to the end of the month. You will need a special condition to check
that you are not on a Saturday when you display the end of the month newline

   > Number of days: 30
   > Offset: 4
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >                    1   2\n    
Exp:                        1   2\n
   >    3   4   5   6   7   8   9
   >   10  11  12  13  14  15  16
   >   17  18  19  20  21  22  23
   >   24  25  26  27  28  29  30

Test 4 failed.
------------------------------------------------------------


============================================================
Failed 4/4 tests.
============================================================

[living4god1991 at LinuxLab01 ~]$ testBed cs124/assign25 assignment25.cpp

a.out:

------------------------------------------------------------
Starting Test 1

This first test is the simplest case. Here the offset from Monday
is zero so we start on Monday

   > Number of days: 28
   > Offset: 0
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >    1   2   3   4   5   6\n    
Exp:        1   2   3   4   5   6\n
   >    7   8   9  10  11  12  13
   >   14  15  16  17  18  19  20
   >   21  22  23  24  25  26  27
   >   28

Test 1 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 2

This is another simple case. The offset from Monday is 3 so
the first day of the month must be Thursday.

   > Number of days: 30
   > Offset: 3
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >    1   2   3\n                
Exp:                    1   2   3\n
   >    4   5   6   7   8   9  10
   >   11  12  13  14  15  16  17
   >   18  19  20  21  22  23  24
   >   25  26  27  28  29  30

Test 2 failed.
------------------------------------------------------------

Here we will be testing the case when the offset is 6. A common
mistake is to have a blank line at the beginning of the calendar.
In order to get around this, you need a special condition (an IF statement)
that checks for offset == 6 and handle that case.

------------------------------------------------------------
Starting Test 3

   > Number of days: 31
   > Offset: 6
   >   Su  Mo  Tu  We  Th  Fr  Sa
   > \n                            
Exp:    1   2   3   4   5   6   7\n
   >    1   2   3   4   5   6   7\n
Exp:    8   9  10  11  12  13  14\n
   >    8   9  10  11  12  13  14\n
Exp:   15  16  17  18  19  20  21\n
   >   15  16  17  18  19  20  21\n
Exp:   22  23  24  25  26  27  28\n
   >   22  23  24  25  26  27  28\n
Exp:   29  30  31\n
   >   29  30  31\n
Exp: No output

Test 3 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 4

Here is another special case. Since the last day of the month also happens
to be the last day of the week, it is a common case to put an extra blank
line in the output. In other words, you put a newline in the output when
the day of the week is Saturday, and you put a newline in the output when
we get to the end of the month. You will need a special condition to check
that you are not on a Saturday when you display the end of the month newline

   > Number of days: 30
   > Offset: 4
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >    1   2\n                    
Exp:                        1   2\n
   >    3   4   5   6   7   8   9
   >   10  11  12  13  14  15  16
   >   17  18  19  20  21  22  23
   >   24  25  26  27  28  29  30

Test 4 failed.
------------------------------------------------------------


============================================================
Failed 4/4 tests.
============================================================

[living4god1991 at LinuxLab01 ~]$ testBed cs124/assign25 assignment25.cpp

a.out:

------------------------------------------------------------
Starting Test 1

This first test is the simplest case. Here the offset from Monday
is zero so we start on Monday

   > Number of days: 28
   > Offset: 0
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >    1   2   3   4   5   6\n    
Exp:        1   2   3   4   5   6\n
   >    7   8   9  10  11  12  13
   >   14  15  16  17  18  19  20
   >   21  22  23  24  25  26  27
   >   28

Test 1 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 2

This is another simple case. The offset from Monday is 3 so
the first day of the month must be Thursday.

   > Number of days: 30
   > Offset: 3
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >    1   2   3\n                
Exp:                    1   2   3\n
   >    4   5   6   7   8   9  10
   >   11  12  13  14  15  16  17
   >   18  19  20  21  22  23  24
   >   25  26  27  28  29  30

Test 2 failed.
------------------------------------------------------------

Here we will be testing the case when the offset is 6. A common
mistake is to have a blank line at the beginning of the calendar.
In order to get around this, you need a special condition (an IF statement)
that checks for offset == 6 and handle that case.

------------------------------------------------------------
Starting Test 3

   > Number of days: 31
   > Offset: 6
   >   Su  Mo  Tu  We  Th  Fr  Sa
   > \n                            
Exp:    1   2   3   4   5   6   7\n
   >    1   2   3   4   5   6   7\n
Exp:    8   9  10  11  12  13  14\n
   >    8   9  10  11  12  13  14\n
Exp:   15  16  17  18  19  20  21\n
   >   15  16  17  18  19  20  21\n
Exp:   22  23  24  25  26  27  28\n
   >   22  23  24  25  26  27  28\n
Exp:   29  30  31\n
   >   29  30  31\n
Exp: No output

Test 3 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 4

Here is another special case. Since the last day of the month also happens
to be the last day of the week, it is a common case to put an extra blank
line in the output. In other words, you put a newline in the output when
the day of the week is Saturday, and you put a newline in the output when
we get to the end of the month. You will need a special condition to check
that you are not on a Saturday when you display the end of the month newline

   > Number of days: 30
   > Offset: 4
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >    1   2\n                    
Exp:                        1   2\n
   >    3   4   5   6   7   8   9
   >   10  11  12  13  14  15  16
   >   17  18  19  20  21  22  23
   >   24  25  26  27  28  29  30

Test 4 failed.
------------------------------------------------------------


============================================================
Failed 4/4 tests.
============================================================

[living4god1991 at LinuxLab01 ~]$ testBed cs124/assign25 assignment25.cpp

a.out:

------------------------------------------------------------
Starting Test 1

This first test is the simplest case. Here the offset from Monday
is zero so we start on Monday

   > Number of days: 28
   > Offset: 0
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >     \n                        
Exp:        1   2   3   4   5   6\n
   > \n                            
Exp:    7   8   9  10  11  12  13\n
   > \n                            
Exp:   14  15  16  17  18  19  20\n
   > \n                            
Exp:   21  22  23  24  25  26  27\n
   > \n    
Exp:   28\n
   > \n
Exp: No output
Timed out!

[living4god1991 at LinuxLab01 ~]$ testBed cs124/assign25 assignment25.cpp

a.out:

------------------------------------------------------------
Starting Test 1

This first test is the simplest case. Here the offset from Monday
is zero so we start on Monday

   > Number of days: 28
   > Offset: 0
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >    0   1   2   3   4   5\n    
Exp:        1   2   3   4   5   6\n
   >    6   7   8   9  10  11  12\n
Exp:    7   8   9  10  11  12  13\n
   >   13  14  15  16  17  18  19\n
Exp:   14  15  16  17  18  19  20\n
   >   20  21  22  23  24  25  26\n
Exp:   21  22  23  24  25  26  27\n
   >   27  28\n
Exp:   28\n

Test 1 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 2

This is another simple case. The offset from Monday is 3 so
the first day of the month must be Thursday.

   > Number of days: 30
   > Offset: 3
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >                0   1   2\n    
Exp:                    1   2   3\n
   >    3   4   5   6   7   8   9\n
Exp:    4   5   6   7   8   9  10\n
   >   10  11  12  13  14  15  16\n
Exp:   11  12  13  14  15  16  17\n
   >   17  18  19  20  21  22  23\n
Exp:   18  19  20  21  22  23  24\n
   >   24  25  26  27  28  29  30\n
Exp:   25  26  27  28  29  30\n

Test 2 failed.
------------------------------------------------------------

Here we will be testing the case when the offset is 6. A common
mistake is to have a blank line at the beginning of the calendar.
In order to get around this, you need a special condition (an IF statement)
that checks for offset == 6 and handle that case.

------------------------------------------------------------
Starting Test 3

   > Number of days: 31
   > Offset: 6
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >                         \n    
Exp:    1   2   3   4   5   6   7\n
   >    0   1   2   3   4   5   6\n
Exp:    8   9  10  11  12  13  14\n
   >    7   8   9  10  11  12  13\n
Exp:   15  16  17  18  19  20  21\n
   >   14  15  16  17  18  19  20\n
Exp:   22  23  24  25  26  27  28\n
   >   21  22  23  24  25  26  27\n
Exp:   29  30  31\n
   >   28  29  30  31\n
Exp: No output

Test 3 failed.
------------------------------------------------------------

------------------------------------------------------------
Starting Test 4

Here is another special case. Since the last day of the month also happens
to be the last day of the week, it is a common case to put an extra blank
line in the output. In other words, you put a newline in the output when
the day of the week is Saturday, and you put a newline in the output when
we get to the end of the month. You will need a special condition to check
that you are not on a Saturday when you display the end of the month newline

   > Number of days: 30
   > Offset: 4
   >   Su  Mo  Tu  We  Th  Fr  Sa
   >                    0   1\n    
Exp:                        1   2\n
   >    2   3   4   5   6   7   8\n
Exp:    3   4   5   6   7   8   9\n
   >    9  10  11  12  13  14  15\n
Exp:   10  11  12  13  14  15  16\n
   >   16  17  18  19  20  21  22\n
Exp:   17  18  19  20  21  22  23\n
   >   23  24  25  26  27  28  29\n
Exp:   24  25  26  27  28  29  30\n
   >   30\n
Exp: No output

Test 4 failed.
------------------------------------------------------------


============================================================
Failed 4/4 tests.
============================================================

[living4god1991 at LinuxLab01 ~]$ 


More information about the NFBCS mailing list