?
Solved

Mathematical Logic

Posted on 2011-10-13
6
Medium Priority
?
225 Views
Last Modified: 2012-05-12
Hello,

In an array, for every 4 elements i have a new member information, example

If my array has only one member, will be something like...

array[0] = "some value";
array[1] = "some value";
array[2] = "some value";
array[3] = "some value";

if my array has two members, will be like

array[0] = "some value";
array[1] = "some value";
array[2] = "some value";
array[3] = "some value";
array[4] = "some value"; //here start a new member info
array[5] = "some value";
array[6] = "some value";
array[7] = "some value";

if i need to know, how many members the array is holding...
(count(array) / 4); //4 = number of elements for each member

Ok, now if i need to loop through members and display each member info?

for (i=0;i<(count(array) / 4);i++)
{
//here how to step and display each member info separated member by member?
}

its not oriented to any language, doesnt matter if you program in C++, Delphi, Java, PHP, etc... will be the same logic hehe

can you help me?

regards!
0
Comment
Question by:cebasso
  • 3
  • 2
6 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36964589
Rather than an array like that why not use a collection of classes?
0
 
LVL 28

Accepted Solution

by:
strickdd earned 2000 total points
ID: 36964745
@Neilsr this is C++ and the collection of objects would require creating the collection class.

@OP

for (i=0;i<(count(array) / 4);i++)
{
     info1 = array[i*4];
     info2 = array[i*4+1];
     info3 = array[i*4+2];
     info4 = array[i*4+3];
}
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36964772
"its not oriented to any language, doesnt matter if you program in C++, Delphi, Java, PHP, etc... will be the same logic"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:cebasso
ID: 36964807
@Neilsr exaclty, but i mean about the logic, simple and pure... as strickdd did [i*4 +1], etc...
0
 
LVL 4

Author Closing Comment

by:cebasso
ID: 36964810
Perfect! thank you!
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36964837
The logic is that as a programmer you would not use a linear array to hold a collection of related data. It is as poor and lazy as it gets in terms of development.

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question