Bench 212 Posting Pro

I have DSL, and was told that there is no speed loss when using a router for up to 4 pc connections. This seems to be confirmed when downloading from one site and surfing the net on my laptop, I do not notice any speed changes.

So, on to my question. If I install 2 ethernet cards on my desktop, and run two lines into my pc from the router, will my download speeds double?

Thanks for the help!

You will still only have one DSL connection, regardless what you connect to it. your download speed is determined by your subscription to the provider

Bench 212 Posting Pro

I believe omitting the 'U' from the expression causes a warning to be thrown up when compiling with warnings at their highest level. Otherwise, its not a problem.

Bench 212 Posting Pro

Hello Salem,
I know that rand() is a pseudorandom.
You probably missed this part of my program:

void randomize ()
{
srand((unsigned)time(NULL));
}
.
.
.
.
randomize();

as you see I seed the generator with current time,therfore
the generator should start with a different number every time,
and the problem I described shouldn't happen.

You shouldn't call srand more than once in the lifetime of your program. Perhaps this is why you're getting repetition?

Also, time isn't exactly the best seed for srand. Its common for the first number to always be the same when seeding with the current time. you could try a different method of seeding the generator, such as the one suggested by Narue here -
http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx

Bench 212 Posting Pro

What do you understand by the assignment you've been given? Have you attempted any of it yet?

Bench 212 Posting Pro

If you're passing it, why do you need to return it?

Arrays are already passed by pointer (by reference), so any modification which occurs in the function will directly affect the array passed into the function - no copies are made.

Bench 212 Posting Pro

The problem would appear to be that you're not sorting your entire list, only half of it.

look in the loop here

for (int i = 0; i <l; i++)
	{
		big = x[0];
		for (int j = 0; j <l; j++)
		{	
			
			if (x[j] > big)
			{
				big = x[j];
				old = j;
			}
		}
		s.push(big);
		x[old] = x[l-1];
		l--;
	}

At the same time as incrementing i, you're decreasing 'l' - which means the for loop stops when you're halfway through the list (the two values converge in the middle).

there are all sorts of ways of doing sorts, but i suggest you leave your 'l' variable alone - also, your inner loop probably wants to start at j = i rather than j=0 (Similarly, your 'big' number probably wants to start at x )

Bench 212 Posting Pro

I think you missed the underlying message - which is that you need to change this line, either to check cin, or to get cin to read 'a' and 'b' as strings.

cin >> a >> b;

Whichever way you do it, you will either need to have the cin code repeated to ask the user again, or to drop out of the block/function completely, passing back an error to the callier

Bench 212 Posting Pro

The best solution, is the one which hamrick describes, avoiding arrays altogether and using an STL vector

The problem with 'returning an array' is that arrays are returned by pointer. Which means one of the following must happen

- The array is declared static (Similar to a global object)
- The array is dynamically created inside the function with new
- The array is passed into the function as a parameter

If the array is passed into the function as a parameter, there's probably no need to return it

If the array is dynamically created with new, then you have all sorts of problems ahead, with regards to keeping track of the memory and ensuring it gets properly delete[] 'd

If the array is declared static, you can return it by reference

int ( &my_func() )[4][5]
{
    static int arr[4][5];
    return arr;
}

Note, that this is essentially the same as having a global variable wrapped in a function

The alternative, that someone else suggested, is to wrap it in a struct, and pass the struct around. (which causes copies to be made)


However, it would be better if you described what exactly you are trying to achieve, and where it fits into your program. returning an array isn't a "normal" activity, so you could probably do something differently elsewhere, without needing a function returning an array.

Bench 212 Posting Pro

yes, reading all your input as a string is one reliable way to do it (That would be my preference). The other reliable way is to use cin as an 'if' or 'while' condition. (Not so great, because you have to deal directly with the cin error flags every time)

#include <iostream>
#include <limits>
#include <sstream>
#include <string>

bool read_double(double& d)
{
    std::string str;
    std::cin >> str;  //Alternatively, use std::getline()
    std::stringstream ss(str);
    if( ss >> d )
        return true;
    else
    {
        //Possibly still bad characters left in cin
        std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
        return false;
    }
}

int main()
{
    double a, b;
    while( !read_double(a) || !read_double(b) )
        std::cout << "Error" << std::endl;
}

or

#include <iostream>
#include <limits>

int main()
{
    double a,b;
    while( ! (std::cin >> a >> b) )
    {
        std::cout << "Invalid Input!" << std::endl;
        std::cin.clear();   //Clear error flags
        std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
    }
}

Getting input from the user is always a little bit messy, there's no clean, easy way about it unfortunately.

Bench 212 Posting Pro

er, so, what was the question?

Bench 212 Posting Pro

I have been trying to return a two dimensional array in a function but it is getting me no where, please tell me how to do it. the code is as follow :

int *population();
int *testCase::population()
		{
				

for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++){

matrix[i][j]=rand()%2;			 

					
							}
	}
		
			
	return matrix[0][0];
  
			
}

when I run the program, it returns a memory address. I want it to return the value for the array.

Then ditch the asterisk which causes your function to return a pointer value. If you want the value stored in the array, then just return a plain int.

Bench 212 Posting Pro

1. Where can i find a ISO 10646\ Universal character names Code charts ?

If you're on Windows, you could use the windows character map. Make sure that you select the font which matches that of your output window.

Bench 212 Posting Pro

I don't know how many others do this, but I've often found myself drafting replies to problems which people have posted, but not actually sending my reply straight away. On many occasions, i've kept the reply in a notepad document, and ended up deleting them, if I think i'm wrong.

What I find interesting, is comparing my drafted reply with the real replies which others like SoS, Salem, Ancient Dragon, Narue, etc come up with. (All of whom make my knowledge of C/C++ look fairly humble)

I can't even begin to quantify how much I've learned by simply drafting replies and comparing them to other peoples' responses over the past couple of years (Its also stopped me posting some of my sloppier responses, which, in the past, got me burnt fingers..)

Sorry for straying off-topic, but it seems appropriate in this thread now. :)

Bench 212 Posting Pro

In general, the steps to getting MSVC++ 2005 to work should be something along the lines of

- Create a new Solution, using a Win32 Console Project

- Right-Click on the project's name in the solution explorer, choose properties.

- In the Configuration Properties Window, look for the option to disable precompiled headers (Under the C/C++ Configuration properties)

- Get rid of stdafx.h and all that rubbish

- use the simplest possible program to test whether you've set it up correctly (you can tell by whether the program compiles) this one will do

int main()
{
}

- Hold [CTRL] and press [F5] to compile & run. (Console Window won't auto-close - this is the 'compile without debugging' mode)
- or, [F7] to build it without running

- if you need the .exe file, look in the project's folder on your computer, in Windows Explorer. The .exe file will be named after the solution.

Bench 212 Posting Pro

completely incorrect. the current version of turbo c++ (the free version is now called 'Turbo C++ Explorer') does support standard ANSI C and ISO/IEC C++ languages and libaries.

From what i've seen, the chance is, anyone posting here claiming to use "turbo C", is most probably referring to the original Borland turbo C from the early/mid 90s, rather than the modern version you linked to. In which case, jbennet is spot on.

~s.o.s~ commented: Bingo. +25
Bench 212 Posting Pro

Posting the errors your get when you try to compile the code would help.

// A tip: you don't need to write 
using std::cin;
using std::cout;

// If you have..
using namespace std;

// Because std::cin and std::cout are all part of the std namespace, so that one line should suffice.

You also don't need to bring the entire std namespace into scope, so just specifying std::cin and std::cout is a far better idea.

Bench 212 Posting Pro

First, look carefully at the compiler errors, and correct spelling/typing mistakes (I see at least one!)

Second, where is your struct definition..? (Perhaps you need to read up on how to create a struct)

Bench 212 Posting Pro

Perhaps, while you're learning, it would be a good idea to leave all the windows stuff alone. at least until you've got a firm grip on the basic language.

There's alot less that can go wrong when you're just dealing with C++ on its own.

Bench 212 Posting Pro

Narue has written an excellent (but somewhat lengthy) article about pointers

If you care to learn more about pointers its well worth the read
http://www.eternallyconfuzzled.com/tuts/languages/jsw_tut_pointers.aspx


edit: Another good article, from DaWei, can be found here
http://daweidesigns.netfirms.com/cgi-bin/pointers.php

Bench 212 Posting Pro

which line ? On line 18 the value of ptr2 is random because it is uninitialized. Line 22 is also random because it is deferencing the integer located at the address of the address, which also has not been initialized and could possibly crash the program.

I don't know how to get cout to print the address of a pointer -- printf() uses "%p" but don't know about cout.

Something like this will probably work, provided unsigned long is large enough to hold a pointer

#include <iostream>

int main()
{
    char* hello("Hello, World");
    unsigned long addr = reinterpret_cast<unsigned long>(hello);
    std::cout << addr << '\n';
}

(MSVC++ throws a warning about pointer truncation, although the warning goes away if I switch the cast to the nonstandard __int64 type)

Bench 212 Posting Pro

it would appear that you're using the wrong kind of single-quote mark (Some character sets have several different ones). you should be using ' ' rather than ` `
(did you copy the code out of a word document or powerpoint presentation?)

Ancient Dragon's solution is the easiest (You'll have to resize the array to fit the extra '\0' character).

Bench 212 Posting Pro

Posting a block of code followed by a request of "please make me the rest of the code" doesn't constitute making an effort. Please don't expect others to finish it off for you.

If you've run in to a problem with code you've already written, then by all means, ask a question here, or show that you've made an attempt at the rest of your assignment and someone will help you with that. But noone will just spoon-feed you with large chunks of code, so that you can pretend to your tutor that you've done all your own homework.

Ancient Dragon commented: you're right +18
Bench 212 Posting Pro

That depends what the program is. I doubt that he's asking you to rewrite the sqrt, log and pow functions from math.h (Unless your course is a mathematics one).

if you post a description of your problem, and the code from your current solution, there might be another way to do it.

Bench 212 Posting Pro

I dont know what to do in further program. Please make me the rest of the code. Thanks in advace

1) Don't be so lazy, read here http://www.daniweb.com/forums/announcement8-2.html

2) This is a 'C' program. you're in the C++ forum.

Bench 212 Posting Pro

Sorry, but the two are not interchangeable. int space [] causes illegal syntax error message (VC++ 2005 Express compiler.). Unless that is something new in C99 standards, which very few compilers support yet.

Hmm, I just tried that on Comeau in strict C90 mode (Comeau tends to be fully standards compliant AFAIK), and it claimed to have compiled successfully with no errors.

void foo(int bar[])
{
}

int main()
{
    int arr[5];
    foo(arr);
}

http://www.comeaucomputing.com/tryitout/

Is Comeau wrong? or were you referring to variable declarations outside of function parameters? (Where I don't believe any version of the C standard allows empty subscript brackets)

Bench 212 Posting Pro

I can see that C++ and python have a few similarities in syntax, but apart from that they're two very different languages,

I've never used eclipse (or python for that matter), but I don't imagine that there is any easy way to magically translate your program into C++.

Just by reading, I can guess what most of it does, and some lines will be fairly easy to convert with straight subsitution, while other parts of the program would be done quite differently in C++, and I imagine the conversion process being somewhat trickier.

Bench 212 Posting Pro

I'm not sure what you're doing there, but your program must have exactly one main() function, and that must stand alone in your program, it cannot form a part of any class.

What error message did you get when you created your saving class?

Bench 212 Posting Pro

Sorry ancient dragon ... hopefully this time i can get the code tag works...
Now i had no problem with the initialising of datas , but i am not too sure how to get the derived classes work in my program(as mention in the first post , i need a saving and current derived class) . Any kind person willing to advise me on that ? Thanks in advance :)

You need to put the

tags around the area of text where your code is


To create a derived class which inherits from Bank is as simple as [CODE=CPP]class saving : public Bank
{
    // saving-specific code in here
};
Bench 212 Posting Pro

After you retrieve data from your input file, convert your string, line, to an int. (Which can be done easily using a stringstream) then you can compare the two highscores, and only choose to overwrite the existing one if the new one is higher.

A few other comments regarding your code -

Global variables are generally a bad thing... break the habit now while you're still in the early stages of learning. In this case, you'll not need to change anything by declaring them just inside the start of your main() block.


change your loop which runs while !EOF, since this will lead to reading past the end of the file. The EOF flag is only set after getline fails to read, so the final iteration of your loop is likely to behave unpredictably. Try this instead while( getline(infile, line) ) This causes the loop to run while the file still has data, and automatically terminates when there's no more data to read, preventing any chance of overrun.

Bench 212 Posting Pro

I think you missed the irony a little bit there... Salem posted a suggestion of putting the char into a string, then your reply contained "I got an idea..", where you went on to describe the same thing :)

I realise that might have been lost on some people ;)

Bench 212 Posting Pro

I haven't tested it, but it looks good to me.

As far as commenting is concerned, the minimalist approach is better IMHO. They're best reserved for nontrivial bits of code where you're likely to come back in 6 months time and wonder what it does.
In places where code speaks for itself, comments are fairly superfluous.

Bench 212 Posting Pro

I believe what you should start on first is the foundations of programming, perhaps start out with Turbo Pascal 7 and learn how variables, arrays, pointers, linked lists, sorting algorithms work etc... TP7 is an out dated language, yes, but can teach you alot and help you build confidence is coding, some schools / universities are still teaching Pascal.

You most likely believe this because thats the way you learned, and thats fine. Although, teaching has evolved, and with good reason.

The idea of an introductory programming course was once, as you describe, to start out with the low level 'fundamentals' .. although, these kinds of courses have been shown for many years to be intensely frustrating for a complete novice who's never had any experience with anything other than office applications. Herein lies the problem that programming has a terrible reputation as a result, of being impossibly hard, and only for "elitist hackers" or "complete geeks". (And the net result is that people are put off programming entirely, because they convince themselves that they can't do it)

So, using languages such as python or java to teach basic programming, this reputation is slowly diminishing, since learners find themselves in more comfortable environments where they can learn all the same concepts and thought processes about programming (loops, arrays, structures, etc) without needing to worry about all the nasty 'gotcha's' (yet!). as a result, far more people feel confident that they can understand programming, than before.

The one …

Bench 212 Posting Pro

If you wanted to make the code smaller, you can use the C++ <string> library. (you have it at your disposal, so you may aswell use it..!)

#include <map>
#include <string>

typedef std::pair<std::string, std::string> entry_t;
typedef std::map<std::string, std::string> dictionary_t;

int main()
{
    const entry_t init[] =
    {
            entry_t( "dog", "four legged pet" ),
            entry_t( "fish", "swims in the sea"),
            entry_t( "clock", "tells the time"),
            entry_t( "radio", "plays music")
    };
    const int entries( sizeof(init) / sizeof(*init) );
    dictionary_t dictionary( init, init+entries );
}

As for the looping issue, the easiest way might be to perform a do...while( str != "EX" )

(the != comparator also only works when 'str' is a C++ string. this is another reason to ditch the char arrays)

Bench 212 Posting Pro

I can think of one way which would involve both _next and _prev being stored in an array, size 2.

The idea being that they're indexed by a boolean value, so that you can "flip" between the two. Your indexes might be node::pointer[true] for _next, and node::pointer[false] for _prev

You'd possibly need to do the same with your head and tail pointers in the main list class.

This, with a combination of templates would probably work - the templates merely to avoid the repeated code - then covered with some public method wrappers as a matter of hiding away this ugly little trick.
- whether or not it would be readable, is another matter entirely.

Bench 212 Posting Pro

I am pretty sure they are. If you go to java's website and grab the SDK's and tool kits they all come packed as C++

That's only for people who choose to use those tools. For example, a platform where there's no C++ compiler available, the JVM would most likely be written in another language.

Bench 212 Posting Pro

I suppose I should add that atoi() has no reliable way of handling any errors that might be thrown up when your conversion fails. This is where stringstreams provide a far more robust solution, that you can test for failure before using the retrieved value.

Bench 212 Posting Pro

Don't use atoi() - here's how to do it in C++

#include <sstream>
#include <iostream>

int main()
{
    const char* foo("1234");
    std::stringstream ss(foo);
    int i;
    if( ss >> i )
        std::cout << "i is: " << i ;
    else
        std::cout << "error";
}

The reason for using stringstreams is that your conversion will fail if the string contains anything which can't be converted to an int - which, if you're dealing with user input, is a real problem. if you use a stringstream, you can detect the error, without it messing up the rest of the program.

Killer_Typo commented: great post +6
Bench 212 Posting Pro

I tried that. However it only made things more difficult.

It split the contents of the file into individual lines therefore splitting up the information that I need.

Example.
>Name
ABCDEFG
HIJKLMNO

I have to extract the name, and then the letters must be stored together????

That's easy enough. Identify and isolate the vector elements which contain names, then concatenate the others together.

There's loads of different ways of doing this .. If this doesn't work for you, then you need to tell us how you intend to store the individual data 'records'. You may or may not be able to do it all in a single step.

Bench 212 Posting Pro

imsorryicantunderstandwhatyourquestionisbecauseitlookslikethis

Try rearranging your post without the LaTex tags

Although, with reference to the subject line - look at the private members in your class (Of which there are far, far too many... if i were you, the first thing i'd do would be to look at a way to cut them down.. such as an array)

You can't directly assign a value to a data member in the class, you need to initialise them in the class constructor instead.

Bench 212 Posting Pro

Just create a constructor in your DayOfYear class, which takes no parameters... just like you've done here

#include<iostream>
#include<conio.h>
using namespace std;
class DayOfYear
{
public:
[B]    DayOfYear(int month,int day);[/B]
    void output();
    void input();
private:
    int month_year;
    int day_year;
};
[B]DayOfYear::DayOfYear(int month,int day)
{
    month_year=month;
    day_year=day;
}[/B]
void DayOfYear::output()
{
    cout<<month_year<<"/"<<day_year;
}
void DayOfYear::input()
{
    cout<<"What's your month of birthday : ";
    cin>>month_year;
    cout<<"What's your day of birthday : ";
    cin>>day_year;
}
Bench 212 Posting Pro

You don't need to use switch at all, try the STL map container instead, where you can link strings to other strings (just like in a dictionary)

Salem commented: A map would be good, if the OP is that far into the course :) +9
Bench 212 Posting Pro

I could - but there's no guarantee that what happens when I try compiling & running it, is going to be the same as what happens when you try compiling & running it (Especially not when you've missed out CODE tags, and your code has got forum icons in it... )

The error you're getting is because the compiler can't find a default constructor in the DayOfYear class.

When you write your own constructor, the default constructor is no longer available automatically, so you either have to make one, or change your code in main, so that its using the constructor you've already written..

DayOfYear bach_birthday(3,21),my_birthday;
Bench 212 Posting Pro

Why are you copying the file contents out of a filestream, into a stringstream, then, into a string, and then, into another string?

you can extract each line of the file one by one straight into your vector, without all that fuss...

#include <iostream>
#include <vector>
#include <fstream>
#include <string>

using namespace std;

int main()
{
    ifstream fs("test.txt");
    string input;
    vector<string> sets;
    while( getline(fs, input) )
        sets.push_back(input);
}

All which remains is to work out which elements in your vector are names (the ones which start with '<' )

Bench 212 Posting Pro

You tell us..? we're not mind readers.

What problem are you having? does it compile? if not, what error message(s) do you get?

Bench 212 Posting Pro

Whenever you're trying to track a whole list of compiler errors, Always look to fix the first error in the list (usually found on the line of the first error, or the line just before the first error) , then try a recompile before fixing any more.

The reason behind this method, very often, just one small mistake can have a knock-on effect, producing a ton of other "phantom" error messages. (ie, error messages which aren't actually errors, and exist only as a result of the compiler being confused by the initial error).


Another tip - use the little-and-often approach to compiling.. ie, write a few lines, then try to compile.. This minimises the chance of getting a long list of errors, but also immediately narrows down the location of the errors when they occur - if everything was working fine on the previous compile, and all you've done is change 1 line of code, you can bet any money the error will be on that line.

Bench 212 Posting Pro

Put the single character into a short string.
Easy isn't it?

...

yeah but the thing is everywhere I had used a char variable, so it would be difficult changing them all. Anyway I got an idea. I will copy the contents of the char to a string.

And then output it.

I bet you never thought of doing it like that, eh, Salem :icon_rolleyes:

Bench 212 Posting Pro
Bench 212 Posting Pro

Initialise is the wrong word here. What he seems to be asking for is actually for you to use the SetStrVal function to copy the input string into the array. you can do that in one line - strcpy(data, user_input); Also be wary of the difference in the size of your CString array, and the user input string - it would be easy for the CString array to overflow. (Your best bet is to make them both the same size)

Bench 212 Posting Pro

You're jumping ahead of yourself.. at the moment you can't do that, because your class member functions haven't got any body to them.

Write the body for your member function void SetStrVal(char*); .. then you can use that

Bench 212 Posting Pro

if you wanted to save yourself a couple of lines of code, you could do this

int temporary = strlen(data) - 1;
cout << data[temporary/2] ;