456 Posted Topics
Re: You may like to see this link re. a way to handle new data types in C ... http://developers-heaven.net/forum/index.php/topic,2598.0.html | |
Re: You could try something like this: // split_demo.cpp // /* i need to parse the input into two categories: user age and user name. for example, the user input -->> [23:Frank] [15:Jack] [45:] [33:sofia] [] in this case i have more than one argument (delimiter, total of 3 ) which … | |
Re: Your problem can be more easily handled if it's broken up into two BIG steps... 1st step: Using the C++ library linked list, you can code and test out the code for the data processing... 2nd step: You could then code/test a linked list ... and sub in that linked … | |
Re: If you can handle more ... and if your spec's are to compile with a C++ compiler, (but to restrict the 'io' to C style), then ... this example ... may give you some more ideas to get you started with a working shell. // entreEtudiant.cpp // /* The presumption … | |
Re: Note: There are many way to design a solution ... Here is just one simple way ... and a shell program that should get you started: // cal_shell.cpp // #include <iostream> using namespace std; // your functions go here ...?? double add( double a, double b ) { return a … | |
Re: This may give you some more ideas ... and some more tools (C utility functions) to use in your code: (You could use a 'Clist' by including file Clist.h available at ... http://developers-heaven.net/forum/index.php/topic,2582.0.html if your prefer) /* 52Cards.c */ #include "readLine.h" /* re. myAssert */ #include <time.h> const char kinds[] … | |
Re: It is possible to create some 'tools' (functions) in C that emulate things available in C++ and Python ... Isn't Python coded in C? You might like to try out some things in this mini library of C utilities ... ... function that are in the following files: readLine.h readWord.h … | |
Re: If you mean that you want the program to prompt for a variable name, you would also want to prompt for the variable type. You could use a C++ map to hold the (unique) name and a pointer to the (new) memory (allocated) to hold that type (and type name). | |
Re: You will find that help comes more readily if you present the problem clearly. Provide the shortest amount of code possible to illustrate the problem. State clearly the problem ... i.e. do NOT just say: 'there is a problem' / 'something is not working' ! | |
Re: Your data-record structure is NOT what you need here ... Try something like this: // bloodGroups.cpp // #include <iostream> #include <string> #include <cstring> // re. strcpy #include <cstdio> // re. FILE const char* FNAME = "users.bin"; const int MAX_NAME_LEN = 39; const int MAX_ADD_LEN = 99; const int MAX_BG_LEN = … | |
Re: Can you write a 'prototype' for the function? (That could get you started?) | |
Re: This example also ensures the prgram will NOT crash if bad data was entered: // drawShape.cpp // #include <iostream> /* **when compiling it gave me the right shape and there is another sol whith a diff way but im not getting it and the other sol goes like ... ** … | |
Re: The data file example you provided above ... looks defective? > ... Consider a data file named STORES.DAT, which contains inventory information for four shops. Each line in the file contains the inventory of five types of merchandize in each store ... So ... the file has 4 lines. BUT … | |
Re: @Petcheco, wrt your suggestion ... please note added comments below: cout << "Enter your string:"; getline(cin, myString); // this will read the whole line cout<<"Enter your name: "; getline(cin, myName); // this will read the whole line // cin.sync(); // SO this is *NOT needed* here // /* cout<<"Age: "; … | |
Re: > We are not allowed to use strlen function. . :/ So ... can you code your own (safe) version of a 'strlen' function? size_t mySafeStrLen( const char* strIn ) { size_t len = 0; if( strIn ) { const char* p = strIn; // rest of your code goes … | |
Re: It would help if you would completely re - design your code ... You are best to use the standard C++ containers ... like vector, list, stack, etc ... rather than messing around with your 'nodes', etc... Also, build your code in steps, fixing each step as you go, and … | |
Re: @Syed Ammar please read the previous posts in this thread, especially the patient explanations by ... @Schol-R-LEA & @deceptikon | |
Re: This new little library of C functions, that eases the reading and parsing of a line of text in C (or 'words' of text) may make your problem mush easier to handle ... http://developers-heaven.net/forum/index.php/topic,2582.msg3142.html#msg3142 It permits using C dynamic strings, almost as easily, as one can use C++ strings with … | |
Re: I found this a short time ago and thought it looked interesting enough to test it out... (I only tested it on a MS Windows OS.) /* cpu_times.h */ /* found at: http://stackoverflow.com/questions/17432502/how-can-i-measure-cpu-time-and-wall-clock-time-on-both-linux-windows */ #ifndef FoundOnWeb_CPU_TIMES_H #define FoundOnWeb_CPU_TIMES_H /* Windows */ #ifdef _WIN32 #include <Windows.h> double get_wall_time() { LARGE_INTEGER time, … | |
Re: I think you are forgetting you are coding in C++ ? You may wish to try something like this ... // addNodesIthPosition.cpp // // 2015-05-11 // #include <iostream> typedef int MyType; struct Node { MyType data; Node* next; // default ctor... Node() : data(MyType()), next(0) {} // ctor's Node( const … | |
Re: I suspect that you are over complicating things ? Take a look at this simplification: // outPutToBeFixed.cpp // #include <iostream> #include <iomanip> #include <vector> #include <string> const char* MENU = "Welcome to the DVD Collection Program! \n" "What do you want to do?\n\n" "1. Add DVD\n" "2. Remove DVD\n" "3. … | |
Re: This may give you a start? const string s = "abcd"; const string n = "1234"; for( size_t i = 0; i < s.size(); ++ i ) { cout << s[i] << n[i]; } | |
Re: It is often a good idea to start with a simple (simpler) version ... Get that working and then upgrade from there. This simpler version may get you started and give you some file read / write ideas to facilitate your progress in your coding problem ... // dataWriteRead.cpp // … | |
Re: @tinstaafl, I aways appreciate your insights, and was wondering about the syntax of using ... 'auto' in C++ 11 with the 'map' container ... (and in the context of the OP, I was pleasently surprised to see that C++ 11 'knows' the size of arrays.) This is the syntax that … | |
Re: I almost never (code in a) return 0; at the end of main ... *IN a C++ program* Wheres as, *IN C* ... one *ALWAYS* needs to return an int value in main, and to code that in explicitly, if the compiler conforms to any standard from C89/C90 forward ... … | |
Re: Do you know what a struct (a data record) is ? Do you know how to use arrays? One nice way to handle this might be to create a const array of pairs of (product, price) ... Maybe something like this: #include <string> // ... struct Item { string name; … | |
Re: @basitji, If you wish help on your C++ programming problem, you need to firstly show us the code that you have tried so far ... and any compiler errors. | |
Re: You may also like to see this: (that attempts to salvage your 'get_word' function ... and then to add some extras) /* get_word.c */ #define MAX_LEN_STR "255" #define MAX_LEN 255 #define NUM_WORDS 3 #include <stdio.h> #include <string.h> #include <stdlib.h> #ifndef dwMYASSERT #define dwMYASSERT void myAssert( int condition, const char* msg … | |
Re: Firstly ... please note that it is a bad idea to use #include <conio.h> // and later ... // getch(); if you wish to have portable code that conforms to standard C++ Maybe, by "hard-coding" you were thinking of this ? Consider: struct Student { int id; string name; }; … | |
Re: @ShiftLeft, I think the OP stated ... > average; // ... display in decimal thus there is a problem with what you suggested, and also ... int Grades [4], Average, Total; // you meant to have Total = 0; // here // for (int count=0; count < 4; count++) { … | |
Re: Can you write a 'shell' program that compiles and runs ok ... producing the exact output expected? What might you put in a start-up working 'shell'? #include <iostream> const int MAX_SIZE_HERE = 10; // keep small at start to keep testing easy // int main() { // print some opening … | |
Re: You might like to see this for beginners in Python ... http://developers-heaven.net/forum/index.php/topic,46.msg89.html#msg89 You will find that Python code is also very compact ... A good (and it is also free online) tutorial/text is called 'Think Python' http://en.wikibooks.org/wiki/Think_Python | |
Re: //Hint: //Do you know what modular arithmetic (here, division) means? //If you have these next two integers stored in 'a' and 'b': int a = 23; int b = 10; // Do you know what values the following x, y would hold? int x = a / b ; int … | |
Re: You may fine this little edit/clean_up of your code ... a useful example for your future coding problems ... Note: little typos in your code will cause your code to NOT compile. For example: >for (moneky = 0, monkey ... What is the typo above? // monkey_food.cpp // #include <iostream> … | |
Re: You could try something like this ... to get you started: // binFile_structStudent.cpp // // This example allows ONLY UNIQUE student ID's // #include <iostream> #include <fstream> #include <cstring> // re. strcpy #include <climits> // re. INT_MAX, INT_MIN using namespace std; // NOTE! file gets created first time program is … | |
Re: Further to the above Posting Pro @ Schol-R-LEA comments ... and since ... the meaning to be helpful @ Aditya_13 ... posted his first code here ... please also note these comments that are also meant to be helpful to, now especially, @ Aditya_13 ... Please take a look at … | |
Re: Ah ha ... @ArpitJ.25 you have arrived at a wonderful spot to hang out to see all the code examples sailing past you ... Now ... if you try out the easy examples ... see if you can make some changes and fixes ... Note all the compiler error messages … | |
Re: Can you show us the code you have so far? in a loop : step 1 input a number after a prompt was printed step 2 check if number was in valid range 1..100 if not after printing error message continue back from loop top step 3 get computer to … | |
Re: You have NOT supplied enough info about your problem. Using some functions would help to see each of the problem steps. Also ... using some global constants could help here ... maybe for something like the following: if total_kms >= STEP3_RATE_KMS use_rate = STEP3_RATE; else if total_kms >= STEP2_RATE_KMS use_rate … | |
Re: This thread should help some ... to get started ... https://www.daniweb.com/software-development/cpp/threads/494420/finding-total-occurrences-of-any-word-in-strings | |
Re: Maybe you are thinking of a hash table... a kind that also uses lists ??? http://en.wikipedia.org/wiki/Hash_table#Separate_chaining_with_other_structures >Chained hash tables with linked lists are popular because they require only basic data structures with simple algorithms, and can use simple hash functions that are unsuitable for other methods. | |
Re: Can you show us what code you have tried so far ... so that we can see where you need help? Can you write out the steps you might do on paper? 1st step ... enter amount of water used in each month (in a loop so can do calculation … | |
Re: See if you can make the changes suggested above ... then try it out and re-submit the new version for help ... if you need more help? I would suggest also some more descriptive variable names ... names that help you see what is happening as the program flows ... … | |
Re: You could use something like this: struct WeekData { int weekNum; int values[7][2]; // ctor... WeekData( int weekNum, int new_values[7][2] ) : weekNum( weekNum ) { for( int i = 0; i < 7; ++ i ) { values[i][0] = new_values[i][0]; values[i][1] = new_values[i][1]; } } double get_avg() const { … | |
Re: What have you tried? It would help if you would show us an example of the (file) data (structure) that you seem to need to read and process, | |
Re: Please post the code you have tried already, the part that is causing you a problem ... and a copy paste of the compiler error message, if any. Also, the specs for the program, (or a brief description of what the program is supposed to do), so we can easily … | |
Re: If one apple costs 65 cents, how much will n apples cost? Do you know how to multiply n*65 for all (positive integer) values of n? | |
Re: You could use a 'Table Look Up' method ... > I need help to display on the screen rock when user picks rock, paper when user picks paper, and scissors when user picks scissors. Thanks // define table ... const char* CHOICES[] = { "ROCK", "PAPER", "SCISSORS" }; // function … | |
Re: I have found Orwell Dev-C++ to work well for C++11 and before ... it is easy for students to use ... can easily compile a single (student type problem) file (withOUT needing to make a project) ... and run to see the output ... without having to add code to … | |
Re: You need to clarify your original problem ... 1. Are you wanting, to instead, sort the array in descending order? Or... 2. having sorted the array in ascending order, do you THEN want to move the element at index 0, to the memory location at index size-1, having moved all … |
The End.