I am writing a Windows Form program, and currently it has 3 Lists. I need to loop through all three, and use each possible combination, so am using three nested for loops.
I found that if the outer loop had less elements than one of the inner loops/lists, some were missed off, as I need to save all the possible combinations of list a + b + c.
This is what I wrote:
Code:
public int CalculateOrderToProcessLists()//for three lists
{
int order = 0;
if (sListOne.Count() > sListTwo.Count() && sListTwo.Count() > sListThree.Count())
{
order = 123;
[Code ....
My problem is I would like to be able to have 4 (or more if possible) lists, and to calculate what order to process the lists will be exponentially more complex.
Any better way of comparing the sizes of the lists, so that I can use the nested loops of say 4 lists, but being able to use N number of lists would be awesome.
Im working on a script compiler and i need to handle different types of data. Actually different categories of items.
Let's say i have two categories: cat's and bird's. They are different and stored in different lists. And let's say there is a simple command: GIVE_FOOD_TO(animal_type, food_type) Animal type here can be either from birds category or cat's category.
And also let's say user gives command: GIVE_FOOD_TO(cat1, fish) and also for example: GIVE_FOOD_TO(bird1, birdfood)
Variable names could be anything, but im storing each variable name in std::map so later i can figure out with what animal current command is used.
When im parsing the script then i must know if user supplied either cat or bird. If i just would have cat's or bird's category then i would have only 2 lists and not a big problem to loop through either cats list or birds list and find out in what list the "cat1" is or in what particular list the "bird1" is. It would be in one or another.
But i have a lot of categories and looping through all of these lists (or std::maps) is slow and doesn't seem like a good. Just to find out in what list it's stored. I can't rely on variable names, they could be anything.
Big picture atm:
1) I have one BIG box which stores all of the categories
2) When i need to find out to which category the variable (animal_type) point's to i must get it quickly, dunno, std::map in std::map or something?
What i need basically is: I have different lists (each one is just a category for either birds or cats in this example) And when i have variable name, i must find out quickly in what particular category this item is stored. So i can work with it.
I'm simply trying to find the length of the linked list, but my findSize() function isn't working right and I'm not sure where it's going wrong...I get a segmentation fault when i run it, so probably out of bounds somewhere...just where?
How to find the size of an array in called function? When we pass the array a argument to function definition we will be having base address of array, so my understanding is that we will not get the size of an array? but is there any hacking for this to find size of array other than passing as size an argument to this called function?
I am trying to find the size of an array using a Try-Catch block. As seen on the code, I want the error to be caught when the index is out of range in "while" loop but at each time, program stops working.
int x[] = {34,5,1,536,2}; int length = 0; int tt = 0; try {
I need validation on what the user inputs. Input should not be an alphabet, empty, and not negative number. This program is for finding the GCD and LCM of multiple numbers.
#include <stdio.h> void bubble_sort(int numbers[], int len) { int i, j; int swapped;
I have array of 100 elements and I'm trying to write elements which index is smaller than the index of the maximum element of the array. My problem is that I can't determine how big this array should be . I found which is my biggest index.
Code:
#include <visual_2013.h> #include <stdio.h> #include <stdlib.h> #define DIM 10 void enterArray(int x[]); void array2(int x[]); int maxAndIndex(int x[], int n, int *index); int main()
I'm currently writing a cross-platform on screen keyboard application that highlights keys on the screen as you type them. My approach was to use an image of a keyboard and layer semi-transparent sprites over each key on key events, and as a consequence I needed to map out precise positions of each of these sprites relative to the background image.
The issue became how to load those positions into my application during runtime? My solution was to use excel to make a .csv of all the x-y coordinates, but instead of just deploying the .csv with my application I decided to write a quick app that parsed each line of the csv for coordinate pairs and write those floating point numbers to a binary file instead. That way the end user can't easily edit the coordinates of the sprites.
Now on to my question. The way I load the data into my application is by this method:
#include <fstream> #include <vector> /* other includes */ /* ... runtime code ... */ std::vector<float> pixmapPosData;
[Code] ....
This works fine on my system, but what if sizeof(float) has a different length their system? Then this function could throw a read access violation towards the end of the file (since the .bin file is exactly 508*sizeof(float) bytes long on my computer), and not to mention the coordinates would be meaningless. Is there any way to avoid this? Or maybe I just just suck it up and deploy a .csv file?
comparing with screen size the height is bigger but lenght is smaller. I don't understand.
I can understand that different printers process the fonts in different way and then to have different lenghts. That's not the problem. The problem is I need to simulate in screen the same behaviour i will have on printer because these texts are being aligned in the document, and I don't want to see that the text si aligned different in text than in paper.
What can I do to render the text on screen with the same size I will have on the printer? Print preview is doing it. Should I change the font parameters? is something related with pixels per inch?
I was wondering why, in C, the sizeof of a struct is larger than the the sum of all the sizeofs of it's members. It only seems to be by a few bytes, but as a bit of a perfectionist I fine this a bit annoying.
I want to develop an application which can host multiple views of explorer (window), where as each window is totally separate from others. So that I can have multiple desktop views through my single explorer. Any built in feature in .NET ?
I've been working on a function that works like a pipeline of a shell but receives a directory, go over it an search for every file to send it to a filter, something like this in bash "cat dir/* | cmd_1 | cmd_2 | ... | cmd_N", The only problem i have with the code is the redirection of the pipe descriptors.
Code:
int main(int argc, char* argv[]){ char** cmd; int Number_cmd; cmd = &(argv[2]); /*list of cmds*/ Number_cmd = argc-2; /*number of cmds*/ }
[code]....
The code is seems to work fine except when i run it with more than one command in example ("./filter DIR wc rev") in this case it returns
wc: standard input: Bad file descriptor wc: -: Bad file descriptor 0 0 0
I'm using multiple C++ files in one project for the first time. Both have need to include a protected (#ifndef) header file. However, when I do that, I get a multiple definition error.
From what I found from research, adding the word inline before the function fixes the error. Is this the right way to do this, and why does it work? Should I make a habbit of just declaring any function that might be used in two .cpp files as inline?
Say I have 5 vectors of unsigned char each of size 5. I want to take the max of each index and store it in a new vector. What is the most optimal way to accomplish this?
See, there are two do while loop, if I need a permutation with more than two lists, there'll be more and more do-while loops, that's make code looks ugly, I wonder if stl has some tricky way that can do this with just one next_permutation.
In our homework assignment it states to, "write a set of dynamic linked lists" and so on. Now, the problem I'm confusing myself is at the storage inside of each node. To my understanding, each node contains the prev and next nodes, but also a pointer to the data, in this case being a string. He has asked us to manage these strings as rows of chars such as
char[0] = c // first node being addressed here char[1] = a char[2] = t char[3] = char[4] = d // second node starting here char[5] = o char[6] = g char[7] =
I have written my code where each node is holding a string, not separated as shown above... my question is to how you can build your doubly linked list where each node is being address a set of chars.
New to this C stuff, and was going through Kochan's book Programming in C and got to chapter 9 structured lists.There's this problem that requires you to set a Variable N that calculates days.
N = 1461 x f(year, month) / 4 + 153 x g(month) / 5 + day where f(year, month) = year-1 (if month <=2) =year (otherwise)
I was having issues getting the right values for N so I tried to see what T1.year gives me when I type in firstDay.month=02, firstDay.day=08 and firstDay.year=1999, and I got 8. According to book I should be getting 1998.
I'm trying to do is let the user type in something like A654321 (note: these are ALL the characters, i.e. 'A', '6', '5', '4', etc..) Then I just want to display that current number back to them and I am getting some weird pointer memory allocation error..
#include<iostream> using namespace std; //To rename data-type "int" or integer to "element" (Both are equivalent).. typedef int element; //To declare an appropriate SENTINEL. char const SENTINEL = '#';
[code]....
It seems like the first part that it bugs out at is in my Clean(); function..
Unhandled exception at 0x01383FBB in VegMe.exe: 0xC0000005: Access violation reading location 0xCCCCCCD0.
It doesn't like head = head->next; ?Also, ignore the ReverseList(); function, it is not being used as of now.
What I want to create is a program that sorts through a huge list (millions of lines).
I want it to get rid of any line that contains a word that isn't in an English dictionary.
Example list:
00sdfdsf ahdadsg angel ksjflsjdf green green000 carrot
and it would go through millions like that, giving me only:
angel green carrot
as my new list.
How could I go about this? What programs would I need? And at the very least how can I remove unwanted things like numbers, double letters, underscores etc.?