用 C++实现的简单物流信息存储

说明:c++简单实现 信息添加、显示、删除


// wuliu.cpp : by lip
//

#include "stdafx.h"
#include
#include
#include 
#include 
#include 
#include 




struct Product {
	char name[20];
	int id; 
	struct Product *next;
};

struct Product *Head;

struct Product *add(struct Product *h);
void show();
void save(struct Product *h);
void del();
void choice();
void main_init();

struct Product *add(struct Product *h){
	system("cls");
	int n=0;
	int i=0;
	h = NULL;
	struct Product *p;
	printf("\n");
	 printf("请输入总物流记录数:");
	 scanf("%d",&n);   
	 for (i=0;iname);
		printf("编号:");
		scanf("%d",&p->id);	 
		printf("  --------------   \n");
		p-> next = NULL;   
		if(h==NULL)	  
			h=p;   
		else     
		{
			struct Product *q=h; 	
			while(q->next!=NULL)	  
				q=q->next;   		
			q->next=p; 	
		}
	 
	 
	 }
	 return(h);
}

void main_init(){
	
	printf("----   -----   ----   ----\n");
	printf("* 1.添加  2.显示  3.删除 *\n");
	printf("----   ----    ----   ----\n");

	struct Product *p;
	p=(struct Product *)malloc(sizeof(struct Product));

	int choice;
	printf("请选择:");
	scanf("%d",&choice);
	switch(choice){
	case 1:
		p = add(p);
		save(p);
		break;
	case 2:
		show();break;
	case 3:
		del();break;
	default:
		exit(1);break;
	
	}
	

}

void show(){

	system("cls");
	printf("正在读取,请稍后...\n");		
	
			struct Product *p;
	p=(struct Product *)malloc(sizeof(struct Product));
	
	struct Product *q;
	q=(struct Product *)malloc(sizeof(struct Product));

	ifstream read("wuliu.txt",ios::in);
    if(!read)
       {
          cout<<"can not rean wuliu.txt"<>p->name>>p->id;
		if(read.fail()){
			break;
		}
		cout<name<<'\t'<id<next=NULL;
    read.close();


	printf("\n");
	printf("读取完毕!\n");
	choice();
}


void del(){
		
	system("cls");
	struct Product *p;
	p=(struct Product *)malloc(sizeof(struct Product));
	
	struct Product *q;
	q=(struct Product *)malloc(sizeof(struct Product));//保存用户要删除物流信息

	ifstream read("wuliu.txt",ios::in);//读入原文件
	if(!read)
    {
		cout<<"can not read wuliu.txt"<>q->name;



	while(read.good()&&!read.eof())
    {        
        read>>p->name>>p->id;
		if(read.fail()){//防止读取时最后一行重复
			break;
		}
		if( strcmp(p->name,q->name)!=0 ){
				save<name<<'\t'<id<name,q->name)==0 ){
			save<name<<'\t'<id<name<<'\t'<id<name<<'\t'<id<next;        
    }
    save.close();
	printf("存储完成...\n");
	choice();


}

void choice(){

	int choice;
	cout<<("\n");
	cout<<"请选择 1.返回主菜单  2.退出 :"<




你可能感兴趣的:(技术杂文)