456 Posted Topics

Member Avatar for Raaavennn

> Hi please help me, im trying to make a program that only accepts numbers ... The presumption is that you are taking in a string then validating that string to ensure it only contains characters in the range '0'..'9' You could use a function like this: bool isNonNegInt( const …

Member Avatar for David W
0
225
Member Avatar for Yahia Farghaly

You are right ... it is NOT correct code to return a ref to that temporary value. You need to have your compiler warnings turned ON. (You seemed to have all turned off.)

Member Avatar for Moschops
0
451
Member Avatar for Yahia Farghaly

Not sure what you are trying to do in your class 'test' ... Is it supposed to be a class for arrays of integers with a pre-fixed maximun size? If that is what you are trying to code, this example may give you some ideas ? // test_classMyArray.cpp // #include …

Member Avatar for David W
0
174
Member Avatar for Kris_3

Your friend will need to have a compatible OS for your executable file to run on that OS.

Member Avatar for Kris_3
0
128
Member Avatar for new_developer

How many different codes can 8 bits hold? ...........................16 .........? ...........................32 .........? ... What you want each unique bit pattern to mean, is up to you. Do you know what 2's compilement means? (If not, Google it.) So, 8 bits has 256 unique code that could represent the numbers 0..255 …

Member Avatar for Slavi
0
263
Member Avatar for Muhammad Shahg

Why don't you Google 'example uses of static variables in C++ or C' ... or something like that ... you will learn, by the 'where' and 'why for' of usage ... much. ... glad to clarify, but if you are serious about learning to program, learning to use Google, or …

Member Avatar for melissad
0
294
Member Avatar for Jjajangmyeon

So ... as @NathanOliver and @L7Sqr and other of Dani's friends have suggested ... you could use this, to provide only what you need to permit the program to recognise the items from the std namespace ... and so then to compile ok. > string and stringstream need to be …

Member Avatar for David W
0
237
Member Avatar for nhrnjic6

Firstly ... take a look at this in your 'main' function: Stack outer_stack; Stack inner_stack; // probably want this here ??? for( int i = 0; i < 100000; ++i ) { //Stack inner_stack; // really ??? inner_stack.push(some_data); //WHAT is 'some_data' ... is it 'i' ? or some value depending …

Member Avatar for tinstaafl
0
152
Member Avatar for fmchua

A nice (general) way to handle questions like this might be to use a (data) struct (record) ... /* def'n of struct ... */ typedef struct { char code; /* 'A', 'B' or 'C' */ char* info; /* a dynamic C string to hold text */ int dollars; } Item …

Member Avatar for David W
0
103
Member Avatar for furalise

No ... vector< vector< vector< int > > > myvector; Note ... you also could grow new objects ...'step-wise' as ... could code a class Matrix using a vector of vectors then could code a class Cube using a vector < Matrix >

Member Avatar for furalise
0
184
Member Avatar for senait.kifle.127

Sometimes looking at some similar problem code examples can give you ideas how to get started ... Suppose you had a Money struct ... typedef struct { unsigned dollars; unsigned cents; } Money ; And you wanted to code a function to take in data from a keyboard user to …

Member Avatar for David W
0
278
Member Avatar for Pazuzu156

> Here is the error message I get: "Error: Unable to access jarfile myJar.jar" So ... try moving the file "myJar.jar" to where it is in the path expected.

Member Avatar for Pazuzu156
0
191
Member Avatar for Rock426

Can you code a shell 'hello world' program that compiles and gives the expected output? Well, if you can do that ... then think how you might print out all those *** char's Hint: Maybe use a loop that prints a line of *** with the number of *** that …

Member Avatar for David W
0
93
Member Avatar for tena.venmathy

A simple method to get you started is always to carefully read the question over and compare that to 'the example output' ... (Your question and example output are really very well given to you ... and you could start out with a small working shell first step program ... …

Member Avatar for David W
-1
240
Member Avatar for Mahkoe
Member Avatar for _echelon

Can you show your code where you think the problem arises? And also explain, what you think that code is supposed to do. It may simply be that you have a path and or fileName not set properly ?

Member Avatar for David W
0
191
Member Avatar for TommyTee

Probably was searching the web and found this page ? So @nonc... Welcome to Dani's place and her C++ help forum. You may not know how to start a new thread? Click on the BOX at the top, or bottom, that says: Start New Discussion And then enter a short …

Member Avatar for David W
0
2K
Member Avatar for nathan.pavlovsky

Just a quick scan and I noticed this: (What is wrong here? Hint what is the tail node value after adding first node to list? What should it be?) //insert node at front of List void insertAtFront(const NODETYPE& value) { ListNode<NODETYPE> *newPtr=getNewNode(value); //new node if (isEmpty()) //List is empty firstPtr=lastPtr=newPtr; …

Member Avatar for nathan.pavlovsky
0
418
Member Avatar for Needhelp2

If your large data file has data that appears as consistently as your example would suggest, then you might use this simple approach: # processlargeFile.py # FNAME = 'largeFile.txt' try: with open( FNAME ) as f: count = 0 data = [] # get an empty list line = f.readline() …

Member Avatar for Needhelp2
0
3K
Member Avatar for Jjajangmyeon

Best thing here ... really ... is to use the STL vector container :) For example ... vector< int > fillVecFromFile( const string& FNAME ) { vector< int > v; v.reserve( 100 ); // or whatever best quess of file size ifstream fin( FNAME.c_str() ) if( fin ) { int …

Member Avatar for David W
0
195
Member Avatar for EarhawkPH

Also, it is 'int main()' and do not use 'getch()' if you want your code to be portable. Please remember that you are asking experienced C programmers for their valuable time and some free advice ... so probably it is your best interests, to present your problematic code as simply …

Member Avatar for David W
0
394
Member Avatar for nathan.pavlovsky

Ok ... you have multiple potential problems. It is often best to solve them one at a time. A 1st problem is your driver test program. So here, I just use the STL list to show a ... 'proof of concept' ... working test program. Once you have all the …

Member Avatar for nathan.pavlovsky
0
4K
Member Avatar for Azhagu

This may be a little simpler C code ... to get you started? -> NO dynamic memory used (stack size pre-fixed at compile time) -> also uses a 'table look-up' method -> note the simple struct used /* stack_stuff2.c */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> /* re. …

Member Avatar for David W
0
173
Member Avatar for sohaib.danish.31

You may like to file your data using commas to delimit the data record fields. That way you can easily handle missing fields: MovieName1,Genre1,HeroOfMovie1,HeroineOfMovie1 MovieName2,Genre2,,HeroineOfMovie2 MovieName3,Genre3,HeroOfMovie3, And display as: MovieName1::::Genre1::::HeroOfMovie1::::HeroineOfMovie1 MovieName2::::Genre2::::NA_HERO::::HeroineOfMovie2 MovieName3::::Genre3::::HeroOfMovie3::::NA_HEROINE This example of sorting data records and finding data records using the C++ library functions may help you …

Member Avatar for David W
0
514
Member Avatar for supermastereu

You can read the returned value when using scanf or fscanf, to see if an appropriate value was 'scanned in': http://developers-heaven.net/forum/index.php/topic,2022.0.html int getValidInt( const char prompt[] ) { for( ; ; ) /* an example of a C/C++ forever loop ... until 'return' */ { int numGood, testInt; fputs( prompt, …

Member Avatar for Learner010
0
363
Member Avatar for abaddon2031

This may give you some ideas to get you started ... # fileTypes.py # myFiles = [ 'news.txt', 'data.dat', 'programcpp.cpp', 'programc.c' ] myTypes = [ '.txt', '.dat', '.cpp', '.c' ] for name in myFiles: found = False for typ in myTypes: if typ in name: found = True; break; if …

Member Avatar for snippsat
0
268
Member Avatar for messr135

If you sort the array of strings ... you can then traverse the sorted array and skip over all duplicates

Member Avatar for David W
0
414
Member Avatar for Jjajangmyeon

This demo of a menu -> choice pattern is simple and easily adapted to many student type menu -> choice problems. Note how it *simply avoids* the very common ... beginning student problem of 'dangling char's left in the cin stream' : // showMenuTakeInChoice.cpp // #include <iostream> #include <string> // …

Member Avatar for Jjajangmyeon
0
116
Member Avatar for yuimikazuki

Further to comment by @vegaseat ... you can print out ... print( type( in_file ) ) # debugging Python object types # print( type( indata ) ) You may like to see this Python 3 revision ... (that uses Python exceptions to handle the 'abort' option) # copyFileToFile.py # from …

Member Avatar for David W
0
224
Member Avatar for kxjakkk

You might try something like this ... # compareTimes.py # class MyTime: # 24 hour clock # def __init__(self, hrs=0, mins=0, secs=0): self.hours = hrs self.minutes = mins self.seconds = secs # normalize ... # if self.seconds >= 60: self.minutes += self.seconds//60 self.seconds = self.seconds % 60 if self.minutes >= …

Member Avatar for David W
0
452
Member Avatar for jalferez1

You seem to be coding in C here in the C++ coding forum. This may be better handled in the C coding area? Not good to use conio.h stuff Shun the dangerous use of gets in C (I use my own readLine to handle the dynamic allocation of C strings …

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

One way (off the top) could be ... struct Bag4 { bool filled; string items[4]; Bag4() : filled(false) {} } ; // etc ...

Member Avatar for David W
0
212
Member Avatar for rzzque

What is wrong with this code? char* processIt( /* */ ) { char local_buf[90]; /* get some stuff into local_buf */ return loacal_buf; /* Hint! Is this line ok? */ }

Member Avatar for David W
0
308
Member Avatar for Sarkurd

re. the other part of your question ... the use of typedef can either be helpful to your code flow or hinder (hide from) your understanding what the code is doing For an example of common use: One can easily make iterators to arrays using typedef For an example of …

Member Avatar for Sarkurd
0
762
Member Avatar for yaldoo

This example may be closer to what would be expected of just a 'beginning student: 1 -> NO STL used 2 -> Simple bubble sort used 3 -> Only tricky part ... counting / outputing ALL repeats // scores_counts.cpp // /* Write a program that reads in a set of …

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

Not sure what you are trying to do ? > function counts the number of digits, small letters, capital letters and symbols in the char array, and returns the counts Are you to read a text file into an array of words? Or ... to read the whole file into …

Member Avatar for David W
0
317
Member Avatar for king.umair523

You could say that a pointer variable holds addresses ... adresses for any kind of 'object' ... including the address of an other pointer variable ... and in that case, you then have a 'pointer to a pointer'. One very common use of pointers is when you allocate dynamic memory …

Member Avatar for tenzinlol
0
142
Member Avatar for supermastereu

Also note: if number is divisible by 10 ... it is ALSO divisable by 5 and 2 ... and it will end with (at least) one 0 if number is divisible by 5, it ends in 5 or 0 if it ends in 0, it is also divisible by 2 …

Member Avatar for rana ranjit
0
146
Member Avatar for supermastereu

Some next steps: 1. validate and 'crash proof' input 2. loop for more input until no more input desired 3. break up program into jobs using functions This little demo revision of your code my give you some more ideas ... /* cylinderAreaVol.c */ #include <stdio.h> #include <ctype.h> /* re. …

Member Avatar for rana ranjit
0
323
Member Avatar for newbiewwcode

Or ... a very simple way to start could be like this ... (that lets readily you use all the STL vector member functions) // schools.cpp // #include <iostream> #include <string> #include <vector> using namespace std; struct Student { string lname, fname; } ; ostream& operator << ( ostream& os, …

Member Avatar for tinstaafl
0
698
Member Avatar for nathan.pavlovsky

I think you can really clean up your code still and simplify it lots ... Take a look at this and see the added comments ... file: HardwareRecord.h // file: HardwareRecord.h // #ifndef HARDWARE_RECORD_H #define HARDWARE_RECORD_H #include <iostream> class HardwareRecord { public: //constructor HardwareRecord( int account =0, std::string name ="", …

Member Avatar for nathan.pavlovsky
0
20K
Member Avatar for Saboor880

Your code above will NOT compile error free. See the '1st round' of corrections suggested ... (see changes and added comments) //#include<iostream.h> #include <iostream> // need to add using namespace std; class id { private: //char *name; // declaration of private data members of class char name[80]; // need to …

Member Avatar for David W
0
229
Member Avatar for yaldoo

Your desired main function (with the merge file function) could look something like this: int main() { ifstream fin1("input1.txt"); ifstream fin2("input2.txt"); ofstream fout("output.txt"); if( fin1 && fin2 && fout ) { mergeFiles( fin1, fin2, fout ); fout.close(); fin2.close(); fin1.close(); } else cout << "There was some problem opening files ...\n"; …

Member Avatar for yaldoo
0
6K
Member Avatar for gu mi nam

What is this: using namespace std; struct karmand{ char nam[10]; char shomare[10]; char sx[10]; char mm[10]; char rgh[10]; }list[s]; /* s = ??? */ Don't you mean to code: struct Contact { // your contact info gets saved here } ; const int MAX_SIZE = 100; Contact MyContacts[MAX_SIZE]; Your code …

Member Avatar for David W
0
297
Member Avatar for ravi_14

You may also like to see this: http://www.parashift.com/c++-faq/inline-functions.html Here is an example that you can see where 'inline' might be appropriately placed and used ... file: nvector.h // file: nvector.h // #ifndef NVECTOR_H #define NVECTOR_H #include <iostream> #include <vector> class Nvector { private: std::vector < double > vec; public: Nvector( …

Member Avatar for David W
0
209
Member Avatar for sys73r

It appears * that you have an even number count in your lists of grades ... and * you want the output to be formatted as a list of list pairs ... but with the name as the fist element in the outer list. So ... # nameGradePairsList.py # grades …

Member Avatar for David W
0
417
Member Avatar for BogdanCov

Hint ... Try finding prime factors of each number, then, gather up (multiply) all the common primes.

Member Avatar for tapananand
0
233
Member Avatar for Jolie Tia

You may like to see this demo (modify to suit your needs): import os def search_linetest(): path = 'C:/Users/dwzavitz/Desktop/2014Files/DaniPython' #'/Users/jolie_tia/Documents' dir = os.listdir(path) for file in dir: print( file ) if '.exe' in file: pass else: #open('/Users/jolie_tia/Documents/sample.txt') f = open( file ) s = f.read() #x= s.find('I was scared to …

Member Avatar for Jolie Tia
0
389
Member Avatar for hema.adel3

Does your program compile? Are there errors? Can you isolate (provide a small sample of code to illustrate where the error seems to be?) (And when you copy/paste your code, to preserve the indentation, 'select' all the code, then press 'tab' before you submit it ... thus, the indents will …

Member Avatar for David W
0
4K
Member Avatar for whitebloodcell

This, (to me), seems to be a much simpler 'first go' ... and a possibly more efficent re-design .... (that yields sets of Playoff Players all ready initialed in a random simulation) ... and thus it may be of interest to you, (and easier for you to understand and re-work?) …

Member Avatar for David W
0
278

The End.