View Single Post
Old 20-03-2008, 05:10 PM   #425 (permalink)
radonryder
Apprentice
 
radonryder's Avatar
 
Join Date: Dec 2006
Posts: 72
Default Re: Post ur C/C++ Programs Here

A lot of this stuff form my comp text..
I can prepare 4 my comp boards with digitXD
Well here's what I did for my school project
It basicaly an inventory tracker software...
I coded the entire thing myself..
I just custumised the menu's for a gunshop...
Im open to reviews.Tell me what you guys think of it....

>>>GUNSHOP<<<
Code:
#include<iostream.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<fstream.h>
#include<conio.h>
class staff
{
char sname[20];                                             //name of employee
int age;                                                    //age of employee
float salary;                                               //salary of employee
char job[20];                                               //type of job done(eg-cashier,delivery man)
public:

void inputs()
{
	cout<<"\nEnter New employee's Name:\n";
	gets(sname);
	cout<<"\nEnter New employee's Age:\n";
	cin>>age;
	cout<<"\nEnter New employee's job:\n";
	gets(job);
	cout<<"\nEnter New employee's Salary:\n";
	cin>>salary;
}
void displays()
{  cout<<"\n";
	cout<<sname;
	cout<<"\t\t"<<age;
	cout<<"\t\t"<<job;
	cout<<"\t\t"<<salary;
}
int searchst(char st1[20])                                          //search by name of employee
{
	if(strcmp(st1,sname)==0)
	return 0;
	else
	return 1;
}
																						  //search by job of employee
	int searchjs(char j1[20] )
{
	if(strcmp(j1,job)==0)
	return 0;
	else
	return 1;
}



};
class guns
{
char gname[20];                                                  //name of gun
char gtype[20];                                                 //type of gun(eg-pistol,shotgun,etc)
int stock;
float cost;																		//no: of guns in stock
public:

void inputg()                                                    //for inputing gun details
{
	cout<<"\nEnter Gun Name:\n";
	gets(gname);
	cout<<"\nEnter Type of Gun:\n";
	gets(gtype);
	cout<<"\nEnter Gun's Price:\n";
	cin>>cost;
	cout<<"\nEnter the Number of Guns in stock:\n";
	cin>>stock;
}

void displayg()                                                  //for displaying gun details
{  cout<<"\n";
	cout<<gname;
	cout<<"\t\t"<<gtype;
	cout<<"\t\t"<<cost;
	cout<<"\t\t"<<stock;
}
int rtstk()
{
return stock;
}

int searchgn(char gn1[20])                                       //search by gun name
{
	if(strcmp(gn1,gname)==0)
	return 0;
	else
	return 1;
}

	int searchct(char ty1[20] )                                    //search by gun type
{
	if(strcmp(ty1,gtype)==0)
	return 0;
	else
	return 1;
}

																					 //updated stock
void update(int i)
{
	 stock=stock+i;


}                                                              //updates cost
void update1()
{
float cos;
cout<<"\nEnter New price:\n";
cin>>cos;
cost=cos;
}                                                       //for purchasing
void update2(int i)
{
stock=stock-i;
}
};
guns g1;
staff s1;
void main()
{
char str[20],a;
fstream f1,f2,f3;
char ch1;
int n,ch,i,j,k,ch3;
char ch4;
cout<<"\n \n\n\nWelcome to Ammunation";
do
{  clrscr();                                                              //start of 1st do while
	cout<<"\nSelect access level";
	cout<<"\n1.Staff";
	cout<<"\n2.Admin";
	cout<<"\n3.Exit\n";
	cin>>ch;
if(ch==1)
{clrscr();
do                                                             //start of staff menu
{
cout<<"\n\nStaff Menu";                                        //gun management
cout<<"\n----------------------------------------";
cout<<"\n1.Display all Guns";
cout<<"\n2.Search by Gun Name";
cout<<"\n3.Search by Gun Type";
cout<<"\n4.Purchase Guns";
cout<<"\n5.Add more Guns";
cout<<"\n6.Update Gun details";
cout<<"\n7.Delete Guns";
cout<<"\n8.Restore deleted Guns";
cout<<"\n9.Create Backup";
cout<<"\n10.restore basckup(Caution!!->Use only if Backup File exits)";
cout<<"\n11.Clear Screen";
cout<<"\nEnter your choice\n";
cin>>ch3;
switch (ch3)
{
case 1:
			f1.open("gun1.dat",ios::in);
			f1.read((char*)&g1,sizeof(g1));
			cout<<"\nGun details";
			cout<<":\n--------------------------";
			cout<<"\nName\t"<<"\tType\t"<<"\tPrice\t"<<"\tStock\t";
			while(f1)
			{
			g1.displayg();
			f1.read((char*)&g1,sizeof(g1));
			}
			f1.close();
			break;
case 2:
			cout<<"\nEnter the Name of the Gun:\n";
			gets(str);
			f1.open("gun1.dat",ios::in);
			f1.read((char*)&g1,sizeof(g1));
			while(f1)
			{

			n=g1.searchgn(str);
			if(n==0)
				{
			cout<<"\nGun details";
			cout<<":\n--------------------------";
			cout<<"\nName\t"<<"\tType\t"<<"\tPrice\t"<<"\tStock\t";
			g1.displayg();
					break;
				}
			f1.read((char*)&g1,sizeof(g1));
			}
			if(n==1)
			{
			cout<<"\nThe Gun was Not Found";
			}
			f1.close();




			break;

case 3:  cout<<"\nEnter Type of Gun:\n";
			gets(str);
			f1.open("gun1.dat",ios::in);
			f1.read((char*)&g1,sizeof(g1));
         i=0;
			while(f1)
			{

			n=g1.searchct(str);
			if(n==0)
				{i++;
				if(i==1)
				cout<<"\nGun details";
			cout<<":\n--------------------------";
			cout<<"\nName\t"<<"\tType\t"<<"\tPrice\t"<<"\tStock\t";
				 g1.displayg();
					break;
				}
			f1.read((char*)&g1,sizeof(g1));
			}
			if(n==1)
			{
			cout<<"\nThere are no guns of "<<str<<" Type";
			}
			f1.close();
			break;

case 4:
			cout<<"\nEnter the Name of the Gun:\n";
			gets(str);
			f1.open("gun1.dat",ios::in|ios::out);
			f1.read((char*)&g1,sizeof(g1));
			k=sizeof(g1);
			while(f1)
			{
			n=g1.searchgn(str);

			if(n==0)
				{
				i=g1.rtstk();
				cout<<"\nEnter the Number of Guns to be Purchased:\n";
				cin>>j;
				if(j>i)
				{
					cout<<"\nThe Number of guns Requested is Not in Stock";
					cout<<"\nOnly "<<i<<" Are Available";
					cout<<"\nDo u still wish to buy?:/n";
					cin>>a;
					if(a=='y'||a=='Y')
					{f1.seekp(-k,ios::cur);
					g1.update2(j);

				 f1.write((char*)&g1,sizeof(g1));
					cout<<"\nPurchased ";
					}
				}
				else
				{ f1.seekp(-k,ios::cur);
					g1.update2(j);

				 f1.write((char*)&g1,sizeof(g1));
					cout<<"\nPurchased ";
				}
				 break;
				}
			f1.read((char*)&g1,sizeof(g1));

			}

			if(n==1)
			{
				cout<<"\nGun not in stock";
			}




			f1.close();



			break;
case 5:
			f1.open("gun1.dat",ios::out|ios::app);
			cout<<"\nEnter the no: of guns:\n";
			cin>>n;
			cout<<"\nEnter Gun Details:\n";
			cout<<"---------------------------------";
			for(i=0;i<n;i++)
			 {
			  g1.inputg();
				f1.write((char*)&g1,sizeof(g1));
			 }

			 f1.close();
			 break;


case 6:	cout<<"\nEnter the Name of the Gun:\n";
			gets(str);
			k=sizeof(g1);
			f1.open("gun1.dat",ios::in|ios::out);
			f1.read((char*)&g1,sizeof(g1));
			while(f1)
			{

			n=g1.searchgn(str);
			if(n==0)
				{
				 g1.update1();
				 cout<<"\nEnter the no: of guns delivered:\n";
				 cin>>i;
             f1.seekp(-k,ios::cur);
				 g1.update(i);

				 f1.write((char*)&g1,sizeof(g1));
				 cout<<"\nUpdated";
					break;
				}
			f1.read((char*)&g1,sizeof(g1));
			}
			if(n==1)
			{
			cout<<"\nThe Gun was Not Found";
			}
			f1.close();


			break;
case 7: f1.open("gun1.dat",ios::in);
		 f2.open("gun2.dat",ios::out|ios::app);
		 f3.open ("gun3.dat",ios::out|ios::app);
		 cout<<"\nEnter Name of the gun";
			gets(str);
			i=0;
			f1.read((char*)&s1,sizeof(s1));
			while(f1)
			{
			n=g1.searchgn(str);
			if(n==0)
			{i++;
			f3.write((char*)&g1,sizeof(g1));
			}
			if(n==1)
			{
			 f2.write((char*)&g1,sizeof(g1));
			}
			f1.read((char*)&g1,sizeof(g1));
			}
			f1.close();
			f2.close();
			f3.close();
			remove("gun1.dat");
			rename("gun2.dat","gun1.dat");
			if(i==0)
			cout<<"\nGun not found";
			break;

case 8: f1.open("gun1.dat",ios::out|ios::app);
		 f2.open("gun3.dat",ios::in);
		 cout<<"\nEnter the Gun's Name:\n";
		 gets(str);
		 i=0;
		 while(f2)
		 {
		 n=g1.searchgn(str);
		 if(n==0)
		 {i++;
		 f1.write((char*)&g1,sizeof(g1));
		 }
		 f2.read((char*)&g1,sizeof(g1));
		 }
		 if(i==0)
		 cout<<"\nGun not found";
		 else
		 cout<<"\nGun Restored";
		 f1.close();
		 f2.close();

			break;
case 9:  f1.open("gun1.dat",ios::in);
			f2.open("bkg.dat",ios::out|ios::app);
			f1.read((char*)&g1,sizeof(g1));

			while(f1)
			{
			f2.write((char*)&g1,sizeof(g1));
			f1.read((char*)&g1,sizeof(g1));
			}
			f2.close();
			f1.close();
			cout<<"\nBackUp Created";
			break;

case 10: remove("gun1.dat");
			rename("bkg.dat","gun1.dat");
			cout<<"\nBackup Restored";
			break;
case 11:
			clrscr();
			break;
default:cout<<"\nWrong choice\n";

}
	cout<<"\nDo u wish to continue?";
	cin>>ch4;

}while(ch4=='y'||ch4=='Y');
											 //end of staff menu
}
if(ch==2)
{

clrscr();
do
{
cout<<"\n\nAdmin Menu";                                     //employee management
cout<<"\n----------------------------------------";
cout<<"\n1.Search by Name of employee";
cout<<"\n2.Display all Staff Details";
cout<<"\n3.Display staff in a specific Catagory ";
cout<<"\n4.Update employee Details";
cout<<"\n5.Hire Staff";
cout<<"\n6.Fire Staff";
cout<<"\n7.Fired Staff History";
cout<<"\n8.Rehire staff";
cout<<"\n9.Create Backup";
cout<<"\n10.restore basckup(Caution!!->Use only if Backup File exits)";
cout<<"\n11.Clear screen";
cout<<"\nEnter Choice?";
cin>>ch3;
switch(ch3)
{
case 1:  f1.open("stf1.dat",ios::in);
			f1.read((char*)&s1,sizeof(s1));
			cout<<"\nEnter Name of the Employee:\n";
			gets(str);
			while(f1)
			{
			n=s1.searchst(str);
			if(n==0)
			{
			cout<<"\nEmployee Details";
			cout<<"\n-----------------------";
			cout<<"\nName\t"<<"\tAge\t"<<"\tJob\t"<<"\tSalary\t";
			s1.displays();
			break;
			}
			f1.read((char*)&s1,sizeof(s1));
			}
			f1.close();
			if(n==1)
			cout<<"\nEmployee does Not Work here";
			break;

case 2:
			f1.open("stf1.dat",ios::in);
			f1.read((char*)&s1,sizeof(s1));
			cout<<"\nEmployee Details";
			cout<<"\n-----------------------";
			cout<<"\nName\t"<<"\tAge\t"<<"\tJob\t"<<"\tSalary\t";

			while(f1)
			{
			s1.displays();
			f1.read((char*)&s1,sizeof(s1));
			}
			f1.close();
			break;

case 3:  i=0;
			f1.open("stf1.dat",ios::in);
			f1.read((char*)&s1,sizeof(s1));
			cout<<"\nPlease Enter job of the employee";
			gets(str);
			while(f1)
			{
			n=s1.searchjs(str);
			if(n==0)
			{i++;
			if(i==1)
			{
			cout<<"\nEmployee Details";
			cout<<"\n-----------------------";
			cout<<"\nName\t"<<"\tAge\t"<<"\tJob\t"<<"\tSalary\t";
			}
			s1.displays();
			}
			f1.read((char*)&s1,sizeof(s1));
			}
			f1.close();
			if(i==0)
							break;
case 4:f1.open("stf1.dat",ios::out|ios::in);
		 cout<<"\nEnter the Employee's Name:\n";
		 gets(str);
		 i=sizeof(s1);
		 f1.read((char*)&s1,sizeof(s1));
		 while(f1)
		 {
		 n=s1.searchst(str);
		 if(n==0)
		 {
		 f1.seekg(-i,ios::cur);
		 cout<<"\nEnter New Details";
		 cout<<":\n--------------------------";
		 s1.inputs();
		 f1.write((char*)&s1,sizeof(s1));
		 break;
		 }
		 f1.read((char*)&s1,sizeof(s1));
		 }
		 if(n==1)
		 cout<<"\nEmployee does Not work here";
		 f1.close();
							break;
case 5: f1.open("stf1.dat",ios::out|ios::app);
		  cout<<"\nEnter the no: New employees:\n";
		  cin>>n;
		  cout<<"\nEnter New employee details";
        cout<<":\n--------------------------";
		  for(i=0;i<n;i++)
			{
			 s1.inputs();
			 f1.write((char*)&s1,sizeof(s1));
			}

		  f1.close();
		  break;

case 6:f1.open("stf1.dat",ios::in);
		 f2.open("stf2.dat",ios::out|ios::app);
		 f3.open ("stf3.dat",ios::out|ios::app);
		 cout<<"\nEnter Name of the Employee:\n";
			gets(str);
			i=0;
			f1.read((char*)&s1,sizeof(s1));
			while(f1)
			{
			n=s1.searchst(str);
			if(n==0)
			{i++;
			f3.write((char*)&s1,sizeof(s1));
			}
			if(n==1)
			{
			 f2.write((char*)&s1,sizeof(s1));
			}
			f1.read((char*)&s1,sizeof(s1));
			}
			f1.close();
			f2.close();
			f3.close();
			remove("stf1.dat");
			rename("stf2.dat","stf1.dat");
			if(i==0)
			cout<<"\nEmployee does Not Work here";
			break;


case 7:
		 f1.open("stf3.dat",ios::in);
			f1.read((char*)&s1,sizeof(s1));
			cout<<"\nFired Employee Histiry";
			cout<<"\n-----------------------";
			cout<<"\nName\t"<<"\tAge\t"<<"\tJob\t"<<"\tSalary\t";

			while(f1)
			{
			s1.displays();
			f1.read((char*)&s1,sizeof(s1));
			}
			f1.close();
			break;
case 8:f1.open("stf1.dat",ios::out|ios::app);
		 f2.open("stf3.dat",ios::in);
		 cout<<"\nEnter the Employee's Name:\n";
		 gets(str);
		 i=0;
		 while(f2)
		 {
		 n=s1.searchst(str);
		 if(n==0)
		 {i++;
		 f1.write((char*)&s1,sizeof(s1));
		 }
		 f2.read((char*)&s1,sizeof(s1));
		 }
		 if(i==0)
		 cout<<"\nName not found";
		 else
		 cout<<"\nEmployee rehired";
		 f1.close();
		 f2.close();
		 break;
case 9:  f1.open("stf1.dat",ios::in);
			f2.open("bks.dat",ios::out|ios::app);
			f1.read((char*)&s1,sizeof(s1));

			while(f1)
			{
			f2.write((char*)&s1,sizeof(s1));
			f1.read((char*)&s1,sizeof(s1));
			}
			f2.close();
			f1.close();
			cout<<"\nBackUp Created";
			break;

case 10: remove("stf1.dat");
			rename("bks.dat","stf1.dat");
			cout<<"\nBackup Restored";
							break;
case 11:

				clrscr();
							break;
default:
	cout<<"\nWrong Choice";

}
	cout<<"\nDo you wish to continue?";
	cin>>ch4;
}while(ch4=='y'||ch4=='Y');
}
if(ch==3)
{

	clrscr();
	exit(0);
}
else
{
	cout<<"\nWrong choice";

cout<<"\nDo u wish to select another access level";
cin>>ch1;

}
}while(ch1=='y'|ch1=='Y');

cout<<"\n\n\n\n";
clrscr();

}                                             //end of program
__________________
I have created over a thousand blades.Unknown to death.Nor to life.Have withstood pain to create many weapons.Yet,those hands will never hold anything.so i pray,"Unlimited Blade Works"
radonryder is offline