本文目錄一覽:
用c語言製作商店商品管理系統
#include stdio.h
#include conio.h
#include bios.h
#include dos.h
#include malloc.h
#define NULL 0
#define LEN sizeof(struct mcd)
struct data /*聲明一個日期的結構體類型*/
{
int year;
int month;
int day;
};
struct mcd /*聲明有關商品信息的結構體類型*/
{
int code; /*編 號*/
char name[12]; /*品 名*/
long price; /*單 價*/
int num; /*數 量*/
char place[20]; /*產 地*/
struct data putdate; /*入庫時間*/
struct data selldate; /*銷售時間*/
struct mcd * next; /*運用指針處理鏈表*/
};
int n; /*記錄鏈表有幾條數據*/
struct mcd *head; /*聲明鏈表頭的指針*/
creat() /*輸入商品信息的函數*/
{
struct mcd *p1,*p2;
n=0;
p1=p2=(struct mcd *)malloc(LEN); /*開闢一個新單元存放信息*/
head=p1;
loop: {
clrscr();
printf(“商品錄入系統\n”);
printf(“錄入號:%d\n”,n+1);
printf(“編 碼:”);
scanf(“%d”,p1-code);
printf(“品 名:”);
scanf(“%s”,p1-name);
printf(“單 價:”);
scanf(“%ld”,p1-price);
printf(“數 量:”);
scanf(“%d”,p1-num);
printf(“產 地:”);
scanf(“%s”,p1-place);
printf(“入庫時間:”);
scanf(“%d-%d-%d”,p1-putdate.year,p1-putdate.month,p1-putdate.day);
}
while(p1-num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2-next=p1;
p2=p1;
p1=(struct mcd *)malloc(LEN);
goto loop;
}
p2-next=NULL;
main();
}
print() /*輸出數據列表的函數*/
{
int m=0;
struct mcd *p;
clrscr();
printf(“編 號||品 名||單 價||數 量|| 產 地 ||入 庫 時 間\n”);
p=head;
if(head!=NULL)
do
{
printf(“%-10d%-14s%-12ld%-10d%-22s%-4d-%-2d-%-2d\n”,p-code,p-name,p-price,p-num,p-place,p-putdate.year,p-putdate.month,p-putdate.day);
p=p-next;
m=m+1;
if(m%23==0){gotoxy(10,25);printf(“按任意鍵繼續.”);getch();}
}while(p!=NULL);
getch();
main();
}
sell()
{
int code,m=3,ch;
long sum=0;
struct mcd *p1;
struct date today;
getdate(today);
clrscr();
printf(“商品銷售系統\n”);
printf(“編 號||||品 名|||| 產 地 ||||單 價(元)||||出 售 時 間\n”);
loop:
do{
gotoxy(23,25);
printf(“按任意鍵繼續,F2結帳,ESC鍵退出”);
ch=bioskey(0);
}while(0);
switch(ch)
{
case 15360:{
if(sum==0)
{
gotoxy(1,m);printf(“還沒有購買商品!”);
getch();
sell();
break;
}
else {
gotoxy(1,m);
printf(“——————————————————————————“);
gotoxy(47,m+1);
printf(“總價: %-12ld元”,sum);
getch();
main();
break;
}
}
case 283:{main();break;}
default:
{
gotoxy(23,25);
printf(“請輸入商品編碼,會顯示商品信息”);
gotoxy(1,m);
scanf(“%d”,code);
if(head==NULL)
{
printf(“你還沒有進貨.”);
getch();
main();
break;
}
p1=head;
while(code!=p1-codep1-next!=NULL)
{p1=p1-next;}
if(code==p1-code)
{
gotoxy(13,m);
printf(“%-16s%-24s%-16ld%4d-%2d-%2d”,p1-name,p1-place,p1-price,today.da_year,today.da_mon,today.da_day);
m=m+1;
p1-num=p1-num-1;
sum=sum+p1-price;
}
}
goto loop;
}
}
go()
{
int ch;
clrscr();
printf(“請問你要進行什麼操作?\n1,插入;2,刪除;3,什麼也不做;\n”);
loop:
do{
ch=bioskey(0);
}while(0);
switch(ch)
{
case 561:insert();break;
case 818:del();break;
case 1075:main();break;
case 283:break;
default:{gotoxy(1,3);printf(“請按數字鍵選擇!”);goto loop;}
}
getch();
main();
}
insert()
{
struct mcd *p0,*p1,*p2;
p0=p1=p2=(struct mcd*)malloc(LEN);
p1=head;
clrscr();
printf(“請輸入要插入的商品的信息:\n”);
printf(“編 碼:”);
scanf(“%d”,p0-code);
printf(“品 名:”);
scanf(“%s”,p0-name);
printf(“單 價:”);
scanf(“%ld”,p0-price);
printf(“數 量:”);
scanf(“%d”,p0-num);
printf(“產 地:”);
scanf(“%s”,p0-place);
printf(“入庫時間:”);
scanf(“%d-%d-%d”,p0-putdate.year,p0-putdate.month,p0-putdate.day);
if(head==NULL)
{
head=p0;
p0-next=NULL;
}
else
{
while((p0-codep1-code)(p1-next!=NULL))
{
p2=p1;
p1=p1-next;
}
if(p0-code=p1-code)
{
if(head==p1)head=p0;
else p2-next=p0;
p0-next=p1;
}
else
{
p1-next=p0;p0-next=NULL;
}
}
n=n+1;
print();
}
del()
{
int code;
struct mcd *p1,*p2;
clrscr();
printf(“請輸入要刪除商品的編號:”);
scanf(“%d”,code);
if(head==NULL)
{
printf(“你還沒有進貨.”);
getch();
main();
}
p1=head;
while(code!=p1-codep1-next!=NULL)
{
p2=p1;
p1=p1-next;
}
if(code==p1-code)
{
if(code==head)head=p1-next;
else p2-next=p1-next;
n=n-1;
print();
}
else
{
printf(“找不到這條商品信息.”);
getch();
print();
}
}
main()
{
do{
clrscr();
printf(” . : : \n”);
printf(” ‘. :””””: : : :””:””:\n”);
printf(” ‘. : : :””” :””” : : :\n”);
printf(” ……………. : : :’, :’, ””’:””’: : :\n”);
printf(” ‘. .’ : : : ‘, : ‘, : :….:….:\n”);
printf(” ‘. .’ : : ,’ ,’ : : : :\n”);
printf(” ‘.’ : : ‘, : : : :\n”);
printf(“………:……….. :……..: : ‘, : :….:….:\n”);
printf(” …………… :”””””””’: ””:”” : \n”);
printf(” : , , : :”””: :”””: ,’ : : \n”);
printf(” : , , : : : : : :””””’: : ,’ : \n”);
printf(” : , , : : : : : : : : ,’ ….:…. \n”);
printf(” :, :”””’: : : : : : : : :,’ : \n”);
printf(” : : : : : : : : :””””” ,’ : \n”);
printf(” : : : : : : : : :………. ,’ : \n”);
printf(” : :…….: : : : : : : : ‘ : \n”);
printf(” : : : : : : : : ……:…..\n”);
printf(” : ..: :……: :……: :………: \n”);
gotoxy(60,19);
printf(“趙飛宇製造 V1.0”);
gotoxy(10,21);
printf(“1,銷售系統;2,進貨系統;3,查看列表;4,插入刪除;5,銷售盈虧;6,幫助文檔”);
gotoxy(32,24);
printf(“按ESC鍵退出”);
key();
}while(0);
}
key()
{
int ch;
loop:
do{
ch=bioskey(0);
}while(0);
switch(ch)
{
case 561:sell();break;
case 818:creat();break;
case 1075:print();break;
case 1332:go();break;
case 283:break;
default:
{
gotoxy(30,22);
printf(“請按數字鍵選擇!”);
goto loop;
}
}
}
怎樣用C語言製作學生信息管理系統
還真不想再寫代碼了啊。。。。。
直接跟你說下思路吧。。。。
首先創建一個結構體,如——
struct student
{
char num[10]; //學號
char name[20]; //姓名
char sex[4]; //性別
int age; //年齡
int flag; //一個標示符(下面會說用法)
};
然後就定義一個student類型的數組stu[max],在前面#define max 1000000,你也可以把max定義得小一點,這是用來表示最大能容納多少個學生信息。。。。
說到flag的用處,我不清楚你了不了解,還是先跟你說下吧。。。。
先考一下你,知道怎樣把一個數組裏面的某一個元素清空嗎?清空就表示能在那個位置再次賦值,沒清空的位置就不能重複賦值。把那個元素設為a[x],可能你會想着把a[x]=0不就得啦,那好,如果用這種方法,那麼如果你想尋找數組a中可以再次賦值的元素,然後進行賦值,你是不是要通過一個判別式來對數組a的每一個元素進行判斷,看看它是否能被再賦值,對吧,那這個判別式肯定就是判斷a中的數值是否為零了。但是你想一下,如果一開始a中某個元素的值就是等於0,並不表示清空狀態,那你這樣的判別式能成立嗎,所以我們要用到一個標示符flag。。。。
當flag=1時,表示該數組的元素已存在,當flag=0時,表示該數組的元素是無效的,這樣的話就不需要對數組中的每個元素進行什麼清空操作了,就像上面的數組stu,這麼多元素,你怎麼清空。。。。
然後有一個最重要的是怎樣存儲數據,因為沒用到數據庫,所以就用txt文件來存儲吧,給你一個相關的代碼——
int load_student() //把已存在的儲存數據的txt文件打開
{
FILE *fp;
if((fp=fopen(“student.txt”,”rb”))==NULL) //判斷文件是否存在
{
printf(“不能打開此文件.\n”);
exit(0);
}
for(int i=0;iSIZE;i++) //存在的話就打開它
{
fread(stu[i],sizeof(struct student),1,fp);
}
fclose(fp);
return 0;
}
int save_student() //把數據存放進txt文件中
{
FILE *fp;
if((fp=fopen(“student.txt”,”wb”))==NULL)
{
printf(“不能打開此文件.\n”);
exit(0);
}
for(int i=0;iSIZE;i++)
{
fwrite(stu[i],sizeof(struct student),1,fp);
}
fclose(fp);
return 0;
}
這是一個比較基本的代碼,你可以靈活的修改一下,實現讀寫過程的代碼也就是這樣了。。。。
然後是功能的實現,這方面就得看你的要求了,不過我建議你把每個界面做成一個函數,實現模塊化,如——
int shouye() //首頁
{
system(“cls”); //清屏
int num1;
printf(“**********************************\n”);
printf(” 學生信息管理系統 \n”);
printf(“**********************************\n”);
printf(“\n\n”);
printf(“1、更改學生信息\n\n”);
printf(“2、查看學生信息\n\n”);
printf(“3、退出系統\n\n”);
scanf(“%d”,num1); //輸入操作
if(num1==1)
update(); //進入學生信息更改模塊
else if(num1==2)
check(); //進入學生信息查看模塊
else
exit(0); //退出系統
return 0;
}
在給多你一個界面函數的代碼吧——
int update()
{
system(“cls”);
int num2;
printf(“**********************************\n”);
printf(” 更改成績 \n”);
printf(“**********************************\n”);
printf(“\n\n”);
printf(“1、增加學生信息\n\n”);
printf(“2、修改學生信息\n\n”);
printf(“3、返回上一層\n\n”);
scanf(“%d”,num2);
if(num2==1)
add();
else if(num2==2)
correct();
else
shouye();
return 0;
}
大概就是這種模式,我就不多弄了,你自己開拓一下吧,可能你會問我主函數怎麼實現,大概就是這樣吧——
int main()
{
load_student(); //讀取txt裏面的內容
shouye();
return 0;
}
這裡要說明一下,我給你這代碼還不怎麼完善的,只是簡單跟你說下思路罷了,如果你招着複製的話,要記住,在你第一次運行之前,要先在你這工程目錄低下創建一個名字為student的txt文件,不然會顯示錯誤,因為load_student()那裡就會判斷是否存在student.txt文件,沒的話就會顯示錯誤的。。。。
我建議你簡單地畫下流程圖,這樣可以讓你的編程思路更清晰,如果還有什麼不清楚的地方可以Q我,410430209。。。。
希望這些對你有所幫助。。。。
C語言如何自製操作系統?
用objcopy做成二進制,格式是:objcopy -I elf格式 -S -R “.eh_frame” -R “.comment” -O binary elf文件 最終的二進制文件.例如: objcopy -I elf32-i386 -S -R “.eh_frame” -R “.comment” -O binary a.obj a.bin
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/240630.html