《软件工程》实验报告******学号:*********班级:网133指导老师:***一.实验目的1.能按照软件工程的思想,采用面向过程的方法开发出一个小型软件系统。
2.在软件系统开发过程中,能综合利用一门编程语言和软件工程等多门课程的知识。
3.培养良好的软件开发习惯,了解软件企业文化。
4.掌握结构化数据流分析技术。
5.掌握结构化程序设计的基本概念与技术,并且养成良好的编码风格。
6.掌握单元测试的一般步骤及技术。
7.掌握集成测试的一般步骤和技术。
二.实验内容1.软件需求分析①、功能需求分析·输入一个年份(1-3000),然后显示12个月的月历·能解决闰年和平年问题·能输出显示结果②、运行需求分析·操作系统:Windows9x, Windows2000, Windows XP及更高版本③、数据流图软件结构图:2.软件设计与编码#include <stdio.h>#include <ctype.h>#include <stdlib.h>#include <math.h>#define firstdayof1 1/* 定义第一年的第一天,星期日=7 */ #define gap " "/* set gap between numbers of dates */#define dent " "/* set right margin. */struct info {int month;int firstdayofmonth;int daysofmonth;int leap;}monthinfo;int checkinput(void);int inputyear(void);int isleap(int y);void output(struct info);void printhead(struct info );void printmonth(struct info);struct info setinit(int);struct info setmonthinfo(struct info );/* 这个作用是判断年, 如果是闰年, return 1, 否则return 0 */int isleap(int y){return ((y%4==0 && y%100!=0) || y%400==0);}/* This module is to accept inputyear() and check if it is correct. if it is correct it return int year, otherwise ask user reenter */int checkinput(void){int y;do{y=inputyear();if(y<1 || y >3000){printf("\n输入错误!。
\n\n");y=0;}}while(y<1);return y;}/* This function is to accept the input year, if it is the integer, it returnsit, otherwise it return -1 */int inputyear(void){char s[80];int i, y;y=-1;printf("请输入年份(1-3000):");for(i=0;i<80;++i){s[i]=getchar();if(s[i]==27)exit(0);if(s[i]==10)break;}for(i=0;i<80;++i){if(s[i]==10) break;else if(!isdigit(s[i]))return y;}y=atoi(s);return y;}/*This module is to accept monthinfo, and print the whole year calender. */void output(struct info monthinfo){char ch;do{printhead(monthinfo);printmonth(monthinfo);printf("按任意键显视下一月, 按Esc键退出. \n");ch=getchar();if(ch==27)exit(0);monthinfo=setmonthinfo(monthinfo);}while(monthinfo.month<13);}/* This module is to accept monthinfo, amd print monthly head like"一月" */void printhead(struct info monthinfo){char *ss;printf("%s",dent);switch(monthinfo.month){case 1: ss="一月";break;case 2: ss="二月";break;case 3: ss="三月";break;case 4: ss="四月";break;case 5: ss="五月";break;case 6: ss="六月";break;case 7: ss="七月";break;case 8: ss="八月";break;case 9: ss="九月";break;case 10: ss="十月";break;case 11: ss="十一月";break;case 12: ss="十二月";}printf(" %s%s%s%s\n\n",gap,gap,gap,ss);}/* This module is to accept monthinfo, and print the numbered dates of the month.*/void printmonth(struct info monthinfo){int i,j,k;printf("%s",dent);printf("一%s二%s三%s四%s五%s六%s日\n\n",gap,gap,gap,gap,gap,gap);printf("%s",dent);for(i=1;i<monthinfo.firstdayofmonth;i=i+1){printf("%s ",gap);}k=monthinfo.firstdayofmonth;for(j=1;j<=monthinfo.daysofmonth;j=j+1){if(k>7){k=k-7;printf("\n\n%s",dent);};k=k+1;printf("%2d%s",j,gap);}printf("\n\n");}/* This module is to accept the monthinfo, and set the monthinfo of next month.*/struct info setmonthinfo(struct info monthinfo){int m;monthinfo.firstdayofmonth= (monthinfo.firstdayofmonth+ \monthinfo.daysofmonth-1)%7+1;monthinfo.month=monthinfo.month+1;monthinfo.daysofmonth=30;m=monthinfo.month;if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m ==12)monthinfo.daysofmonth=31;if(m==2){if(monthinfo.leap)monthinfo.daysofmonth = 29;elsemonthinfo.daysofmonth = 28;}return monthinfo;}/* This module is to initialize the monthinfo. */struct info setinit(int year){int i,days,total;struct info monthinfo;monthinfo.month=1;monthinfo.firstdayofmonth=firstdayof1;for(i=1;i<year;i=i+1){if(isleap(i))days=366;elsedays=365 ;monthinfo.firstdayofmonth=(monthinfo.firstdayofmonth+days-1)%7+1;}monthinfo.daysofmonth=31;monthinfo.leap=isleap(year);return monthinfo;}void main(){printf(" \t\t************************************ \n");p rintf(" \t\t欢迎使用万年历演示程序\n");p rintf(" \t\t************************************ \n");int year ;struct info monthinfo;year = checkinput();monthinfo = setinit(year);output(monthinfo);}3.单元测试①.白盒测试②.黑盒测试2015年三月四月五月六月2016年:三.总结和体会本次用C语言编写的万年历系统主要实现了年历、月历、日历的显示。
我根本就不喜欢敲代码了,看见代码就头疼。
所以感觉厌恶这门专业,对学习也不感兴趣了。
而且,还有一件更头疼的事是在写一个简单的程序时竟然老是出错,难一点的,复杂一点的程序竟然无从下手。
但是去看程序的参考答案时都看得懂,又感觉很容易。