Results 1 to 8 of 8

Thread: Calender program...

  1. #1
    Guest

    Red face

    I am so embarassed (),
    I don't normally ask for help with my homework, but I just can't figure this one out..

    this is the basic layout we are supposed to use:

    Code:
       Sun     Mon     Tue     Wed     Thu     Fri     Sat
    *********************************************************
    *       *       *       *       *       *       *       *
    *       *       *       *       *       *       *       *
    *       *       *       *       *       *       *       *
    *********************************************************
    *       *       *       *       *       *       *       *
    *       *       *       *       *       *       *       *
    *       *       *       *       *       *       *       *
    *********************************************************
    *       *       *       *       *       *       *       *
    *       *       *       *       *       *       *       *
    *       *       *       *       *       *       *       *
    *********************************************************
    *       *       *       *       *       *       *       *
    *       *       *       *       *       *       *       *
    *       *       *       *       *       *       *       *
    *********************************************************
    *       *       *       *       *       *       *       *
    *       *       *       *       *       *       *       *
    *       *       *       *       *       *       *       *
    *********************************************************
    we are supposed to ask for the number of days in a month, and the day in which the month starts..

    then display it properly.


    here is my code:
    it all works fine, but I just can't figure out how to display the dates in the correct places...
    I have tried so many different things, and I can't get it...

    BTW, I am using Borland Turbo C++ 4.5, which has some non-ANSI functions, such as gotoxy, when goes to a point, and also clrscr, which clears the screen.



    Code:
    /*
    Dennis Wrenn
    12/8/00
    Computer Science Period 6
    e5-11
    */
    #include <iostream.h>
    #include <conio.h>
    #include <inc.h>
    
    
    void showcal(int numdays, int startday);
    void dowords();
    
    int main()
    {
    int numday, startday;
    cout << "Enter the number of days in the month(30 or 31): ";
    cin >> numday;
    cout << "Enter the number for the day the month starts(1 = sunday, etc): ";
    cin >> startday;
    
    clrscr();
    
    showcal(numday, startday);
    return 0;
    }
    
    void showcal(int numdays, int startday)
    {
    	int i = 0;
    	int odd = 0;
    
    	dowords();
    
    	for (i = 1; i <= 57; i += 8)
    	{
    		drawbar('v', i, 2, 21, '*');
    	}
    
    	for (i = 2; i <= 22; i +=4)
    	{
    		drawbar('h', 1, i, 57, '*');
    	}
    
    }
    
    
    void dowords()
    {
    	gotoxy(4,1);
    	cout << "Sun";
    
    	gotoxy(12,1);
    	cout << "Mon";
    
    	gotoxy(20,1);
    	cout << "Tue";
    
    	gotoxy(28,1);
    	cout << "Wed";
    
    	gotoxy(36,1);
    	cout << "Thu";
    
    	gotoxy(44,1);
    	cout << "Fri";
    
    	gotoxy(52,1);
    	cout << "Sat";
    }
    you may have seen a wierd header file in there..... inc.h
    I wrote that so I didn't have to include my drawbar function in all the projects:

    Code:
    #include <conio.h>
    void drawbar(char d, int l, char c)
    {
    int i = 0;
    switch (d)
    {
    case 'v':
    //verticle
    for(i = 0; i < l; i++)
    {
    cout << c << "\n";
    }
    break;
    case 'h':
    //horizontal
    default:
    for(i = 0; i < l; i++)
    {
    cout << c;
    }
    break;
    }
    cout << endl;
    
    }
    
    void drawbar(char d, int x, int y, int l, char c)
    {
    int i = 0;
    int y2 = y;
    gotoxy(x,y);
    switch (d)
    {
    case 'v':
    //verticle
    for(i = 0; i < l; i++)
    {
    gotoxy(x,y2);
    y2++;
    cout << c << "\n";
    }
    break;
    case 'h':
    //horizontal
    default:
    for(i = 0; i < l; i++)
    {
    cout << c;
    }
    break;
    }
    cout << endl;
    }

    I would like help on this soon, as it's bugging the crap out of me, but you can take your time, because I am way ahead of the class, and this is the 11th excersize in the book, and everybody else is still on #1...



    Thanks a lot....

    Dennis Wrenn

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I don't see what the problem is dennis. I haven't pasted the code and run it but why don't you do it like this:
    1. Draw the table first.
    2. Then put in the numbers using gotoxy.

    The number for each box should be X+Y*7+Start whereas if that number<1 or number>dayisinmonth then don't display it
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Well i reckon this should do it:

    (I don't have Borland)

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    char *weekdays[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
    int daysinmonth, startday;
    
    void getinput()
    {	cout << "How many days in the month?  ";
    	cin >> daysinmonth;
    	cout << endl << "On which day does the month begin? (Sun = 1, Mon = 2 etc.)  ";
    	cin >> startday;
    	cout << endl << endl;
    }
    
    void drawheaders()
    {	for(int x = 0; x<7; x++)
    		cout << "   "<< weekdays[x] << "  ";
    	cout << endl;
    }
    
    void drawline()
    {	for(int x = 0; x<57; x++)
    		cout << '*';
    	cout << endl;
    }
    
    void drawcolumns()
    {	for(int x = 0; x<7; x++)
    		cout << "*       ";
    	cout << '*' << endl;
    }
    
    void drawdays(int weekbegin)
    {	for(int x = 0; x<7; x++)
    	{	cout << "* "; 
    		if((weekbegin+x-startday+2 > daysinmonth) || (weekbegin+x-startday+2 < 1))
    			cout << "   ";
    		else
    			cout << setw(3) << weekbegin+x-startday+2;
    		cout << "   ";
    	}
    	cout << '*' << endl;
    }
    
    
    void main()
    {	
    	getinput();
    	drawheaders();
    	drawline();
    	for(int y = 0; y<5; y++)
    	{	drawcolumns();
    		drawdays(y*7);
    		drawcolumns();
    		drawline();
    	}
    	if (daysinmonth + startday > 35)
    	{	drawcolumns();
    		drawdays(35);
    		drawcolumns();
    		drawline();
    	}
    
    }
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    Guest
    Thanks harry,

  5. #5
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305
    dennis you wouldn't happen to live in West New York, NJ

    cause i have that same prob too

  6. #6
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305
    is that the easiest way to do it?

    cause i sure know that we haven't learn that much

    i wonder how this teacher of mine expects us to do it

  7. #7
    Guest
    Nope, I don't..
    I live in Arlington, Virginia

    is your textbook called "a guide to programming in C++" printed by lawrenceville press?


  8. #8
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305
    nope my book is called "introduction to computer science using c++"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width