#include <stdio.h>
#include <stdlib.h>
struct date {
int year;
int month;
int day;
};
//定义一个日程
struct richeng {
struct date dt;
char anpai[100];
};
struct richeng rc[100]= {2020,12,27,"C语言培训",2021,01,17,"C语言期末考试"};
int num=2;//表示日程数组的有效元素个数
//打印主菜单
void printmenu() {
system("cls");
system("color 27");
printf("****************主菜单**************** \n");
printf("* 1.添加日程 * \n");
printf("* 2.修改日程 * \n");
printf("* 3.查询日程 * \n");
printf("* 4.删除日程 * \n");
printf("* 5.列出日程 * \n");
printf("* 6.退出程序 * \n");
printf("请输入选:");
}
void listRiCheng() {
int i;
printf("\n 日程安排如下:");
for(i=0; i<num; i++) {
printf("\n %4d-%2d-%2d的安排:%s",rc[i].dt.year,rc[i].dt.month,rc[i].dt.day,rc[i].anpai);
}
}
//添加日程
void addRiCheng() {
struct richeng rc1;
printf("\n 请输入要添加的日程日期yyyy-mm-dd:");
scanf("\n %4d-%2d-%2d",rc1.dt.year,rc1.dt.month,rc1.dt.day);
printf("\n 请输入日程安排:");
scanf("%s",rc1.anpai);
if(num>99) {
printf("\n 日程安排已满,请联系管理员");
return;
}
rc[num]=rc1;
num++;
printf("\n 日程添加成功");
}
//查询日程 quaryRiCheng()
void quaryRiCheng(){
struct date dt1;
printf("\n 请输入要查询的日期yyyy-mm-dd:");
scanf("\n %4d-%2d-%2d",&dt1.year,&dt1.month,&dt1.day);
int i;
int hasfound=0;
for(i=0; i<num; i++) {
if((dt1.year==rc[i].dt.year)&&(dt1.month==rc[i].dt.month)&&(dt1.day==rc[i].dt.day)) {
printf("\n 该日的日程安排为%s",rc[i].anpai);
hasfound=1;
break;
}
}
if(hasfound==0) {
printf("\n 该日无日程安排");
}
}
void modifyRiCheng() {
struct date dt1;
printf("\n 请输入要修改的日期yyyy-mm-dd:");
scanf("\n %4d-%2d-%2d",&dt1.year,&dt1.month,&dt1.day);
int i;
int hasfound=0;
for(i=0; i<num; i++) {
if((dt1.year==rc[i].dt.year)&&(dt1.month==rc[i].dt.month)&&(dt1.day==rc[i].dt.day)) {
printf("请输入新的日程");
scanf("%s",rc[i].anpai);
printf("\n 修改后:%4d-%2d-%2d的新的日程为:%s",rc[i].dt.year,rc[i].dt.month,rc[i].dt.day);
hasfound=1;
break;
}
}
if(hasfound==0) {
printf("\n 该日无日程安排,无法修改");
}
}
void delRiCheng() {
struct date dt1;
printf("\n 请输入要删除的日期yyyy-mm-dd:");
scanf("\n %4d-%2d-%2d",&dt1.year,&dt1.month,&dt1.day);
int i,j;
int hasfound=0;
for(i=0; i<num; i++) {
if((dt1.year==rc[i].dt.year)&&(dt1.month==rc[i].dt.month)&&(dt1.day==rc[i].dt.day)) {
for(i=0;i<num-1;i++)
{
rc[j]=rc[j+1];
}
num--;
hasfound=1;
printf("删除成功");
break;
}
}
if(hasfound==0) {
printf("\n 该日无日程安排,无法删除");
}
}
int main() {
int choice;
while(1)
{
printmenu();
scanf("%d",&choice);
switch(choice)
{
case 1:
addRiCheng();
break;
case 2:
modifyRiCheng();
break;
case 3:
quaryRiCheng();
break;
case 4:
delRiCheng();
break;
case 5:
listRiCheng();
break;
case 6:
return;
}
printf("\n 按任意键继续");
getchar();
getchar();
}
return 0;
}
#include <stdlib.h>
struct date {
int year;
int month;
int day;
};
//定义一个日程
struct richeng {
struct date dt;
char anpai[100];
};
struct richeng rc[100]= {2020,12,27,"C语言培训",2021,01,17,"C语言期末考试"};
int num=2;//表示日程数组的有效元素个数
//打印主菜单
void printmenu() {
system("cls");
system("color 27");
printf("****************主菜单**************** \n");
printf("* 1.添加日程 * \n");
printf("* 2.修改日程 * \n");
printf("* 3.查询日程 * \n");
printf("* 4.删除日程 * \n");
printf("* 5.列出日程 * \n");
printf("* 6.退出程序 * \n");
printf("请输入选:");
}
void listRiCheng() {
int i;
printf("\n 日程安排如下:");
for(i=0; i<num; i++) {
printf("\n %4d-%2d-%2d的安排:%s",rc[i].dt.year,rc[i].dt.month,rc[i].dt.day,rc[i].anpai);
}
}
//添加日程
void addRiCheng() {
struct richeng rc1;
printf("\n 请输入要添加的日程日期yyyy-mm-dd:");
scanf("\n %4d-%2d-%2d",rc1.dt.year,rc1.dt.month,rc1.dt.day);
printf("\n 请输入日程安排:");
scanf("%s",rc1.anpai);
if(num>99) {
printf("\n 日程安排已满,请联系管理员");
return;
}
rc[num]=rc1;
num++;
printf("\n 日程添加成功");
}
//查询日程 quaryRiCheng()
void quaryRiCheng(){
struct date dt1;
printf("\n 请输入要查询的日期yyyy-mm-dd:");
scanf("\n %4d-%2d-%2d",&dt1.year,&dt1.month,&dt1.day);
int i;
int hasfound=0;
for(i=0; i<num; i++) {
if((dt1.year==rc[i].dt.year)&&(dt1.month==rc[i].dt.month)&&(dt1.day==rc[i].dt.day)) {
printf("\n 该日的日程安排为%s",rc[i].anpai);
hasfound=1;
break;
}
}
if(hasfound==0) {
printf("\n 该日无日程安排");
}
}
void modifyRiCheng() {
struct date dt1;
printf("\n 请输入要修改的日期yyyy-mm-dd:");
scanf("\n %4d-%2d-%2d",&dt1.year,&dt1.month,&dt1.day);
int i;
int hasfound=0;
for(i=0; i<num; i++) {
if((dt1.year==rc[i].dt.year)&&(dt1.month==rc[i].dt.month)&&(dt1.day==rc[i].dt.day)) {
printf("请输入新的日程");
scanf("%s",rc[i].anpai);
printf("\n 修改后:%4d-%2d-%2d的新的日程为:%s",rc[i].dt.year,rc[i].dt.month,rc[i].dt.day);
hasfound=1;
break;
}
}
if(hasfound==0) {
printf("\n 该日无日程安排,无法修改");
}
}
void delRiCheng() {
struct date dt1;
printf("\n 请输入要删除的日期yyyy-mm-dd:");
scanf("\n %4d-%2d-%2d",&dt1.year,&dt1.month,&dt1.day);
int i,j;
int hasfound=0;
for(i=0; i<num; i++) {
if((dt1.year==rc[i].dt.year)&&(dt1.month==rc[i].dt.month)&&(dt1.day==rc[i].dt.day)) {
for(i=0;i<num-1;i++)
{
rc[j]=rc[j+1];
}
num--;
hasfound=1;
printf("删除成功");
break;
}
}
if(hasfound==0) {
printf("\n 该日无日程安排,无法删除");
}
}
int main() {
int choice;
while(1)
{
printmenu();
scanf("%d",&choice);
switch(choice)
{
case 1:
addRiCheng();
break;
case 2:
modifyRiCheng();
break;
case 3:
quaryRiCheng();
break;
case 4:
delRiCheng();
break;
case 5:
listRiCheng();
break;
case 6:
return;
}
printf("\n 按任意键继续");
getchar();
getchar();
}
return 0;
}