Intrade 33 Junior Poster

Hmmm

This is A WAY of going about it. You don't have to follow this word-for-word. This will give you an idea of what you can do.

--

You can make a class called BigInt that accepts a const char* or string as a number (or int), converts whatever case into individual digits in an array that is initially sized to be big enough for the first number.

Obviously have a flag (bool) called positive and set it based on the user's input (if the user inputs a string with a minus sign as its first character, or the user inputs a negative int, set the flag accordingling).

Create a set method that enables you to "set" the BigInt (in fact, you can simply have the constructor call the set method and put the work of assigning the number there). If the new number to be assigned is bigger (in terms of digits, not value!) than the old number, you'll have to resize the array to make up for that. You have two variables (one called size, and one called capacity) to keep track of the current size of the BigInt and to track whether or not the array needs to be resized.

So in all it is highly recommended that you have variables that cover these requirements-

*Array of ints
*ArraySize
*Capacity
*Positive flag
*3 different versions of the public function 'set' (one that accepts const char*, one …

Intrade 33 Junior Poster

Edit: this was for the first page ;p

Doesn't compile on VC++ 2010

Intrade 33 Junior Poster

The algorithm is explained in detail here:

http://en.wikipedia.org/wiki/Magic_square

Intrade 33 Junior Poster
//Phone_Directory.cpp
#include "StdAfx.h"
#include "Phone_Directory.h"
#include "Directory_Entry.h"
using namespace std;


void Phone_Directory :: load_data(const string& source_name)
{
    this->source_name = source_name;
    // Maybe you need to import a header file for ifstream?
    ifstream in(source_name.c_str());

http://www.cplusplus.com/reference/iostream/ifstream/ifstream/

Intrade 33 Junior Poster

Between lines 10 and 11 you could add some error checking for the input.

cin >> num;
if(num <= 1){

   cout << "Invalid number entered. Exiting program.\n" << endl;
   return 0;
}else if(num == 2){
   cout << "2 is a prime number.\n" << endl;
   return 0;
}
cout << "The number you entered is: " << num << endl;
Intrade 33 Junior Poster

http://broadband.motorola.com/consumers/products/VT2400/downloads/VT2442_User_Manual_US_UK.pdf on page 40 it describes turning on/off the remote web feature. You'll want this disabled.

The "Remote Web Access" feature was already disabled before my friend used my IP.

Intrade 33 Junior Poster

I'm using a (Vonage) Motorola VT2442 router.

Intrade 33 Junior Poster

The problem is that I logged into my router and the remote access feature is turned off yet somehow my friend enters my WAN IP address and can access my router.

I don't know why this is. I'm honestly confused.

I thought for sure he would reach my website. I have Apache 2.2 listening on port 80 for my LAN IP Address. I thought for sure that someone entering my WAN IP address without a specific port would access the directory Apache is pointing to and therefore be capable of accessing my files... but so far I haven't had such luck.

I'm using a Vonage router... I know that's REALLY vague but once I get some more information I'll let you know. Thank you.

Intrade 33 Junior Poster

It's not just a matter of code that works, but good practices also.

Intrade 33 Junior Poster

int* resizeArray is a declaration that states "hey, I want space for a pointer to an int"

int resizeArray is a declaration that states "hey, I want space for an int"

int* resizeArray is a pointer to an int that can be treated as an array, whereas int resizeArray can only be treated as an integer.

That's the short story of it.

Intrade 33 Junior Poster

3 problems

Declaration of a copy constructor should be of a const reference variable parameter and not just a reference variable parameter--

Exforsys(const Exforsys& e)

--you might get away with it during compile/run but your professor may dock you points.

second, not sure if void main() is going to work on all c++ compilers, use int main and return 0.

finally, I'm pretty sure you have to type "using namespace std;" to use cout... not to mention the missing endl or flush statement after pushing a string into the stream.

Intrade 33 Junior Poster

Thank you Ancient Dragon! =)

Intrade 33 Junior Poster

I managed to get that far, but I can't use the .dll file in the second portion of the example.

I have the .dll generated, I just can't seem to use it via the References window...

Upon further inspection I tried reading ahead and realized that I may have needed to do additional steps, so I did.

I corrected my mistake by including the PATH of the .dll and to reference the header file and not the actual .dll--

"#

To reference the header files of the dynamic link library, you must modify the include directories path. To do this, on the Property Pages dialog box, expand the Configuration Properties node, expand the C/C++ node, and then select General. Next to Additional Include Directories, type the path of the location of the MathFuncsDll.h header file.
#

The executable does not load dynamic link libraries until runtime. You must tell the system where to locate MathFuncsDll.dll. You do so by using the PATH environment variable. To do this, on the Property Pages dialog box, expand the Configuration Properties node and select Debugging. Next to Environment, type the following: PATH=<path of MathFuncsDll.dll file>, where <path of MathFuncsDll.dll file> is replaced with the actual location of MathFuncsDll.dll. Click OK to save all the changes."

And I still see nothing in the Reference window on the new project.

My additional include directory is C:\Documents and Settings\****\My Documents\Visual Studio 2010\Headers_References, a new folder I created to …

Intrade 33 Junior Poster

Can you try compiling the code again and giving us the errors?

Intrade 33 Junior Poster

I followed this guide for VC++ 2010,

http://msdn.microsoft.com/en-us/library/ms235636.aspx

and apparently I either have a missing module/component or I did something wrong.

I followed everything smoothly up until step 6--

"6. To build the project into a DLL, from the Project menu, select MathFuncsDllProperties…. On the left pane, under Configuration Properties, select General. On the right pane, change the Configuration Type to Dynamic Library (.dll). Click OK to save the changes."

There was no option in the configuration type for .dll's.

The documentation then states that I can use a compiler-specific command to make a .dll file (/LD) which I think works, but then I go to import references and my file doesn't show up in the reference list.

I tried to, manually, add my .dll generated fie to my project by stuffing the .dll in the ReferenceAssemblies folder (C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v4.0) with no luck, so I'm not sure what I'm supposed to do to get the .dll to appear in my reference window so I can link it to other projects.

I'm not sure if this is a known issue or not, or if I somehow did something wrong during the installation? Or if the /LD command dumps the .dll in the folder I need it to.

Any help is appreciated. Thanks!

Intrade 33 Junior Poster

I modified it but still feel I have a major error somewhere. Any ideas?

#include <iostream>
#include <iomanip>

using namespace std;
int main () 
{
int num;
int i;
cout << "Please enter a positive integer. Enter # to quit." << endl;
cin >> num;
if (num <=1)
cout << "Not a prime number" << endl;
else
{
for (i = 3; i <=num; i++)
cout << "Is a prime number." << endl;
{
 if (num % i == 0)
{
    cout << "Not a prime number." << endl;
    system ("pause");
return 0;
    }
}
}
system ("pause");
return 0;
}

Between this code--

//...
if (num <=1)
cout << "Not a prime number" << endl;
// no check for num % 2
else
{
for (i = 3; i <=num; i++)
//...

-- you forgot to check for num % 2 before testing against i=3+

Other than that it's fine, but good luck testing on big numbers... squaring the number will save you significant runtime.

Intrade 33 Junior Poster

I am writing a program that outputs whether or not a number is prime. Can anyone help me find where my syntax error is? Also, i get that i = 3; i <= num; i++ would be true for it being a prime number from the other forums I have read but I honestly don't get why, can someone explain? I get everything else I have done thus far.

#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
    int num;
    int i;
    
    cout << "Please enter a positive integer: " << endl;
    
    if (num <=1)
    return false;
else if (num == 2)
    return true;
else if (num % 2 == 0)
    return false;
else (i = 3; i <= num; i++);
    return true;
    
    system ("pause");

    return 0;
}

Vernon is saying that the code "else (i = 3; i <= num; i++);" is NOT a boolean expression. It can't be true or false.

What I think is required is a constant check on the number. Before referring to code outside, think about the problem itself.

Let's take a few minor examples for all numbers within the range [3-*)

Is 3 a prime number? Yes it is. Why? Because no other positive multiples exist to obtain 3 except 1*3 (only one set of multiples).
Is 4 a prime number? No it isn't. Why? Because there exist multiples 2*2 and 1*4.
Is 5 a prime number? Yes it is. Only set of multiples are 1*5.

Intrade 33 Junior Poster

Hello everyone. Sorry in advance if my question seems noobish.

I'd like to know if it's possible to change my router such that it uses another, dynamically assigned IP address to be accessed as opposed to my current.

Let's assume my WAN IP address is A.B.C.D and I turn my router firewall off and enable port forwarding on port 80. People now have access to my router (which I don't want). Instead, I would like to somehow make it so that my server is reached from the same IP address (because my server is listening on port 80).

Is there any way to accomplish this?

My network configuration is a Modem, a phone router connected to my modem which sends packets to my computer, and then I have a Wireless Internet router connected to my phone router.

Intrade 33 Junior Poster

Oh, it seems this question was already covered in another post (well, sortof).

http://www.daniweb.com/forums/thread240738.html

Intrade 33 Junior Poster

Hmm its been awhile since I made a windows-based application.

From what I remember there was a loop running in my WinMain that blocked until a message was sent to the msg queue. Events that fired were collected into a buffer and handled in a linear manner.

It's probably better if another developer on this site answers your question, or you look into programming with the windows api to write your own windows programs.

Usually, each windows-based program has some sort of shell for collecting events/msgs where you can code around it or within it to handle the events. Look for them on google, I'm sure a number of them are around for you to modify and use for your own purpose(s).

Intrade 33 Junior Poster

Correct me if I'm wrong, but when running a windows application where you're collecting messages from the event queue, aren't you supposed to use a completely different program entry point?

http://msdn.microsoft.com/en-us/library/ms633559%28VS.85%29.aspx

Actually, upon some sifting I found a potentially useful set of functions in that Microsoft document.

http://msdn.microsoft.com/en-us/library/ms632654%28VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/ms632655%28VS.85%29.aspx

Extended documentation for collecting mouse input also from msdn--

http://msdn.microsoft.com/en-us/library/ms645610%28VS.85%29.aspx

Intrade 33 Junior Poster

Proper formatting is definitely key here...

Intrade 33 Junior Poster

Can you show the entire script you're running for this?

Intrade 33 Junior Poster

Not sure if I udnerstand the question, but I think you mean something along the lines of setting a value of one of the Z variables in the array?

struct Z{

    int a;
    int b;

    Z() : a(0), b(0) {}

    void setA(int x){ a = x; };
    void setB(int y){ b = y; };
};

int main(){

   Z arrayOfZ[10];
   Z[0].setA(5);
   
   // ... etc
   

   return 0;
}

If not and you want to construct an array of Z's with a specified constructor to apply for each Z, I don't know but I think its possible.

Intrade 33 Junior Poster

I fiddled around with the code and came up with this.

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

struct Student{

      double gpa;
      int id;
      int age;
      
      Student(int a = 0, int b = 0, int c = 0){
                  gpa = a;
                  id = b;
                  age = c;
      }      
};

struct TreeNode{
      
      TreeNode* left;
      TreeNode* right;
      Student student;
      
      TreeNode() : left(0), right(0){}
};

struct IntBinaryTree{
      
      TreeNode* root;
      
      void displayMaxandMin(TreeNode* nodePtr);
      double findMin(TreeNode* nodePtr, double);
      double findMax(TreeNode* nodePtr, double);
      void displayTree();

      private:
              
              void displayTreeHelper(TreeNode* node, string tab);
};

void IntBinaryTree::displayTree(){
     
     if(root){
              displayTreeHelper(root, "");
     }
}

void IntBinaryTree::displayTreeHelper(TreeNode* node, string tab){
     
     if(node == 0){
             return;    
     }else{
            
           displayTreeHelper(node->right, tab + "\t");
           cout << tab << node->student.gpa <<endl;
           displayTreeHelper(node->left, tab + "\t");
     }
}

double IntBinaryTree::findMin(TreeNode *nodePtr, double min)
{
	if (nodePtr)
	{
		if (nodePtr->student.gpa < min)
			min = nodePtr->student.gpa;
		min = findMin(nodePtr->left, min);
		min = findMin(nodePtr->right, min);
	}
    return min;
}


double IntBinaryTree::findMax(TreeNode *nodePtr, double max)
{
	if (nodePtr)
	{
		if (nodePtr->student.gpa > max)
			max = nodePtr->student.gpa;
		max = findMax(nodePtr->left, max);
		max = findMax(nodePtr->right, max);
	}
    return max;
}

void IntBinaryTree::displayMaxandMin(TreeNode* nodePtr)
{
	double min, max;
	min = findMin(nodePtr, 1000);
	cout << "The lowest gpa in the class is: "<< min<<endl;
	max = findMax(nodePtr, 0);
	cout << "The highest gpa in the class is: "<< max<<endl;
}

int main(int argc, char *argv[])
{
    IntBinaryTree ibt;
    
    TreeNode a, b, c, d, e, f, g, h, i;
    a.left = &b;
    a.right = &c;
    b.left = &d;
    b.right = &e;
    c.left = &f;
    c.right …
Intrade 33 Junior Poster

Well you're comparing the gpa of each individual node to a seperate "min"/"max" on the stack.

Of course your output wont be correct.

Keep in mind that you're using recursion, and you want to pass the new minimum value to each method as well to determine the true minimum value.

Intrade 33 Junior Poster

now, I went into windows.h and related headers, and extracted those struct definitions, and put them directly into the code. then removed the include line of windows.h.

Honestly, why did you do this? It's possible that some of the windows code uses defined values that may be modified outside of those files.

Example

file a has code in it, some of the code uses a define called MAX_NUMBER and it is set to 5. When the end of the file is reached MAX_NUMBER has the value 7. If you're using the same code as file a in a different file where MAX_NUMBER is 7, you'll get different results.

Extracting code from one file to migrate into your own is dangerous, because some of the definitions may have different values (or no value?)

Intrade 33 Junior Poster
struct PhoneTones
{
   int rowTone,   // Frequencies of the tones generated by a key press
       colTone;
};

// Function prototype

PhoneTones keyToTones ( char key );

//--------------------------------------------------------------------

int main()
{
    char inputKey;         // Input key
    PhoneTones keyFreqs;   // Frequencies of the corresponding tones

    // Read in a series of keys and output the corresponding tones.

    cout << endl << "Enter key pressed (0-9, *, or #): ";
    cin >> inputKey;
    keyFreqs = keyToTones(inputKey);
    cout << "Tones produced at " << keyFreqs.rowTone << " and "
         << keyFreqs.colTone << " Hz" << endl;
    system("pause");
	return 0;
}

//--------------------------------------------------------------------
// Insert your keyToTones function here.
//--------------------------------------------------------------------

PhoneTones keyToTones ( char key )
{
    PhoneTones Freqs;

    switch (key)
    {
      case '1': case '2': case '3': Freqs.rowTone = 697; break;
      case '4': case '5': case '6': Freqs.rowTone = 770; break;
      case '7': case '8': case '9': Freqs.rowTone = 852; break;
      case '*': case '0': case '#': Freqs.rowTone = 941; break;
    }
    
    switch (key)
    {
    case '1': case '4': case '7': case '*': Freqs.colTone = 1209; break;
    case '2': case '5': case '8': case '0': Freqs.colTone = 1336; break;
    case '3': case '6': case '9': case '#': Freqs.colTone = 1477; break;
    }
}

Notice that in your function you declare a PhoneTones Freqs local to that function, but it isn't used anywhere else.

Why not pass your keyFreqs by reference to the function and modify it?

struct PhoneTones
{
   int rowTone,   // Frequencies of the tones generated by a key press
       colTone; …
Intrade 33 Junior Poster

I did some experimenting after running the console window on my computer (Windows Vista SP 2) and I produced ^B with ctrl + b keys pressed.

Intrade 33 Junior Poster

It seems like you may want to consider collecting the characters themselves into a vector, then extract the contents of the vector into a string, then pushback the string into your vector of strings.

It would cause additional overhead but you wouldn't have to worry about the string classes limitation on substring.

I'm also curious about the following--

for(int i=0; i < nStrings; i++)
{
	static int j=0;
	j= j + i;

myVector.push_back(str.substr( j, (i+1) ));

printVector(myVector);
myVector.clear();

}

-- why not j%26 for first character selection in the event that j+i > your array length - 1?

That's only half the battle. Eventually with nStrings at a high value you'll have to cycle through the array many more times than just one to concatenate appropriate characters.

I would strongly recommend using a second for loop to collect character together then store them in the vector of strings.

Intrade 33 Junior Poster

Is this like a rental car program? That's what I can see from this but correct me if I'm wrong.

Again, if you want to have variability in your array size use a vector or a pointer.

Also I noticed something very odd in your code--

double charge (double time[],int n)
	{ 
		double charge;
		double sum=0;

		for ( int i=1; i<=n; i++)
		{

			if (time <= 3.00)
				charge= 2.00;

			if (time == 24.0)
				charge = 10.0;
	
				else 
					charge = (time - 3)*0.5 + 2.00;

			sum_charge= sum+charge;

			return charge;
		}
}

1) Your for loop starts with the iteration counter at 1 instead of 0. I can see how you would make this kind of mistake if you've previously programming in Lua. Keep in mind that arrays start at index 0.

2) Your array goes up to, and includes n which means that if you have an array of size 3 with indices 0, 1, 2 with data {9, 13, -1} where 9 is located at index 0, 13 is located at index 1 and -1 is located at index 2, yet you want to access index 3 you will get an error from your application for attempting to access memory that doesn't belong to it. Change your iteration of i <= n to i < n.

3) You have a return statement in the iteration of your for loop, meaning after one iteration the process of looping stops and you return charge.

4) Your …

Intrade 33 Junior Poster

Thanks for replying .. I'll try it but can I use this declaration :

int time[];
	int cars[];

instead of putting "i" or "n" inside ?

I'm fairly certain that you have to give the array a size parameter before your code can compile.

int time[3];
int cars[3];

but as you can see, you cannot assign time and cars a new set of input once they are declared with their size. They keep that size and the only way for them to lose it is for those variables to go out of scope.

Again, if you're doing something with variability in array sizes, use pointers or use the standard library vector.

Intrade 33 Junior Poster

To be honest, I would rewrite some of the code to use pointers as parameters versus an array parameter. It's been awhile since I've worked directly with C++ so I'm not entirely sure.

I am a bit concerned about this chunk of code though--

# include <iostream>
# include <iomanip>
using namespace std;

int read_car (int cars[], int n);
double read_time (double time[], int n);
double charge (time[]);
void print ();

double sum_time, sum_charge;

int main()
{
	int time;
	int cars[n];
	int n;

The last 3 lines of the information I grabbed from your snippet I realize that n isn't declared until after int cars[n], yet you use int cars[n] as if n has been declared and is a constant.

If you want to dynamically adjust an array size consider using a pointer--

int main(){

	int time;
	int n;

	cout << "Welcome to the Car Parking fee calculater." <<endl;
	cout << "Please enter the numbers of the cars." <<endl;
	cin >> n;

        int* cars = new int[n];

        // .. sometime later in code
        delete n;
        return 0;
}

This is only half the battle. You use time in your functions as if its an array (or pointer) but the declaration

int time;

suggests that time is not an array/pointer type and only holds one value.

There are probably other problems but I'm not near a compiler, nor do I want to overstep my bounds. Try making the fixes I suggested first and see if …

Intrade 33 Junior Poster

How would one do this?

I've tried extended searches for this and apparently any time I mention WoW and a socket (in reference to WoW the game and socket as in the socket API for Lua), I get a bunch of crap about socketing items in WoW and not any relevant information on how to use the Socket api to import/export data from WoW.

My overall goal is to create an addon that performs updates on an external database, rather than a local one. This is so that multiple users can handle the same data without having to synchronize files on the fly or save times + operations then synching.

As an example, let's assume I'm using an addon and a guildmate is using the same addon.

When I make a change to the addon, and my guildmate makes a change, I want it to be made such that the moment I perform a change he gets the update in a very fast manner. I also want to be able to rely on the addon to send him information that I've stored even when I'm offline.

The only truly good means of doing this is to communicate with an external database that both him and I can access when we're online. It would solve a world of problems.

If anyone has experience with communicating with an external database, from WoW via the wow-api or even their own library please let me know.

Intrade 33 Junior Poster

Here's an update.

import java.util.Iterator;
import java.util.Arrays;
import java.util.LinkedList;

/**
 * A CircularBuffer data structure that can have its elements accesses in guaranteed
 * constant time.
 * In addition, ranges can be set on the data and a start-point can
 * be chosen.
 *
 * Technically everything about this implementation is circular, from getting
 * the value from a particular indice to setting the position. The only
 * restriction set is the range, which cannot exceept the length of the
 * backing array.
 *
 * @author Intrade
 */
public class CircularBuffer<T extends Comparable<? super T>> implements Iterable<T>{

	protected Object values[];
	private int initPosition = 0, picked, range;

	/**
	 * A CircularIterator that exists as an indirect helper class
	 * for iterating through the contents of a CircularBuffer
	 */
	public static class CircularIterator<E extends Comparable<? super E>>
		implements Iterator<E>{

		private CircularBuffer<E> bufRef;
		private int current = 0;
		private boolean finished = true;

		/**
		 * Constructs a CircularIterator, with the specified CircularBuffer
		 */
		CircularIterator(CircularBuffer<E> bufRef){

			this.bufRef = bufRef;
		}

		/**
		 * Returns true if this Iterator hasn't reached the first element
		 * again, and false otherwise.
		 */
		public boolean hasNext(){

			if(current % bufRef.range == 0)
				finished = !finished;
			return !finished;
		}

		/**
		 * Returns the "next" element
		 */
		public E next(){

			return (E)bufRef.get(current++);
		}

		/**
		 * Not supported!
		 */
		public void remove(){}
	}

	/**
	 * An indirect helper 'Exception' class for Bad Data.
	 */
	public static class BadDataException extends Exception{

		private int code = 0;
		private static final String bde = …
Intrade 33 Junior Poster

I'm sure this has already been done, but to practice understanding Data Structures better I decided to try making one of my own, given only an idea of what type of functionality I want, a pencil and some paper (as well as .txt file, modified into a .java file =p ).

The motivation of this Data-Structure is to enable a user (programmer) to be able to traverse through an array of data easily as if it were "circular." For example, if I want to jump back to the front of an array after reaching the index, to treat the data as if it were circular, how do I do it without reproducing code, again and again, to get there? This class solves that problem and acts like a collection-type by being "Iterable" (usable by the improved for-loop). Not only that, but the range and starting position can be adjusted so certain data can be ignored since as if it is "outside of the circle."

Note: I think I need to refer back to the Modulos discussions of my Discrete Mathematics book to determine how to give the user the positive-version (or close-enough value) of the negative request they submit when retrieving data in constant time.

A final note: This class is incomplete - I'm still working on it. I did not set a restriction of Comparable data types for nothing.

Thank you for viewing my code! =)

Intrade 33 Junior Poster

You did this in half an hour!?

Wow that's crazy! O_O

You are indeed a fast programmer XD

However I did need to convert the C-style cast into a static_cast from the random generator (for Dev-Cpp, Mingw compiler)--

//.. blah...

  srand( static_cast<unsigned int>(time(NULL)) );

//.. blah...
Intrade 33 Junior Poster

You're looking at the right language, you're just not looking hard enough! =)

I don't want to say anything more than that. I'd rather leave the explanations to the experts, since I myself am tackling C++, running into more abstract problems than real-world ones.

Intrade 33 Junior Poster

I can't tell if this is a joke or not.

It sounds like a homework question. How about doing a little bit of research on Data Structures and on information represented through an array?

As for hacking tips on cracking your friends password, I don't know. I don't like cracking into other people's information or personal databases. Why do you want to hack into your friend's account anyways?

Intrade 33 Junior Poster

This is for you: Click Here

Why even bother clicking it? You can see what it says just by hovering over it XD

Intrade 33 Junior Poster

Without using some new language like Perl, how would one be able to access a web-page, given specific session information?

And also, which C/C++ libraries are good for doing this kind of job?

If this is at all a weird question, I'll explain. I'd like to be able to write a script that parses a remote file for specific tags and information between those tags, but in order to do so I must be logged into an account (or rather, have some kind of connection between me and my personal information).

Let's say that a website has the web page www.mypage.com/index and when you attempt to go to that page without first establishing a session you will get redirected to a page that requests your login information. This means that if I try to access the remote file from a C++ program, I'll most likely parse tags that are not of interest to me. I need to be able to somehow send login information with the location of the file, but I'm uncertain of how to do this.

If this is still confusing, my apologies. Long-story short I'd like to access a file with a generic address and still be able to get my personal data, without manually logging into the site (basically, logging in from the application itself and access the file after, or send session data while accessing the file, or some other better alternative).

Intrade 33 Junior Poster

Ok I think I'm misunderstanding something here.

When you mean a string of 5 arrays you really mean an array of depth 5 that can store strings?

Also, are we at all backtracking? And what is really the first character?

If we try using an implementation that parses your line of text (one big string) into 5 smaller strings, each one a sentence, Which character do you want to be the first?

Let's assume that the first character is a letter and that you break up the big string into 5 smaller ones. If that's true, and you're only analyzing the first letter, then none of your letters will be capitalized. Now let's assume that the first letter is a '.'. If that's true then you have to modify your file to have a . in the first sentence and split your big string into smaller ones with a space-char delimiter.

Now let's assume that you don't split your string and keep it as one big string, which is fine too. You then need to consider which character is really the next. Since you are keeping the space chars, without using them as delimiters and skipping them they will persist, but you don't want to capitalize the space character instead of the actual next alphabet-based character... so as you are finding your '.' characters, you need to skip other character until you find one that can be capitalized.

If that's at all confusing please …

Intrade 33 Junior Poster

Hmm, to do something like this in Java I'd assume that you would have to create code to handle these kind of problems--


Potential Pseudocode

-At startup, run program and have a thread that constantly checks if you have a web browser running such as FireFox or Internet Explorer, and in addition constantly check which website the user is currently browsing.
-IF user accesses <insert website here>
    -Parse remote file (the web page) for the link to sign into
    -push data into the link to sign in as last user to sign in (of course
     you would have a data file with this information stored somewhere on your computer)

-Else do nothing

of course you dont have to run the program at start-up, but it would be nice if it was an automatic thing you didn't have to run on your own.

And of course the problem might be more complicated than this. Suppose you're already logged into yahoo.com and you access the site again. You don't want to waste time parsing the file for information if you already have a session ID associated with your personal info. It might cause problems.

I'm just rambling though, so forgive me.

Intrade 33 Junior Poster

If you're good with algorithms you'll probably be ok.

If not then good luck?

I guess that's not the only issue though. There are also other things to consider such as space an application can (or will) take up, how long something will take to run and knowledge about particular sorts, structures, concurrency, compiler grammar... etc... it depends on who you're working for and what you're expected to do.

Can you be more elaborate about the company and their business, or more specifically what they want you to do?

Intrade 33 Junior Poster

I'm trying to figure out how to merge to full, complete binary heaps if their heights differ by more than 1.

For example, a heap with 7 elements merged with a heap with 31 elements, etc.

Here's my Java Code for the problem. I can't quite figure out what I'm supposed to do. I made a theory but I'm not sure, even after doing some research. And we were told that changing the internal structure before merging counts against our runtime.

/**
 * Answer to problema 21.17 a, b and c
 *
 * Insertion and Deletion take slightly more time than a normal array-based
 * binary heap, however merging of two full/complete heaps can be done in
 * better timing than array-based ones.
 *
 * @author Intrade
 */
public class ExplicitLinkBinaryHeap<T extends Comparable<? super T>>{

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

		ExplicitLinkBinaryHeap<Integer> elbh = new ExplicitLinkBinaryHeap<Integer>();
		ExplicitLinkBinaryHeap<Integer> elbh2 = new ExplicitLinkBinaryHeap<Integer>();

		final java.util.Random rgen = new java.util.Random();

		for(int i = 0; i < 7; i++){
			elbh.add(rgen.nextInt(40) + 5);
			elbh2.add(rgen.nextInt(99) + 50);
		}

		System.out.println(elbh);
		System.out.println(elbh2);
		ExplicitLinkBinaryHeap<Integer> mergedTreeA = mergeA(elbh, elbh2/*, 1*/);
		System.out.println("\nThe result of these two trees merged via method a is...\n");
		System.out.println(mergedTreeA);
		System.out.println("\n\n");


		elbh = new ExplicitLinkBinaryHeap<Integer>();
		elbh2 = new ExplicitLinkBinaryHeap<Integer>();

		for(int i = 0; i < 7; i++){
			elbh.add(rgen.nextInt(40) + 5);

			if(i % 2 == 1)
				elbh2.add(rgen.nextInt(99) + 50);
		}

		System.out.println(elbh);
		System.out.println(elbh2);
		ExplicitLinkBinaryHeap<Integer> mergedTreeB = mergeB(elbh, elbh2/*, 1*/);
		System.out.println("\nThe result of these two trees merged via method b is...\n");
		System.out.println(mergedTreeB);
		System.out.println("\n\n");

		elbh = new ExplicitLinkBinaryHeap<Integer>();
		elbh2 = …
Intrade 33 Junior Poster

I don't get it...

Why is it that whenever I view posts of homework assignments and projects that a fair amount of the time (in Computer Science or C++), it seems as if--

Oh hang on. I already know what'll happen from here.

If I don't write a topic that has something to do with C++ programming I'll get banned, so give me a moment please.

#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main(){

   cout << "Why so serious?" << endl;
   cin.get();
   return 0;
}

-- Ok now that I've gotten that out of my system, I'll continue.

Like I was saying, why does it seem like some of the posts here are an ego-contest?

Some things to bring to light--

Result 1: Student/User asks for help, another Student gives help then a Vet comes in and provides a better solution that the original poster doesn't understand because it contains much more information than what the OP originally asked for.

Result 2: Original Poster has no idea on how to start the assignment and posts the question, yet individuals immediately assume that the OP is requesting the answer and not some hints on how to start.

Result 3: Original Poster thinks he/she knows what they're talking about, then a Vet comes in and explains to them how stupid they are (in a "polite" manner) then some posts later (usually after flaming) the Vets finally either give up or the OP …

Intrade 33 Junior Poster

Hex number: AD which is 16^1 * 10 + 16 ^ 0 * 13 which is 160 + 13 = 173,

Hex number: 53 which is 16^1 * 5 + 16^0 * 3 = 83

So the sum of 173 and 83 is 256, so your hex result should be the same--

Hex result: AD + 53 = 100 (in Hex)

1-carried from (1 + A + 5)
1 - carried from (D + 3)
AD
+53
___
100


[content removed - irrelevant]
[more content removed - irrelevant]


Considering the worst case scenerio (high single-digits)--

FF
FF

then what?

16 ^ 1 * 15 + 16 ^ 0 * 15 = 255
16 ^ 1 * 15 + 16 ^ 0 * 15 = 255

255 + 255 = 510 = is the sum result of FF + FF

1 - carried (31 - 16 is 15. 16 subtracts into 31 once so we carry 1)
1 - carried (30 - 16 is 14. 16 subtracts into 30 once so we carry 1)
FF
+FF
___
E - the leftover '14' from 14
F - the leftover '15' from 14 + the carried 1
1 - the leftover 1 from the carry


I omitted some information because Vernon said it in a better way than I would have.

By the way, since we're doing only sums and not multiplication you should consider the fact that your carry value should never be higher than 1 unless you're summing more than 2 hex-values.

Intrade 33 Junior Poster

Honestly, you're not giving us enough information.

This is what I managed to come up with, based on many assumptions--

#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::size_t;

// determines the difference between two sets
// this function assumes that one set is the subset of the other
// and that the elements in each set are ordered.
// the elements of each set consist of 3-char strings in sequential order
const char** difference(const char**, size_t, const char**, size_t);

int main(){
    
    const char* a[] = {"abc" , "def" , "ghi"};
    const char* b[] = {"abc" , "def" };
    const char** d = difference(a, 3, b, 2);
    
    cout << *d << endl; // as an example, though more values in d could exist
    
    cin.get();
    return 0;
}

const char** difference(const char** first, size_t s1, 
      const char** second, size_t s2){

      const char** result = 0;
      
      // the location of difference
      size_t differingPosition = 0;
      
      // determining the difference in sizes - which set is the set with more
      // values?
      size_t minSize = (s1 < s2) ? s1 : s2;
      
      /*
       * Here we're simply iterating through all of the elements of each array
       * attempting to locate the point where things start to change.
       *
       * I'm also making the assumption that each string consists of 3 characters,
       * hence the modulo 3.
       */
      for(size_t i = 0; first[i][i%3] == second[i][i%3] && i < minSize * 3; i++)
                 differingPosition = i + 1;
      
      // if no point …
Intrade 33 Junior Poster

Well when a derived object is declared then the derived class inherits the public and protected variables and functions, not the private variables or functions of the base class. I was wondering what would happen if the constructor of the base class(which is inherited always) initializes some of those private variables that weren't inherited. It would be trying to modify a variable that was not part of the derived class, not part of the derived class object. Would it modify them or just produce errors...? Anyways I am going to test this with a program (always the best solution to a tough question) and see what happens.

...

So your base class is doing its job and initializing values that were defined in its scope. Even if you define a derived class of the base class, if you are calling the constructor(s) that initialize data in the base class, it is still valid because you are passing data from the derived class to the base class.

Because you are passing data from the derived class as a parameter for the base class, and because the private variable is accessible within the scope of the base class, the derived class can indirectly modify values in the base class.

To make things easier to understand, think of the Constructor of the base class as a public means of initializing data defined in the base class, and the derived class is using that constructor itself (which should be valid since …

Intrade 33 Junior Poster

OMG thank you! IT WORKS :}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} When would you use string vs. char arrays?

When I need to perform searches for characters to a particular string, or modify a string, or provide a self-contained method of measuring the string's 'components'.

There are many other reasons that this to use strings, but the ones I just mentioned are the general reasons why most would use strings.