C 언어 코드 주문 시스템 구현

본 고 는 사례 를 통 해 C 언어 가 주문 시스템 을 실현 하 는 구체 적 인 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.

#include<iostream>
#include<cstring>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<cstring>
#include<conio.h>
using namespace std;

typedef struct member
{
 char username[20];//   
 char password[20];//  
}Member;

typedef struct product
{
 char name[20];//   
 int price;
 int num;//    
}Product;

/*     */
void menu1();/*   */
void menu2();/*     */

void all_info();//    
void member_log_up();//  
void member_log_in_interface();//      
int member_log_in();//  
void check();

/*       */
void sell_info();//      
void password_manage();//       
int compare_password(char password[]);//      

int main()
{
 int flag1=1,flag_member=0,flag_admin=0;
 int choice1,choice2;

 while(flag1){
 menu1();
 printf("
"); printf(" (1-5):"); scanf("%d",&choice1); if(choice1==1)/* */ { member_log_in_interface(); flag_member=member_log_in(); while(flag_member) { all_info(); check(); } } else if(choice1==2)/* */ { printf("


\t\t\t ...
"); member_log_up(); } else if(choice1==3)/* */ { printf(" :"); char password[20]={0}; scanf("%s",password); if(compare_password(password)) { printf("

\t\t\t\t -- !--

\t\t\t\t== ==
"); flag_admin=1; } else { printf("

\t\t\t\t -- !--
"); } while(flag_admin) { menu2(); printf(" (1-3):"); scanf("%d",&choice2); switch(choice2) { case 1:password_manage();break; case 2:sell_info();break; case 3:flag_admin=0;break; } } } else if(choice1==4)/* */ { flag1=0; } } printf(" !( )

\t !

"); return 0; } void menu1() { system("color E9"); printf("

"); printf("\t\t\t *=======================================*
"); printf("\t\t\t| * - * - * Zhou Cheng - System - * - * |
"); printf("\t\t\t| * * |
"); printf("\t\t\t| | [1] | |
"); printf("\t\t\t| * * |
"); printf("\t\t\t| | [2] | |
"); printf("\t\t\t| * * |
"); printf("\t\t\t| | [3] | |
"); printf("\t\t\t| * * |
"); printf("\t\t\t| | [4] | |
"); printf("\t\t\t| * * |
"); printf("\t\t\t| * - * - * - * - * - * - * - * - * - * |
"); printf("\t\t\t *=======================================*
"); } void menu2() { printf("

"); printf("\t\t\t *======================================*
"); printf("\t\t\t| | * - * - * - - - - * - * - * | |
"); printf("\t\t\t| * * |
"); printf("\t\t\t| | [1] | |
"); printf("\t\t\t| * [2] * |
"); printf("\t\t\t| * [3] * |
"); printf("\t\t\t| | | |
"); printf("\t\t\t| * - * - * - * - * -- * - * - * - * - * |
"); printf("\t\t\t *======================================*
"); } int compare_password(char password[])/* */ { int i,flag=1; for(i=0;i<6;i++) { if(password[i]!='1'+i)flag=0; } return flag; } void member_log_up()// { Member member; while(1) { printf(" username( ):"); scanf("%s",member.username); printf(" (20 ):"); scanf("%s",member.password); printf(" (y/n):"); char ch=getch(); if(ch=='n')continue; else if(ch=='y') { FILE *fp=fopen("memberInfo.txt","a+"); fprintf(fp,"%s %s ",member.username,member.password); fclose(fp); printf("

"); printf("-------- --------"); return ; } } } int member_log_in() { Member member[100]; FILE *fp=fopen("memberInfo.txt","a+"); int i=0; while(!feof(fp)) { fscanf(fp,"%s %s",member[i].username,member[i].password); i++; } char username[20],password[20]; scanf("%s",username); printf("\t\t\t (password):"); scanf("%s",password); int flag=0; for(int j=0;j<i;j++) { if(strcmp(username,member[j].username)==0&&strcmp(password,member[j].password)==0) { flag=1; break; } } return flag; } void member_log_in_interface()/* */ { printf("


\t\t\t***================================***
"); printf("\t\t\t
"); printf("\t\t\t (username):"); } void all_info() { Product product[100]; FILE *fp=fopen("productInfo.txt","a+"); int i=0; while(!feof(fp)) { fscanf(fp,"%s %d %d",product[i].name,&product[i].price,&product[i].num); i++; } printf(" -- --------- ---
"); for(int j=0;j<i;j++) { printf("%-6d%-15s%-7d
",j+1,product[j].name,product[j].price); } printf(" ( ):"); int num,count; scanf("%d %d",&num,&count); printf(" ...
"); printf(" :"); char c; scanf(" %c",&c); } void sell_info() { Product product[100]; FILE *fp=fopen("productInfo.txt","a+"); int i=0; while(!feof(fp)) { fscanf(fp,"%s %d %d",product[i].name,&product[i].price,&product[i].num); i++; } printf("-- --------- --- --- --
"); for(int j=0;j<i;j++) { printf(" %-15s%-7d%-9d%-8d
",product[j].name,product[j].price,product[j].num,product[j].price*product[j].num); } printf(" :"); char c; scanf(" %c",&c); } void password_manage() { Member member[100]; FILE *fp=fopen("memberInfo.txt","a+"); int i=0; while(!feof(fp)) { fscanf(fp,"%s %s",member[i].username,member[i].password); i++; } printf("---- ------------ ----------"); for(int j=0;j<i;j++) { printf("
%-17s %-15s",member[j].username,member[j].password); } printf(" :"); char c; scanf(" %c",&c); } void check() { printf(" ...
"); printf(" :"); char c; scanf(" %c",&c); }
더 많은 학습 자 료 는 주제 인 에 주목 하 세 요.
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기