mrnutty 761 Senior Poster

The problem is in line 4. The user never entered anything so there isn't anything to discard, thus your first input gets discarded. And the rest follows. That's why you should first get the input and check for failure instead of checking for failure then getting the input and so on.

mrnutty 761 Senior Poster

"knowingly accessed a computer without authorization or exceeding authorized access"

But from above, Mr.X wasn't accessing a computer per say. So then wouldn't this fail?

mrnutty 761 Senior Poster

Hypothetically speaking, supposed Mr.X was able to get into a restricted link in daniweb where Mr.X didn't have the privilege to do so regularly. What would happen to Mr.X is he was caught? Is there any laws against it?

mrnutty 761 Senior Poster

You need to remove the redundant code and use a function:

int getInt(){
 int input = 0;
 while( !(cin >> input) ){
   cout << "\nPlease enter a valid input: ";
   cin.clear(); 
   while(cin.get() != '\n');   
 }
 return input;
}
int main(){
 int x = getInt() , y = getInt(), z = getInt();
}

But to answer your question, your ordering is wrong. See if you can figure it out.

mrnutty 761 Senior Poster

Thanks, this seems to mostly get the code working, however, I am still getting an error from another member function that I haven't listed here.

The call that throws the error is

vector<int> time;
current_data.grab(0).dump2ivector(1,time);

dump2ivector is declared as:

void csv_File::dump2ivector(int column, vector<int> &data) {....}

where {....} has inside of it a line like

data.push_back(atoi(access(0,0).c_str()));

Is there some problem with passing in a reference to a member function? That is the only thing I see special about dump2ivector

More specifically, the error is

error: no matching function call to csv_File::dump2ivector(int, std::vector<int. std::allocator<int> >&) const

Also don't name it time, because that might cause a name clash. Call it something like timeList or something.

mrnutty 761 Senior Poster

I might be in that boat in a couple months, lol. I just hope I can find an internship to tell the truth. What kind of work are you doing, is it interesting, and what programming languages do you get to use, etc?

Using heavy javascript with Backbone Jquery and Underscore support. Its going to be a standalone app, that is designed to run on all mobile devices and desktops. They really aren't paying me enough for what I'm doing lol. And I think its interesting. I like it actually. I can't believe they are actually paying me for something I would probably do for free lol. Also I got to use java when I first started.

mrnutty 761 Senior Poster

You should be returning by reference not by value

std::string & access(int row, int column);

csv_File & grab(int index);

And also provide a const reference version

mrnutty 761 Senior Poster

I just found out that my work might get into the companies next release. Whoot whoot. Partayyy. But first I need to make this program bug free, or at least cover upto 80% of it.

mrnutty 761 Senior Poster

Who cares? I had just used for a week.
Have dumped it now.

Just curiosity.

mrnutty 761 Senior Poster

Thanks for the reply.

What if I want to avoid this, lets say I have to create 10 millions of this object (10 million is too much?, mmm lets say I have unlimited memory?) then this padding will cost me 30 million of extra byte.

I have tried the rearranging of data types which is suggested on the link you posted, but all the time I am getting the same result which is class size 8 bytes.

Regards,
S.

http://publications.gbdirect.co.uk/c_book/chapter6/bitfields.html

mrnutty 761 Senior Poster

First of all, what do you intend to do with the data?

mrnutty 761 Senior Poster

Feel free to ignore this rant. I am up to my neck with programming, so much so that I'm getting sick of it. I know I can't believe I would ever say that either. I'm at work right now( internship ), and I just want to leave. I don't want to program for this whole week. I want to go away from Connecticut. I go to work and program for hours and hours. I come home and sleep. Then do it all over again. Then the weekend comes, and guess what? I program some more for my professor. I think I programmed for like 50-60 hours last week. Anyways this thread has no point, but I needed to write my stress. Thank you for listening, you may now get back to your regular scheduled programming( hahahaha nice pun, I know I know ).

regards, D,F-en Chhetri

mrnutty 761 Senior Poster

Actually, my computer isn't old, the book that I was reading was old(kind of) - it even has instructions on compiling .cpp files on DOS and Unix.LOL:D
Nevertheless, thanks to everyone for helping!

Looks like you need to update the book you read from. From googling the first link seems good for free C++ books online. Check it out here

mrnutty 761 Senior Poster

a) In a 32-bit system, a reference variable needs at least 4 bytes of memory and in a 64-but system, it needs at least 5 bytes. That's because a reference points to the memory of the variable its pointing to. Thus it needs only enough memory to store a memory address.

b) It will be a compile error because you have two of the same identifier/variable name.

mrnutty 761 Senior Poster

In your peek check if size() == 0 instead. And for dequeAll just deque until size == 0

mrnutty 761 Senior Poster

Why don't you give it a try. If your stuck on something post it. We can surely do this for you, but then when time comes for you to work on your own, then your gonna have a heck of a hard time. So start early and start now. So take a stab at it and post back

mrnutty 761 Senior Poster

You might consider sorting then evaluating it.

mrnutty 761 Senior Poster

Note you should expose your vector like that instead return it by const-reference and if you need to update it, then provide proper interface. Also typedefs also might come in handy, as it is more clearer.

typedef std::vector<MySurvey::SurveyQuestion> Questions;
//...
const Questions& getSurveyQuestions()const{ return questions; }
mrnutty 761 Senior Poster

And the problem with that is what again??? binary search will always be faster than linear search. See this link

Yes I know, but sorting cost nlogn using std::sort. So if a new element gets added, then its gonna cost him nlogn again before he could use binary search again. This is true for each elements he wants to add one by one

mrnutty 761 Senior Poster

What makes you think interns do anything useful :) college credit should IMO be considered pay.

:( I wouldn't want to work for you then lol

mrnutty 761 Senior Poster

Agree if the search is done only one time. But when multiple searches are needed, the data is only sorted once (the first time), and with a vector of thousands of rows the binary search would quickly become much more efficient than linear search.

Agreed, but look at it another way, supposed he wants to add more elements. Then the list would have to be sorted each time.

mrnutty 761 Senior Poster

Sorting and binary search will take nlogn + logn time. Instead you can simply run through the list and spit out anyone that satisfies the requirement-- this takes linear time.

mrnutty 761 Senior Poster

How do I invoke the int operator < instead of the int* operator < ?

vector<int*> pVec;
std::sort(pVec.begin(),pVec.end(), /*????*/);

Why do you need to store int* anyways? Either store it as vector<int> or vector< vector<int> >

mrnutty 761 Senior Poster

You mean interns actually get paid in $$$??? I thought all you got was college credit for your work.

Yea there is a variety of internships. Some do not compensate, others compensate through college credits, and some actually pay money. Actually, there is more that pays money than not, at least when I searched for it.

mrnutty 761 Senior Poster

When you get a first entry-level programming job you will most likely not be writing all new code yourself, but instead you will be modifying and debugging existing code (program maintenance). The only new code you might write is to make product enhancements to existing products. No one is going to sit you down at a computer and expect you to write an entirely new program all by yourself.

Looks like my job should be paying me more, because I had to and still am writing the same application from scratch. Sometimes, I feel used. The entry level dude next to me, is maintaining code and adding a little features like you said. I guess I'll stay an intern for a while If I want to continue coding.

mrnutty 761 Senior Poster

FacePalm. Tricky one. Its definitely because of the const char*. I'm not completely sure but the const char*msg in D::print is the value of the const char* in B::print, because initially, the base pointer is calling the function? I need some explanation.

mrnutty 761 Senior Poster

Here's another one:

#include <iostream>

struct B
{
    virtual void print(const char * msg = "wtf? -.-")
    {
        std::cout << msg << std::endl;
    }

    virtual ~B() {}
};

struct D : B
{
    void print(const char * msg = "Hello, World!")
    {
        std::cout << msg << std::endl;
    }
};

int main()
{
    B * pb = new D;

    pb->print();

    delete pb;

    return 0;
}

At first I wouldn't have guessed correctly. But when you call pb->print() pb looks for matching function in D, that is a function with no parameter, but since B doesn't have a virtual function with that signature, the compiler doesn't bother to look at the table. Which is why 'wtf' gets printed. WTF

mrnutty 761 Senior Poster

I solved most of the originals right :) I did not only solve 1 (I think).
Int cannot hold that many values?

Think more of promotion and representation.

mrnutty 761 Senior Poster

Time to time I see some common mistakes or even make some my self. I figure I would post some of these, with hopes that people will learn from my and others mistakes.

1) Why you no work?

int sum = 0;
for(int i = 1; i < MAX; ++i);
{
  sum += i;
}

2)Why you work so well?

char * arguments[argCount] //argCount defined somewhere else
for(int i = 0; i < argCount; ++i){
 char *arg = new char[256];
 initialize(arg,256); //assume 
 arguments[i] = arg;
 delete arg;
 arg = NULL;
}

3) I use C++ like I use math!

int input = 0;
cin >> input;

char letterGrade;
if(50 <= input <= 60) letterGrade = 'F'; //Fail
else letterGrade = 'P'; //Pass

4)Why you garbage one time and work other?

int x;
get(x);
doStuff(x);
//....
void get(int& x){
 if(! (cin >> x) ){ resetStream(cin); } //assume resetStream resets cin to valid
}

5)Why you garbage one time and work other?

int input;
char letterGrade;
cin >> input;
if( 0 < input && input < 70) letterGrade = 'F';
else if(70 < input && input < 100) letterGrade = 'P';

6)Why you not print all?

void print(int *arr){
 for(int i = 0; i < sizeof(arr)/sizeof(*arr); ++i){ cout << arr[i] << endl; }
}

7) Why you wrong value?

//x,y are passed coordinates and buttonID is the id of which button is clicked
void mousePressed(int x, int y, char buttonID){ …
mrnutty 761 Senior Poster

Also I just realize your using somewhat java with this. There is no static void main. What you want is this :

#include <vector>
using namespace std;
class YourClass{
 //...
};
int main(){
 //your main 
}
mrnutty 761 Senior Poster

>>Random ;*randSelection;

what do you think this means? I assume you want int randomSelection .

And add a semicolon after '}' in line 62

mrnutty 761 Senior Poster

Post your code.

mrnutty 761 Senior Poster

Project is making project. It is not coding. No waste time make project. Code first. Worry about projects later :)

This is so contradictory, that my head just exploded.

mrnutty 761 Senior Poster

My 2cents:

1) Use IDE first. Concentrate on creating actual project rather than handling how its made.

2) After you have enough experience, you might want to learn about makefiles and whatnot.


3) Just START ALREADY. Pick one and start instead of contemplating for days. You could be using those hours to code.

mrnutty 761 Senior Poster

Will that actually solve the "problem" here? That a console does not automatically close itself when a program running within it finishes?

If he is using an IDE like visual studio then the IDE automatically pauses the console before an input, so in a sense it wouldn't automatically shut it down, but when he runs the .exe file without an IDE, the console doesn't get paused, so the above would close it.
But I think, I may have interpreted his question incorrectly. I was proposing a proper way to flow the program to exit rather than simply calling exit. Judging by the nature of his post and wording, I assumed he was looking something more towards what I posted, but who knows.

mrnutty 761 Senior Poster

Use a if statement and a state variable.

int main(){
 bool shouldContinue = true;
 do{
    /***code here***/

   //ask user if he want to continue
   char input;
   cout << "Continue(y/n) : " ;
   cin >> input;
   if(input != 'y') shouldContinue = false;
 }while(shouldContinue);


}
mrnutty 761 Senior Poster

Just one more things, for question 2, its not a char type, its a array to chars, which is why in the above post, you see an array of chars

mrnutty 761 Senior Poster

I find it weird when people who use metric, also use miles to measure distance.

Yea I know, I always tend to use pixels as a measure. Like I ran approximately 100-200 billion pixel length.

mrnutty 761 Senior Poster

As the problem instructions say, you need to have the second loop nested inside the first loop. in this case, all you really need do is remove the two cout lines between the loops, and move the endl off of the the inner loop's output, and you should be good to go:

for(i=0; i<row; i++)
    {
        for(i=0; i<width; i++)
        {
            cout << "O";
        }
        cout << endl;
    }

You may need to modify this slightly if you need to make a box rather than a filled rectangle.

Note that it is almost always best to explicitly brace any blocks, even when there is only one following statement inside the block. The only real exception to this that I can think of is when using the if/else if/else idiom.

Next time try to guide him please.

mrnutty 761 Senior Poster

I suggest Microsoft Visual Studio or eclipse or netbeans.

mrnutty 761 Senior Poster

It's used in both Rabbit.cpp and main.cpp to detect any type of event

You know you can have more than one instance of SDL_Event right?

mrnutty 761 Senior Poster
void dofunc(int a, int b){a+=b;}
void foo(int near,int far){dofunc(near,far);}//Syntax error, expected primary expression before , and )
void poo(int vnear,int vfar){dofunc(vnear,vfar);}//Compiles fine?

int main(){}

that works fine for me? Whats the real code ?

mrnutty 761 Senior Poster

Thanks a ton! That worked perfectly.. however now there is the issue of declaring a variable without defining it - this gives me the same multiply defined error...
I declare SDL_Event event; in the header file and when I do not define it I get the error, because it is undefinable really unless an event takes place

Why does that need to be a global?

Schol-R-LEA commented: Why oh why didn't I think to ask that? +7
mrnutty 761 Senior Poster

Don't initialize the variables in the header file. Initialize them in the .cpp file. In the header file, just declare them.

Alternately you can do this:

//foo.h
struct Constants{
 static const float PI;
 static const float DEGTORAD;
 //...
};
//foo.cpp
const float Constants::PI = 3.1415f;
//...

Your globals should only be const variables. Other than that, you should pass needed variables to whatever that needs it.

mrnutty 761 Senior Poster

Oh gosh! I sure as heck hope not! >_<

aww man, Now I'm scared. My face looks like my avatar right about now

mrnutty 761 Senior Poster

Okay, so if I want to switch everything over from my Vec and Mat to valarray, will I lose any functionality?

I use the .push_back() function sometimes, and I resize vectors on occasion.

Secondly, would this be the way to go about it?...

#include <valarray>
using namespace std;

typedef valarray<double> Vec;
typedef valarray<Vec> Mat;

If it is that simple then it seems I wouldn't have to edit my actual code much, except to simplify things of course.

unfortunately, valarray doesn't behave the same as vector or doesn't have the same interface. So maybe your better off using std::transform. Or create a push_back method for the valarray and the resize method as well

mrnutty 761 Senior Poster

But if you don't want to use that, then check out std::tranform

Here is an example of use :

#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <iterator>
#include <cmath>
using namespace std;


template<typename ITR>
void print( ITR begin, ITR end){
	while(begin != end) cout << *begin++ << " ";
	cout << endl;
}
int main(){
	int data[] = {1,4,9,16,25};
	typedef std::vector<int> Array;
	Array src(data,data + sizeof(data)/sizeof(*data) );
	Array dest;	

	
	cout << "Before: ";
	print(src.begin(),src.end());

	std::transform( src.begin(), src.end(), //our source
					std::back_insert_iterator<Array>(dest), //our destination					
					std::bind2nd(std::multiplies<int>(),2) //multiply by 2 to each number
					);

	cout << "After: ";
	print(dest.begin(),dest.end());
}
mrnutty 761 Senior Poster

Your using the wrong structure, check out std::valarray

mrnutty 761 Senior Poster

Im afraid of Dinosaurs. <--Even though i know they are extinct.--->

Lol, but...but... I see them all the time, is that normal?

mrnutty 761 Senior Poster

>>#define J sqrt(-1.0)

there is no such thing as sqrt(-1.0), the parameter to sqrt shouldn't be negative. Instead just imagine the second paramter of complex type is imaginary.

typedef std::complex<float,float> Complex;
typedef std::vector<float> TimeDomainData;
typedef std::vector<Complex> FrequencyDomainData;
int main(){
 const int SAMPLE_POINTS = 1024;
 const TimeDomainData data = generateTimeDomainData(SAMPLE_POINTS); //or something
 FrequencyDomainData freqData;
 for(int n = 0; n < SAMPLE_POINTS; ++n){
    const float theta = 2 * PI * n/SAMPLE_POINTS ; //straight from definition
    const float realValue = std::cos(theta);
    const float imaginaryValue = std::sin(theta)
    freqData.push_back( Complex(realValue,imaginaryValue) );
 }
}