456 Posted Topics
Re: I would use a struct (with a typedef) to create a data record to track the frequencies of each value in the int array. Maybe something like this ... Firstly: /* most_frequent.c */ #include <stdio.h> #include <stdlib.h> /* re. malloc */ typedef struct { int val; int count; } ValCount … | |
Re: There are few things about your style of coding that could be improved: /* use Global const (in C use #define) instead of 'magic numbers' */ #define MAX_LEN 31 /* pick numbers that give multiplies of 4 (or 8) bytes */ typedef struct { char name[MAX_LEN+1], /* recall need space … | |
Re: There are several steps to the final solution of your problem ... The first step that I would suggest you take would be to get some test data, perhaps like this ... to get a bin file to test the rest of your code: /* spiltInto2Files.c */ #include <stdio.h> #include … | |
Re: You could form a string and print the reversed string ... (i.e. similar to using a 'stack' to unwind the recursive calls) like this: #include <stdio.h> /* Write an iterative function char* conversion(unsigned int num, int base), that converts an integer num into any base (base <=10). How to transform … | |
Re: You might also like to see the info/examples here: http://www.cplusplus.com/doc/tutorial/polymorphism/ | |
Re: As Dani's own @rubberman has indicated ... the char '0' has the ASCII int value of 48 But you do not need to worry about memorizing that (48) value, as you can convert form char to int for the digits 0...9 very easily like this: /* problem3.c */ #include <stdio.h> … | |
Re: Try this ... /* problem2.c */ #include <stdio.h> #include <stdlib.h> #define MAX_SIZE 8 void print( int ary[MAX_SIZE][MAX_SIZE], int, int ); /* void main() */ int main() { int ary[MAX_SIZE][MAX_SIZE]; int row, col; for( row = 0; row < MAX_SIZE; ++ row ) { for( col = 0; col <MAX_SIZE; ++ … | |
Re: If you will Google "C stack" ... you may be surprised how much is at your finger tips but you never looked to see? A 'stack' is a 'last-in-first-out' (LIFO) data structure that has many uses in programming. So ... say you have the word "first" and you have a … | |
Re: Your code would do well to have a fresh start ... Do NOT use getch if you want your code to be portable. Do not mix C and C++ style. Use functions with good discriptive names to handle each job. For example, your input could be handled by a function … | |
Re: Try looking here to see some working examples ... http://en.cppreference.com/w/cpp/utility/bitset | |
| |
Re: You could also use a list ... All these containers mentioned so far... 'know their' size (hint for menu item 2) And, using iterators ... you can easily traverse a list (hint re. menu item 3) And using push_front and then pop_back ... you can easily do next menu item. | |
Re: So you have several problems ... /* 1) using the C++ library deque (FIFO) container to the hold the int's input from file 2) using pop / push onto a 2nd deque ... get sum/size to get average 3) start with setting the 1st int in the new deque as … | |
Re: You may like to know that this problem could nicely be handled using a struct and a C++ vector to hold all the struct's ... struct Temps { double high, low; } ; See example below ... // takeInHighLowTemp.cpp // /* The program should output the * average high, * … | |
Re: What code have you tried do far? (You have not yet given us any real clue about where you are stuck.) | |
Re: Hi @rose_2, Do you know how to code an "Hello World" type program in C++ ? If you do, then you can prompt for input. Then the next thing ... is to code to take in some number ... and then to take in numbers in a loop and to … | |
Re: For your simple program ... the first suggest by Dani's @ryantroop is quite adequate. include stdlib.h and time.h. then ... /* seed the random gerator ... */ srand (time(0) ); /* somewhere near the top of main */ /* then can do this as needed */ /* give me a … | |
Re: Firstly ... please note that if you wish your code to be portable, do not use <conio.h> You can use a C struct and a typedef to create whatever data record you need. typedef struct { char* name; int id; int scores[5]; } Student; And then in your main function … | |
Re: Why are you using C strings in a C++ program ? (Way better to use C++ string, most of the time.) | |
Re: Can you code a C ++ shell program to get started? Can you code to take in data in a loop? If not ... look here: http://developers-heaven.net/forum/index.php/topic,2019.0.html | |
Re: A pointer is simply a variable that holds an address. // compiler told val is a label to access this int '10' it puts into memory somewhere // int val = 10; cout << "val = " << val << endl; //compiler knows val is an int and block address … | |
Re: This may help you to get started ... | |
Re: I would re-design ... bottom up and use table lookups and not use pointers at all. Also, you seem to have redundant data ... for example ... temperature and temperature string ... but only need to store the temperature ...and then can lookup the other when needed. | |
Re: I think you firstly need to get more info to be able to understand the question. The question (part 3 below) is poorly worded! > input : > 1)it is an array of n integers depecting number of seats won by the party one in each state > 2)it is … | |
Re: You could use some functions ... maybe something like this to start: from turtle import * from math import * speed(5) def rectangle( x, y, w, h ): up() goto( x, y ) setheading(0) down() for repeat in range( 2 ): fd(w) left(90) fd(h) left(90) def peak( x, y, w, … | |
Re: #include<iostream> #include<conio.h> // don't use to keep code portable #include<string.h> // use <cstring> #include<iomanip> #include<iostream> #include<fstream> #include<Windows.h> // don't use to keep code portable using namespace std; // don't use to avoid 'name clashes as code grows in size // // and use ... .h and .cpp clas files and … | |
Re: If you will show us the code thta you have tried, then we may be able to help. | |
Re: Nice little problem you posted ... there are many ways to code a solution. Some nice and neat way would be best with clear logic flow. Probably using a C++ struct ( or class ) would help quite a bit. Please show us what code you have tried so far. … | |
Re: I would re-think what you are trying to do? This example of a 'class Cube' may give you some ideas re. a simpler design. example of a test main file: // cube_test.cpp // #include "cube.h" int main() { Cube cu( Point(0, 0, 0), 1 ); cu.show(); printf( "Press 'Enter' to … | |
Re: @Hafiz ... welcome to Dani's. Please note: the post you added to was already 4 years old ... so best to start your own new thread. And it's generally a good idea to NOT 'hijack' another persons post ... so please start you own new thread if you want more … | |
Re: Or ... maybe ... something like in this recent example ... is what you are aiming to do ? https://www.daniweb.com/programming/software-development/threads/500762/need-help-starting-this-program#post2189803 You make like to see this modification to the demo ... that also shows the destructors being called. Note the use of new / delete here ... and the use … | |
Re: You may also like to learn how to program using the Python computer programming language :) ![]() | |
Re: This related demo may help you to get started ... // airCraft.cpp // #include <iostream> using namespace std; class AirCraft { public: AirCraft( int e = 1 , int s = 1 ) : engines(e), seats(s) {} int get_engines() const { return engines; } int get_seats() const { return seats; … | |
Re: > Define an int array variable named arx with 3 slots, and stuff a 7 in the last slot > Is this correct? int arx[2]=7; // NO // > or is it: // int arx[3]; // this has 3 slots // or better ... initial all to 0 at creation … | |
Re: Take it in steps ... Firstly just read in the file and display it back ... Get that working before you add any other methods. You may like to look here for some more ideas ... http://developers-heaven.net/forum/index.php/topic,2019.0.html | |
Re: You need to start coding, implementing the steps you were given ... and then to show us the code you tried. Re. the unclear graphic output part ... you will have to clear that up with the source. | |
Re: An other way to approach your problem is to 'huffle the deck' before dealing it out ... Take a look: /* 52Cards.c */ /* You can find file "readline.h" at: http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864 You can find file "Cvec.h" at: http://developers-heaven.net/forum/index.php/topic,2580.0.html */ #include "readLine.h" /* re. myAssert */ #include <time.h> const char kinds[] … | |
Re: > It's pretty hard to say where the problem could be > without seeing ***the code IN QUESTION.*** | |
Re: One way to handle your problem of comparing decimal values to see if they are equal could be ... If your largest number to handle is (about) 99999.9999 ... then if you multiply all decimals by 10000 ... add 0.5 to round up then truncate to an int then note … | |
Re: Why don't you start fresh and code a little name, phone_number and email type data base? You could use a C++ vector container to hold all the data records (objects) You might start out with something like this: class Person { public: Person( const string& name="", const string& phone="", const … | |
Re: ... have things ever got so slack around Dani's place ... in the last several weeks ? So many ... *dead threads* ... now ... being resuscitated? | |
Re: @Ashik_2 ... did you NOT read the previous post before yours? THIS *was/is* a *dead thread.* | |
Re: Oops ... see following ... duplicate accidently posted here. | |
Re: A first approach might be to use a struct to order all the cards in the deck struct Card { int value; char suit; int place; // 0..51 // } ; Then could use the 'place value' to compare cards ... | |
Re: Hey there @ Rodrigo_2 ... Did you know that it is *not* good manners, in help forums like this, to "hijack" some other persons "thread" ? If you really hope to get help, then please start a new thread with your particular question. Note: you MUST also show the code … | |
Re: The code ? maybe ? something like this: template< class T > void tqkeInAndInsertItem( TreeClass< T >& tree ) { cout << "Enter item: "; T tmp; cin >> tmp; // MUST HAVE defined >> for type T // tree.insert( tmp ); cout << "Item inserted:" << tmp; // MUST … | |
Re: I would firstly take in a validated binary string ... then convert that. | |
Re: I think the project is not well worded ... and also, it seems to me to be poorly thought out, since creating an 'hole' for a new value ... at the front of an enlarged array ... this is usually handled by an 'insert' function or ... in a linked-list … |
The End.