456 Posted Topics
Re: This may be what you were looking for ? #include <iostream> using namespace std; int const ROWS = 2; int const COLS = 3; void print( int a[][ROWS][COLS], int numTables ); void print( int a[ROWS][COLS] ); int main() { int ary3d[][ROWS][COLS] = { { {1,2,3}, {4,5,6} }, { {7,8,9}, {0,1,2} … | |
Re: I think what you are looking for is 'error handling' for input of 'invalid data' ... so that your running program will NOT then crash ... when the user enters invalid data. You may like to see this (simple student) example of getting valid integer input from the user: [Click … | |
Re: This related example may help ... may give you some ideas ? // classStack.cpp // #define MAX_ITEMS 50 template < typename T > class Stack { public: Stack(); bool isEmpty() const; bool isFull() const; void push( const T& ); void pop(); T top() const; T topPop(); int size() const; void … | |
Re: Ok ... you still need to clean it up a lot ... I only edited enough so that I could compile it with an up to date C++ compiler ... and run it so it would not crash ... Fixed up formatting a bit ... too ... so that you … | |
In the last few days, I have noticed a very old thread ... resurrected ... about a non-standard C getline function. To all who may like a C readLine function ... a C function that reads in a dynamic C string of any length ... a function with a similar … | |
Re: If your input data is close to what you show above ... something like the following could do ... /* sortAlphaNum.cpp */ /* 2020-02-24 */ /* Here is what I have to do: To have numbers sorted properly even when they aren't justified with leading 0's: 1 2 ... 9 … | |
Re: You may have other errors ... best to post the whole section (or program). /* char year= "YYYY"; char month="MM"; char day= "DD"; */ /* But ... I suspect you want to have: */ const char* year= "YYYY"; const char* month="MM"; const char* day= "DD"; | |
Re: [see](http://www.daniweb.com/software-development/cpp/threads/474369/how-to-make-program-of-this-question) | |
Re: [link](http://www.daniweb.com/software-development/cpp/threads/474369/how-to-make-program-of-this-question) | |
Re: http://www.daniweb.com/software-development/cpp/threads/474369/how-to-make-program-of-this-question[Click Here](http://www.daniweb.com/software-development/cpp/threads/474369/how-to-make-program-of-this-question) | |
Re: Do you know how to use Google ... or some other search site ... to do a search? That is a 'basic tool' to master ... in learning computer programming ... these days. Then ... trying out your own code ... and fixing it up to get it working the … | |
Re: When I just did a Google Search, on *[pure virtual function](http://www.learncpp.com/cpp-tutorial/126-pure-virtual-functions-abstract-base-classes-and-interface-classes/)* right now, this was at the top: (You can do that too ... Yes ?) >When we add a pure virtual function to our class, we are effectively saying, “it is up to the derived classes to implement this … | |
Re: Hope 'your new web site' bristols with bright business. Are you thinking of franchises yet ... like one near Toronto Ontario Canada area :) Best regards, David W Zavitz P.S. I noticed your student programming (C/C++, etc.) help site ... some years ago ... but it was only last summer … | |
Re: You are also using a C getchar() call with no C/C++ header <cstdio> to match. But since ... coding in C++ ... use cin.get() instead. | |
Re: A quick *Google* turned up this ... (for starters) http://www.cprogramming.com/tutorial/function-pointers.html > ... > Callback Functions > Another use for function pointers is setting up "listener" or "callback" functions that are invoked when a particular event happens. The function is called, and this notifies your code that something of interest has … | |
Re: A common student 'overload' ... is, overloading operator << to output the data in a (student) data set ... See the following: Data file: myData.txt 1 20000101 Jane Doe 4 19711203 Hannah Mariam Johnston 2 19900303 Joe 3 19990324 James Harry Robinson Program: // simpleVecStructFromFile.cpp // 2013-03-23 // #include <iostream> … | |
Re: To the OP: Have you thought about doing some assembly coding? HLA (High Level Assembly by Randy Hyde) is a great way to start to get a feel for what is going on under the hood ... and it 'leverages' your C/C++ coding skills to let you get to a … | |
Re: Perhaps the OP means ... 'under what star' was that DOB ? If so ... then the programmer needs a program that has a table of 'Stars' and dates (or date ranges) ... The program can loop to ask the user to input a (VALID) date of birth ... then … | |
Re: Further to the above by *Ancient Dragon* ... you may like to recall that C strings are pointers to ... (a '\0' terminated block of) char ... (i.e. addresses) So ... do you wish to ask ... if the addresses are the same? Probably not ... most of the time … | |
Re: Since you are coding ALL in C, why not start fresh in the C forum ... I think I have some ideas that you may find useful. | |
Re: This parsing could be a breeze if you use C++ string and stringstream to parse ... using : istringstream iss( cppStrToParse ); // construct iss getline( iss, cppStrMth, '/' ); // to get month and then getline( iss, cppStrDay, '/' ); // to get day and then getline( iss, cppStrYr … | |
Re: Just noticed this post, that seems to go with your other post ... Again, it would seem best to use the C++ STL stack (or list) to hold the char's This could serve as a 'quick/cheap' test program ... (and your eval... section, could be vastly cleaned-up/simpified.) // testPalindrome.cpp // … | |
Re: A first step to coding a solution to any problem is a clear understanding (and statement) of the problem. What is the expected input (validate input to make sure ok.) What is the desired output (is the program to loop for more input, if invalid ... or to loop again.) … | |
Re: Is what you are trying to do is to transform a vector? i.e. M1*v1 => v2 i.e. Matrix1 times vector1 = vector2 ? | |
Re: > give me coding for search and edit a file in c++ Can you supply an example of the types of files you wish to search ... and the types of editing that you wish to do? Also, please show the code that you have coded so far, to do … | |
Re: I think "Schol-R-LEA" meant to type: using namespace std; // :) It it always good, (especially for beginner coders), to start out with a working shell C++ program like 'Hello World' ... that compiles and gives the exact expected output ... Then ... add a few lines ... (or a … | |
Re: Can you show us what code you have tried? Start with a working C++ shell ... and add from there, in steps. Show us where you are having trouble(s) ... | |
Re: To get you started ... pseudocode/comments could look something like the following ... #include <stdio.h> int main() { // declare variables // input with prompt to user, the lower starting value // input ... , the upper ending value // input ... , the 'step' value // using a for … | |
Re: There are numerous problems with your code. 1. Do not use conio.h if you want portable code. 2. Avoid the dangerous use of gets ... use fgets instead. 3. ... ... This sample code below may help you get started ... It is good to develope in steps, making sure … | |
Re: So ... are you saying that you need to keep asking for more cents to be input in a loop ... until the user indicates that they are done ? And each time, show the dollar and the cents totals so far? Since you do not wish to use pass … | |
Re: > Conversion from any base to base 10 Is that what your example tries to do? No! You may glean some ideas there ... though? If you are to code it in C++ ... best to start to do that. Get a working shell that takes (some) input and gives … | |
Re: Here is a demo of sorting an array of struct (the array holds a 'Contact list'.) typedef struct Contacts { char name[16]; int area; int phone; } Contacts; Here is the program: /* C qsort examples ... NOTE: needs a C compiler with qsort and const var's demos ... qsort … | |
Re: Where is your 'int main()' function ? Every C or C++ program needs one. #include <iostream> // use < > brackets using namespace std; int main() { // your code goes here ... double monthly_sales, commission; bool more = true; do // main loop where you input & output ... … | |
Re: Would you like to show us the program you have ... | |
Re: If you remember that pointer variables hold addresses, you will be well on your way. Just remember to 'dereference' that pointer, when you wish access the value at 'that address' !!! Pointers are an example of the use of indirect addressing. int x = 10; int* p_x = &x; // … | |
Re: This modified code example may help you to see what is being done as the program executes ... /* permutationsOfString.c */ /* 2014-02-25 */ /* I have an example, coded in C, for printing all permutation of string. I have a problem in understanding, how recursion works in a for … | |
Re: string spc( 3, ' ' ); cout << '*' << spc << '*'; Is short code ... But ... what is a 'word' ? Does it need to be a real word that is in the English dictionary? If so ... that is NOT what you are doing. See this … | |
Re: if each line in the file is exactly numberA someBinaryOp number B then the problem is a breeze //example file: 23.2 + -11.7 -11 * -77.9 128.99 / -11 23.91 - 123.99 | |
Re: If you were to use stringstream objects, your file conversion from .. 7 regular data 'words' on each line ... to ... all 7 sequential words on their own sequential line, (with the exception that the 2nd and 3rd words are both on the 2nd line, separated by one space) … | |
Because things, these days, seem a little 'slow' around this forum, please forebare this old post, (that was recently resurrected by an inquiring mind), and humour this 'update', in good faith that this update might be appreciated by some beginning students of C++ ... :) // beginnerBadCppExampleCodeBeforeFixedUp.cpp // 2013-08-14 // … | |
![]() | Re: Well ... best to avoid C code style and also avoid pointers in C++ unless REALLY needed ... (C++ has pass by reference) //#include<stdio.h> // #include <cstdio> // but use <iostream> // #include<conio.h> // don't use to have portable code // #include<iostream.h> // use as belowe ... #include <iostream> #include … ![]() |
Re: Great post Jason ! In C++ when you call: fout << value << std::endl; the C++ compiler 'knows' what type of object 'value' is and will output what '<<' is supposed to do for that C++ type of object ... (if '<<' is defined for that object) Note: you can … | |
Re: Also, a few pretty basic coding suggestions ... int main() { //cin.clear() ; // clears the buffer// <- NO ... it clears cin (error) flags that were set on some cin input // // ... //system("PAUSE") ; // Not portable code // cout << "\nPress 'Enter' to continue/exit ... " … | |
Re: If you don't know about dynamic memory or function pointers ... you can just do this modification of the above ... /* partition_C_ary.c */ #include <stdio.h> /* my partion 'truth function' used here ... */ int isEven( int a ) { return a % 2 == 0; } void partition( … | |
Re: There were actually several problems with the code ... please see added comments, fixes and ... small test program ... // test_DoublyLinkedList.h.cpp // #ifndef DoublyLinkedList_H #define DoublyLinkedList_H #include <iostream> #include <cassert> //Definition of the node template < class Type > struct NodeType { Type info; NodeType < Type >* next; … | |
Re: 1. If you know the range of values in the integer matrix 'm', say the values range form 10 to 1009 then you could create an array to hold the counts for each value // initial all values to 0 int freq[1000] = {0}; //then you could run though the … | |
Re: You said you were learning C++ ... but did you realize that your code was in the C style? In C++, one can pass by reference ... and so will not have to dereference a value passed into a function using the * dereference operator (that is used with passed … |
The End.