2,712 Posted Topics
Re: Also, notice that your case function looks like this : [code] switch(number) { case 1: //blah case 2: //blah } [/code] There is a problem with that. The problem is that you used constant numbers in your switch case. Usually, those numbers means something, so making a const variable for … | |
Re: [QUOTE=hag++;1108338]You do need a second for loop (one for the rows, one for the columns, in the array) It may be easier to use pointers: [CODE] int* return_ptr(int str[][20], int x, int max_rows, int max_col) { int* a_ptr = new int; for (int i = 0; i < max_rows; i++) … | |
Re: [QUOTE=hag++;1108268]Hey, welcome to the forums. Typically this forum is used for learning/ correcting purposes even on the more advanced stuff (which is in the 'Please read before posting' section of the forum rules) which means that forum members are not typically going to do the work for you. Instead, post … | |
Re: Here is an example : 5. Write a C++ statement that defines a Square object named square1 with side length 5. [code] Square square1 = Square(5); [/code] The above is assuming the class is Square is similar to this : [code] class Square{ private: int len_; public: Square(const int Length) … | |
Re: Can you give an example of what you mean ? | |
Re: if you mean for example , <input> hello <output> olleh then all you have to do is this : [code] string input; cin >> input; reverse(input.begin(),input.end()); cout << input << endl; [/code] | |
Re: Pointer to class becomes useful when you get into data structures. | |
Re: >>When assigning a pointer variable, it must always point to an address. Thats incorrect. Hint what about null pointers? | |
Re: It could look something like this, simplified for your pleasure( not Compiled) [code] typedef int DataType; class SingleList { public: struct Node{ DataType value; Node * nextNode; Node(const DataType& initVal) : value(initVal), nextNode(0){} }; typedef Node* NodePtr; private: NodePtr front_; NodePtr back_; public: SingleList() : front_(0), back_(0) {} SingleList(const size_t … | |
Re: I just did this last semester for my java class. If that makes you feel better. | |
Re: You need a forward decleration. Put this at the top of your file : [code] template <class typos_stoixeiou> struct akmi; template <class typos_stoixeiou> struct korifi{ ... } [/code] | |
Re: when you use cin >> , it reads until it sees a space. Do this : [code] char firstName[100] = {0}; char lastName[100] = {0}; cin >> firstName >> lastName; [/code] Thats the easy solution and error prone. The better solution is the use strings. [code] string firstName, lastName; cin … | |
Re: Use this : [code] #include <iostream> #include <string> using namespace std; int getInt(const string& messageBeforeInput){ cout << messageBeforeInput; int result = 0; while(! (cin >> result) ){ //check for bad input cout << messageBeforeInput ; cin.clear(); //clear the stream bits while(cin.get() != '\n') continue; //get rid of the junk } … | |
Re: >>I thought about using an Exception There is no need to use exception here because it will only complicate your code. Why not just display nothing? Or display a message saying no employees to show. Do something like this : [code] if(choice == VIEW_EMPLOYEES){ if(employees.empty()) { displayErrorMessage() } else displayEmployees(); … | |
Re: >> The program cannot get the name. In fact, it doesn't allow me to type That because when you read the age, the stream reads the number and the newline character. That new line character is being read into the variable name. To fix that problem add this : [code] … | |
Re: 1) Do you know how to access the elements in the array 2) Do you know how to use a for loop 3) Do you know how to use add a value If so then you know how to do it, else ask about a even more specific question. | |
Re: >>void expense::setmonth() { cout<<"\n Enter the Month: "; getMonth(); } Change to : [code] void expense::setmonth(std::string month){ currentMonth= month; } [/code] I am not sure what your class does exactly but general idea is given above. | |
Re: printf is faster than cout, in visual studio 2008 express. Try substituting that. How about you post some code that you might think is the bottle neck of your program and we will see how you can improve it. | |
Re: Sin(x) = x - x^3/3! + x^5/5! + x^7/7! ... Cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! ... Cos(x) = Sin( x - 90 ) ; //assuming x is in degrees Tan(x) = Sin(X)/cos(X) "!" means factorial. for example to calculate Sinus you can do this : [code] … | |
Re: >> a+b=23 Not taking into account floating points and just positive natural numbers. Then if b > 23 then no Answer Possible if b = 23, then a = 0; if b = 22, then a = 1 if b = 22, then a = 2 General Equation : B … | |
Re: >>[B]u = new double[I*sizeof(double)];[/B] No! This is not C. In C++ its used like this : [B] u = new double[ I ]; [/B] The value inside [ ], is the number of elements. No need for the sizeof. Put your printing loop out side separately. Like this : [code] … | |
Re: >>[B] expected class-name before[/B] Is wxNoteBook a class ? | |
Re: >> But I feel that this is abusing memory quite a bit how so ? >> My feeling is that it might not be necessary, or even possible, to use the new operator with vectors. It is possible to use the new operator for vectors. It is not necessary to … | |
Re: I think either one of these will do for me : [I]That idea was [B]sooo [/B]not [B]stupiiiddd[/B][/I] [I]That idea was so not stupid<sarcasm>[/I] [I]That idea was so not stupid, cough* bullSh**cough[/I] | |
Re: You are on the right track. Consider making the name of that function better. Also you might want to make the base case more explicit like this : [code] void convertDecimalToRadix(int num, int base) { if( num == 0 ) return; //base case binequ(num/base, base); cout<< num % base; } … | |
Re: Just use the stringstream to break a string into tokens : [code] stringstream tokenBreaker; string aLine = "Please break this into six tokens"; tokenBreaker << aLine; //insert string string tokens[7]; //for now lets not use vectors and do it manually int currentToken = 0; while( tokenBreaker >> tokens[currentToken] && currentToken … | |
Re: [QUOTE=jonsca;1103782]Also, your method definitions, e.g., [code] void dayOfTheWeek::printDay() { cout << "Today is: " << day[dayNum] << endl << endl; }[COLOR="Red"];[/COLOR] [/code] and onward should not end with a semicolon after the brace (you do still need the ones at the end of your class declaration and your const array).[/QUOTE] … | |
Re: Use vectors of string. [code] vector< string > customers; //size == 0 //do stuff //menu stuff; if(!customers.empty() ) cout << "Display Members ? \n"; //other menu stuff [/code] To add customers, you can use the push_back method of vectors; [code] vector< string > customers; customers.push_back("Phil"); customers.push_back("Tyler"); [/code] Here is some … | |
Re: 1) How about using vectors ? 2) How about using 1d array to represent 2d ? 3) In passing 2D arrays, you need to specify the number of columns before hand, like so : [code] const int COL = 5; void init(int Array[][COL], const int ROW){ //TODO logic here } … | |
Re: This function can be more simple : [code] int isnum(const char *p) { if (*p) { char c; while ((c=*p++)) { if (!isdigit(c)) return 0; } return 1; } return 0; } [/code] Maybe to this ? [code] bool isDigits(const char * strNum){ while(*strNum){ if(isdigit(*strNum++) ) continue; else return false; … | |
Re: operator new returns a void*, in which it is converted implicitly to whatever type you are using with assignment operator. operator delete does not return anything. | |
Re: >>[b] Who would design a page with a bright red background and white text[/b] Obviously reptilians! Their visions can handle colors better than we can. | |
Re: Obviously your add function is wrong. How about you ditch the sorting part of this and make a regular linked list, unless you haven't done that already? And your print function is wrong : [code] void printall() { for(node* x = bottom; [COLOR="Red"]x [/COLOR]!= NULL;) { std::cout <<x->data<<"\n"; x = … | |
Re: Google blender. Its a good 3d modeler. You can create some 3d model and use C++ to load it in, and display it with some API like openGL or direct3D. | |
Re: >>[b] Computers can't generate random numbers the way our mind does[/b] Citation please? I am interested on where you got this info. | |
Re: A char cannot hold "312,000". You are probably thinking about an array of chars, or a string. Use something like this : [code] #include <iostream> #include <string> #include <sstream> using namespace std; string deleteChar(string str, char charDelete = ','){ size_t pos = str.find(charDelete); if(pos == string::npos) return str; str.erase( pos, … | |
Re: Basically it shifts bits. Take for example, the number 4. In binary, its 0100. Each digit in the binary for is called bits. 8 bits = 1 byte. If we use the bitshift operator like this [code] int shiftVal = 1; int value = (4 << shiftVal); [/code] we shift … | |
You know you are a geek you find it more natural to count numbers in the power of 2 then decimal. | |
Some background. We all used the string class, but some of you might not know that string is just a typedef of basic_string. In fact here is the typedef you might find when looking in the XString library. [code] typedef basic_string<char, char_traits<char>, allocator<char> > string; [/code] This code snippet shows … | |
Re: For your print maze do this instead, [code] void printMaze(char maze[100][100],int mazeSize) { for(int i = 0; i < mazeSize; i++)//printing the maze { for(int j = 0; j < mazeSize;j++) cout << maze[i][j] << " "; cout << endl; } } [/code] As for your problem, where does the … | |
Re: >>[b] You need to simulate an array with a pointer and dynamic memory[/b] Better yet, you should use the standard containers. Depending on your situation, certain one will be better suited. But Below I will give an example of how to use std::vector to simulate a variable sized array. [code] … | |
Re: For every C++ program, you need a starting point, and that starting point should be either "int main()" or "int main(char *arg, char *argv[])" Here is a complete C++ program : [code] #include <iostream> using namespace std; int zero(){ return 0; } int main() { int x = zero(); cout … | |
![]() | Re: Just go for C++. Learning C afterwards will be easy. And you will see the real difference between the two. |
My friend passed it onto me and its only right I pass it onto [URL="http://www.maniacworld.com/maze_game.htm"] you [/URL]. Its the most simple game. Can you pass all 4 levels? | |
Re: >>[b] Their cubes are: 1, 4, ..., 81[/b] no their cubes are 1^3, 2^3 , 3^3 ... 9^3 |
The End.