Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
[+] feat: Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Ron-1337 committed Dec 24, 2024
0 parents commit fb20f48
Show file tree
Hide file tree
Showing 9 changed files with 756 additions and 0 deletions.
403 changes: 403 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions CourseDesign.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35514.174 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CourseDesign", "CourseDesign.vcxproj", "{B2F00E08-12C5-4C7D-9F12-295F1AD0582F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B2F00E08-12C5-4C7D-9F12-295F1AD0582F}.Debug|x64.ActiveCfg = Debug|x64
{B2F00E08-12C5-4C7D-9F12-295F1AD0582F}.Debug|x64.Build.0 = Debug|x64
{B2F00E08-12C5-4C7D-9F12-295F1AD0582F}.Debug|x86.ActiveCfg = Debug|Win32
{B2F00E08-12C5-4C7D-9F12-295F1AD0582F}.Debug|x86.Build.0 = Debug|Win32
{B2F00E08-12C5-4C7D-9F12-295F1AD0582F}.Release|x64.ActiveCfg = Release|x64
{B2F00E08-12C5-4C7D-9F12-295F1AD0582F}.Release|x64.Build.0 = Release|x64
{B2F00E08-12C5-4C7D-9F12-295F1AD0582F}.Release|x86.ActiveCfg = Release|Win32
{B2F00E08-12C5-4C7D-9F12-295F1AD0582F}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
135 changes: 135 additions & 0 deletions CourseDesign.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{b2f00e08-12c5-4c7d-9f12-295f1ad0582f}</ProjectGuid>
<RootNamespace>CourseDesign</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
22 changes: 22 additions & 0 deletions CourseDesign.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# C 程序设计 课程设计 2024秋季

这是我的C程序设计课程设计作业代码库
Binary file added docs/2024年程序设计题目.docx
Binary file not shown.
Binary file added docs/2024年课程设计要求.docx
Binary file not shown.
Binary file added docs/C语言程序设计常用函数.docx
Binary file not shown.
165 changes: 165 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#define _CRT_SECURE_NO_WARNINGS
#include <conio.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>

#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_ENTER 13

/* 日期 */
typedef struct Date {
int year;
int month;
int day;
} Date;

Date today;

/* 用户等级 */
typedef enum Level { BRONZE = 1, SILVER, GOLD, DIAMOND } Level;

/* 订单信息 */
typedef struct Order {
char name[20];
int level;
char destination[20];
Date startDate;
int days;
double amount;
struct Order* next;
} Order;

/* 菜单结构体 */
typedef struct Menu {
char* items;
int (*callback_function)();
} Menu;

/* 菜单 */
int init();
int menu();
int create_order();
int exit_program();

// 添加全局变量来保存订单链表的头指针
Order* head = NULL;

int main() {
int flag = 0;
while (flag != -1) {
flag = menu();
}
return 0;
}

int init() {
/* 当前日期 */
time_t now = time(NULL);
struct tm* tm = localtime(&now);
today.year = tm->tm_year + 1900;
today.month = tm->tm_mon + 1;
today.day = tm->tm_mday;
return 0;
}

int menu() {
// 菜单项
const Menu menu[] = {{"创建订单", create_order}, {"退出程序", exit_program}};
const int MENU_ITEMS = sizeof(menu) / sizeof(menu[0]);
int currentChoice = 0;
char key;

while (1) {
system("cls");
printf("\n=====旅游信息管理系统=====\n");
printf("当前日期:%d-%d-%d\n", today.year, today.month, today.day);

// 显示菜单项
for (int i = 0; i < MENU_ITEMS; i++) {
if (i == currentChoice) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x70);
printf("[%c] %s", 'A' + i, menu[i].items);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x07);
printf("\n");
} else {
printf("[%c] %s\n", 'A' + i, menu[i].items);
}
}
printf("============================================\n");
printf("使用方向键↑↓选择,回车确认,或直接按选项字母\n");

// 读取按键
key = _getch();
if (_kbhit()) {
key = _getch();
switch (key) {
case KEY_UP:
currentChoice = (currentChoice - 1 + MENU_ITEMS) % MENU_ITEMS;
break;
case KEY_DOWN:
currentChoice = (currentChoice + 1) % MENU_ITEMS;
break;
}
} else if (key == KEY_ENTER) {
return menu[currentChoice].callback_function();
} else if (toupper(key) >= 'A' && toupper(key) <= 'A' + MENU_ITEMS - 1) {
currentChoice = toupper(key) - 'A';
return menu[currentChoice].callback_function();
}
continue;
}
return 0;
}

int create_order() {
Order* new_order = (Order*)malloc(sizeof(Order));
if (new_order == NULL) {
printf("内存分配失败!\n");
return 0;
}

system("cls");
printf("\n=====创建新订单=====\n");

printf("请输入姓名:");
scanf("%s", new_order->name);

printf("请选择用户等级(1-铜牌,2-银牌,3-金牌,4-钻石):");
scanf("%d", &new_order->level);

printf("请输入目的地:");
scanf("%s", new_order->destination);

printf("请输入出发日期(年 月 日):");
scanf("%d %d %d", &new_order->startDate.year, &new_order->startDate.month,
&new_order->startDate.day);

printf("请输入旅游天数:");
scanf("%d", &new_order->days);

printf("请输入订单金额:");
scanf("%lf", &new_order->amount);

// 将新节点插入到链表头部
new_order->next = head;
head = new_order;

printf("\n订单创建成功!\n");
system("pause");
return 0;
}

int exit_program() {
// 释放链表内存
Order* current = head;
while (current != NULL) {
Order* temp = current;
current = current->next;
free(temp);
}

printf("程序退出\n");
return -1;
}

0 comments on commit fb20f48

Please sign in to comment.