Monday, May 24, 2010

Eigenvectors calculation (from Numerical Recipes in C book)?

Hi,


I implemented the algorithms tred2() (page 474) and tqli() (page 480) for calculating eigenvectors and eigenvalues of real matrices, and comparing the results to the ones obtained with MatLab, some of the eigenvectors have the opposite sign. Every single value is ok, but the vector seems to be multiplied by -1.





Does anyone know why is this, and if this is actually an error?





Thanks in advance.





PS: the book can be found online at





http://www.nr.com/nronline_switcher.php

Eigenvectors calculation (from Numerical Recipes in C book)?
Eigenvectors are not unique. If your matrix has an eigenvector of





[ 1, -2]'





for example, then any multiple of that eigenvector is also an eigenvector for that hypothetical matrix, so





[2, -4]'


[50, -100]'


[-1, 2]'


[-1000, 2000]'





are all eigenvectors for this hypothetical matrix. That is because for any square matrix A with eigenvector x corresponding to eigenvalue λ and for any constant c





A(c*x) = c*Ax


= c*λx


= λ(c*x)





Which means that c*x is an eigenvector for A.





So, there is no error. Some are just multiplied by -1. You're good.





edit: No, the eigenvalues do not change. Note in my "proof" above that the same eigenvalue λ was used for the vectors x and c*x. Like I said, eigenvectors aren't unique; not even for a particular eigenvalue.





Here's an example.





A =


[ 4 -2 ]


[ 1 1]





x =


[ 2 ]


[ 1 ]





Ax =


[ 6 ]


[ 3 ]


= 3x





So x is an eigenvector of A with an eigenvalue of 3. Now let's look at y = -x = [-2 -1]'.





Ay =


[ -6 ]


[ -3 ]


= 3y





So y = -x is also an eigenvector of A with an eigenvalue of 3.





I can't message you, so send me a message if you have any questions.


AS Basic as it can get C++ Hangman?

i need help in hangman only using %26lt;iostream%26gt;, %26lt;lvp\string%26gt;, %26lt;lvp\vector%26gt; or bool..

AS Basic as it can get C++ Hangman?
wow, thats a great question... lets see... my answer is... around the corner


Can anyone write this code for c++?

Write a function that computes the alternating sum of all elements in a


alternating_sum is called with a vector containing


1 4 9 16 9 7 4 9 11


Then it computes


1 – 4 + 9 – 16 + 9 – 7 + 4 – 9 + 11 = -2

Can anyone write this code for c++?
Take a look at here:





http://www.msoe.edu/eecs/cese/resources/...


Finding the mode of an array C++?

I have a vector that records the number of occurances based on user input, but I cannot figure out how to find the mode of that data here is my code listing the occurances and what I have so far for the mode:





cout%26lt;%26lt;"Roll"%26lt;%26lt;" "%26lt;%26lt;"Count"%26lt;%26lt;endl;


for(num = 1; num %26lt;=50;num++){


cout%26lt;%26lt;num%26lt;%26lt;" "%26lt;%26lt;Count[num]%26lt;%26lt;endl;


}





void Mode(CountType %26amp;Count, int %26amp;num, int %26amp;i)


{





int pos_mode;


int mode;


for(pos_mode = 1; pos_mode %26lt;=50;pos_mode++){


if (Count[pos_mode] %26gt; Count[num]){


mode = pos_mode;





}

















}


cout%26lt;%26lt;"The mode is: "%26lt;%26lt;mode;


}

Finding the mode of an array C++?
Try this:





I'm assuming CountType to be integer.





void Mode(CountType* Count)


{


//first sort the count array yourself





int n = 0;


int count = 0;


int max = 0;


int mode = 0;





for(int i = 0;i%26lt;50;i++)


{





if(n != Count[i])


{


n = Count[i];


count = 1;


}


else


{


count++;


}





if(count %26gt; max)


{


max = count;


mode = n;


}





}





cout%26lt;%26lt;"Mode: "%26lt;%26lt;mode%26lt;%26lt;endl;


}








Don't forget to sort the array first, it is important.

phone cards

How do you make a C++ histogram?

for the program i need a function that displays a histogram showing the numbers (that the user has given using a vector) in each 5 five unit range (i.e. 1-5,6-10

How do you make a C++ histogram?
The trick to this is using the proper coding structure... a switch statement. A histogram is basically a bar chart that shows relative frequencies (total counts for a given value... how many fives, how many eights etc) so that you can see a distribution of values.





int firstrange = 0;


int secondrange = 0;


int thirdrange = 0;


int howmanyunknowns = 0;





for(int i=0;i %26lt; int_Vector.size(); i++)


{


int d = int_Vector.at(i);





switch (d) {


case 1:


case 2:


case 3:


firstrange++;


break;





case 4:


case 5:


case 6:


secondrange++;


break;





case 7:


case 8:


case 9:


thirdrange++;


break;





default:


howmanyunknowns++;


}





}





The above loop would run through a integer vector looking for 1's, 2's, 3's...etc and count them up, placing them in the correct range variable counter. (Values of 1, 2, 3 go into one variable... firstrange)





At the end you would have a count of each range for displaying as you like.





Granted this switch statement can only handle a limited set of ranges, but if you need more and bigger ranges, remember you can write a switch statement into a series of if statements...





if ((x %26gt;=1) %26amp;%26amp; (x %26lt;= 20)) { firstrange++; }


if ((x %26gt;=21) %26amp;%26amp; (x %26lt;= 40)) { secondrange++; }





etc etc etc.





Side Note: You could use a vector iterator instead of a for loop. I just used one to make it a bit more simple looking.





Hope you get the idea.


How do u program this c++ visual program using the following libraries?

Topic: Write a program that allows the user to enter numbers in the range 0-19, terminated by a sentinel, and then perform the following functiosn on the numbers: the average number, the maximum number, the range, the median





#include%26lt;iostream%26gt;


#include%26lt;vector%26gt;


#include%26lt;string%26gt;


#include%26lt;stdlib.h%26gt;


#include%26lt;time.h%26gt;





using namespace std;

How do u program this c++ visual program using the following libraries?
Try this:





cout %26lt;%26lt; "1"


cout %26lt;%26lt; "am 2"


cout %26lt;%26lt; "st"


cout %26lt;%26lt; "up"


cout %26lt;%26lt; "id"


cout %26lt;%26lt; "an"


cout %26lt;%26lt; "d la"


cout %26lt;%26lt; "zy 2"


cout %26lt;%26lt; "due"


cout %26lt;%26lt; "hom"


cout %26lt;%26lt; "e"


cout %26lt;%26lt; "work"
Reply:Why do you have to use those libs?





Looks like all you'd need is iostream.





int myInput=0;


do {


cout %26lt;%26lt; "Give me a number: ";


cin %26gt;%26gt; myInput;


if (myInput == -1) {


cout %26lt;%26lt; "C-ya!" %26lt;%26lt; endl;


}


else if (myInput %26lt; 0 || myInput %26gt;19) {


cout %26lt;%26lt; "Bad number... Try again!" %26lt;%26lt; endl;


}


else


numbersRead++;


numberTotal+=myInput;


if (myInput%26gt;maxNumber)


maxNumber=myInput;





and so on...





Your instructor would probably want you to complete it yourself.


I am trying to write a program with C++ which acts like an E-6B.?

I need an equation which will give me the wind vector, if i have the ground speed being 478 kts with a true heading 350, and a true airspeed of 500 kts and a true course of 355.

I am trying to write a program with C++ which acts like an E-6B.?
The wiki site has some fomulas you may find useful.


Distance between a point and a Vector.?

There is a vector from point A to B


VectorAB= %26lt; 4,1,-2%26gt;


Then there is a point C(4,1,2) .





What is the shortest distance between C, and vector AB?

Distance between a point and a Vector.?
You must know the coordinates of either A or B to answer this fully. As it is states, C could be in Vector AB. Thus, the shortest distance is zero.


**************************************...


UPDATE UPDATE UPDATE UPDATE UPDATE





OK. So point A is at (0,0,2) B is at (4,1,0) and point C is at C(4,1,2). Consider A, B, and C veritces of a triangle. Find the lengths of each side. Then, ignore the 3D stuff. Find the altitude of triangle ABC from C to side AB.





For lengths of sides, use


(x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2 = d^2.





This works for this specific problem when distance is the main concern.





The previous poster has the hardcore, pure math method that works in more general cases.
Reply:Find the vector orthogonal to AB that passes through the point C. Then calculate the length of that vector.

orange

Binary error in C++? How to fix?

epsfile.open("EPS.DAT", ios::in);


if(epsfile)


{


do


{


epsfile %26gt;%26gt; epsfile[i];


i++;


}


while (epsfile[i - 1] !="End");


}


epsfile.close();

















Both places that the "[ ]" appear seem to be having issues, the compiler says that std::ifstream doesn't define the operator. No sure what to do to fix it. I have included iostream, ifstream, string, and vector. Is there something i'm missing?

Binary error in C++? How to fix?
As the compiler says, there is no operator[ ] for ifstream. The two statements where you're trying to index into epsfile are invalid. I'm not even sure what you're trying to do with the statement: epsfile %26gt;%26gt; epsfile[i]. I guess you're trying to read from the file, but your syntax is wrong.





Have a look here:


http://www.cplusplus.com/doc/tutorial/fi...


Help with an C++ homework question.?

i'm having problems creating and implementing the final requirment:void remove_message(int i) const;





This is my question:





You have to create a class called mailbox. You don't yet know how to store a collection of message objects. Instead, use the following brute force approach: The mailbox contains one very long string, which is the concatenation of all messages. You can tell where a new message starts by searching for a From: at the beginning of a line. This may sound like a dumb strategy, but surprisingly, many e-mail systems do just that.


Implement the following member functions:


void Mailbox::add_message(Message m);


Message Mailbox::get_message(int i) const;


void remove_message(int i) const;








I would appreciate any input or comments anyone can make about what I have so far and if what I am doing or trying to do makes sense.








class Mailbox


{


public:


Mailbox(string u);


void add_message(Message m);


Message get_message(int i) const;


int count_messages() const;


string get_user() const;


private:


vector%26lt;Message%26gt; messages;


string user;


};





Mailbox::Mailbox(string u)


{


user = u;


}





string Mailbox::get_user() const


{


return user;


}





void Mailbox::add_message(Message m)


{


messages.push_back(m);


}





Message Mailbox::get_message(int message_num) const


{


return messages[message_num];


}





int Mailbox::count_messages() const


{


return messages.size();


}

Help with an C++ homework question.?
The first problem with this is that you say you want to implement the function:





void remove_message(int i) const





This doesn't make sense, since only member functions can be declared const. Global functions can never be declared const. I assume you meant:





void Mailbox::remove_message(int i) const





The problem with this is that if this function is meant to effectively delete some data from the Mailbox class, then it is not legally allowed to do so because the function is declared as being const, which means it is not allowed to alter any members of the class of which it is itself a member.





However, the following would be legal:





void Mailbox::remove_message(int i)





In order to implement this in your version of the Mailbox class you would do:





void Mailbox::remove_message(int i)


{


messages.erase( members.begin() + i );





// Your compiler might not like the members.begin() + i.


// If this is the case use the following code instead





// std::vector%26lt; Message %26gt;::iterator itr;


// for ( int iCount = 0; iCount %26lt; i; iCount++ )


// {


// ++itr;


// }


// messages.erase( itr );


}





While your approach would work, it's not what you've been asked to do. The question states:





"You don't yet know how to store a collection of message objects. Instead, use the following brute force approach: The mailbox contains one very long string, which is the concatenation of all messages. You can tell where a new message starts by searching for a From: at the beginning of a line."





This means you shouldn't be using a member vector to store the messages. Instead you should be using a single very long string member to store all the messages, which you then parse to find a particular message. Basically, all the code you have to write is a bunch of string manipulation functions. I suggest you use a STL string object rather than a C style char array as this means you don't have to have a maximum string length for your storage string when you declare it nor do you have to manage the string's internal memory allocation yourself.





As you haven't included any details about the Message class I can't tell how you extract a string from a Message. Is Message a class/struct that has a string member, or is it just a typedef to std::string?


Help with an C++ assignment question.?

i'm having problems creating and implementing the final requirment:void remove_message(int i) const;





This is my question:





You have to create a class called mailbox. You don't yet know how to store a collection of message objects. Instead, use the following brute force approach: The mailbox contains one very long string, which is the concatenation of all messages. You can tell where a new message starts by searching for a From: at the beginning of a line. This may sound like a dumb strategy, but surprisingly, many e-mail systems do just that.


Implement the following member functions:


void Mailbox::add_message(Message m);


Message Mailbox::get_message(int i) const;


void remove_message(int i) const;








I would appreciate any input or comments anyone can make about what I have so far and if what I am doing or trying to do makes sense.








class Mailbox


{


public:


Mailbox(string u);


void add_message(Message m);


Message get_message(int i) const;


int count_messages() const;


string get_user() const;


private:


vector%26lt;Message%26gt; messages;


string user;


};





Mailbox::Mailbox(string u)


{


user = u;


}





string Mailbox::get_user() const


{


return user;


}





void Mailbox::add_message(Message m)


{


messages.push_back(m);


}





Message Mailbox::get_message(int message_num) const


{


return messages[message_num];


}





int Mailbox::count_messages() const


{


return messages.size();


}

Help with an C++ assignment question.?
You don't show how Message is defined, but with vector%26lt;Message%26gt;, which would probably give you a nicer implementation, I don't think you're doing what the assignment asks. Mailbox::messages needs to be a string; and for convenience, give Mailbox a count attribute.





The signature of add_message would be :


void Mailbox::add_message(const string%26amp; m);


It would use string's operator+= to concatenate m to messages, and then increment the count attribute. (Mailbox::remove_message decrements the count attribute, and count_messages just returns the current value of count.)





The string class provides various find operations you can use to search for a message, using the keyword "From:", that get_message or remove_message is looking for.





Assignments like this usually make you do something one way when you know there's an easier way to do it. So, use a string instead of your vector, and you'll probably learn a few things about all the good operations the string class provides.


Need help in dynamic arrays of c++?

how can i increase the size of a dynamic array even though i dont know what its end size will be...please tell me this without the use of std vector thingy..only use the basic stuff like while,for loops etc to do it..

Need help in dynamic arrays of c++?
Not an uncommon question.





Usually what's done is instead of increasing the size every time you insert something (it causes a large load on the processor)


you do the easier and less intensive process of doubling the size when you see that you need more space.





let's assume we have a dynamic array of books?


so:





const int START_SIZE = 5





Book* myArray = new Book[START_SIZE]





ok, now we know that when we have a dynamic array we must always keep track of it's capacity and it's size (usually you store those in variables).


Our new array has a capacity of 5 and since we didn't add anything it has a size of 0.





so:


int capcacity(5);


int size (0);





great!


We're on a roll, now let's say we add a book.


so the process of adding a book to the Dynamic array is the following





1.) first you check that your new size does not equal your capacity.





in our case if we add one book our capacity is still 5 and our new size (after adding a book ) is now 1.





that's great, so just say:


Book treasure_island("Treasure Island") ;


myArray[size] = treasure_island;


size++;





(keep in mind the order! It's important! arrays start storing at 0...)





ok, that works great as long as we have space, what do we do if we dont have anymore space!?!?!





well, first we have to do a check for that, so before we add a book we do:





size++; //our new size





if (size == capacity)


{


//double the capacity (or increase it however u want)


capacity = capacity *2;





//make a temporary array of that size


Book* tempArray = new Book [capacity];





//copy the old values across to the temp array





for (int i=0 ; i %26lt; size; i++)


{


tempArray[i] = myArray[i];


}





//delete the old array (otherwise a memory leak!)


delete [] myArray;





//make our array pointer point at the tempArray


myArray = tempArray;





}


// all done! now, we can add the new book knowing we have //space for it!





myArray[size] = (the book you wanted);








Hope this helps!
Reply:Well, even though you said not to use it, an stl vector really is the fastest and easiest way to do this, I'd recommend that over reinventing the wheel.





To "roll your own" using just the new/delete, you'll just have to keep track of the current maximum size of the array, and the number of items you've added. Whenever you add an item to the array, check if it would push the number of items over the maximum. If it will, you'll have to double (doubling is the most common, but you could increment it by some other amount if you want) the maximum, allocate a new array of the entire new maximum size, copy all the old elements over, and then delete the old array. If you look at the vector source, you'll see this is pretty much what it does when it goes beyond its size limit.





// initialize


int maxItems=100


int numItems=0;


itemType *array=new itemType[maxItems];





// ...


//... add something to array ...


if(numItems+1%26gt;=maxItems)


{


maxItems*=2;


itemType *newArray=new itemType[maxItems];


// in practice, memcpy and a for loop usually take


// about the same time for me, but this looks nicer


memcpy( newArray, array, sizeof ( itemType ) * numItems );


delete array;


array=newArray;


// note that the location of the array is now a new address


// so anything that was passed the location of the old array


// by reference now has a BAD pointer


}


array[numItems]=something;


numItems++;


// note that numItems is incremented only AFTER using


// it as the index. This could be written in 1 step as


// array[++numItems]=something; but it makes it a little less


// readable IMO








Ideally, the above would be in some dynamic array class, which overloads the [] operators for access, and has some add_item(itemType) method. And if you want to use it for different types, you'd really want to make it a template class. But then, this would be really close to stl vector, which you requested not using. In that case, maybe you do want to go linked list or tree as suggested above.
Reply:This is a bit complicated as you are going to have to dynamical cast the array size on the fly; however, the code will look something like this:





char * myArray = NULL;


// Demonstrate increasing the array based on loop iterations


// This code would cause errors and should only be used as


// a basic example of how to create dynamic arrays, all data


// is lost when the size is increased!


for (int ndx = 0; ndx %26lt; 10; ndx++) {


myArray = new char[ndx];


}


// Release the memory used


delete [] myArray;
Reply:You can just call a function to copy the array into a temporary array of the same size, delete the original array, and create a new array that is the size of the old array + 50 or so.





void lengthenArray(int/char/whatever *array) {


length = length of array;


int/char/whatever temp[length];


copy(array, temp);


delete array;


create array[length of array + 50 or so];


}





I'm sure there are better ways, but that's the best I could think of off-hand.
Reply:The other answerers are dangerously wrong. JordTeic's idea is inefficient (copy the array to a temp, and then delete and recreate array?).





Rjzii is just plain wrong (that's not how new and delete work, and that's not what your link suggests. Read it carefully).





CrazyCoder thinks C and C++ are the same. Wrong language.





%26gt; how can i increase the size of a dynamic array even though i dont know what its end size will be





Actually, you might not know the precise end size, but you can make an educated guess as to how big it needs to be in the short term right? One thing you could do is allocate a new array that is big enough, and copy the old array to the new array. Depending on what your array contains (complex objects for example), this could end up being an expensive operation.





A btree or linked list of buffers may be a better technique, depending on what your array contains and how it being used. Just link up arrays, and you can keep extending your “array”.
Reply:first of all you should include the header file %26lt;stdio.h%26gt;


there is a funtion named malloc you can use that function to allocate more memory to your array.





if you still have problem send me an email at mr_sheikhazad@yahoo.co.in

flash cards

Want help in c++ program?

Q.1 An election is contested by five candidates.The Candidates are numbered 1 to 5 %26amp; the voting is done by marking the candidates number on the ballot paper.Write a prog to read the ballots and count the votes cast for each candidate using an array variable count.In case a number read is outside the range 1 to 5,the ballot should be considered as a 'spoilt ballots' and the prog should also count the number of spoilt ballots.





Q.2 Write a function that creates a vector of user-given size M using new operator.

Want help in c++ program?
May be you can search at project assignment help website like http://askexpert.info/


Why should I use iterators rather than int for traversing through a list in C++.?

Why should I use


____________________


using namespace std;





vector%26lt;int%26gt; myIntVector;


vector%26lt;int%26gt;::iterator myIntVectorIterator;





// Add some elements to myIntVector


myIntVector.push_back(1);


myIntVector.push_back(4);


myIntVector.push_back(8);





for(myIntVectorIterator = myIntVector.begin();


myIntVectorIterator != myIntVector.end();


myIntVectorIterator++)


{


cout%26lt;%26lt;*myIntVectorIterator%26lt;%26lt;" ";


//Should output 1 4 8


}











Rather than


____________________





using namespace std;





vector%26lt;int%26gt; myIntVector;


// Add some elements to myIntVector


myIntVector.push_back(1);


myIntVector.push_back(4);


myIntVector.push_back(8);





for(int y=0; y%26lt;myIntVector.size(); y++)


{


cout%26lt;%26lt;myIntVector[y]%26lt;%26lt;" ";


//Should output 1 4 8


}

Why should I use iterators rather than int for traversing through a list in C++.?
Hi





well iterator have a main function, to access data from a container. when you have an stack, queue or some special container from STL you must use iterator to access the data inside those structure. It is impossible or very difficult to use other thing.





It is best practice to learn how to use iterator when you are dealing with complex data structures. Here i put some links.





good luck
Reply:safety, for one

flower girl

Need Help in making this c++ program?

Implement and thoroughly test a class named IVector that represents a


dynamic array of integers. It will have 3 private data members: int


capacity, int count, and int * items. The 'capacity' is the physical


size of the dynamic array (its actual number of elements). The 'count'


is the number of elements currently in use (indices 0, 1, ...,


count-1). The pointer 'items' points to the first element of the


dynamic array, which will be created by the operator 'new'.





Class IVector will have three constructors: 1) a default constructor


that creates an array of capacity = 2 and count = 0; 2) a constructor


with parameter int cap that creates an array of capacity = cap and


count = 0; and 3) a copy constructor with parameter "const IVector %26amp; V"


that creates an array that is identical to IVector V.





Class IVector will have the following public member functions: 1) two


getters that return the capacity and the count of an IVector object;


2) one declared "void Append( int item )" that adds 'item' to 'items'


at position 'count' and increments 'count' by one; 3) one declared


"void Insert( int index, int item ) "that adds 'item' to 'items' at


position 'index' and increments 'count' by one; and one declared "void


Delete( int index )" that deletes the item at position 'index' and


decrements 'count' by one.





Overload the operator '[ ]' to access elements of the vector by


subscript.

Need Help in making this c++ program?
Sounds pretty straightforward to me. So do you always get your homework done this way? Explains a lot about the state of the Software Industry.....
Reply:What is the question?
Reply:Does not look easy. May be you can contact a C++ expert at websites like http://askexpert.info/


Help: cal 3 - the cross product?

i have no idea how to do these:





1. let a = a_1i + a_2j and b = b_1i + b_2j be nonzero vectors in the xy plane. Show that a x b is parallel to k





2. show that (a x b) * b = 0 for all vectors a and b





3. let a, b and c be vectors. which of the following expressings make sense and which do not? explain you answer in each case.





a.) a * (b x c)


b.) a x (b * c)


c.) a * (b * c)


d.) a x (b x c)

Help: cal 3 - the cross product?
1 a and b are vectors in the x y plane because they have no k component. the cross product is a vector perpendicular to a and b so it must be parallel to k, You can also prove it by writing a and b with a zero k component and formally taking the Cross product.





2 axb is perpendicular to b and so dotted with b=0





3 b*c is not a vector but a scalar and a vectorX scalar does not make sense.


Programming in C++?

In the following code I am trying to resize the array at the correct place, my teacher said to use a temp variable and I can't figure this out. thanks.





while(!infile.eof())//this while loop resizes the vector and inputs the names from the file until the file ends


{//begin while


infile%26gt;%26gt;recordList[recordList.length()].... this!!!


int temp = recordList[recordList.length()].sku;


if(temp != infile.eof())//this if


{//begin if





infile.ignore(2,'\n');


getline(infile,recordList[recordList.len...


getline(infile,recordList[recordList.len...


infile%26gt;%26gt;recordList[recordList.length()]....


infile%26gt;%26gt;recordList[recordList.length()]....


recordList.resize(recordList.length() + 1);


}//end if


}//end while

Programming in C++?
Why do not you consult a C++ expert? Check http://k.aplis.net/
Reply:Seriously, ask on a forum. I've used this forum tons of times :





http://cboard.cprogramming.com/





You can get answers in like a couple of minutes. They're quite helpful, check the site out.





Like the other guy said, programmers don't usually lurk in Yahoo Answers. They spend their time in message boards, which is implied through the crazy fast replies.
Reply:This is not a good place to ask for C++ homework help. Your code is all truncated.





Find another forum.


When I compile my C++ code in linux, this error is printed: "no such file or directory",?

the error belongs to these lines:


#include %26lt;iostream%26gt;


using namespace std;


#include %26lt;vector%26gt;

When I compile my C++ code in linux, this error is printed: "no such file or directory",?
Maybe the setup your compiler is wrong.





patch up this codes, if you can run this then your compiler is working.





#include %26lt;iostream%26gt;


using namespace std;





int main()





{


cout %26lt;%26lt; "Hello World" %26lt;%26lt; endl;





return 0;





}





Note : your headers format is wrong, this the correct one.





#include %26lt;iostream%26gt;


#include %26lt;vector%26gt;





using namespace std; // always after all the headers otherwise you will use %26lt;vector.h%26gt; with "h" extension.
Reply:check to make sure you have those files. sometimes when folks build their linux box, the forget to install the headers for development. try doing a search for those files
Reply:check that all files and directories you are referrencing actually exist. I don't think vector is correct. read your documentation that came with the compiler.

curse of the golden flower

C++ dynamic array function help?

Write a program that will keep track of the enrollment of one class. Use a dynamic array to keep track of the enrollment. When enrolling a new student, the dynamic array will increase by one. You must use a function call to add student. I have been working on this problem all day and my code just does not work. My teacher said we do not need to use vector to increase the array size so any tips on how to solve this problem would be great because I just keep hitting a dead end.

C++ dynamic array function help?
C++ does not have any native "dynamic array" capability. The closest thing would be the use of the ANSI realloc() function, but that's a C thing, and not special to C++.


Now you *could* write your own class that manages an array. Let's say your class is something like this:





class Array {


a_class *m_array;


size_t m_nCurrentArraySize;


void Resize(size_t nNewSize);


...


};





Then your implementation might looks like this





void Array::Resize(size_t nNewSize) {


a_class *pNewArray = new a_class[nNewSize];


for (size_t i = 0; i %26lt; m_nCurrentArraySize; i++)


pNewArray[i] = m_array[i];


m_nCurrentArraySize = nNewSize;


delete [] m_array;


m_array = pNewArray;


}
Reply:You can use a linked list for this type of operation but your teacher wanted you to use 'dynamic' arrays. Nothing like making things more difficult.





one_student is assumed to be a structure.


student_class is assumed to be a dynamic array of one_student.





class MyClassArray


{


public:


MyClassArray() {student_enrol = NULL; student_count = 0;}


void AddStudent(one_student %26amp;student);


private:


typedef one_student *student_array;


student_array student_enrol;


int student_count;


...


};





MyClassArray::AddStudent(one_student %26amp;student)


{


student_class temp = new one_student[student_count+1];


for (int i = 0; i %26lt;= student_count; ++i)


temp[i] = student_enrol[i];


temp[student_count++] = student;


delete student_enrol;


student_enrol = temp;


}
Reply:It might be useful for you to paste the code you've got, and tell us specifically what error you're seeing.


C++ maxtrix?

I have to create a gradebook that reads in any amount of students and what their grades are. The user can add more to the matrix if they need another column of grades. I am having a problem with my addGrades function and need help on what is worng and how I can fix it. Here is the function for my "Add Grades" function:





void AddGrades(vector%26lt;String%26gt; %26amp;name, TTTBoard %26amp;Board)


{








int Row = Board.numrows() - 1;


int Col = Board.numcols() - 1;





//Board.resize(Col,Row);


//for(int j=0;j%26lt;= Col;j++){





for(int i = 0; i %26lt; Row; i++){


cout%26lt;%26lt;"Please enter a grade for "%26lt;%26lt;name[i]%26lt;%26lt;" ";


cin%26gt;%26gt;Board[Row][i]; //j,i ?


Row++;


}//end for





//}//end for











}//end fun.





//Thanks.

C++ maxtrix?
void AddGrades(vector%26lt;String%26gt; %26amp;name, TTTBoard %26amp;Board)


{


int Row = Board.numrows() - 1;





for(int i = 0; i %26lt; Row; i++){


cout%26lt;%26lt;"Please enter a grade for "%26lt;%26lt;Name[i]%26lt;%26lt;" ";


cin%26gt;%26gt;Board[i];


}//end for





}//end fun.
Reply:This if for a console app fight? Hence the cout statements? If so, the cin statement only needs to be seperated by commas.... and why are you using { instead of ; for the endings of a few of your lines of code?