C language realizes the ordering system

  • 2020-10-23 21:07:20
  • OfStack

The example of this paper shares the specific code of C language to realize ordering system for your reference. The specific content is as follows


#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];// The user name 
 char password[20];// password 
}Member;

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

/* Menu function area */
void menu1();/* The main menu */
void menu2();/* Administrator interface */

void all_info();// Order information 
void member_log_up();// registered 
void member_log_in_interface();// Appearance of login interface 
int member_log_in();// The login 
void check();

/* Administrator menu function */
void sell_info();// All information of dishes 
void password_manage();// Username and password information 
int compare_password(char password[]);// Contrast cipher function 

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

 while(flag1){
 menu1();
 printf("\n");
 printf(" Please you to choose (1-5):");
 scanf("%d",&choice1);
 if(choice1==1)/* Member login */
 {
  member_log_in_interface();

  flag_member=member_log_in();

  while(flag_member)
  {

   all_info();
   check();
  }
 }
 else if(choice1==2)/* Registered members */
 {
  printf("\n\n\n\t\t\t Entering the user registration interface ...\n");

  member_log_up();
 }
 else if(choice1==3)/* Administrator login */
 {
  printf(" Please enter your password: ");
  char password[20]={0};
  scanf("%s",password);
  if(compare_password(password))
  {
   printf("\n\n\t\t\t\t -- Enter password correctly !--\n\n\t\t\t\t== Entering the administrator interface ==\n");
   flag_admin=1;

  }
  else
  {
   printf("\n\n\t\t\t\t -- Incorrect password entry !--\n");

  }
  while(flag_admin)
  {
   menu2();
   printf(" Please you to choose (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)/* Log out */
 {
  flag1=0;
 }
 }
 printf(" You have safely logged out of the system !( Press any key to close the interface )\n\n\t Welcome to use again !\n\n");
 return 0;
}

void menu1()
{
 system("color E9");
 printf("\n\n");
 printf("\t\t\t *=======================================*\n");
 printf("\t\t\t| * - * - * Zhou Cheng - System - * - * |\n");
 printf("\t\t\t| *          * |\n");
 printf("\t\t\t| | [1]  Member login       | |\n");
 printf("\t\t\t| *          * |\n");
 printf("\t\t\t| | [2]  Registered members       | |\n");
 printf("\t\t\t| *          * |\n");
 printf("\t\t\t| | [3]  Administrator login      | |\n");
 printf("\t\t\t| *          * |\n");
 printf("\t\t\t| | [4]  Log out       | |\n");
 printf("\t\t\t| *          * |\n");
 printf("\t\t\t| * - * - * - * - * - * - * - * - * - * |\n");
 printf("\t\t\t *=======================================*\n");
}

void menu2()
{
 printf("\n\n");
 printf("\t\t\t *======================================*\n");
 printf("\t\t\t| | * - * - *  tube - Richard - member - world - surface  * - * - * | |\n");
 printf("\t\t\t| *         * |\n");
 printf("\t\t\t| | [1]  Member password management     | |\n");
 printf("\t\t\t| * [2]  Product sales information     * |\n");
 printf("\t\t\t| * [3]  Exit administrator interface     * |\n");
 printf("\t\t\t| |         | |\n");
 printf("\t\t\t| * - * - * - * - * -- * - * - * - * - * |\n");
 printf("\t\t\t *======================================*\n");
}

int compare_password(char password[])/* Administrator password comparison function  */
{
 int i,flag=1;
 for(i=0;i<6;i++)
 {
  if(password[i]!='1'+i)flag=0;
 }
 return flag;
}

void member_log_up()// Member registration function 
{

 Member member;

 while(1)
 {
  printf(" Please enter what you want to create username (Username) : ");
  scanf("%s",member.username);

  printf(" Please enter your password ( 20 (less than 2 characters) : ");
  scanf("%s",member.password);

  printf(" Are you sure to create ( 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("\n You have registered successfully! \n");
   printf("-------- Returning to the lobby --------");

   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  (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()/* Login interface */
{
 printf("\n\n\n\t\t\t***================================*** \n");
 printf("\t\t\t         \n");
 printf("\t\t\t  The user name  (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(" Serial number -- Food name --------- The unit price ---\n");
  for(int j=0;j<i;j++)
  {
   printf("%-6d%-15s%-7d\n",j+1,product[j].name,product[j].price);
  }
  printf(" Please enter the number and quantity of the item you want to purchase (separated by space) : ");
  int num,count;
  scanf("%d %d",&num,&count);
  printf(" This function is not yet written ...\n");
  printf(" Press any key to go to the settlement interface: ");
  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("-- Food name --------- The unit price --- sales --- sales --\n");
  for(int j=0;j<i;j++)
  {
   printf(" %-15s%-7d%-9d%-8d\n",product[j].name,product[j].price,product[j].num,product[j].price*product[j].num);
  }
  printf(" Press any key to return to the menu: ");
  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("---- The user name ------------ password ----------");
  for(int j=0;j<i;j++)
  {
   printf("\n %-17s %-15s",member[j].username,member[j].password);
  }
  printf(" Press any key to return to the menu: ");
  char c;
  scanf(" %c",&c);
}

void check()
{
  printf(" This function hasn't been written yet ...\n");
  printf(" Press any key to return to the menu: ");
  char c;
  scanf(" %c",&c);
}

For more information, please pay attention to the topic management System Development.


Related articles: