|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On January 24 2014 08:57 obesechicken13 wrote:Oh that's pretty cool. Has anyone had any experience with leveldb? https://code.google.com/p/leveldb/I have to use it for a course and my TA is saying that I have to "install" it? I can make leveldb just fine with the default make file but I'm supposed to use a specific make file and two other files. CC = g++ OPTS = -I $(LEVELDB_DIR)/include -lpthread $(LEVELDB_DIR)/libleveldb.a
all: read write read: read.cc $(CC) -o read read.cc $(OPTS)
write: write.cc $(CC) -o write write.cc $(OPTS)
clean: rm -rf read write leveldb_dir
test: all ./write ./read
I have read.cc and write.cc in the same folder as the makefile. Every time I run make, I get an error message: g++ -o read read.cc -I /include -lpthread /libleveldb.a g++: error: /libleveldb.a: No such file or directory make: *** [read] Error 1 wut do? nvm I'm getting it slowly.
Two things you can do:
1) Drop it into an existing folder that are included by default in your linker, like this
ldconfig -v 2>/dev/null | grep -v ^$'\t'
And drop your .a file into one of those folders, or
2) Add the folder in which the library is in to your makefile with the -L<path_to_library> switch.
Should fix your problem
|
On January 24 2014 08:57 obesechicken13 wrote: CC = g++ OPTS = -I $(LEVELDB_DIR)/include -lpthread $(LEVELDB_DIR)/libleveldb.a
all: read write read: read.cc $(CC) -o read read.cc $(OPTS)
write: write.cc $(CC) -o write write.cc $(OPTS)
clean: rm -rf read write leveldb_dir
test: all ./write ./read
I have read.cc and write.cc in the same folder as the makefile. Every time I run make, I get an error message: g++ -o read read.cc -I /include -lpthread /libleveldb.a g++: error: /libleveldb.a: No such file or directory make: *** [read] Error 1 wut do? nvm I'm getting it slowly.
alternatively make sure the LEVELDB_DIR variable is set correctly. note how your $(LEVELDB_DIR)/libleveldb.a resolves to just /libleveldb.a, meaning LEVELDB_DIR is not set at all. make sure LEVELDB_DIR is set to the folder libleveldb.a resides in.
[nunez@gimli src]$ export TEAM='liquid' [nunez@gimli src]$ echo $TEAM liquid [nunez@gimli src]$
|
Yeah, the instructions on the course page are not great. I should have gone to the first tutorial though.
|
Do you guys use a GUI builder for Java? If not, any tutorial/ebook that you'd recommend?
|
On January 25 2014 02:23 darkness wrote: Do you guys use a GUI builder for Java? If not, any tutorial/ebook that you'd recommend? The IDE I used at work was eclipse though netbeans is also used.
|
Any recommendations on good Object Oriented design books? I mostly do C#.net, though I don't think that should matter.
|
Would someone have article or forum post about enum, define, const for c++. They seem to work same in most cases, so i would like to know if there is any big reason to use one over another. Or is the difference only cosmetic?
For example is there something wrong with way i use them? + Show Spoiler +/* Array sizes */ const int HEIGHT = 200; const int WIDTH = HEIGHT; const int PLAYERINFORMATIONS = 9; const int UNITINFORMATIONS = 5;
/* Positions of the game on command line */ const int SCREENPOSITION1 = 0; const int SCREENPOSITION2 = 20;
/* Stage txt files */ const string STAGE1 = "map1.txt"; const string STAGE2 = "map2.txt";
/* Unit/Player array usage */ enum{ VERTICAL, HORIZONTAL, OLDVERTICAL, OLDHORIZONTAL, UNITCODE, KEYUP, KEYRIGHT, KEYLEFT, SCREENPOSITION };
/* Different game components */ enum{ PLAYER1 = '1', PLAYER2 = '2', ENEMY = 'V', GROUND = 'M', EMPTY = '_', GOAL = 'G' };
/* Unit movements */ enum{ UP = -1, DOWN = 1, RIGHT = 1, LEFT = -1 };
/* Defines for keyboard keys */ #define VK_1 0x31 // Keyboard key 1 #define VK_W 0x57 // Keyboard key W #define VK_D 0x44 // Keyboard key D #define VK_A 0x41 // Keyboard key A
|
#define identifier replacement-listThe #define directives define the identifier as macro, that is instruct the compiler to replace all successive occurrences of identifier with replacement-list, which can be optionally additionally processed. If the identifier is already defined as any type of macro, the program is ill-formed. source
enum name { enumerator = constexpr , enumerator = constexpr , ... }An enumeration is a distinct type whose value is restricted to one of several explicitly named constants ("enumerators"). The values of the constants are values of an integral type known as the underlying type of the enumeration. source
cv (const-volatility) specifiers and qualifiersAppear in any type specifier, including decl-specifier-seq of declaration grammar, to specify constness or volatility of the type being declared.
const - defines that the type is constant. source
so a #define is a preprocessor macro! an enum is a type! and const is a type qualifier!
i think you should avoid #defines, and choose either an enum or a const numeric type!
|
On January 24 2014 02:11 RoyGBiv_13 wrote: EDIT: It may also be the case that the programmer implemented both ways in order for you to use whichever one makes your program easier to understand. My guess is that the Builder pattern was implemented in order to avoid the long list of arguments for the Gson constructor. An advantage of doing it this way (having many arguments in the constructor, having the builder just call .build()/.create()/etc, instead of passing the builder to the object's constructor):
testability!
It's much easier to mock arguments directly into the constructor when need be. Much more annoying to have to use deep mocks, or create test container objects. And when you don't need to use mocks ('cus you shouldn't if you can avoid it), you can just pass the object directly, instead of having to ball it up inside a builder in your test.
|
|
|
Need a little bit of help here:
int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30}; Scanner scan = new Scanner (System.in); System.out.print("Please input a number"); int SearchValue = scan.nextInt(); for (int i = 0; i < array.length; i++){ if (SearchValue == array[i]){ break; } } System.out.println("Found"); } }
The assignment is to use a linear search in order to find a value inside an array. If the value is found, then we print found, if not, then we print not found.
The code above works fine for values that are found. However, when I input suppose 100, it keeps giving me that it was found, when it is obviously not in array. Any ideas?
|
On January 26 2014 14:07 Housemd wrote: Need a little bit of help here:
int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30}; Scanner scan = new Scanner (System.in); System.out.print("Please input a number"); int SearchValue = scan.nextInt(); for (int i = 0; i < array.length; i++){ if (SearchValue == array[i]){ break; } } System.out.println("Found"); } }
The assignment is to use a linear search in order to find a value inside an array. If the value is found, then we print found, if not, then we print not found.
The code above works fine for values that are found. However, when I input suppose 100, it keeps giving me that it was found, when it is obviously not in array. Any ideas?
?? You print found after the loop?
|
On January 26 2014 14:07 Housemd wrote: Need a little bit of help here:
int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30}; Scanner scan = new Scanner (System.in); System.out.print("Please input a number"); int SearchValue = scan.nextInt(); for (int i = 0; i < array.length; i++){ if (SearchValue == array[i]){ break; } } System.out.println("Found"); } }
The assignment is to use a linear search in order to find a value inside an array. If the value is found, then we print found, if not, then we print not found.
The code above works fine for values that are found. However, when I input suppose 100, it keeps giving me that it was found, when it is obviously not in array. Any ideas? Put System.out.println("Found"); right before the break to fix it temporarily. Right now you are just running a search and then printing "found" regardless.
Since you want to be able to print out "not found" (which the above fix does not change) I would use a while loop. Go for it, and think a little more than you did for what you just posted. You could alternatively use your current structure and add just like three lines or so...
|
On January 26 2014 14:13 mishimaBeef wrote:Show nested quote +On January 26 2014 14:07 Housemd wrote: Need a little bit of help here:
int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30}; Scanner scan = new Scanner (System.in); System.out.print("Please input a number"); int SearchValue = scan.nextInt(); for (int i = 0; i < array.length; i++){ if (SearchValue == array[i]){ break; } } System.out.println("Found"); } }
The assignment is to use a linear search in order to find a value inside an array. If the value is found, then we print found, if not, then we print not found.
The code above works fine for values that are found. However, when I input suppose 100, it keeps giving me that it was found, when it is obviously not in array. Any ideas? ?? You print found after the loop?
Shit, I didn't notice that and I worded my question terribly wrong. That wasn't the intention of my question:
So I fixed that code like this:
int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30}; Scanner scan = new Scanner (System.in); System.out.print("Please input a number"); int SearchValue = scan.nextInt(); for (int i = 0; i < array.length; i++){ if (SearchValue == array[i]){ System.out.println("Found"); break;
So now, I need to print "Not Found" for let us just say 100. Should I just use an else statement?
Sorry for dumb questions, I'm a newbie 
|
On January 26 2014 14:20 Chocolate wrote:Show nested quote +On January 26 2014 14:07 Housemd wrote: Need a little bit of help here:
int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30}; Scanner scan = new Scanner (System.in); System.out.print("Please input a number"); int SearchValue = scan.nextInt(); for (int i = 0; i < array.length; i++){ if (SearchValue == array[i]){ break; } } System.out.println("Found"); } }
The assignment is to use a linear search in order to find a value inside an array. If the value is found, then we print found, if not, then we print not found.
The code above works fine for values that are found. However, when I input suppose 100, it keeps giving me that it was found, when it is obviously not in array. Any ideas? Put System.out.println("Found"); right before the break to fix it temporarily. Right now you are just running a search and then printing "found" regardless. Since you want to be able to print out "not found" (which the above fix does not change) I would use a while loop. Go for it, and think a little more than you did for what you just posted. You could alternatively use your current structure and add just like three lines or so...
Just to clarify, I need to use a for loop. Would your suggestion of a while loop eliminate the for loop or just add on to the current code?
|
On January 26 2014 14:29 Housemd wrote:Show nested quote +On January 26 2014 14:20 Chocolate wrote:On January 26 2014 14:07 Housemd wrote: Need a little bit of help here:
int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30}; Scanner scan = new Scanner (System.in); System.out.print("Please input a number"); int SearchValue = scan.nextInt(); for (int i = 0; i < array.length; i++){ if (SearchValue == array[i]){ break; } } System.out.println("Found"); } }
The assignment is to use a linear search in order to find a value inside an array. If the value is found, then we print found, if not, then we print not found.
The code above works fine for values that are found. However, when I input suppose 100, it keeps giving me that it was found, when it is obviously not in array. Any ideas? Put System.out.println("Found"); right before the break to fix it temporarily. Right now you are just running a search and then printing "found" regardless. Since you want to be able to print out "not found" (which the above fix does not change) I would use a while loop. Go for it, and think a little more than you did for what you just posted. You could alternatively use your current structure and add just like three lines or so... Just to clarify, I need to use a for loop. Would your suggestion of a while loop eliminate the for loop or just add on to the current code? Just think: how could you use a boolean here?
If you were a bit newer I would just tell you but since this is an assignment for what is probably a second semester class you should be able to figure this out yourself.
|
On January 26 2014 14:32 Chocolate wrote:Show nested quote +On January 26 2014 14:29 Housemd wrote:On January 26 2014 14:20 Chocolate wrote:On January 26 2014 14:07 Housemd wrote: Need a little bit of help here:
int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30}; Scanner scan = new Scanner (System.in); System.out.print("Please input a number"); int SearchValue = scan.nextInt(); for (int i = 0; i < array.length; i++){ if (SearchValue == array[i]){ break; } } System.out.println("Found"); } }
The assignment is to use a linear search in order to find a value inside an array. If the value is found, then we print found, if not, then we print not found.
The code above works fine for values that are found. However, when I input suppose 100, it keeps giving me that it was found, when it is obviously not in array. Any ideas? Put System.out.println("Found"); right before the break to fix it temporarily. Right now you are just running a search and then printing "found" regardless. Since you want to be able to print out "not found" (which the above fix does not change) I would use a while loop. Go for it, and think a little more than you did for what you just posted. You could alternatively use your current structure and add just like three lines or so... Just to clarify, I need to use a for loop. Would your suggestion of a while loop eliminate the for loop or just add on to the current code? Just think: how could you use a boolean here? If you were a bit newer I would just tell you but since this is an assignment for what is probably a second semester class you should be able to figure this out yourself.
I'm taking AP Computer Science. We are doing searches and this was extra credit work.
|
|
|
Update on Program:
int array [] = {15, 26, 27, 74, 65, 36, 73, 46, 73, 29, 30}; Scanner scan = new Scanner (System.in); boolean x = true; System.out.print("Please input a number"); int SearchValue = scan.nextInt(); for (int i = 0; i < array.length; i++){ if (x == true){ SearchValue = array [i]; break; } } if (x){ System.out.println("Found"); } else { System.out.println("Not Found"); } } }
Works perfectly fine for values that are in the array. For values that are not, it still prints out found. I believe that I have a small syntax error (in the last if-else statement?) but I cannot spot it. I tried to use Chocolate's suggestions of booleans and it looks promising.
|
NVM I GOT IT WOOOOOOOOOOOT
|
|
|
|
|
|