April 15, 2021, 04:22:26 AM

Author Topic: Basic C++ Programming Help  (Read 22770 times)

0 Members and 1 Guest are viewing this topic.

ajastru2000

  • Guest
Basic C++ Programming Help
« on: July 05, 2003, 01:49:19 AM »
Hi All,I'm a beginner in C++, try 2 stil grasp it- 1 week old. My Problem:
a1  b1  c    a2  b2  c
1    2   0     2   4    4
1    3   1     2   5    3  
1    4   3     2   6    2
1    5   6     2   7    0

Above re 2 array data, 1:a1,b1,c 2:a2,b2,c    In both arrays a1 n a2 have fixed values,can be ignored. Wat i wan is how do i get C++, by having d 1st array fixed n 2 compare d 'c' value with 2nd array's 'c' value. when both d value re d same(or +/- 2 d value), i need C++ to record both d 'b1' n 'b2' value for d corresponding 'c' values.
Problems:
1)firstly the fixed arrays 1st 'c' value need to scan thru d 2nd array when its value is d same(+/- 2 d 2nd 'c;c value)
2)After getting d first point, d 2nd point wil b d next value or +/- 2 'c' of d 2nd array.If it doesn't find a corresponding value, it needs 2 proceed to the 3rd value of d 1st array, n repeat d above process.
3)C value ranges from 0 to 32, after 32 it starts with 0 again til 32 n so on.

Sorry 2 all i think this a simple problem, wil appreciate if anyone could shed some light into it. :(

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #1 on: July 05, 2003, 05:39:11 PM »
I'm trying to decipher what you're after but I just can't... Can you try to explain again ? I'm so lost in your post I don't even know what you're asking.

(No offense when I say this) to me, your question is not coherent... It's the English I don't understand....

Met.
"My Terminal is my Soul"

ajastru2000

  • Guest
Re:Basic C++ Programming Help
« Reply #2 on: July 06, 2003, 01:43:59 AM »
Hi sorry for the confusion,i'l try again to put my Q in the best possible form.

1)I'l explain my set of data characteristics: Ihave 2 sets of them as shown below(This just apart of it not the complete)

a1  b1  c1    a2  b2  c2
1    2   0       2  4    4
1    3   1       2  5    3  
1    4   3       2  6    2
1    5   6       2  7    0

a1 & a2 have fixed values alwayz. b1 & b2 varies according to their respective c1 & c2 value.

2)I need C++ , firstly to use set1 as an reference, than it needs to scan c2 for the same value as in c1, once it gets c1=c2, it needs to record both the value for b1 & b2.

3) this what it basicaly needs to do. But since the 'c' values vary from 0 to 32(0,1,2......30,31,32,0,1,2.....30,31,32,0...).There is a possibility of a number repeating twice or thrice n so on.

4)So to avoid the problem, the program needs to record the first c1=c2 first. The next c1 + 1 value wil be in the following c2 +1/+2/+3. (Here the + refers to the next row n so on)

5)If it can't detect c1 + 1 in the given range, it needs to move to c1 + 2, and scan at c2 +1/+2/+3. In short if it had detected a corresponding value for c1 + n at let's say at c2 + x, for the following c1 + (n+1), it has to scan from c2 + (x+1/+2/+3). If it doesnt it has to move to c1 + (n+2) and scan at the same c2 + (x+1/+2/+3), if it gets a similar value for c1 + (n+2) = c2 + (x+2), than the next scanning for c1 +(n+3) wil be at c2 + ((x+2) +1/+2/+3)) and so on.

I hope i havent complicated things again, if its stil confusing i'l try again,thanx for the responz, appreciate it.






Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #3 on: July 06, 2003, 02:34:50 PM »
Okay, a little more clear.

Let me make sure I have it understood somewhat...

What you want to do is scan the first array for characters that exist in the second array. Upon finding this, you set the corresponding value in the non-constant element of the array ?

I'm not 100% sure I understand it but that's what I gathered (roughly). Can you elaborate on what I said or tell me what is wrong or right ? I apologize I'm not understanding this, but I'm willing to try to help as much as possible.

Met.
 
"My Terminal is my Soul"

Offline wilnix

  • mv user /dev/null
  • Administrator
  • Forum Hero
  • *****
  • Posts: 690
  • Country:
  • Gender: Male
  • You're not the fastest packet in the subnet...
    • Wilnix - The NetAdmin's Resource
Re:Basic C++ Programming Help
« Reply #4 on: July 06, 2003, 03:48:41 PM »
did you want the answer or just help with the answer? reply and i'll post it either way...

wilnix
alt email address: wilnix@hackphreak.org

ajastru2000

  • Guest
Re:Basic C++ Programming Help
« Reply #5 on: July 06, 2003, 06:45:10 PM »
Hi thanx Met & wilnix,

Met, wat u understood is rite, i need the first array of column c1 to scan thru d second array for the same values in the column c2, and set the corresponding value of the both arrays of the column b1 & b2. Dat wil b al, thanx.

Wilnix, I want the answer, would appreciate if u could post it.

Thanx guyz for d help being rendered.

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #6 on: July 06, 2003, 10:11:45 PM »
Okay what this example (in C) does is:

defines MAX to be of size 5.
Then it makes two integers (i and j) and two arrays (array1 and array2).

Next it fills the array up.

It then checks every number in array2 and compares it to the CURRENT array1 elements. If there is a match it prints out the element of BOTH arrays and that it matched.

I think it should give you a start. I'd do more but still not sure 100%. You can from here fill in the necessary parts (I hope).

If nothing else, it gives you the skeleton code to scan more than one array at a time to find matches.

Code: C++
  1.  
  2. #define MAX 5
  3. int main(void)
  4. {
  5. int i, j, array1[5], array2[5];
  6.  
  7. array1[0] = '1';
  8. array1[1] = '0';
  9. array1[2] = '0';
  10. array1[3] = '7';
  11.  
  12. array2[0] = '1';
  13. array2[1] = '5';
  14. array2[2] = '0';
  15. array2[3] = '2';
  16.  
  17.  
  18. for (i=0;i<MAX-1;i++) {
  19.    for(j=0;j<MAX-1;j++) {
  20.        if (array1[i] == array2[j]) {
  21.          printf("we found a match at array1 element %d and array2 element %d \n", i, j);
  22.  
  23.            }
  24.         }
  25.     }
  26.  
  27. return 0;
  28.  
  29. }
  30.  

This example code would print out:

we found a match at array1 element 0 and array2 element 0
we found a match at array1 element 1 and array2 element 2
we found a match at array1 element 2 and array2 element 2

That's about all I can offer right now. Maybe Will can offer more since he seems to undersand it a bit more. Just play around with it.

Met.
« Last Edit: July 06, 2003, 10:13:49 PM by Metgod »
"My Terminal is my Soul"

ajastru2000

  • Guest
Re:Basic C++ Programming Help
« Reply #7 on: July 07, 2003, 08:20:48 AM »
Hi Met,thanx for ur suggested solution, its nearly fills my requirements. I've got one question here,

Below is the answer for ur program, how do i make the scanning done once when a match is found, wat i mean is, in the second line array1 element 1 = array2 element 2. Once if the elements are matched they musn't be scanned again, here element 2 is again matched element 2 in the 3rd line.
In short once a match is found between both elements in both the arrays, the scanning musn't backtrack to this matched elements.
Hope u could shed some light here too.

we found a match at array1 element 0 and array2 element 0
we found a match at array1 element 1 and array2 element 2
we found a match at array1 element 2 and array2 element 2

Anyway thanx man, i'm using ur method as my building blocks, tryin to modify here and there and learn.thanx.


Offline wilnix

  • mv user /dev/null
  • Administrator
  • Forum Hero
  • *****
  • Posts: 690
  • Country:
  • Gender: Male
  • You're not the fastest packet in the subnet...
    • Wilnix - The NetAdmin's Resource
Re:Basic C++ Programming Help
« Reply #8 on: July 07, 2003, 02:02:19 PM »
all you need to do is exit out of the loop when you've found what you need and keep track of where you left off...keywords: more variables. Then you could go back to that point in the array...

wilnix
alt email address: wilnix@hackphreak.org

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #9 on: July 07, 2003, 02:05:19 PM »
Okay

here's an idea:

You make a function that actually does the checking and then returns a value. If no match is found, then you return NULL.

Example:

Code: C++
  1.  
  2.  
  3. #define MAX 5
  4. int find_value(int array1[], int array2[]);
  5.  
  6. int main(void)
  7. {
  8. int x, array1[MAX], array2[MAX];
  9. array1[0] = 1;
  10. array1[1] = 0;
  11. array1[2] = 0;
  12. array1[3] = 7;
  13.  
  14. array2[0] = 5;
  15. array2[1] = 5;
  16. array2[2] = 0;
  17. array2[3] = 2;
  18.  
  19.  
  20. x = find_value(array1, array2);
  21.  
  22. printf("found match: %d", x);
  23.  
  24.  
  25.  
  26. return 0;
  27. }
  28.  
  29. int find_value(int array1[], int array2[]) {
  30.  
  31. int i, j;
  32.  
  33. for (i=0;i<MAX-1;i++) {
  34.    for(j=0;j<MAX-1;j++) {
  35.        if (array1[i] == array2[j]) {
  36.          printf("we found a match at array1 element %d and array2 element %d \n", i, j);
  37.          return (array1[i]);
  38.  
  39.        }
  40.  
  41.    }
  42.  
  43.  
  44. }
  45.  
  46. return (NULL);
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  


Now what you do is you call the function and if it returns NULL then there is no match (so do error checking). If it finds a match it'll return the actual character found.

Just play around with this and let me know if you need anymore help. If you want to set the value to another part of another array then just grab the value returned and then set it to the value in the array.

Met.
« Last Edit: July 07, 2003, 02:12:03 PM by Metgod »
"My Terminal is my Soul"

ajastru2000

  • Guest
Re:Basic C++ Programming Help
« Reply #10 on: July 07, 2003, 07:25:56 PM »
Thanx guys,i'l try out n keep u'l updated,really appreciate both ur guidance.

Offline wilnix

  • mv user /dev/null
  • Administrator
  • Forum Hero
  • *****
  • Posts: 690
  • Country:
  • Gender: Male
  • You're not the fastest packet in the subnet...
    • Wilnix - The NetAdmin's Resource
Re:Basic C++ Programming Help
« Reply #11 on: July 08, 2003, 01:02:33 PM »
Metgod hooked you up. You should buy him the drink of his choice...or just send him money....

wilnix
alt email address: wilnix@hackphreak.org

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #12 on: July 08, 2003, 04:55:41 PM »
Hrm... I like that idea.. Money sounds really good.. I could sure use some for more computer stuff, so I could help you out more...

Thanks !

Met.
"My Terminal is my Soul"

Offline wilnix

  • mv user /dev/null
  • Administrator
  • Forum Hero
  • *****
  • Posts: 690
  • Country:
  • Gender: Male
  • You're not the fastest packet in the subnet...
    • Wilnix - The NetAdmin's Resource
Re:Basic C++ Programming Help
« Reply #13 on: July 08, 2003, 07:13:29 PM »
Pay up buster, or we're telling Bush you carry weapons of mass destruction!!  :P

wilnix
alt email address: wilnix@hackphreak.org

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #14 on: July 08, 2003, 09:02:10 PM »
hahaha.. yeah, we mean business mister ! pay me now !!


mail from: someone@someone.com
rcpt to: president@whitehouse.gov
data

This guy has WMD ! Take him down now !

Now you have one final chance.. if you don't pay up I'll enter a period and hit enter ! I mean it !!

hehe, something like that....

Met.
"My Terminal is my Soul"