Follow us on Twitter!
Things are more like they are now than they have ever been before. - Dwight D. Eisenhower
Friday, April 18, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 29
Guests Online: 26
Members Online: 3

Registered Members: 82824
Newest Member: devilslegion
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-09-06 20:03
Hmmmm......does anyone know how I can implement a search function within an array in C++???
Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-09-06 20:55
Same coding as in my other post


Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-09-06 21:03
What kind of search are you looking to do?

give an example of the array you want to search ect.




Edited by on 21-09-06 21:04
Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-09-06 21:09
cubeman372 wrote:
What kind of search are you looking to do?

give an example of the array you want to search ect.




[see below for codes]




Edited by on 27-09-06 11:08
Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-09-06 21:14
Hmm a chunk of code that asks for details and stores them in an array right?

Now what do you want the search function to search for exactly?


Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-09-06 21:19
The array is gonna store data about employees and i need to be able to retrieve the data for ex by using name as a parameter...

Search for the record of Mr X for example...


Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-09-06 21:53
Ahh in that case use the names of people array[MrX] instead of the standard integer form array[0]

and then just cin the name to a empty variable loop through the array for name matches and cout the matches.

NOTE: I know this is long winded and there is a simpler way to do it, but I cant be arsed to get my C++ book out. Pfft


Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 22-09-06 19:28
a more smplistic way of finding the contents of an array, is to use a for loop:

Code
#include <iostream>
using namespace std;

int main ()
{
   int arr[10];
   arr[0]=1;
   arr[1]=2;
   arr[2]=3;
   arr[3]=4;
   arr[4]=5;
   arr[5]=6;
   arr[6]=7;
   arr[7]=8;
   arr[8]=9;
   arr[9]=10;
   //search for the number 1;
   for(int b=0;b<10;b++)
   {
      if(arr[b] == 1)
      {
         cout << "arr[" << b << "] holds the value of 1" << endl;
      }
      else
      {
         cout << "arr[" << b << "] doesnt not hold the value of 1" << endl;
      }
   }
   system("pause");
}





Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 23-09-06 19:19
Thnx but it's not based on ay parameter the user would input...


Author

RE: Drowning into an ocean of despair called C++

knutrainer
Member



Posts: 243
Location:
Joined: 08.07.05
Rank:
Apprentice
Posted on 23-09-06 23:30
Then edit it to do so.


img389.imageshack.us/img389/974/knu5ui1ja.jpg
~PM me if you need help or instant message me.


knutrainer@gmail.com
Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-09-06 11:05
Updated the code...NOW IT DOESN'T WORK!!!!


// 789.cpp : main project file.

#include "stdafx.h"
#include "stdlib.h"
#include "time.h"
#include <sys/types.h>
#include <sys/timeb.h>
#include <stdio.h> //Returns values to the progra fo the Date function
#include <iostream>
#include <string.h>
using namespace std;

struct employee
{
char name[30];
char address[35];
char gender;
char team;
char project[30];
char department;
float number_project_completed;
float sales_pro;//sales made from the totality of projects
float rank;//an assignment for the renk which the person possese within the company. The smallest number representing the most important
char not;//nothing to do with program//to be removed

};
//array decl
employee dbase[10];
int i = 1;
int choice;

int main()
{
//nothing to do with program//to be removed

//Declarations for time reading and displaying
char tmpbuf[128], timebuf[26], ampm[] = "AM";//setting AM format
struct _timeb tstruct;


cout<<"\n================================================================================";
cout<<" ey3s of cha0s program S.P";
cout<<"\n================================================================================";

// Set time zone from TZ (Time Zone) environment variable. If TZ is not set,
// the operating system is asked to obtain the default value
// for the variable in order to find the time.
//
_tzset();

// Displaying operating system-style date and time. in this case, that of Windows XP
_strtime_s( tmpbuf, 128 );
printf( "\n time:\t\t\t\t%s\n", tmpbuf );
_strdate_s( tmpbuf, 128 );
printf( "\n date:\t\t\t\t%s\n", tmpbuf );

cout<<"\n--------------------------------------------------------------------------------";
cout<<"\ Enter Choice.. 1: enter new record...2Grino nothing";
cin>>choice;
switch (choice)
{
case 1:
cout<<"\n [If a statement appears several times, then you have surely made a mistake] \n";
cout<<"Please use only non-capital letters...<<a>> not <<A>>";
cout<<"\n ";

cout << "\n Please enter name: ";
cin >> dbase[i].name;
cout << "\n Please enter address: ";
cin >> dbase[i].address;

//Start of loop aiming at restricting values for "gender"
//While loop
do

{cout<<"\n Enter gender of employee:";
cout<<"Key in M for Male and F for Female: ";
cin>>dbase[i].gender;


} while (dbase[i].gender != 'f'&& dbase[i].gender != 'm'Wink;

if (dbase[i].gender == 'm' )
cout<<"\n You entered male";
else
if (dbase[i].gender == 'f'Wink
cout<<"\n You entered Female";
cout << "\n ";

//Start of loop aiming at restricting values for "department"
//While loop
do

{cout<<"\n Enter Department. R: Research D: Development ";
cin>>dbase[i].department;

} while (dbase[i].department != 'd'&& dbase[i].department != 'r'Wink;
//Capital letters not considered by program
if (dbase[i].department == 'd' )
cout<<"\n You entered Development Department";
else
if (dbase[i].department == 'r'Wink
cout<<" \n You entered Research Department";

cout<<"\n";

// Start of loop aiming at restricting values for "team"

do {cout<<"\n Enter Team. a: Team Alpha o: Team Omega ";
cin>>dbase[i].team;
} while (dbase[i].team != 'a'&& dbase[i].team != 'o'Wink;

if (dbase[i].team == 'a' )
cout<<"\n You entered Team Alpha";
else
if (dbase[i].team == 'o' )
cout<<"\n You entered Team Omega";


cout<<"\n";

cout<<"\n Enter Project the person is responsible of :";
cin>>dbase[i].project;
cout<<"Project name is: "<<dbase[i].project;
cout<<"\n";

cout<<"\n Enter number of projects completed by the employee: ";
cin>>dbase[i].number_project_completed;
cout<<"The employee has acheived "<<dbase[i].number_project_completed<<" projects ";
cout<<"\n ";
cout<<"\n Input name";
cin>>dbase[i].name;

for(dbase[i] < 11);
{
if
(dbase[i]== dbase[i].name)
{
cout<<"array"<<dbase[i].name<<dbase[i].address;
}
else cout<<"not found";
}



cout<<"\n This shit works!!!!!!!!";
cin>>dbase[i].not;

break;

case 2:
cout<<"\n This **** works!!!!!!!!";
cin>>dbase[i].not;
break;
default:
cout<<"Error!!!! Brain Crash!!";
cin>>dbase[i].not;

}
return 0;
}





Edited by on 27-09-06 11:10
Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-09-06 12:56
The only thing I can say about your code is that 'o' != 'O'

(POC)
Code

void CompareOutput()
{
static char lowercaseO = 'o';
static char uppercaseO = 'O';

/* Proof of Concept that 'o' != 'O' */

std::cout<<(int)lowercaseO
         <<"\n\r"
         <<(int)uppercaseO
         <<"\n\r";

/* Solution: Use toupper() or tolower() to
   make input conform to one case         */

std::cout<<"\n\r"
         <<(int)(toupper(lowercaseO))
         <<"\n\r"
         <<(int)(toupper(uppercaseO))
         <<"\n\r";
}



Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 29-09-06 06:59
Okay...thnx..

got it!

Problem solved...

...hmm..now i need to make a file...and be able to extract data from it....




Edited by on 29-09-06 07:53
Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-06 10:52
ey3s here::
modified the code..works now..

Code
// 789.cpp : main project file. p2

#include "stdafx.h"
#include "stdlib.h"
#include "time.h"
#include <sys/timeb.h>
#include <stdio.h>
#include <iostream>
//#include <string> to be used later for files i think
using namespace std;

struct employee
{
   //different data types
   char name[30];
   char address[35];
   char gender;
   char team;
   char project[30];
   char department;
   float number_project_completed;
   float sales_pro;//sales made from the totality of projects
   float rank;//an assignment for the renk which the person possese within the company. The smallest number representing the most important
   char not;//nothing to do with program//to be removed

};
//array declaration
employee dbase[10];
int i = 0; //pointer 1
int x = 0;// pointer 2
int choice;

int main()
{
   
   char tmpbuf[128], timebuf[26], ampm[] = "AM";//setting AM format
 

   cout<<"\n=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=";
   cout<<"         ey3s of cha0s program            S.P";
   cout<<"\n==*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=";
   
   // Set time zone from TZ (Time Zone) environment variable. If TZ is not set,
    // the operating system is asked to obtain the default value
    // for the variable in order to find the time.
    //
    _tzset();

    // Displaying operating system-style date and time. in this case, that of Windows XP
    _strtime_s( tmpbuf, 128 );
    printf( "\n time:\t\t\t\t%s\n", tmpbuf );
    _strdate_s( tmpbuf, 128 );
    printf( "\n date:\t\t\t\t%s\n", tmpbuf );

//selection
   cout<<"\n--------------------------------------------------------------------------------";
   cout<<"\ Enter Choice...  Enter New Record:1    Test:2   ";//test 2 to be rm
   cin>>choice;

   switch (choice)
   {
   case 1:
      cout<<"\n [If a statement appears several times, then you have surely made a mistake] \n";
      cout<<"Please use only non-capital letters...<<a>> not <<A>>";//problem to be fixed later
      cout<<"\n      ";

      cout << "\n Please enter name: ";
      cin >> dbase[i].name;
      cout << "\n Please enter address: ";
      cin >> dbase[i].address;

//Start of loop aiming at restricting values for "gender"
   //While loop [iteration]
   do
    
   {cout<<"\n Enter gender of employee:";   
   cout<<"Key in M for Male and F for Female: ";
      cin>>dbase[i].gender;


      }  while (dbase[i].gender != 'f'&& dbase[i].gender != 'm');
         
         if (dbase[i].gender == 'm' )
         cout<<"\n You entered male";
         else
            if (dbase[i].gender == 'f')
            cout<<"\n You entered Female";
      cout << "\n ";

//Start of loop aiming at restricting values for "department" [iteration]
   //While loop
   do
            
      {cout<<"\n Enter Department. r: Research      d:   Development   ";
      cin>>dbase[i].department;
      
      }  while (dbase[i].department != 'd'&& dbase[i].department != 'r');
         //Capital letters not considered by program--2 be fixed LATER but SOON
      
         if (dbase[i].department == 'd' )
         cout<<"\n You entered Development Department";
         else
            if (dbase[i].department == 'r')
            cout<<" \n You entered Research Department";
         
      cout<<"\n";

// Start of loop aiming at restricting values for "team" [iteration]

   do    {cout<<"\n Enter Team.   a: Team Alpha   o: Team Omega   ";
      cin>>dbase[i].team;
      }   while (dbase[i].team != 'a'&& dbase[i].team != 'o');
            
            if (dbase[i].team == 'a')
            cout<<"\n You entered Team Alpha";
            else
               if (dbase[i].team == 'o'&& dbase[i].team == 'O' )
               cout<<"\n You entered Team Omega";


      cout<<"\n";

      cout<<"\n Enter Project the person is responsible of :";
      cin>>dbase[i].project;
      cout<<"Project name is: "<<dbase[i].project;
      cout<<"\n";
      
      cout<<"\n Enter number of projects completed by the employee: ";
      cin>>dbase[i].number_project_completed;
      cout<<"The employee has acheived "<<dbase[i].number_project_completed<<" projects ";
      cout<<"\n ";

//searching technique -- for statement/loop
      char name1[30];
      cout<<"\n Input name of employee you wanna search data for: ";
      cin>>name1;
   
      for( x=0; x<=i ; x++)
         {
            if (strcmp(dbase[i].name, name1) == 0)
      
               cout<<"address  "<<dbase[i].address;
               
            else cout<<"not found";
         }
         


      cout<<"\n This one** works!!!!!!!!";
      cin>>dbase[i].not;
      
      break;

   case 2:
      cout<<"\n This **** works too!!!!!!!!!!";
      cin>>dbase[i].not;
      break;


   default:
      cout<<"Error!!!! No such choice available!!";
      cin>>dbase[i].not;

   }
//end of searching

return 0;
}

//FILE STRUCTURE TO BE DONE





Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-10-06 10:52
ey3s here::
modified the code..works now..

Code
// 789.cpp : main project file. p2

#include "stdafx.h"
#include "stdlib.h"
#include "time.h"
#include <sys/timeb.h>
#include <stdio.h>
#include <iostream>
//#include <string> to be used later for files i think
using namespace std;

struct employee
{
   //different data types
   char name[30];
   char address[35];
   char gender;
   char team;
   char project[30];
   char department;
   float number_project_completed;
   float sales_pro;//sales made from the totality of projects
   float rank;//an assignment for the renk which the person possese within the company. The smallest number representing the most important
   char not;//nothing to do with program//to be removed

};
//array declaration
employee dbase[10];
int i = 0; //pointer 1
int x = 0;// pointer 2
int choice;

int main()
{
   
   char tmpbuf[128], timebuf[26], ampm[] = "AM";//setting AM format
 

   cout<<"\n=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=";
   cout<<"         ey3s of cha0s program            S.P";
   cout<<"\n==*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=";
   
   // Set time zone from TZ (Time Zone) environment variable. If TZ is not set,
    // the operating system is asked to obtain the default value
    // for the variable in order to find the time.
    //
    _tzset();

    // Displaying operating system-style date and time. in this case, that of Windows XP
    _strtime_s( tmpbuf, 128 );
    printf( "\n time:\t\t\t\t%s\n", tmpbuf );
    _strdate_s( tmpbuf, 128 );
    printf( "\n date:\t\t\t\t%s\n", tmpbuf );

//selection
   cout<<"\n--------------------------------------------------------------------------------";
   cout<<"\ Enter Choice...  Enter New Record:1    Test:2   ";//test 2 to be rm
   cin>>choice;

   switch (choice)
   {
   case 1:
      cout<<"\n [If a statement appears several times, then you have surely made a mistake] \n";
      cout<<"Please use only non-capital letters...<<a>> not <<A>>";//problem to be fixed later
      cout<<"\n      ";

      cout << "\n Please enter name: ";
      cin >> dbase[i].name;
      cout << "\n Please enter address: ";
      cin >> dbase[i].address;

//Start of loop aiming at restricting values for "gender"
   //While loop [iteration]
   do
    
   {cout<<"\n Enter gender of employee:";   
   cout<<"Key in M for Male and F for Female: ";
      cin>>dbase[i].gender;


      }  while (dbase[i].gender != 'f'&& dbase[i].gender != 'm');
         
         if (dbase[i].gender == 'm' )
         cout<<"\n You entered male";
         else
            if (dbase[i].gender == 'f')
            cout<<"\n You entered Female";
      cout << "\n ";

//Start of loop aiming at restricting values for "department" [iteration]
   //While loop
   do
            
      {cout<<"\n Enter Department. r: Research      d:   Development   ";
      cin>>dbase[i].department;
      
      }  while (dbase[i].department != 'd'&& dbase[i].department != 'r');
         //Capital letters not considered by program--2 be fixed LATER but SOON
      
         if (dbase[i].department == 'd' )
         cout<<"\n You entered Development Department";
         else
            if (dbase[i].department == 'r')
            cout<<" \n You entered Research Department";
         
      cout<<"\n";

// Start of loop aiming at restricting values for "team" [iteration]

   do    {cout<<"\n Enter Team.   a: Team Alpha   o: Team Omega   ";
      cin>>dbase[i].team;
      }   while (dbase[i].team != 'a'&& dbase[i].team != 'o');
            
            if (dbase[i].team == 'a')
            cout<<"\n You entered Team Alpha";
            else
               if (dbase[i].team == 'o'&& dbase[i].team == 'O' )
               cout<<"\n You entered Team Omega";


      cout<<"\n";

      cout<<"\n Enter Project the person is responsible of :";
      cin>>dbase[i].project;
      cout<<"Project name is: "<<dbase[i].project;
      cout<<"\n";
      
      cout<<"\n Enter number of projects completed by the employee: ";
      cin>>dbase[i].number_project_completed;
      cout<<"The employee has acheived "<<dbase[i].number_project_completed<<" projects ";
      cout<<"\n ";

//searching technique -- for statement/loop
      char name1[30];
      cout<<"\n Input name of employee you wanna search data for: ";
      cin>>name1;
   
      for( x=0; x<=i ; x++)
         {
            if (strcmp(dbase[i].name, name1) == 0)
      
               cout<<"address  "<<dbase[i].address;
               
            else cout<<"not found";
         }
         


      cout<<"\n This one** works!!!!!!!!";
      cin>>dbase[i].not;
      
      break;

   case 2:
      cout<<"\n This **** works too!!!!!!!!!!";
      cin>>dbase[i].not;
      break;


   default:
      cout<<"Error!!!! No such choice available!!";
      cin>>dbase[i].not;

   }
//end of searching

return 0;
}

//FILE STRUCTURE TO BE DONE





Author

RE: Drowning into an ocean of despair called C++

Uber0n
Member



Posts: 1963
Location: Sweden‭‮
Joined: 13.06.06
Rank:
Hacker Level 3
Posted on 03-10-06 13:35
ey3s_of_cha0s wrote:
ey3s here::
modified the code..works now..


Sweet Grin see you on msn


img230.imageshack.us/img230/724/uber0nsig3hj6.gif
http://uber0n.web. . .
Nope http://uber0n.webs.com/
Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 06-10-06 06:38
i need to know how to convert char to int in c++....

also got problems with the file structure...

and need to compare fields within the array to sort them out...is this possible???

Kinda like display all the records in order of [any integer related to them]




Edited by on 07-10-06 19:00
Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 07-10-06 08:15
Take a look at std::atoi()

As for your other two questions, I'm not quite sure what you're asking.
Author

RE: Drowning into an ocean of despair called C++


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-10-06 06:57
No need for atoi(), a simple
Code
static_cast<int>(myCharValue);


will work just fine (assuming he really wants char to int and not an array of characters). Also, C++ has the standard template library for a reason, so why aren't you using std::string etc. As for your other questions, well you'll have to be a bit more specific on what you mean.

Cheers,
T-Metal

Edited by on 21-10-06 09:05