Google Community
Latest Forums Rules Resources
Custom Search

Go Back   Google Community > The Community > Chit Chat

GoogleCommunity Sponsor

Reply
 
LinkBack Thread Tools Display Modes
Old 05-14-2009, 05:22 AM   #1 (permalink)
Googler
 
Join Date: Dec 2008
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
wolfyy1 is on a distinguished road
Comppppuuuteeerrrrr

// Hero's Inventory Program
#include<iostream.h>
using namespace std;
void search_binary(int x[100],int low, int hi, int search_num);
int main()
{
const int MAXITEMS=10;
string inventory[MAXITEMS];
cout<<"Modern Day Knight's Inventory"<<endl;
cout<<endl;
int numItems=0;
inventory[0]="Pistol";
numItems=numItems+1;
inventory[1]="Bulletproof Vest";
numItems=numItems+1;
inventory[2]="Smoke Bomb";
numItems=numItems+1;
inventory[3]="Dagger";
numItems=numItems+1;
inventory[4]="AK-47";
numItems=numItems+1;
inventory[5]="Nunchucks";
numItems=numItems+1;
inventory[6]="Night Vision Goggles";
numItems=numItems+1;
inventory[7]="Utility Belt";
numItems=numItems+1;
inventory[8]="Sniper";
numItems=numItems+1;
cout<<"Your items:\n";
for(int i=0; i<numItems; ++i)
cout<<inventory[i]<<endl;
cout<<"\nYou found a first aid kit \n\n";
if(numItems<MAXITEMS)
{
inventory[numItems]="First Aid Kit";
numItems=numItems+1;
}

else
cout<<"You have too many items and can't carry another.";
cout<<"Your items:\n";
for(int i=0; i<numItems; ++i)
cout<<inventory[i]<<endl;
cout<<endl;
cout<<"The current number of items is "<<numItems<<endl;

//----------------------------------------------------------------------------
cout<<endl;
cout<<endl;
cout<<"Star Wars Druid's Inventory"<<endl;
cout<<endl;
const int MAXITEMS1=10;
string inventory1[MAXITEMS1];
int numItems1=0;
inventory1[0]="Laser";
numItems1=numItems1+1;
inventory1[1]="Shield Deflector";
numItems1=numItems1+1;
inventory1[2]="Lightsaber";
numItems1=numItems1+1;
inventory1[3]="Snipe Laser";
numItems1=numItems1+1;
inventory1[4]="The Force";
numItems1=numItems1+1;
inventory1[5]="Walkie-Talkie";
numItems1=numItems1+1;
inventory1[6]="Force Pike";
numItems1=numItems1+1;
inventory1[7]="Microwelder";
numItems1=numItems1+1;
inventory1[8]="Macrobinoculars";
numItems1=numItems1+1;
cout<<"Your items:\n";
for(int i=0; i<numItems1; ++i)
cout<<inventory1[i]<<endl;
cout<<"\nYou found a health kit \n\n";
if(numItems1<MAXITEMS1)
{
inventory1[numItems1]="Health Kit";
numItems1=numItems1+1;
}

else
cout<<"You have too many items and can't carry another.";
cout<<"Your items:\n";
for(int i=0; i<numItems1; ++i)
cout<<inventory1[i]<<endl;
cout<<endl;
cout<<"The current number of items is "<<numItems1<<endl;
int array[20]=
{inventory[0],inventory[1],inventory[2],inventory[3],inventory[4]};
search_binary(array,0,9,10);

return 0;
}
void search_binary(int x[100],int low, int hi, int search_num)
{
cout<<"Enter the search number"<<endl;
cin>>search_num;
int search_pos=(low+hi)/2;
while(x[search_pos]!=search_num&&low<=hi)
{
if(x[search_pos]>search_num)
hi=search_pos-1;
else low=search_pos+1;
search_pos=(low+hi)/2;
}
if(low<=hi)cout<<"Number found in the "<<search_pos+1<<" position";
else cout<<"NUMBER NOT FOUND!";
}
wolfyy1 is offline   Reply With Quote
 
Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -8. The time now is 11:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© 2004–2007 Google Community