⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vstore.cpp

📁 Complete video store application in C++ using linked lists to store data in files. it keeps track of
💻 CPP
字号:
/*This video and customer software is developed by Muhammad Junaid Raza
Under the share guidance of Mr. Iftikhar Ahmad
Since it looks simple but has a great work
Infact it gives all information in its Menu
CopyRight "The Wisdom International" Pakistan
This software is shareware and one has to take permissions
from the owner of the software
real_minds@hotmail.com

*/
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <fstream.h>
//using namespace std;

int search(char []);
void input(char []);


class customer{
public:
	char fname[20];
	char lname[20];
	int v_c_out;
	customer *next;

	customer()
	{
		strcpy(fname," ");
		strcpy(lname," ");
		v_c_out=0;
		next=NULL;
	}

};

class video{
public:
	char name_video[30];
	int total_copies;
	int copies_out;
	video *next;
	video()
	{
		strcpy(name_video," ");
		total_copies=0;
		copies_out=0;
		next=NULL;
	}
};


class linklist_video{
public:
	video *head;
	video *tail;
	linklist_video()
	{
		head=NULL;
		tail=NULL;
	}


//video link list start here
void video_add()
	{
		//clrscr();
		puts("\n*******Welcome to Video Insertion Screen*******\n");
		char vn[30];int tc,co;
		fflush(stdin);
		puts("\nEnter your Video Name with _ within whole word\t");
		gets(vn);
		puts("\nEnter total number of its copies\t");
		cin>>tc;
		co=tc;
		//puts("\nEnter Number of Videos to Check out\t");
		//cin>>co;
		video* temp=new video;
		strcpy(temp->name_video,vn);
		temp->total_copies=tc;
		temp->copies_out=co;


	if(head==NULL)
	{
		head=temp;
		tail=temp;
	}
	else
	{
		video* c;
		video* p=NULL;
		c=head;
		int Bool=0;

	   while(Bool==0 && c!=NULL)
		{
			if(strcmpi(vn , c->name_video)>0)
			{
			   p=c;
			   c=c->next;
			}
			else
			{
			   Bool=1;
			}

		}

	   if(p==NULL)
	   {
		   temp->next=head;
		   head=temp;
	   }

	   else
	   {
	   temp->next=c;
		p->next=temp;
	   }

	}

	}

	//function to add in a video file at the end of program
	void video_addfile()
	{
	 ofstream outfile("video.txt",ios::out);
	 video* c=NULL;
	 c=head;
	 while(c!=NULL)
	 {
	 outfile<<c->name_video<<' '<<';'<<' '<<c->total_copies<<' '<<c->copies_out<<endl;
	 c=c->next;
	 }

	 }
	//************//
	void video_readfile()
	{
	 char nv[30];int tv,co;char ch;
	 ifstream infile("video.txt",ios::in);
	 //clrscr();
	 while(infile>>nv>>ch>>tv>>co)
	   {
		video* temp=new video;
		strcpy(temp->name_video,nv);
		temp->total_copies=tv;
		temp->copies_out=co;


		if(head==NULL)
			{
				head=temp;
				tail=temp;
			}
		else
			{
				video* c;
				video* p=NULL;
				c=head;
				int Bool=0;

			while(Bool==0 && c!=NULL)
				{
						if(strcmpi(nv , c->name_video)>0)
						{
						   p=c;
						   c=c->next;
						}
						else
						{
						   Bool=1;
						}

				}//end of while

				if(p==NULL)
					{
				   temp->next=head;
				   head=temp;
					}

			   else
				   {
					temp->next=c;
					p->next=temp;
					}

			}//end of else

		}  //end of while


	 }//end of video read file

   int lookup(char ch[])
	{

	if(head==NULL)
	return(0);
	video* current=head;int  found=0;
	while(current!=NULL && !found)
	{
		if(strcmpi(current->name_video,ch)==0)
		{
			found=1;
		}
		else
		current=current->next;
	}//end of while
	if(found)
		{

	cout<<"\nName of Video Found\t"<<current->name_video;
	cout<<"\nTotal Copies\t"<<current->total_copies;
	cout<<"\nCopies out\t"<<current->copies_out;cout<<endl;
	cout<<endl;
	int temp=current->copies_out;
	return(temp);
	}
	else
	cout<<"\n!!!!Sorry No Match Found Try Again!!!!\n";
   return (0);
}
//*******************************************//
video* search_video(char vn[])
	{
	   if(head==NULL)
		{
		return (NULL);
		}
	   video *c=head;
	   int found=0;
	   while(!found && c!=NULL)
	    {
	       if(strcmpi(c->name_video,vn)==0)
			{
				found=1;
				return(c);
			 }
	      else
		c=c->next;
	      }
	   return(NULL);
	 } //end of video search pointer function


	//***********************//
	void video_display()
	{
		video *current=head;
		while(current!=NULL)
		{
		  cout<<endl;
		  cout<<"VIdeo Name                       "<<current->name_video;
		  cout<<"\nTotal Number of Copies         "<<current->total_copies;
		  cout<<"\nVideos copies Out to customers "<<current->copies_out;
		  current=current->next;
		  cout<<endl;
		}
   //	del();
	}
	void del()
	{
		while(head!=NULL)
		{
		video *temp=NULL;
		temp=head;
		delete(temp);
		head=head->next;
		}
	   }



};//end of link list video specification

//customer link list
class linklist_customer{
public:
	customer *head;
	customer *tail;
	linklist_customer()
	{
		head=NULL;
		tail=NULL;
	}

//customer addition when data in memory
void customer_add()
	{

		puts("\n*******Welcome to Customer Insertion Screen*******\n");
		char fn[20], ln[20];int co;
		fflush(stdin);
		puts("\nEnter your First Name\t");
		gets(fn);
		input(fn);
	   //	cout<<endl<<fn;
		puts("\nEnter your Last Name\t");
		gets(ln);
		input(ln);
		puts("\nEnter Number of Videos to Check out\t");
		cin>>co;
		customer* temp=new customer;
		strcpy(temp->fname,fn);
		strcpy(temp->lname,ln);
		temp->v_c_out=co;


	if(head==NULL)
	{
		head=temp;
		tail=temp;
	}
	else
	{
		customer* c;
		customer* p=NULL;
		c=head;
		int Bool=0;

	   while(Bool==0 && c!=NULL)
		{
			if(strcmpi(fn , c->fname)>0)
			{
			   p=c;
			   c=c->next;
			}
			else
			{
			   Bool=1;
			}

		}   //end of while

	   if(p==NULL)
	   {
		   temp->next=head;
		   head=temp;
	   }

	   else
	   {
	   temp->next=c;
		p->next=temp;
	   }

	}//end else

	}   //end of function

	//function to add in a customer file at the end of program
	void customer_addfile()
	{
	 ofstream outfile("customer.txt",ios::out);
	 customer* c=NULL;
	 c=head;
	 while(c!=NULL)
	 {
	 outfile<<c->fname<<' '<<c->lname<<' '<<c->v_c_out<<endl;
	 c=c->next;
	 }

	 }

	void customer_readfile()
	{
	 char fn[20],ln[20];int co;
	 ifstream infile("customer.txt",ios::in);
	 while(infile>>fn>>ln>>co)
	   {
		customer* temp=new customer;
		strcpy(temp->fname,fn);
		strcpy(temp->lname,ln);
		temp->v_c_out=co;


		if(head==NULL)
			{
				head=temp;
				tail=temp;
			}
		else
			{
				customer* c;
				customer* p=NULL;
				c=head;
				int Bool=0;

			while(Bool==0 && c!=NULL)
				{
						if(strcmpi(fn , c->fname)>0)
						{
						   p=c;
						   c=c->next;
						}
						else
						{
						   Bool=1;
						}

				}

				if(p==NULL)
					{
				   temp->next=head;
				   head=temp;
					}

			   else
				   {
					temp->next=c;
					p->next=temp;
					}

			}//end of else

		}  //end of while


	 }//end of customer read file
	customer* search_customer(char f[],char l[])
	{
	   if(head==NULL)
		{
		return (NULL);
		}
	   customer *c=head;
	   int found=0;
	   while(!found && c!=NULL)
	    {
	       if((strcmpi(c->fname,f)==0) &&(strcmpi(c->lname,l)==0))
			{
				found=1;
				return(c);
			 }
	      else
		c=c->next;
	      }
	   return(NULL);
	 } //end of customer search pointer function

	int customer_count(char f[],char l[])
	{
	if(head==NULL)
	return (-1);
	customer *c=head;
	int found=0;
	while(!found && c!=NULL)
	{
		if((strcmpi(c->fname,f)==0) &&(strcmpi(c->lname,l)==0))
			{
				found=1;
				return(c->v_c_out);
			 }
		else
		c=c->next;

	}  //end of while
   return(-1);
   }//end of count function



	void customer_display()
	{
		clrscr();
		customer *current=head;
		while(current!=NULL)
		{
			cout<<endl;
			cout<<"Customer First Name        "<<current->fname;
			cout<<"\nCustomer Last  Name        "<<current->lname;
			cout<<"\nCustomer Videos Check Outs "<<current->v_c_out;
			current=current->next;
			cout<<endl;
		}
	//del();
	}
 //delete all node in memory and free all locations
	void del()
	{
		while(head!=NULL)
		{
		customer *temp=NULL;
		temp=head;
		delete(temp);
		head=head->next;
		}
	   }



};


int main()
{
	linklist_customer custom;
	custom.customer_readfile();
	linklist_video vid;
	vid.video_readfile();
	int digit=20;
	while(digit!=0)
	{
		clrscr();
		gotoxy(10,5);
		cout<<"***************************************************";
		gotoxy(10,6);
		cout<<"***************WELCOME TO ZEE VIDEO****************";
		gotoxy(10,7);
		cout<<"***************************************************";
		gotoxy(23,10);
		cout<<"1. Press This Key to Add New Customer";
		gotoxy(23,11);
		cout<<"2. Press This Key to Add New Video";
		gotoxy(23,12);
		cout<<"3. Press This Key to Check Out a Video for Customer";
		gotoxy(23,13);
		cout<<"4. Press This Key to Return a Video";
		gotoxy(23,14);
		cout<<"5. Press This Key to Check Availability of a Video";
		gotoxy(23,15);
		cout<<"6. Press This Key to  Customer Count";
		gotoxy(23,16);
		cout<<"7. Press This Key to List All Customers";
		gotoxy(23,17);
		cout<<"8. Press This Key to LIST ALL VIDEOS";
		gotoxy(23,18);
		cout<<"9. Press This Key to LookUp a Video";
		gotoxy(23,20);
		cout<<"0. Press This Key to Exit ";
		gotoxy(30,22);
		cout<<"This Software is Exclusively Developed by ";
		gotoxy(30,23);
		cout<<"Muhammad Junaid Raza MCS2B(E) DSA (Mr. Iftikhar)";
		gotoxy(60,20);
		cin>>digit;
		clrscr();
		switch(digit)
		{
		case 1: //clrscr();
				custom.customer_add();
				break;
		case 2: //clrscr();
				vid.video_add();
				break;

		case 3:{//give video name,give customer name
			//search customer name first return current pointer
			//from function created and see customer check out
			customer *cc=NULL;
			video *vp=NULL;char vn[30];
			char fn[20],ln[20];
			puts("\nEnter First Name of Customer \t");
			gets(fn);
			puts("\nEnter Last Name of Customer \t");
			gets(ln);
			cc=custom.search_customer(fn,ln);
			if(cc==NULL)
			{
			cout<<"\nNo Customer have been Found to issue a video\n";
			//cout<<cc->v_c_out;
			getch();
			break;
			}
			else
			{
			 if(cc->v_c_out>=5)
			   {
			    cout<<"\nSorry You Can't Check Out More Videos\n";
			   cout<<"\nYou Already Have "<<cc->v_c_out<<" videos\n";
			    getch();
			    break;
			    }
			   else
			    {
			     puts("\nEnter Name of Video");
			     gets(vn);
			     vp=vid.search_video(vn);
			     if(vp->copies_out<5 && vp->copies_out>0)
			      {
			      cc->v_c_out++;
			      vp->copies_out++;

			      }
			      else
			       {
			       cout<<"\nSorry All Copies are out\n";
			       cout<<"\nYou Can't get this time\n";
			       getch();
			       }

			     }
			 }


			getch();
			break;
			}

		case 4:{//return a video give name of customer,name of video
		      //search customer & name of video, if both are succesful
		      //customer_checkout -1 video_copiesout -1
		       customer *cc=NULL;
			video *vp=NULL;char vn[30];
			char fn[20],ln[20];
			puts("\nEnter First Name of Customer \t");
			gets(fn);
			puts("\nEnter Last Name of Customer \t");
			gets(ln);
			cc=custom.search_customer(fn,ln);
		   if(cc==NULL)
		   {
		   cout<<"\nNo Customer have been Found to return a video\n";
		   //cout<<cc->v_c_out;
		   getch();
		   break;
		   }
		   else
		   {
			puts("\nEnter Name of Video to Return");
			gets(vn);
			vp=vid.search_video(vn);
			 if(vp==NULL)
			    {
			     cout<<"\nSorry no Video exists of this name\n";
			     getch();
			     break;
			     }
			     else
			      {
			       cc->v_c_out--;
			       vp->copies_out--;
			       cout<<"\nVideo has been returned Thanks\n";
			       getch();
			       break;
			       }
		     //break;
		     }//end of else
		     }//end of case 4 return a video


		case 5: { int avlb;
			 char ch1[30];
			 puts("Enter name of video to search\t");
			 gets(ch1);
			 avlb=vid.lookup(ch1);
			 if(avlb<5&&avlb>0){
			 cout<<"\nThe Video is Available\n";
			 }
			 else
			 cout<<"\nSorry!The video is not available";
			 getch();
			 break;
			 }

		case 6:{
			char c1[20],c2[20];int count;
			puts("\nEnter First Name of Customer\t");
			gets(c1);
			puts("\nEnter Last Name of Customer\t");
			gets(c2);
			count=custom.customer_count(c1,c2);
			if(count!=-1)
			{
			cout<<"\nThe Customer Holds "<<count<<" movies\n";
			 }
			 else
			 cout<<"\nThe Customer has no Movies\n";
			 getch();
			break;
			}
		case 7://clrscr();
			custom.customer_display();
			getch();
			break;
		case 8: //clrscr();
			vid.video_display();
			getch();
			break;
		case 9:{
			char ch1[30];
			puts("Enter name of video to search\t");
			gets(ch1);
			vid.lookup(ch1);
			getch();
			break;
			}

		case 0:{ gotoxy(23,20);
			 char ch='y';
			 cout<<"Are You Sure to Write the current data on disk";
			 gotoxy(23,21);
			 cout<<"Press y to Write Data Permanently\t";
			 cin>>ch;
			 if(ch=='y'|| ch=='Y')
			 { clrscr();
			  gotoxy(23,21);
			  cout<<"The Data Have been Written to Files";
			  custom.customer_addfile();
			 vid.video_addfile();
			 gotoxy(23,22);
			 cout<<"You are going to exit";
			 gotoxy(23,23);
			 cout<<"Thanks, Press any key ";
			 }
			 else
			 {
			 clrscr();
			 gotoxy(23,22);
			 cout<<"Good Bye This Time";
			 gotoxy(23,23);
			 cout<<"Thanks, Press any key ";
			 }
			 custom.del();
			 vid.del();
			 getch();
			 exit(0);
			 }
		}//end of switch statement
	 }//end of while loop

	return 0;

}

//end of main
//these are the modules to take name without spaces
void input(char ch[])
{
	int x=search(ch);
	if(x==1){
	puts("\nPlease ReEnter Name!!!!!!\t");
	gets(ch);
	cout<<endl;

	input(ch);
	}
	else{
   //	cout<<"\nYour name is correct\n";
	return;}
}

int search(char ch[])
{
int len=strlen(ch);
	for(int i=0;i<=len;i++)
		{
			if(ch[i]==' ')
			{
			return 1;
			}
		}
return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -