456 Posted Topics

Member Avatar for glao

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 …

Member Avatar for glao
0
240
Member Avatar for negru

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 …

Member Avatar for David W
0
189
Member Avatar for negru

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 …

Member Avatar for David W
0
247
Member Avatar for negru

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 …

Member Avatar for David W
0
268
Member Avatar for wh196785615

You might also like to see the info/examples here: http://www.cplusplus.com/doc/tutorial/polymorphism/

Member Avatar for David W
0
182
Member Avatar for waseem1345

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> …

Member Avatar for David W
0
8K
Member Avatar for waseem1345

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; ++ …

Member Avatar for David W
0
385
Member Avatar for Rimaa21

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 …

Member Avatar for David W
0
172
Member Avatar for sanraj_1

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 …

Member Avatar for David W
0
203
Member Avatar for rose_2

Try looking here to see some working examples ... http://en.cppreference.com/w/cpp/utility/bitset

Member Avatar for David W
0
139
Member Avatar for progteacher2
Member Avatar for hudahamid

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.

Member Avatar for David W
0
229
Member Avatar for preslav_milev

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 …

Member Avatar for David W
0
364
Member Avatar for Callie C.

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, * …

Member Avatar for David W
0
375
Member Avatar for KittyKat15

What code have you tried do far? (You have not yet given us any real clue about where you are stuck.)

Member Avatar for David W
0
73
Member Avatar for rose_2

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 …

Member Avatar for rose_2
0
177
Member Avatar for napo15

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 …

Member Avatar for David W
0
379
Member Avatar for campuzcrazyness

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 …

Member Avatar for David W
0
225
Member Avatar for Emily_2

Why are you using C strings in a C++ program ? (Way better to use C++ string, most of the time.)

Member Avatar for David W
0
367
Member Avatar for Joe_14

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

Member Avatar for David W
0
116
Member Avatar for surfingturtle

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 …

Member Avatar for David W
0
272
Member Avatar for Ivan_9
Member Avatar for TObannion

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.

Member Avatar for David W
0
304
Member Avatar for Nivetha.R

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 …

Member Avatar for David W
0
150
Member Avatar for Sukka_1

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, …

Member Avatar for David W
0
539
Member Avatar for Hamza_9

#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 …

Member Avatar for overwraith
0
344
Member Avatar for Max_14

If you will show us the code thta you have tried, then we may be able to help.

Member Avatar for jnneson
0
166
Member Avatar for diane110

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. …

Member Avatar for David W
0
306
Member Avatar for sirlink99

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 …

Member Avatar for David W
0
474
Member Avatar for norEdz

@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 …

Member Avatar for David W
0
11K
Member Avatar for me vicky

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 …

Member Avatar for David W
0
365
Member Avatar for kavinsac
Member Avatar for diafol
0
574
Member Avatar for DS9596

> How does an array variable indexing expression differ from an array definition size expression? Recall arrays in C/C++ are 0 based ... i.e. if 'n' slots ... first index i is at i = 0 nth index i is at i = n-1

Member Avatar for rubberman
0
141
Member Avatar for jxxop1

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; …

Member Avatar for David W
0
527
Member Avatar for DS9596

> 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 …

Member Avatar for David W
0
229
Member Avatar for DS9596

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

Member Avatar for David W
0
636
Member Avatar for joe97

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.

Member Avatar for joe97
0
1K
Member Avatar for Leonard_3

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[] …

Member Avatar for tinstaafl
0
3K
Member Avatar for tgreiner

> It's pretty hard to say where the problem could be > without seeing ***the code IN QUESTION.***

Member Avatar for David W
0
233
Member Avatar for new_developer

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 …

Member Avatar for rubberman
0
12K
Member Avatar for Hamza_9

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 …

Member Avatar for David W
0
248
Member Avatar for jdpjtp910

... have things ever got so slack around Dani's place ... in the last several weeks ? So many ... *dead threads* ... now ... being resuscitated?

Member Avatar for David W
0
2K
Member Avatar for mags11

@Ashik_2 ... did you NOT read the previous post before yours? THIS *was/is* a *dead thread.*

Member Avatar for David W
0
16K
Member Avatar for Zerk
Member Avatar for David W
0
265
Member Avatar for redtribal23

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 ...

Member Avatar for David W
0
550
Member Avatar for DS9596
Re: C++

You seem *lost* with repect to coding for a class (or a struct?) in C++ You best start simple ... Here is a simple example of using a C++ struct with a constructor ... Note: in C++ the contents of a struct have default state of 'public' in C++ the …

Member Avatar for David W
0
460
Member Avatar for rizrash

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 …

Member Avatar for David W
0
675
Member Avatar for LibraryCode

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 …

Member Avatar for deceptikon
0
347
Member Avatar for Queen_1
Member Avatar for David W
0
245
Member Avatar for stef02

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 …

Member Avatar for David W
0
326

The End.