当前位置:网站首页>Commodity information management system (C language document version)
Commodity information management system (C language document version)
2022-07-02 22:31:00 【Humble-4663】
Catalog
One : Header file section (system .h)
Two : Interface part (test.cpp)
3、 ... and : Main functions (systemfunc.cpp)
The complete code is as follows :
Preface :
This system belongs to the homework assigned by the school , Is a console program , File operation is required . Make such a system , Can strengthen the understanding of C Understanding and application of language .
Do this system , I finished it twice in total . The first time took fourorfive days , We managed to do something reluctantly , The basic functions have been realized , But what? , A big disadvantage is that all the code is written together , It looks very messy , Dazzling , Um. , The most important thing is that I'm afraid the teacher will faint ^ _ ^ .
therefore , forehead , In fact, at the beginning, I didn't have the idea of doing the second time . I mainly saw an article written by others , What he did is a similar system , After reading his code, I sincerely feel that my code is too much . Why is it the same person , He can write such neat code ? therefore , After a heavy blow , I finished reading all his codes . After watching the , Learned a lot , So the idea of doing the second time was born .
In fact, the functions of the second pass and the first pass are the same , Just the code looks cleaner . Mainly, it looks a little more professional ^_^.
Well, a lot of wordiness , Thank you for your patience to see here , Next, the text begins !
Text :
The overview : The system code is mainly divided into three parts .
1. Header file section (system .h)
2. Interface part (test.cpp)
3. Main functions (systemfunc.cpp)
The tool used is VS2015 . more goto function .
One : Header file section (system .h)
The header file part mainly includes header files of some common functions , Such as : Clear the screen , Pause and wait . Using macro definitions can save some time , Don't repeatedly type the same code . Define the member structure , To store data .book There are two variables in the structure , Namely date and count , That is, data and total .book The function of structure is to make it easier to manage data . An enumeration type is also defined , In the interface . Finally, the function declaration .
Here is the code :
#pragma once
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<Windows.h>
#define C system("cls") // Clear the screen
#define S(x) Sleep(x) // Pause
#define LEN 20
#define Max 1000
typedef struct num
{
char number[LEN];
char name[LEN];
double price;
int stock;
char tpye[10];
}num;
typedef struct book
{
num date[Max];
int count;
}book;
enum conmenu
{
sign out ,
add to ,
Inquire about ,
modify ,
Delete ,
Statistics ,
format ,
};
void Add(book* p);
void AddFromText(book *p);
void Hello();
void Search(book *p);
void Change(book *p);
void Del(book *p);
void Sort(book *p);
void Sort0(char m[], book *p);
void DelAll(book *p);
void Show(book *p);
void save(book* p);
void Bye();
Two : Interface part (test.cpp)
The interface part is main Function part . Contains the main page 、 Initialization and function selection module before entering the system . Initialization before entering the system refers to reading data from the file and storing it in the structure .
#include"system.h"
void menu(book *p)
{
printf(" Commodity information management system \n");
printf(" ----------------------------------------------------------\n");
printf(" 1) Add product information \n");
printf(" 2) Query product information \n");
printf(" 3) Modify inventory \n");
printf(" 4) Delete product information \n");
printf(" 5) Statistical function \n");
printf(" 6) format \n");
printf(" 0) sign out \n");
printf(" The current is %d A commodity .\n", p->count);
printf(" ----------------------------------------------------------\n");
}
int main()
{
int input;
book con;
AddFromText(&con); //(1)
Hello(); //(2)
do
{
menu(&con);
printf(" Please select :");
scanf("%d", &input);
switch (input) //(3)
{
case sign out :
Bye();
break;
case add to :
Add(&con);
break;
case Inquire about :
Search(&con);
break;
case modify :
Change(&con);
break;
case Delete :
Del(&con);
break;
case Statistics :
Sort(&con);
break;
case format :
DelAll(&con);
break;
default:
C;
printf("error! ! ! Please enter a valid instruction .\n");
Sleep(1500);
C;
};
} while (input);
save(&con); //(4)
return 0;
}
*(1) Read the data from the corresponding file and store it in the structure , As an initialization operation into the system
*(2) The welcome screen
*(3) Function selection module
*(4) Exit the saving operation of the system , That is to rewrite the modified data into the file
(1)、(3) It's all file manipulation , If there is no operation of the file part , Then every time you enter the system, you have to re-enter all the information of the product . Because all memory will be released after the program terminates . With the file, the data can be stored in the file , The next time you use the system, you can directly get the last saved data from the file , No need to re-enter the product information . It is equivalent to realizing a simple local saving .
The following is the specific code of file operation :
AddFromText function :
void AddFromText( book *p) {
FILE *fp ;
if ((fp = fopen("GoodsImformation.txt", "r")) == NULL) {
FILE *fp = fopen("GoodsImformation.txt", "w");
fprintf(fp, "%d\n", 0);
printf(" An error occurred , Please try again !\n");
S(2000);
exit(0);
} //(1)
fscanf(fp, "%d\n", &p->count); //(2)
for (int j = 0; j < p->count; j++) {
fscanf(fp, "%s %s %lf %d %s\n", p->date[j].number, p->date[j].name, &p->date[j].price, &p->date[j].stock, p->date[j].tpye);
} //(3)
fclose(fp); //(4)
}
*(1) If the specified file cannot be opened , Note that there is no such document , Then create a new file , Format and output a 0 Into the file , Prompt to retry , And then terminate the program . When it turns on again , The files exist , Because it was built last time , And there is one in the file 0, Represents no goods . This initializes successfully .
*(2) Enter the total number of products from the file .
*(3) Enter the product information from the file .
*(4) Close file .
save function :
void save( book* p) {
FILE* fp = fopen("GoodsImformation.txt", "w");
fprintf(fp, "%d\n", p->count); //(1)
for (int j = 0; j < p->count; j++) {
fprintf(fp, "%s %s %lf %d %s\n", p->date[j].number, p->date[j].name, p->date[j].price, p->date[j].stock, p->date[j].tpye);
} //(2)
fclose(fp); //(3)
}
*(1) Format the total number of output products to the file .
*(2) Format and output product information to file .
*(3) Close file .
3、 ... and : Main functions (systemfunc.cpp)
Overview of all functions :
1. add to
2. Inquire about
3. modify
4. Delete
5. Statistics
6. format
7. sign out
This part is the core part . Basically, a function corresponds to a function .
1. Add functionality
Realization principle : Input the product information from the keyboard and save it to the structure .
The code is as follows :
void Add(book* p) {
C;
again11:
printf("< Adding ...>\n*");
printf(" Please enter the item number :"); //(1)
scanf("%s", p->date[p->count].number);
printf(" Please enter the product name :");
scanf("%s", p->date[p->count].name);
printf(" Please enter the unit price :");
scanf("%lf", &p->date[p->count].price);
printf(" Please enter the item inventory :");
scanf("%d", &p->date[p->count].stock);
printf(" Please enter the product type :");
scanf("%s", p->date[p->count].tpye);
p->count += 1; //(2)
Sleep(1000);
save(p);
printf(" Add to complete .\n");
int a;
Sleep(500);
again:
printf(" 1) Continue to add 2) Go back to the home page \n");
scanf("%d", &a);
if (a == 1) {
C;
goto again11;
}
else {
if (a == 2) {
system("cls");
return;
}
else {
printf("error!\n");
goto again;
}
}
}
*(1) Enter product information .
*(2) Total goods plus 1 .
2. Query function
Realization principle : use strcmp Function to traverse the structure array .
The code is as follows :
void Search(book *p) {
again0:
C;
printf("< Query operation in progress ...>\n*");
printf(" Please enter the product number to query :");
char temp[20];
int cnt = 0;
scanf("%s", temp);
for (int z = 0; z < p->count; z++) { //(1)
if (strcmp(temp, p->date[z].number) == 0) {
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[z].number, p->date[z].name, p->date[z].price, p->date[z].stock, p->date[z].tpye);
cnt++;
break;
}
}
if (cnt == 0) { //(2)
printf(" No such product !\n");
}
again1:
printf(" Continue to query ?\n");
printf(" 1) continue \n");
printf(" 2) Back to the front page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again0;
}
else {
if (b == 2) {
system("cls");
return;
}
else {
printf("error!\n");
goto again1;
}
}
}
*(1) Traverse , Output corresponding information .
*(2)cnt==0 Means not found .
3. Modify the function
Realization principle : Re input and overwrite the original data .
The code is as follows :
void Change(book *p) {
again2:
C;
if (p->count == 0) { //(1)
printf(" No goods , Unable to modify !\n");
S(2500);
return;
}
printf("< Modification in progress ...>\n*");
Show(p);
printf(" Please enter the item number to be modified :");
char temp[20];
int cnt = 0;
scanf("%s", temp);
for (int z = 0; z < p->count; z++) { //(2)
if (strcmp(temp, p->date[z].number) == 0) {
cnt++;
break;
}
}
if (cnt == 0) { //(3)
printf(" Item does not exist !\n");
Sleep(1000);
again4:
printf(" 1) Continue to find 2) Back to the front page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again2;
}
else {
if (b == 2) {
system("cls");
return;
}
else {
printf("error!\n");
Sleep(1000);
goto again4;
}
}
}
else {
int t;
for (int z = 0; z < p->count; z++) {
if (strcmp(temp, p->date[z].number) == 0) {
t = z;
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[z].number, p->date[z].name, p->date[z].price, p->date[z].stock, p->date[z].tpye);
printf(" Please enter the modified inventory :");
scanf("%d", &p->date[z].stock); //(4)
Sleep(1000);
printf(" Modification successful !");
break;
}
}
save(p);
Sleep(800);
printf(" The modified data is :\n");
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[t].number, p->date[t].name, p->date[t].price, p->date[t].stock, p->date[t].tpye);
Sleep(2000);
again5:
printf(" Continue to find ?\n");
printf(" 1) continue \n");
printf(" 2) Back to the front page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again2;
}
else {
if (b == 2) {
system("cls");
return;
}
else {
printf("error!\n");
Sleep(1000);
goto again5;
}
}
}
}
*(1) No goods , Do not modify , direct return.
*(2) Traverse to find whether there is any product to modify .
*(3)cnt==0 It means that the goods do not exist .
*(4) Re enter the information to be modified and overwrite the original value .
4. Delete function
Realization principle : It also uses coverage , Copy the last product information to the location to be deleted , The total number of goods can be reduced by one .
void Del(book *p) {
char temp1[LEN];
char temp2[LEN];
int cnt = 0;
int t;
again7:
C;
if (p->count == 0) { //(1)
printf(" No goods , Unable to delete !\n");
S(2500);
return;
}
printf("< Deleting operation in progress ...>\n");
Show(p);
printf("* Please enter the item number to be deleted :");
scanf("%s", temp1);
printf("* Please enter the product name to be deleted :");
scanf("%s", temp2);
for (int z = 0; z < p->count; z++) { //(2)
if (strcmp(temp1, p->date[z].number) == 0 && strcmp(temp2, p->date[z].name) == 0) {
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[z].number, p->date[z].name, p->date[z].price, p->date[z].stock, p->date[z].tpye);
t = z;
cnt++;
break;
}
}
if (cnt == 0) { //(3)
printf(" Item does not exist or The number and name do not match !\n");
Sleep(1000);
again8:
printf(" Continue to delete function ?\n");
printf(" 1) continue \n");
printf(" 2) Back to the front page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again7;
}
else {
if (b == 2) {
system("cls");
return;
}
else {
printf("error!\n");
goto again8;
}
}
}
else {
printf(" Are you sure you want to delete !\n");
printf(" 1) yes \n");
printf(" 0) no \n");
int c;
scanf("%d", &c);
if (c == 1) { //(4)
strcpy(p->date[t].number, p->date[p->count-1].number);
strcpy(p->date[t].name, p->date[p->count - 1].name);
p->date[t].price = p->date[p->count - 1].price;
p->date[t].stock = p->date[p->count - 1].stock;
strcpy(p->date[t].tpye, p->date[p->count - 1].tpye);
p->count--;
Sleep(1000);
save(p);
printf(" deleted !\n");
Sleep(800);
goto again8;
}
else {
Sleep(1000);
goto again8;
}
}
}
*(1) No goods , Can't delete .
*(2) Traverse to find whether there are products to be deleted .
*(3)cnt==0 Indicates that there is no such product .
*(4) This step is the core of deletion . Variable t Record the location of the item to be deleted , Then copy the last product information to t That's where it is .p->count - 1 The location of is the location of the last product information . The last save .
5. Statistics module
So far, the most basic functions of adding, deleting, checking and modifying have been basically realized , The statistics module is too verbose because it writes multiple functions in the same function , I'm not going to go into the code .
6. format
Realization principle : Let the total number of goods be 0, And write it to a file .
The code is as follows :
void DelAll(book *p) {
again30:
C;
printf("< Formatting operation in progress ...>\n*");
printf(" Please make sure the !!!\n");
int a;
printf(" 1) confirm 2) Cancel and return to \n");
scanf("%d", &a);
if (a == 1) {
S(800);
FILE* fp = fopen("GoodsImformation.txt", "w");
p->count = 0; //(1)
fprintf(fp, "%d\n", p->count); //(2)
fclose(fp); //(3)
printf(" Formatting ......\n");
printf("\n");
S(1500);
printf(" Format successful ! \n");
S(3000);
C;
return;
}
else {
if (a == 2) {
C;
return;
}
else {
printf("error!\n");
S(1500);
goto again30;
}
}
}
*(1) The total number of goods is assigned 0.
*(2) Write it to a file . Equivalent to saving locally .
*(3) Finally close the file .
7. sign out
Out of the loop , Save the data and terminate the program . Check in the interface section , No corresponding function .
System rendering :
The complete code is as follows :
1. Header file section (system .h)
#pragma once
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<Windows.h>
#define C system("cls") // Clear the screen
#define S(x) Sleep(x) // Pause
#define LEN 20
#define Max 1000
typedef struct num
{
char number[LEN];
char name[LEN];
double price;
int stock;
char tpye[10];
}num;
typedef struct book
{
num date[Max];
int count;
}book;
enum conmenu
{
sign out ,
add to ,
Inquire about ,
modify ,
Delete ,
Statistics ,
format ,
};
void Add(book* p);
void AddFromText(book *p);
void Hello();
void Search(book *p);
void Change(book *p);
void Del(book *p);
void Sort(book *p);
void Sort0(char m[], book *p);
void DelAll(book *p);
void Show(book *p);
void save(book* p);
void Bye();
2. Interface part (test.cpp)
#include"system.h"
void menu(book *p)
{
printf(" Commodity information management system \n");
printf(" ----------------------------------------------------------\n");
printf(" 1) Add product information \n");
printf(" 2) Query product information \n");
printf(" 3) Modify inventory \n");
printf(" 4) Delete product information \n");
printf(" 5) Statistical function \n");
printf(" 6) format \n");
printf(" 0) sign out \n");
printf(" The current is %d A commodity .\n", p->count);
printf(" ----------------------------------------------------------\n");
}
int main()
{
int input;
book con;
AddFromText(&con); //(1)
Hello(); //(2)
do
{
menu(&con);
printf(" Please select :");
scanf("%d", &input);
switch (input) //(3)
{
case sign out :
Bye();
break;
case add to :
Add(&con);
break;
case Inquire about :
Search(&con);
break;
case modify :
Change(&con);
break;
case Delete :
Del(&con);
break;
case Statistics :
Sort(&con);
break;
case format :
DelAll(&con);
break;
default:
C;
printf("error! ! ! Please enter a valid instruction .\n");
Sleep(1500);
C;
};
} while (input);
save(&con); //(4)
return 0;
}
3. Main functions (systemfunc.cpp)
#include"system.h"
void AddFromText( book *p) {
FILE *fp ;
if ((fp = fopen("GoodsImformation.txt", "r")) == NULL) {
FILE *fp = fopen("GoodsImformation.txt", "w");
fprintf(fp, "%d\n", 0);
printf(" An error occurred , Please try again !\n");
S(2000);
exit(0);
} //(1)
fscanf(fp, "%d\n", &p->count); //(2)
for (int j = 0; j < p->count; j++) {
fscanf(fp, "%s %s %lf %d %s\n", p->date[j].number, p->date[j].name, &p->date[j].price, &p->date[j].stock, p->date[j].tpye);
} //(3)
fclose(fp); //(4)
}
void Hello() {
printf(" ----------------------------------------------------------\n");
printf(" \n");
printf(" \n");
printf(" Welcome to this system !\n");
printf(" \n");
printf(" \n");
printf(" \n");
printf(" ----------------------------------------------------------\n");
Sleep(3000);
C;
}
void Add(book* p) {
C;
again11:
printf("< Adding ...>\n*");
printf(" Please enter the item number :"); //(1)
scanf("%s", p->date[p->count].number);
printf(" Please enter the product name :");
scanf("%s", p->date[p->count].name);
printf(" Please enter the unit price :");
scanf("%lf", &p->date[p->count].price);
printf(" Please enter the item inventory :");
scanf("%d", &p->date[p->count].stock);
printf(" Please enter the product type :");
scanf("%s", p->date[p->count].tpye);
p->count += 1; //(2)
Sleep(1000);
save(p);
printf(" Add to complete .\n");
int a;
Sleep(500);
again:
printf(" 1) Continue to add 2) Go back to the home page \n");
scanf("%d", &a);
if (a == 1) {
C;
goto again11;
}
else {
if (a == 2) {
system("cls");
return;
}
else {
printf("error!\n");
goto again;
}
}
}
void Search(book *p) {
again0:
C;
printf("< Query operation in progress ...>\n*");
printf(" Please enter the product number to query :");
char temp[20];
int cnt = 0;
scanf("%s", temp);
for (int z = 0; z < p->count; z++) { //(1)
if (strcmp(temp, p->date[z].number) == 0) {
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[z].number, p->date[z].name, p->date[z].price, p->date[z].stock, p->date[z].tpye);
cnt++;
break;
}
}
if (cnt == 0) { //(2)
printf(" No such product !\n");
}
again1:
printf(" Continue to query ?\n");
printf(" 1) continue \n");
printf(" 2) Back to the front page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again0;
}
else {
if (b == 2) {
system("cls");
return;
}
else {
printf("error!\n");
goto again1;
}
}
}
void Change(book *p) {
again2:
C;
if (p->count == 0) { //(1)
printf(" No goods , Unable to modify !\n");
S(2500);
return;
}
printf("< Modification in progress ...>\n*");
Show(p);
printf(" Please enter the item number to be modified :");
char temp[20];
int cnt = 0;
scanf("%s", temp);
for (int z = 0; z < p->count; z++) { //(2)
if (strcmp(temp, p->date[z].number) == 0) {
cnt++;
break;
}
}
if (cnt == 0) { //(3)
printf(" Item does not exist !\n");
Sleep(1000);
again4:
printf(" 1) Continue to find 2) Back to the front page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again2;
}
else {
if (b == 2) {
system("cls");
return;
}
else {
printf("error!\n");
Sleep(1000);
goto again4;
}
}
}
else {
int t;
for (int z = 0; z < p->count; z++) {
if (strcmp(temp, p->date[z].number) == 0) {
t = z;
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[z].number, p->date[z].name, p->date[z].price, p->date[z].stock, p->date[z].tpye);
printf(" Please enter the modified inventory :");
scanf("%d", &p->date[z].stock); //(4)
Sleep(1000);
printf(" Modification successful !");
break;
}
}
save(p);
Sleep(800);
printf(" The modified data is :\n");
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[t].number, p->date[t].name, p->date[t].price, p->date[t].stock, p->date[t].tpye);
Sleep(2000);
again5:
printf(" Continue to find ?\n");
printf(" 1) continue \n");
printf(" 2) Back to the front page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again2;
}
else {
if (b == 2) {
system("cls");
return;
}
else {
printf("error!\n");
Sleep(1000);
goto again5;
}
}
}
}
void Del(book *p) {
char temp1[LEN];
char temp2[LEN];
int cnt = 0;
int t;
again7:
C;
if (p->count == 0) { //(1)
printf(" No goods , Unable to delete !\n");
S(2500);
return;
}
printf("< Deleting operation in progress ...>\n");
Show(p);
printf("* Please enter the item number to be deleted :");
scanf("%s", temp1);
printf("* Please enter the product name to be deleted :");
scanf("%s", temp2);
for (int z = 0; z < p->count; z++) { //(2)
if (strcmp(temp1, p->date[z].number) == 0 && strcmp(temp2, p->date[z].name) == 0) {
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[z].number, p->date[z].name, p->date[z].price, p->date[z].stock, p->date[z].tpye);
t = z;
cnt++;
break;
}
}
if (cnt == 0) { //(3)
printf(" Item does not exist or The number and name do not match !\n");
Sleep(1000);
again8:
printf(" Continue to delete function ?\n");
printf(" 1) continue \n");
printf(" 2) Back to the front page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again7;
}
else {
if (b == 2) {
system("cls");
return;
}
else {
printf("error!\n");
goto again8;
}
}
}
else {
printf(" Are you sure you want to delete !\n");
printf(" 1) yes \n");
printf(" 0) no \n");
int c;
scanf("%d", &c);
if (c == 1) { //(4)
strcpy(p->date[t].number, p->date[p->count-1].number);
strcpy(p->date[t].name, p->date[p->count - 1].name);
p->date[t].price = p->date[p->count - 1].price;
p->date[t].stock = p->date[p->count - 1].stock;
strcpy(p->date[t].tpye, p->date[p->count - 1].tpye);
p->count--;
Sleep(1000);
save(p);
printf(" deleted !\n");
Sleep(800);
goto again8;
}
else {
Sleep(1000);
goto again8;
}
}
}
void Sort(book *p) {
again21:
C;
printf("< Statistics operation is in progress ...>\n");
printf(" Please select the statistical method :\n");
printf(" 1) Count the total number of goods of a certain type \n");
printf(" 2) See all the products \n");
printf(" 3) Sort the unit price of goods of the same type \n");
printf(" 0) Go back to the home page \n");
int a;
int cnt = 0;
scanf("%d", &a);
if (a == 1) {
char temp[LEN];
again20:
cnt = 0;
printf(" Please enter a product type :");
scanf("%s", temp);
for (int z = 0; z < p->count; z++) {
if (strcmp(temp, p->date[z].tpye) == 0) {
cnt++;
}
}
if (cnt == 0) {
printf(" No such product type !\n");
Sleep(2000);
again22:
printf(" 1) Re input 2) Cancel and return to the previous page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again20;
}
else {
if (b == 2) {
goto again21;
}
else {
printf("error! \n");
Sleep(1500);
goto again22;
}
}
}
else {
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
for (int z = 0; z < p->count; z++) {
if (strcmp(temp, p->date[z].tpye) == 0) {
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[z].number, p->date[z].name, p->date[z].price, p->date[z].stock, p->date[z].tpye);
}
}
printf(" The total number of goods of this type is %d. \n", cnt);
Sleep(800);
again24:
printf(" 1) Re input 2) Cancel and return to the previous page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again20;
}
else {
if (b == 2) {
goto again21;
}
else {
printf("error! \n");
Sleep(1500);
goto again24;
}
}
}
}
else {
if (a == 2) {
printf(" Loading ......");
Sleep(2000);
printf("\n");
Show(p);
again26:
printf(" 1) Back to previous page \n");
int c;
scanf("%d", &c);
if (c == 1) {
goto again21;
}
else {
printf("error! \n");
Sleep(1500);
goto again26;
}
}
else {
if (a == 3) {
char temp[LEN];
again40:
cnt = 0;
printf(" Please enter a product type :");
scanf("%s", temp);
for (int z = 0; z < p->count; z++) {
if (strcmp(temp, p->date[z].tpye) == 0) {
cnt++;
}
}
if (cnt == 0) {
printf(" No such product type !\n");
Sleep(2000);
again42:
printf(" 1) Re input 2) Cancel and return to the previous page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again40;
}
else {
if (b == 2) {
goto again21;
}
else {
printf("error! \n");
Sleep(1500);
goto again42;
}
}
}
else {
Sort0(temp, p);
Sleep(800);
again44:
printf(" 1) Re input 2) Cancel and return to the previous page \n");
int b;
scanf("%d", &b);
if (b == 1) {
goto again40;
}
else {
if (b == 2) {
goto again21;
}
else {
printf("error! \n");
Sleep(1500);
goto again44;
}
}
}
}
else {
if (a == 0) {
system("cls");
return;
}
else {
printf("error!\n");
S(2000);
goto again21;
}
}
}
}
}
void Sort0(char m[], book *p) {
int min;
char temp[LEN];
double t0;
int t1;
for (int z = 0; z < p->count; z++) {
min = p->date[z].price;
for (int k = z; k < p->count; k++) {
if (p->date[k].price < min) {
t0 = min;
min = p->date[k].price;
p->date[z].price = p->date[k].price;
p->date[k].price = t0;
t1 = p->date[z].stock;
p->date[z].stock = p->date[k].stock;
p->date[k].stock = t1;
strcpy(temp, p->date[z].name);
strcpy(p->date[z].name, p->date[k].name);
strcpy(p->date[k].name, temp);
strcpy(temp, p->date[z].number);
strcpy(p->date[z].number, p->date[k].number);
strcpy(p->date[k].number, temp);
strcpy(temp, p->date[z].tpye);
strcpy(p->date[z].tpye, p->date[k].tpye);
strcpy(p->date[k].tpye, temp);
}
}
}
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
for (int z = 0; z < p->count; z++) {
if ((strcmp(m, p->date[z].tpye)) == 0) {
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[z].number, p->date[z].name, p->date[z].price, p->date[z].stock, p->date[z].tpye);
}
}
AddFromText(p);
}
void DelAll(book *p) {
again30:
C;
printf("< Formatting operation in progress ...>\n*");
printf(" Please make sure the !!!\n");
int a;
printf(" 1) confirm 2) Cancel and return to \n");
scanf("%d", &a);
if (a == 1) {
S(800);
FILE* fp = fopen("GoodsImformation.txt", "w");
p->count = 0; //(1)
fprintf(fp, "%d\n", p->count); //(2)
fclose(fp); //(3)
printf(" Formatting ......\n");
printf("\n");
S(1500);
printf(" Format successful ! \n");
S(3000);
C;
return;
}
else {
if (a == 2) {
C;
return;
}
else {
printf("error!\n");
S(1500);
goto again30;
}
}
}
void Show(book *p) {
if (p->count > 0) {
printf("------------------------------------------------------------\n");
printf(" Number name The unit price stock type \n");
}
for (int z = 0; z < p->count; z++) {
printf("%-13s %-13s %-13.2lf %-13d %-13s\n", p->date[z].number, p->date[z].name, p->date[z].price, p->date[z].stock, p->date[z].tpye);
}
printf("------------------------------------------------------------\n");
Sleep(800);
printf(" The total number of goods is %d. \n", p->count);
Sleep(500);
}
void save( book* p) {
FILE* fp = fopen("GoodsImformation.txt", "w");
fprintf(fp, "%d\n", p->count); //(1)
for (int j = 0; j < p->count; j++) {
fprintf(fp, "%s %s %lf %d %s\n", p->date[j].number, p->date[j].name, p->date[j].price, p->date[j].stock, p->date[j].tpye);
} //(2)
fclose(fp); //(3)
}
void Bye()
end !!!
边栏推荐
- TinyMCE visual editor adds Baidu map plug-in
- Market Research - current market situation and future development trend of aircraft audio control panel system
- Market Research - current market situation and future development trend of high tibial osteotomy plate
- Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
- [Jianzhi offer] 57 And are two numbers of S
- 腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
- 在beforeDestroy中销毁localStorage中的值无效
- Market Research - current situation and future development trend of environmental friendly fireworks Market
- [shutter] shutter gesture interaction (small ball following the movement of fingers)
- New feature of go1.18: introduce new netip Network Library
猜你喜欢
The difference between include < > and include ""
Perceptron model and Application
phpcms实现订单直接支付宝支付功能
"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"
C language, to achieve three chess games
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
Reading experience of just because
LandingSite eBand B1冒烟测试用例
How do I access the kubernetes API?
随机推荐
[shutter] shutter gesture interaction (click event handling | click OnTap | double click | long press | click Cancel | press ontapdown | lift ontapup)
Lightgbm principle and its application in astronomical data
Market Research - current market situation and future development trend of aircraft front wheel steering system
What "real skills" should a million year old cloud native developer master? Alibaba, Tencent, meituan and byte decrypt together
Gee: (II) resampling the image
数据库系统概论第一章简答题-期末考得怎么样?
PHP微信抢红包的算法
[sword finger offer] 56 - I. the number of numbers in the array
Market Research - current market situation and future development trend of total nutrition products
[C question set] of V
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
Etcd raft protocol
【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
Unity3d learning notes 4 - create mesh advanced interface
tinymce可视化编辑器增加百度地图插件
Try to get property'num for PHP database data reading_ rows' of non-object?
Interpretation of CVPR paper | generation of high fidelity fashion models with weak supervision
Oriental Aesthetics and software design
Ransack combined condition search implementation
如何访问kubernetes API?