456 Posted Topics
Re: > 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 … | |
Re: 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.) | |
Re: 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 … | |
Re: Your friend will need to have a compatible OS for your executable file to run on that OS. | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 > | |
Re: 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 … | |
Re: > 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. | |
Re: 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 … | |
Re: 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 ... … | |
Re: 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 ? | |
Re: 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 … | |
Re: 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; … | |
Re: 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() … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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. … | |
Re: 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 … | |
Re: 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, … | |
Re: 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 … | |
Re: If you sort the array of strings ... you can then traverse the sorted array and skip over all duplicates | |
Re: 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> // … | |
Re: 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 … | |
Re: 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 >= … | |
Re: 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 … | |
Re: One way (off the top) could be ... struct Bag4 { bool filled; string items[4]; Bag4() : filled(false) {} } ; // etc ... | |
Re: 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? */ } | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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. … | |
Re: 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, … | |
Re: 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 ="", … | |
Re: 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 … | |
Re: 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"; … | |
Re: 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 … | |
Re: 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( … | |
Re: 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 … | |
Re: Hint ... Try finding prime factors of each number, then, gather up (multiply) all the common primes. | |
Re: 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 … | |
Re: 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 … | |
Re: 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?) … |
The End.