Alex Edwards 321 Posting Shark

I had a hard time understanding the concept of memory in a computer, but something my Instructor told me gave me some hope.

He mentioned that memory isn't really created upon invocation of "new" in C++, and stated also that memory isn't really removed upon the invocation of "delete."

I was very shocked by this! I felt slightly more inspired to understand the construct of memory, because I thought that (somehow) information was written out to sectors or omitted (and considered some type similar to null), but I did not ever think of memory always being there and simply being modified then "fenced" or "unfenced."

I wonder... is there any way to unfence memory from C++ such that you could use memory without declaring "new" and instead work in a managed secton? I.e, pass pointers memory address of a managed section and simply copy objects right on tops of them, or is "new" absolutely required to map out the necessary amount of space needed for an object?

I'm still pretty fuzzy on memory, and I will continue to study it. I'm pretty curious about this, since C++ is such a strong language and there's almost nothing you can't do.

Thank you very much,

-Alex

Alex Edwards 321 Posting Shark

I typically don't post anything unless I have a question or comment... but I am still trying to understand Serialization for Network-Applications and I ran into a brick wall (repeatedly) during a project that required sending and receiving chunks of data from one Client to another.

Be aware of using ArrayLists during Serialization and consider creating your own Collection-implementation for storing objects and sending/receiving them across Sockets--

I learned the hard way...

X_X

Ezzaral commented: Good link. Serialization can be a little trickier than many newcomers realize. +12
Alex Edwards 321 Posting Shark

Correct me if I'm wrong, but doesn't the cavet ^ symbol in C++.NET mean that the type is actually a pointer?

List1.Add(Vec1());

looks fishy... Vec1 is a pointer-type, so doesn't that mean you need to call gcnew to properly instantiate that Vec? O_O

List1.Add(gcnew Vec1());

I'd assume.

Alex Edwards 321 Posting Shark

Without looking at the code... I must ask... is it truly required for both vectors to be of the same type ( <string> ) to complete the assignment?

Your if statement will almost always evaluate to be true because you're using the single = (assignment) operator as opposed to the == (equals) operator. Is this really what you want to do? I haven't seen all of your code so it is hard to tell @_@

Alex Edwards 321 Posting Shark

This is off topic, but I'm curious...

Why did you use msiL implementation with unmanaged code? Why not purely managed or purely unmanaged?

Alex Edwards 321 Posting Shark

I had to edit what you posted... the indentation got to me--

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <sstream>

using namespace std;

void getfile (ifstream&);
void input (ifstream&, int&, string*);
void write (int, string*, int*, string);
void createArray (string*, string*, int, int, string*, int&);
void run (int, string*, string*, int, int&);
bool check (string*, string*, int);
bool check2 (string*, string*, int, int, int);
void set (int*, int);
void createBit (string*, string*, int, int, int*);
void removeDup (string*, int);
void developArray (string*, string*, string*, int, int, int&, int*, int*, int*);
void intersect (int*, int*, int*, string*, string*, int);

main (){   

	int ALast, BLast, ABLast=1, x=0;
	string letter[5] = {"A", "B", "AUB", "A^B", "A-B"};
	int BitA[ABLast], BitB[ABLast], BitAUB[ABLast], BitAIB[ABLast];
	string A[10], B[10], AB[20], AIB[20], A_B[20];
	ifstream InData;

	getfile (InData);

	input (InData, ALast, A);  // Puts the lines into an array
	input (InData, BLast, B);  // Puts the lines into an array

	developArray (A, B, AB, ALast, BLast, ABLast, BitA, BitB, BitAUB);

	set (BitAIB, ABLast);
	intersect (BitA, BitB, BitAIB, AIB, AB, ABLast);

	//print outputs
	write (ABLast, A, BitA, letter[0]);
	cout << endl;
	write (ABLast, B, BitB, letter[1]);
	cout << endl << endl << endl;
	write (ABLast, AB, BitAUB, letter[2]);
	write (ABLast, AIB, BitAIB, letter[3]);

	cout << endl;
	system ("pause");
	return 0;
}

void getfile (ifstream& InData){// Gets the file from the user 

	string file;
	cout << "Enter the name of the file: ";
	cin >> file;
	InData.open (file.c_str());
	while(!InData){// Prompt for new file name if not able to open …
Alex Edwards 321 Posting Shark

Thank you for the reply,

but wrong way, I believe you're showing pushing an array of character strings into a vector<string>.

Regards.

Not quite. It would be valid if your array consisted of const char* values because strings accept const char* (and also chars) as a constructor argument via the ADT implementation in C++. Since the constructor of the string class isn't marked explicit, using const char* arguments where a string is expected will cause the compiler to generate a string object with the given const char* argument as a parameter for the constructor.

So during a push_back call using a const char* for a vector<string>, you will generate string objects to be stored inside the vector<string>

string

vector

Alex Edwards 321 Posting Shark

I am working on a logger showing showing types and values for classes and sql statements (ie parameters in sql statements)

From the example above I will need to show output as something like
Long: null and BIGINT: null

What is a possible recommendation to be able to do this?

Should I create overloaded methods for each type or pass in the class at runtime? Any other suggestions are welcome and thanks for your help!!!

This might help--

public class NullTest{
	
	public static void main(String... args){
		
		Object obj = null;
		System.out.println(determineNull(obj));
		obj = new Object();
		System.out.println(determineNull(obj));
	}

	private static String determineNull(Object o){
		return (o == null) ? "Object is null": "Object is not null";
	}
}
Alex Edwards 321 Posting Shark

Is there a reason you are using '/n' instead of '\n' ?

Also, is there a defined expression for a string being equivalent to a char? If not then you could try line != "\n" instead, though I don't mess with file I/O in C++ too much so I can't completely confirm this without a brief look-up =P

Edit: After looking here I realized that you might have to encapsulate the "\n" value in a string object before doing the comparison.

Alex Edwards 321 Posting Shark

I marked the Thread daemon as a good practice. Unfortunately it makes the example hard to see, the way the code is currently written. Consider this example instead--

import javax.swing.*;

public class NameSpaceClass001{

	class A extends JPanel{

		// blah... mumble...
		private B myB = null;
		public A(){
			myB = new B(this);
			Thread t = new Thread(myB);
			t.setDaemon(true);
			t.start();
		}

		public B getB(){
			return myB;
		}
	}

	class B implements Runnable{

		private A panel = null;
		public boolean running = true;

		public B(A ref){
			panel = ref;
		}

		public int safeWait(int seconds){
			long l = System.currentTimeMillis(); // get current time
			long next = l + (seconds * 1000); // get current time + future time
			while(l < next) l = System.currentTimeMillis(); // wait specified seconds
			return seconds;
		}

		@Override public void run(){
			while(running){
				System.out.println("Calling repaint after " + safeWait(3) + " seconds...");
				panel.repaint();

			}
		}
	}

	public static void main(String... args){
		NameSpaceClass001 nsc001 = new NameSpaceClass001();
		NameSpaceClass001.A myA = nsc001.new A();

		myA.getB().safeWait(15);
	}
}
stephen84s commented: The good guy guiding everyone to the finish and ensuring people get there ;) +3
Alex Edwards 321 Posting Shark

Though Stephen has already pointed this out, you need to get rid of the access modifiers when declaring data types in your main method.

The reason is because it is irrelevant for a method to have access specifiers within its scope when you are declaring local variables that will not "escape" the scope of the method unless returned, and even so it would be a copy of that value (or a copy of a pointer) in which you will have access to it publicly.

Also consider the following--

import java.util.Scanner; //input scanner

public class Inventory001
{

	// main method begin program execution
	public static void main( String args[] )
	{
		String productName;  // product name
		double number;  // product item number
		double units;   // number of units in stock
		double price;   // price per unit
		double value;   // total value of all units in stock



		// scanner to obtain user input
		Scanner input = new Scanner ( System.in );

		Product001  p = null;

		// scanner product object
		{
			// You need to specify 5 values for your constructor!
			//p = new Product001(productName, number, units, price);
		}


		// value total of all units
		{
			System.out.printf(p.toString() );
		}


	}  // end main method
} // end Inventory class

I attempted to fix your constructor problem, but I want you to think of a few reasons of why it is incorrect so that you wont make the same mistake again.

Alex Edwards 321 Posting Shark

I do not recall the arrow keys having a virtual key code associated with them from standard C++.

I think the only way to do it is through the OS interpretation of the virtual key code of the keyboard, though I could be wrong...

http://delphi.about.com/od/objectpascalide/l/blvkc.htm

Alex Edwards 321 Posting Shark

Why exactly does class B have to extend A?

From an immediate glance I can see a potential cycle instantiation issue.

Think about it--

1) Class A, after static initialization, will instantiate a class B object--

2) Class B extends A, so when a B object is constructed, the super constructor of A is called but between that process the pre-initialization is done again leading back to step 1!

--which means that your program will cause new memory to be called and constructors to be (in theory) pushed on stack memory along with variables that are used within them, and additional growth of objects in the heap due to subsequent calls of new that are not resolved to make objects unreachable since there is a valid reference pointing to it.

What you want to do is something like this--

import javax.swing.*;

public class NameSpaceClass001{

	class A extends JPanel{

		// blah... mumble...
		private B myB = null;
		public A(){
			myB = new B(this);
			Thread t = new Thread(myB);
			t.setDaemon(true);
			t.start();
		}
	}

	class B implements Runnable{

		private A panel = null;
		public boolean running = true;

		public B(A ref){
			panel = ref;
		}

		private int safeWait(int seconds){
			long l = System.currentTimeMillis(); // get current time
			long next = l + (seconds * 1000); // get current time + future time
			while(l < next) l = System.currentTimeMillis(); // wait specified seconds
			return seconds;
		}

		@Override public void run(){
			while(running){
				System.out.println("Calling repaint after " + safeWait(3) …
Alex Edwards 321 Posting Shark

when i do...

String menu;

Scanner keyboard = new Scanner(System.in);
menu = keyboard;

if (menu = "D"){
   ....
}

there is error sign under "menu = "D"" <can't convert String to boolean>
why menu is boolean? I stated in String....

There are a number of issues with the above code.

First of all, when declaring a variable (like menu), you should initialize it on the spot... even if it is a null initialization.

Secondly, you are attempting to assign menu (which is a String type) to a Scanner type with the expression menu = keyboard. You probably meant to do something like--

menu = keyboard.nextLine()

-- such that you will receive a block until input is entered in the Scanner (in this case, from the Standard InputStream which is your keyboard).

The next seriously incorrect statement is the expression in the if statement. The problem is that it will always evaluate to be true because what you're asking the compiler to interpret is if the assignment of "D" to menu was not a null assignment, and since "D" is a valid String and menu can hold Strings, it will evaluate to be true.

You probably meant to do something like--

if(menu == "D")

-- such that there will be a boolean return based on the evaluation of menu being equivalent to "D".

However, this kind of comparison between objects is considered lazy and can result in behavior that is not predictable in a …

Ezzaral commented: All relevant and more help than asked for. +12
Alex Edwards 321 Posting Shark

I made a few fixes--

// reverse_stuff.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

void initial(int *v, size_t N)
{   
	size_t i;
	for(i=1; i < (N + 1); i++)
		v[i-1] = i;
}
void write (int *v, size_t N)
{
	for (size_t i = 1 ; i < (N + 1); i++)
		cout << v[i-1];
	cout << "\n";
}

void reverse (int *v, size_t N)
{
	for (size_t i = 1; i < static_cast<size_t>(N/2) + (size_t)1; i++)
	{
		int tmp = v[i-1];
		v[i-1] = v[N-i];
		v[N-i] = tmp;
	}
}


int main()
{   
	size_t  N;
	cout << "enter size of element:";
	cin >> N;
	if (N<=100){
		int *v = new int [N];
		initial (v,N);
		write (v,N);
		reverse (v,N);
		write(v, N);
		delete v;
	}
	cin.ignore();
	cin.get();
	return 0;
}

--I don't like providing solutions to non-existent problems, but I believe this is correct unless otherwise noted.

Alex Edwards 321 Posting Shark

Your reverse function looks suspicious.

You are overwriting the initial element before you store it to replace the last element, so the data is unrecoverable and you will end up with a mirrored half-way reversed array instead of the entire original array reversed.

The tmp implementation isn't helping because its only done once for only one location (which is the 2nd indice) of the array.

You probably meant to do something like this--

for (int i = 1; i<N-2; ++i)
{
	int tmp = v[i];
	v[i] = v[N-i-1];
	v[N-i-1] = tmp;
}

--also if efficiency is an issue, keep in mind that you're reversing the order of the elements, so your array has the same elements, just mirrored across a pivot-point, or center element.

This means that you only need to do int-division based on the size of the array, and reverse values across that pivot point.

Alex Edwards 321 Posting Shark

Yes, thank you AD for the clarification. I saw a developer mention a max size of the std::string class but didn't really investigate sources until recently. Here's some more information.

Edit: Depending on what a kilo-byte, etc means these days, you'll be in reasonable hands if you pull a 30 MB file into a string.

For example, if a megabyte is 1024 kilobytes and a kilobyte is 1024 bytes, and each char is a byte (which, a standard char should be) then you are looking at 30 * 1024 * 1024 bytes of information, which is only 251658240 bytes which is far under the limit of a string object.

If MB means 1000 kilobytes and a kilobytes is 1000 bytes, you're looking at a slightly smaller number than the one mentioned.

To be safe, assume 1024 for every additional "step" in bytes.

Alex Edwards 321 Posting Shark

Previous: strings can only hold a certain amount of data, so I'd assume so.

Have you considered using the non-standard rope to meet your data needs? Or possibly a vector<char> implementation?

Edit: Actually my previous post might need some more investigation, so I'm omitting it. My apologies.

Alex Edwards 321 Posting Shark

Remive the semi-colon by your while-statement and you should be in business =)

stephen84s commented: The more I see posts like above the more I feel good debuggers are breed nearing extinction :P !!! +3
staneja commented: Good Catch +2
Alex Edwards 321 Posting Shark

no....i really need help here...
i just duuno what to respond better than that....i knw this is just an easy stuff for you guys out there....but i am ashame with myself cause i cant even face it...i cant even do own part as a trainee...how the hell am i going to success....i am going through a lot of difficulties and i have to face it...it is just too burden for me ....i am just 19 yrs old but i am having more 16 problems? ....and i am still trying to face it!!!....money, time, work, studies, plan, friends, health, etc....i dun have time to take my own rest at all....think and i see....once you wake up ...you need to think about financial...then you have to work with a poor health condition, to make life easier is to have more money....with more money i have to earn more with more job....when more job i have money for my educations, after educations is done i have to plan for my own future...when i use up all my time i dun even have time for my friends!! and i cant even think what should do!!...tell me then EXPERT....if you all knw it so well....GUIDE ME!!!!....i am just asking this little help and i cant even get a good reply on this....sorry ...no hard feelings but i aint going to just lying at there...i will try my best to figure out by myself rather than waiting for ppl to help me...cause by time i …

Alex Edwards 321 Posting Shark

Oh I'm sorry. I understand now.

I see that you want to tokenize the actual control cards to determine their size, etc and then collect additional information for the actual control-cards (such as their data sections and the attributes for the data sections).

I thought you needed an easier means of grouping the data, but I misunderstood at first.

It's still possible to use my first suggestion, however you will need to determine what defines a control card. For example, will all sizes of user programs be 16+ in hexadecimal? Is the data reliably grouped in the .txt file?

I can see of another way of this being done, but I need more information about how the information is organized in the .txt file (consistency, etc) and if there is a specific format for user programs (do they always have a number at the end of their name to identify them?), and do Data section always start with the word Data?

Alex Edwards 321 Posting Shark

UML is stupid and should be avoided. And definitely shouldn't be studied and studied and studied and studied and studied...

Such a cold hear you have there X_X

UML is a wonderful language. I'm starting to get the hang of it! It's just hard as hell to study from an exam book with little prior knowledge @_@

Alex Edwards 321 Posting Shark

Yay Alex is back!...Heres a sample data of how the strings are going to look like and if you take a look at post #12...u'll see what they mean.

// JOB 1 17 2
0xC050005C
0x4B060000
0x4B010000
0x4B000000
0x4F0A005C
0x4F0D00DC
0x4C0A0004
0xC0BA0000
0x42BD0000
0x4C0D0004
0x4C060001
0x10658000
0x56810018
0x4B060000
0x4F0900DC
0x43970000
0x05070000
0x4C060001
0x4C090004
0x10658000
0x5681003C
0xC10000AC
0x92000000
// Data 14 C C
0x0000000A
0x00000006
0x0000002C
0x00000045
0x00000001
0x00000007
0x00000000
0x00000001

I used the above example in a .txt file called Loader_Information in this code snippet--

import java.util.*;
import java.io.*;

public class OS_Loader{

	private static HashMap<String, ArrayList<String> > hm
			= new HashMap<String, ArrayList<String> >();

	public static void main(String... args){

		OS_Loader.store("F:/123456789/Loader_Information.txt");
		for(String element : OS_Loader.getCodeValues("// JOB 1 17 2")){
			System.out.println(element);
		}

	}

	public static boolean store(String arg){
		BufferedReader br = null;
		FileReader fr = null;
		File f = null;

		try{
			f = new File(arg);
			fr = new FileReader(f);
			br = new BufferedReader(fr);
		}catch(FileNotFoundException fnfe){
			fnfe.printStackTrace();
			return false;
		}

		String s = "", currentKey = "";

		try{
			while((s = br.readLine()) != null){
				if(s.substring(0, 2).equalsIgnoreCase("//")){
					currentKey = s;
					hm.put(currentKey, new ArrayList<String>(0));
				}else{
					hm.get(currentKey).add(s);
				}
			}
		}catch(IOException ioe){
			ioe.printStackTrace();

		}finally{
			try{
				br.close();
			}catch(Throwable t){System.exit(1);}
		}

		return true;
	}

	public static ArrayList<String> getCodeValues(String key){
		return hm.get(key);
	}
}

--notice the advantage of doing this. In the event that you need a particular set of instructions you can obtain them via the associated control card.

Alex Edwards 321 Posting Shark

I'm not near a Java compiler at the moment, so I'll have to give you a pseudo-code suggestion.

(I'll make an attempt at an implementation, but don't expect too much).

Create a BufferedReader (import java.util.*) and read lines from the file using the method BufferedReader.readLine() method.

Create a HashMap<String, ArrayList<String> >

After each successful read, check to see if the first char starts with a backslash and if it does, use that as a key for a HashMap and store the following information in a new ArrayList for the cooresponding map then add the ArrayList to the map.

Alex Edwards 321 Posting Shark

This looks like C and not C++...

Use C++ implementations--

#include <iostream>

using namespace std;

int main(){

     cout << " Testing 123... " << endl;
     cin.get();
     return 0;
}
Alex Edwards 321 Posting Shark

Hmmm, are these variable strings?

You may need to specify a switch-case for them.

Then again, you'll need to provide some more information on the representation of these strings.

There's a number of ways it can be done, but before introducing any let's see if we can make the process simpler by having you supplying some more information =)

Alex Edwards 321 Posting Shark

Give the assignment a try, and we'll probably help you @_@

Alex Edwards 321 Posting Shark

This example may help. Notice that you only need the starting point of the Square, relative to whatever plane it exists within, and the length of 1 side to determine the square--

public class Square{

	public short x = 0, y = 0, length = 0;

	public Square(short x, short y, short length){
		this.x = x;
		this.y = y;
		this.length = length;
	}

	public Square(Coord c, short length){
		x = c.first;
		y = c.second;
		this.length = length;
	}

	public final void displayCoords(){
		System.out.println(getULCoord() + "--" + getURCoord());
		System.out.println("|\t\t\t |");
		System.out.println("|\t\t\t |");
		System.out.println("|\t\t\t |");
		System.out.println("|\t\t\t |");
		System.out.println("|\t\t\t |");
		System.out.println("|\t\t\t |");
		System.out.println("|\t\t\t |");
		System.out.println("|\t\t\t |");
		System.out.println("" + getLLCoord() + "--" + getLRCoord());
	}

	public final class Coord{
		short first = 0, second = 0;

		public Coord(short first, short second){
			this.first = first;
			this.second = second;
		}

		@Override public String toString(){
			return "< " + first + ", " + second + " >";
		}
	}

	public final Coord getULCoord(){
		return new Coord(x, y);
	}

	public final Coord getURCoord(){
		return new Coord((short)(x + length), y);
	}

	public final Coord getLLCoord(){
		return new Coord(x, (short)(y - length));
	}

	public final Coord getLRCoord(){
		return new Coord((short)(x + length), (short)(y - length));
	}

	public static void main(String... args){
		System.out.println("\n");
		Square s1 = new Square((short)400, (short)500, (short)200);
		s1.displayCoords();
		System.out.println("\n\n\n");
	}

	public static void checkMemBefore(String arg){
		System.out.println(Runtime.getRuntime().freeMemory() + arg);
	}

	public static void checkMemAfter(String arg){
		System.out.println("\n" + Runtime.getRuntime().freeMemory() + arg);
	}
}

EDIT: For mathematical and visual reasons, I made the square a square relative to a …

Alex Edwards 321 Posting Shark

AD provides a good suggestion. In fact, learning anything that is .NET compatible (C#, C++, ADO, VB, J#, etc) is advantageous.

Alex Edwards 321 Posting Shark
Alex Edwards 321 Posting Shark

This is the C++ forum, so why would you use strcmp?

You can use string objects. Include <string> and you can compare 2 string objects lexigraphically with the string.compare(string) method.

I'm not near a c++ compiler atm, but the implementation will looks something like this-

#include<iostream>
#include <string>

using namespace std;

int main(){

  string a ("John");
  string b ("Mark");
  
  int result = a.compare(b);

  cout << "result of comparison between John and Mark is: " << result << "\n"; 

  cin.get();
  return 0;
}

Edit: This isn't to trash on AD's post. C is very useful, and if performance isn't an issue then consider using the char-array--encapsulating class string.

Alex Edwards 321 Posting Shark

You could create a class for the information that you read in (such as a Person class) and assign the attributes to data (i.e., a String for the line being read).

Then make each Person object implement Comparable<Person>

After generating the objects based on the data retrieved from the file, store the person object in an ArrayList after doing a check to see if that object already exists--

you will have to overwrite the Comparable<Person> compareTo method and then determine when 2 people are "equal" before you can do this.

Afterwards iterate through the list and do comparisons per person. If any 2 objects compareTo be the same, then don't insert them in the list.

Alex Edwards 321 Posting Shark

Whoops, I'm incredibly sorry!

Yes Vernon is right. I confused points with squares! In this case you would have to use 4, not 2 points (or at least 4 kinds of data - if you know the starting point of the squares location and the length and width of the Square, you have fully defined it).

And I do believe Vernon is correct about the points. If you have 160,000 points divide the points by 4 and you have that many squares.

My class would need to be reworked - instead of 2 shorts, make 4 and accept 4 points from the user. You can make methods (final) such that they return the displacement between x's and y's to retrieve the distance and also the area.

Alex Edwards 321 Posting Shark

Here's an example--

public class Square{

	public short x = 0, y = 0;

	public Square(short x, short y){
		this.x = x;
		this.y = y;
	}

	public static void main(String... args){

		Square.checkMemBefore(" - free mem before Square array");
		Square lotsOfSquares[] = null;
		try{
			lotsOfSquares = new Square[160000];
		}catch(Exception e){
			e.printStackTrace();
			System.exit(1);
		}

		Square.checkMemAfter( " - free mem after Square array\n");

		System.out.println("\n\n\n");

		Square.checkMemBefore(" - free mem before allocating Square objects");

		try{
			for(int i = 0; i < lotsOfSquares.length; i++){
				lotsOfSquares[i] = new Square((short)-200, (short)200);
			}
		}catch(Exception e){
			e.printStackTrace();
			System.exit(1);
		}

		Square.checkMemAfter(" - free mem after allocating Square objects");
	}

	public static void checkMemBefore(String arg){
		System.out.println(Runtime.getRuntime().freeMemory() + arg);
	}

	public static void checkMemAfter(String arg){
		System.out.println("\n" + Runtime.getRuntime().freeMemory() + arg);
	}
}
Alex Edwards 321 Posting Shark

160,000 elements in an array can be memory-expensive... so let's try to find a way to make things less expensive.

First of all, what is the range of your points (what are they for, and what is the maximum number you're planning on using per coordinate)?

If the point-value is under 256, you can get away with making 2 arrays (one with x points, and one with y points) and have corresponding "vectors" based off of the index of both elements.

That or you can do it a potentially more expensive way by creating objects that hold the coordinate information. Depending on the Java Object Model, you may end up using more memory per object generated, especially since all methods in Java are virtual so you may want to use publicly accessible points in that object if you decide to go that route.

Then again, the more important thing right now is understanding what your range is for points. What's the limit, and do your points ever reach negative numbers, or are they unlimited naturals?

Alex Edwards 321 Posting Shark

You have given no details at all, you didn't even ask a question or describe a problem :icon_confused: , exactly what do you need help with?

Deduction: He wants us to do it for him.

Conclusion: Wait for him to show some effort, or if he's lucky some chump will do it for him =P

Alex Edwards 321 Posting Shark

Hmm..

What have you done so far?

Alex Edwards 321 Posting Shark

It seems to me that you have a set of values returned to you from a traversal order and you would like to reconstruct the tree?

If you refer to this Tree-pedia link, you will see different methods of traversing trees and how they are mapped out with values =)

Also remember that Preorder starts with the root! I believe the algorithm for Pre-order traversal is to analyze the root, then move left then move right, though I could be a bit off on the entire definition @_@

I never understand how people seem to print the Tree's to the console with absolute ease... especially Narue and RadicalEdward... but nonetheless they do it well!

Here's a less efficient example that I managed to cook up in 2.5 hours #_# --

#include <iostream>
#include <string>
#include <exception>
#include <vector>
#include <sstream>

using std::cout;
using std::cin;
using std::endl;
using std::ostream;
using std::string;
using std::exception;
using std::vector;
using std::stringbuf;

typedef class troolean{
    short num;
        short diminish(short arg)       {return  (( (arg < 0)
                                        ? (-1) : ((arg > 0)
                                        ? (1) : (0) ) ));}
    public:
        troolean(short arg = 0)         {assign(arg);}
        short assign(short arg)         {return num = diminish(arg);}
        short assign(short arg) const   {return arg;}
        short getValue()                {return num;}
        short getValue() const          {return const_cast<troolean&>(*this).getValue();}
        short operator=(short arg)      {return assign(arg);}
        short operator=(short arg) const{return assign(arg);}
        bool operator==(short arg)      {short val = diminish(arg); return num == val;}
        bool operator==(const troolean& enemy){
            return this->getValue() == enemy.getValue();
        }
        friend ostream& operator<<(ostream& out, …
Alex Edwards 321 Posting Shark

Oh, word of caution when using StringBuilder and StringBuffer! I believe that if you append regular characters, they may be interpreted as numbers.

To prevent this (char c is an example--) , try append(c + "");

Alex Edwards 321 Posting Shark

To make an example of the difference via implementation--

#include <iostream>
#include <memory>

using std::cout;
using std::cin;
using std::ostream;
using std::auto_ptr;

template<bool>class B;
template<bool>class C;
template<bool>class D;

class A{
    public:
        ostream& run(ostream& out = cout){
            return out << "Class A\n";
        }
};

template<> // when true, run is virtual, when false run is not virtual
class B<true> : public A{
    public:
        virtual ostream& run(ostream& out = cout){
            return out << "Class B\n";
        }
};

template<>
class B<false> : public A{
    public:
        ostream& run(ostream& out = cout){
            return out << "Class B\n";
        }
};

template<> // when true, run is virtual. When false, run is non-virtual
class C<true> : public B<true>{
    public:
        virtual ostream& run(ostream& out = cout){
            return out << "Class C\n";
        }
};

template<>
class C<false> : public B<false>{
    public:
        ostream& run(ostream& out = cout){
            return out << "Class C\n";
        }
};

template<> // no difference between true and false in this case
class D<true> : public C<true>{
    public:
        ostream& run(ostream& out = cout){
            return out << "Class D\n";
        }
};

template<>
class D<false> : public C<false>{
    public:
        ostream& run(ostream& out = cout){
            return out << "Class D\n";
        }
};

int main(){

    auto_ptr< B<true> > test1 (new D<true>); // B virtual run is true
    auto_ptr< B<false> > test2 (new D<false>); // B virtual run is false (it isn't virtual)
    auto_ptr< B<true> > test3 (new C<true>); // B virtual run is true
    auto_ptr< B<false> > test4 (new C<false>); // B virtual run is false

    test1->run();
    test2->run();
    test3->run();
    test4->run();

    cout …
Alex Edwards 321 Posting Shark

I believe Masijade had something like this in mind, though I could be a bit off--

import java.io.*;
import java.util.ArrayList;

public class Driver
{
 //--------------------------------------------------< main >--------//

	public static void main (String[] args)
	{
		//array to hold data
		//String[] Data = new String[0];
		Driver D = new Driver();
		System.out.println(D.loader().toString()); // displays the information collected by the StringBuilder in loader
	}


	//--------------------------------------------< loader >--------//

	public StringBuffer loader()
	{

		String line = null;
		int count = 0;
		String example = ""; // dummy string, change this to the file that needs to be read
		ArrayList<String> variableSizeArray = new ArrayList<String>(0); // resizable array that is initially 0 lengthed
		StringBuffer sb = new StringBuffer();

		try
		{															// does FileReader.input() exist? And does it return a FileReader object?
			FileReader input = new FileReader(/*args[0]*/ example)/*.input()*/;
															// BufferedReaders wrap Reader objects, and input is already a Reader =P
			BufferedReader  buffRead = new BufferedReader(/*new FileReader(*/input/*)*/);

			line = new String();

			while((line=buffRead.readLine()) != null)
			{
				System.out.println(count+": "+line);
				variableSizeArray.add(line); //add each line to the array as it reads
				count++;
			}
			buffRead.close();
		}
		catch (IOException e)
		{
			// catch possible io errors from readLine()
			System.out.println("File input error!");
			e.printStackTrace();
		}

		String Data[] = variableSizeArray.toArray(new String[variableSizeArray.size()]);

		print(Data);

		for(int i = 0; i < Data.length; i++)
			sb.append(Data[i]);

		return sb;

	}
	/*
	private static String[] add(String s, String[] array)
	{
		int len = array.length;
		String[] temp = new String[len+1];
		System.arraycopy(array, 0, temp, 0, len);
		temp[len] = s;
		return temp;
	}
	*/

	private static void print(String[] data)
	{
		for(int i = 0; i < data.length; i++) …
Alex Edwards 321 Posting Shark

wxWidgets, qt, OpenGL, Ultimate C++, Win32 API, MFC (AFX), and I think .NET cover the general potential GUI implementations, though I'm sure there are more.

Alex Edwards 321 Posting Shark

Correct me if I'm wrong, but you are using the .NET Frameworks with C++, are you not?

If you are, have you tried looking up information on individual Components in the .NET Frameworks the way you want them to?

I was capable of compiling and running this example using Visual C++ 9.0 express edition (in CLR Console Application mode).

Alex Edwards 321 Posting Shark

You know C++ right, you java should be not much difficult. Get the book Head First Java and read it. And one thing, there is no such thing as pointers in java only references, though it internally uses the concept of pointers, dont confuse between the two, there area lot of low level differences, ok.

Get Head First Java, avery good book, read it chapter by chapter, don't skip any, and try to do exercises, your concepts will be very clear and good. Its avery good and easy to understand book presented in a very good way with no loss in info. You should be able to complete in 15 days. i did it.

There are pointers in Java, you just can't dereference them to access the object at the address. You always have to use indirection to manipulate objects in Java, but instead of the indirection symbol you use the "." symbol.

Alex Edwards 321 Posting Shark

What specific implementations do you need?

Learning Java is quite the trial.

To get a decent dosage of Java, I strongly STRONGLY recommend "Java, How to Program 7e" by Deitel & Deitel.

But this isn't good enough. Simply learning the language and some implementations might not be enough. What if you need to implement MVC via JavaScript, DHTML or JSP front-end and Java Servlet Controller with potential Java back-end?

Is the whole application going to be done in Java? Why did you migrate from C++ to Java for your task? What is it that you're trying to accomplish that you feel the need to learn Java?

Please, justify your reasoning.

Alex Edwards 321 Posting Shark

The problem wasn't the import. It looked like the OP already had the import listed.

The problem is that the Scanner class does not provide a "default" constructor for Scanner objects.

For a list of proper Constructors for Scanner objects, refer to this link.

The most common use for a Scanner object is the provide a way for pulling specific information out of a File or InputStream.

Example--

import java.util.Scanner;

public class MyScannerTest{

	public static void main(String... args){

		Scanner kb = new Scanner(System.in);

		System.out.println("Enter something, please... anything!\n");
		System.out.println("\nYou entered: " + kb.next());
	}
}

--though I think BufferedReader does the job much better than Scanner. Then again, each class solves a different problem in a similar way.

Alex Edwards 321 Posting Shark

I've recently started studying the Unified Modeling Language.

I'm currently using an exam book as a study guide, because it presents features without holding back on information-representation at all. Afterward, I will study the book made by the first 3 who started developing UML (since OOPSLA/OOSE I believe, though I could be off by a few years >_<).

But, as I started learning the features in the UML, I realized that UML itself is a language O_O

Some of you may laugh at this, but I didn't at first think of UML as its own language. I thought that UML was a model with specific features for describing things, though this example is probably still not a convincing defense.

I realized that it has such a defined set a features for organizing information (not just data, but practical things too) that it is probably the most portable concept across different languages and design-ideas.

This makes me curious, though. If this language is so versatile and variable, why is there no forum dedicated to design-ideas and refinement of UML? Is the UML too easy to be placed in a forum (because, to me it "looks" easy, but understanding the fundamentals of UML and improving organization skills and data-representation isn't quite as easy)? Is it too broad?

-Alex

Alex Edwards 321 Posting Shark

Sometimes the best way to test to see if something is concurrent or not is to use a tracing technique.

Basically split the code that is shared by threads onto different pieces of paper and pretend that one each paper resembles a Thread attempting to access or perform an operation.

If two threads enter the same function, is the function Thread safe? Are you accessing a reference of one object between two threads? Are you doing initialization that may not be thread safe (basically, both Threads may pass a particular condition test and cause something to be initialized twice) ?

The above code I provided is actually not thread safe, now that I think about it. If two threads are accessing the optionSelected(String) method and they are nearly as fast as each other, then there may be 2 requests to submit 2 different threads, however in this case it's even worse because the ExecutorService is initialized with 1 reusable Thread which means the other request may or may not be tossed aside. Even if it is tossed aside, it's still poor programming practice to simply leave it up to objects to handle errors that they were not defined to handle.

In this event I'd use a Double-Checked lock, so that when the method is called the first time it is synchronized upon a lock object and initialized properly. Afterward, there should be no cost of synchronization when a Thread is already doing its job.

An …

Alex Edwards 321 Posting Shark

It always comes up with an error:

The Directory "C:\config_file_directory" doesn't exist. Dev-C++ will now quit, please create the directory first.

I tried reinstalling the program but that also didn't work.

Did you try using C:/config_file_directory instead?

It may be that the \c is being mistaken for a special escape character, and not exactly two separate characters.

Edit: Also, for clarification, Dev C++ isn't a compiler. It is merely an IDE that uses compilers (such as mingw, etc).

Alex Edwards 321 Posting Shark

Oh, and in case it hasn't been addressed my tokenizer makes tokens out of substrings, not char's.