| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3109 人关注过本帖
标题:这程序到底应该怎么编出很多功能的?还有那个输出的边框怎么做的。。头炸了 ...
只看楼主 加入收藏
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
再给你一个办法:把一年的日历都填在一个以星期为单元的数组中,再把数据抽出来输出。
挑一个感觉容易点的办法自己做吧,做得出这个,比你做五十道数学题有益得多。

授人以渔,不授人以鱼。
2012-07-14 14:27
罗庇鹏ksq
Rank: 5Rank: 5
来 自:太平洋
等 级:职业侠客
帖 子:220
专家分:310
注 册:2012-6-30
收藏
得分:0 
源程序有错。。。

从来都是无所谓,现在也该学着有所谓。✿咱们一个人,别坐井观天❀
2012-07-14 14:48
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:5 
只要你算出来一年内每天是几月几号,存储起来

显示只是个方式问题

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2012-07-14 15:21
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册


[ 本帖最后由 TonyDeng 于 2012-7-14 16:45 编辑 ]

授人以渔,不授人以鱼。
2012-07-14 15:51
米小兔
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2012-7-14
收藏
得分:0 
# include <stdio.h>
#define STARS "********************"
int main(void)
{
    int year,month,day1,day2,c,Y,W,i1,i2,j,w,k,flag1=0,flag2=0,p,q;
  
    int t[]={31,0,31,30,31,30,31,31,30,31,30,31};
    printf("%s A calendar program %s\n",STARS,STARS);
    printf("\n Please enter a year (enter q to exit) :");
    scanf("%d",&year);
    while(year>0&&year!='q'){
        if(year%4==0&&year%100!=0||year%400==0)
            t[1]=29;
        else
            t[1]=28;

   
        for(month=1;month<=12;month=month+2)
        {
        
            flag1=0;flag2=0;        /*每次循环flag1;flag2的初始都应该为0*/
            if(month<3)  
            {
            
                c=((int)(year-1)/100);
                Y=(year-1)-((int)((year-1)/100))*100;
                w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(13*(month+13)/5));
                W=(w+70)%7;

            }
            else if(month>=3)
            {
                c=((int)(year/100));
                Y=year-((int)(year/100))*100;
                w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(13*(month+1)/5));
                W=(w+70)%7;
            }
            printf("\n%15d月%30d月\n",month,month+1);
            printf("                |               六\n");
            i1=W;                              
            for(j=1;j<=W;j++)                  
                printf("    ");
            for(day1=1;day1<=t[month-1]&&flag1==0;day1++)
            {
                i1++;printf("%4d",day1);
                if(i1%7==0) flag1=1;
            }
            printf("  | ");
            i2=(W+t[month-1])%7;
   
            for(k=1;k<=((W+t[month-1])%7);k++)
                printf("    ");
            for(day2=1;day2<=t[month]&&flag2==0;day2++)
            {
                i2++;
                printf("%4d",day2);
                if(i2%7==0)
                    flag2=1;
            }
            printf("\n");
            for(p=8;p<=50;p=p+7)                 
            {   
                i1=0;flag1=0;
                for(day1=p-W;day1<=t[month-1]&&flag1==0;day1++)
                {
                    i1++;printf("%4d",day1);
                    if(i1%7==0) flag1=1;
                }
                for(q=i1;q<7;q++)                  
                    printf("    ");
                printf("  | ");
                i2=0;flag2=0;
                for(day2=p-(W+t[month-1])%7;day2<=t[month]&&flag2==0;day2++)
                {
                    i2++;printf("%4d",day2);
                    if(i2%7==0) flag2=1;
                }
      
                printf("\n");

            }
        }
        printf("\nPlease enter the year (enter q to exit) :");
        if(scanf("%d",&year)!=1)
            break;
    }
    printf("%s  Thanks for using  %s\n",STARS,STARS);
    getchar();
    return 0;
}
2012-07-14 15:53
米小兔
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2012-7-14
收藏
得分:0 
这下我这个,差不多了。
2012-07-14 15:54
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:5 
程序代码:
using namespace System;

void PrintWeek(DateTime firstDayOfMonth, int row, int col);

void main(void)
{
    Console::Title = "年历测试程序";
    Console::SetWindowSize(120, 40);
    Console::Clear();

    int year = 2008;
    Console::SetCursorPosition(48, 0);
    Console::Write("{0:D}年年历", year);
    int row = 2;
    int col = 1;
    for (int month = 1; month <= 12; ++month)
    {
        PrintWeek(DateTime(year, month, 1), row, col);
        if (month % 3 == 0)
        {
            row += 7;
            col = 1;
        }
        else
        {
            col += 35;
        }
    }
    Console::SetCursorPosition(0, ++row);
    Console::Write("按任意键结束程序...");
    Console::ReadLine();
}

void PrintWeek(DateTime firstDayOfMonth, int row, int col)
{
    Console::SetCursorPosition(col, row);
    Console::Write("{0,2:D} SUN MON TUE WED THU FRI SAT", firstDayOfMonth.Month);
    Console::SetCursorPosition(col + 3, ++row);
    for (DayOfWeek index = DayOfWeek::Sunday; index < firstDayOfMonth.DayOfWeek; ++index)
    {
        Console::Write("    ");
    }
    DayOfWeek counter = firstDayOfMonth.DayOfWeek;
    for (int day = firstDayOfMonth.Day; day <= DateTime::DaysInMonth(firstDayOfMonth.Year, firstDayOfMonth.Month); ++day)
    {
        Console::Write("{0,3:D} ", day);
        if (counter < DayOfWeek::Saturday)
        {
            ++counter;
        }
        else
        {
            Console::SetCursorPosition(col + 3, ++row);
            counter = DayOfWeek::Sunday;
        }
    }
}


[ 本帖最后由 TonyDeng 于 2012-7-14 16:23 编辑 ]

授人以渔,不授人以鱼。
2012-07-14 16:12
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
挺好玩的题目,凑个热闹。

程序代码:
#include<stdio.h>
int getweek(int year, int month, int week, char * str)
{
    const int m[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int d[] = {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
    int leap, from, last, i;
    leap = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
    year--;
    from = week * 7 - (year * 365 + year / 4 - year / 100 + year / 400 + d[month] + (month > 2 && leap) + 1) % 7 - 6;
    last = m[month] + (month == 2 && leap);
    for(i = 0; i < 7; i++, from++) sprintf(str + i * 4, (from > 0 && from <= last ? "%4d" : "    "), from);
    return from <= last + 7;
}
void print_calendar(int year)
{
    const char *week_title = " SUN MON TUE WED THU FRI SAT";
    char s1[32], s2[32];
    int i, j;
    printf("|------------------- The Calendar of Year %04d -------------------|\n", year);
    for(i = 1; i <= 6; i++)
    {
        printf("| %d %s  %2d %s |\n", i, week_title, i + 6, week_title);
        for(j = 1; getweek(year, i, j, s1) | getweek(year, i + 6, j, s2); j++) printf("|   %s     %s |\n", s1, s2);
    }
    printf("|-----------------------------------------------------------------|\n");
}
int main()
{
    int year;
    printf("Please input the year whose calendar you want to know: ");
    scanf("%d", &year);
    print_calendar(year);
    return 0;
}


重剑无锋,大巧不工
2012-07-14 23:16
米小兔
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2012-7-14
收藏
得分:0 
18楼的一模一样……哇塞,大神
2012-07-15 10:57
罗庇鹏ksq
Rank: 5Rank: 5
来 自:太平洋
等 级:职业侠客
帖 子:220
专家分:310
注 册:2012-6-30
收藏
得分:0 
两个版主的编译都有错呢。

从来都是无所谓,现在也该学着有所谓。✿咱们一个人,别坐井观天❀
2012-07-15 10:58
快速回复:这程序到底应该怎么编出很多功能的?还有那个输出的边框怎么做的。。头 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031919 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved