164 Posted Topics
Re: I read your first lesson. It was....interesting. Here are a few highlights [quote] You can name your variable anything (as long as it doesn't correspond with any keywords used in the C++ language; no spaces are allowed). You put a semicolon at the end of the line. [/quote] So, i … | |
Re: You really should describe what your problems are in greater depth. Usually I would just make that comment and quit, but I'm waiting to see if my [URL="http://www.daniweb.com/forums/thread260869.html"]question[/URL] gets answered soon, so I'll help [code] class Truck: public Vehicle { [COLOR="Red"]bool DieselTypeStatus; [/COLOR] Truck(); [COLOR="Red"][B]void Truck(bool); [/B][/COLOR] ~Truck(); void DieselTypeStatus(bool); … | |
Re: My preliminary solution works, though there's one logical step that I'm whittling down. Did you want us to post our solution here, or leave the question unanswered for others? | |
Re: You, sir, are a perennial fail-monkey. I looked over some of your other posts, and it appears you aspire to meddle, if not maliciously, then carelessly with windows processes. [url]http://www.daniweb.com/forums/post1096793.html#post1096793[/url] [url]http://www.daniweb.com/forums/thread251123.html[/url] [url]http://www.daniweb.com/forums/thread251121.html[/url] At any rate, you certainly aren't contributing anything worthwhile to the community... | |
Re: [QUOTE=mikabark;1130022]I hope to copy from container to another container. But it is not easy. gdb said I'm trying to copy const string to string. --------------------------------------------------------------------------------- 0x00007ffff7b760f3 in std::string::assign(std::string const&) () from /usr/lib/libstdc++.so.6 --------------------------------------------------------------------------------- I don't know how to copy from container to container one by one. WiIl you help me? … | |
Re: > :) My mind went blank for a bit and I couldn't figure out such a simple programme. But then I had a shower and all was well :) int factorial(int i){ int fact = 1; for(int j = 1; j < i + 1; j++) { fact *= j; … | |
Re: With the age of parallel computing dawning and the age of Moore's Law closing, it might behoove you to read up on parallelism. In particular, OpenMP is a nice approach to introducing parallelism into C++ without a lot of overhead ( if you're careful ). Using constructs like: [code] #pragma … | |
Re: [QUOTE=soapyillusion;1118788]Ok nevermind i thought i had this going right and im getting a funny number as an answer to the standard deviation. heres the code got so far [CODE] double findStdDev(double x1, double x2, double x3, double x4, double x5,double x) { double sDev; sDev=sqrt((x1-pow(x,2))+(x2-pow(x,2))+(x3-pow(x,2))+(x4-pow(x,2))+(x5-pow(x,2))/5); return sDev; } [/CODE][/QUOTE] in … | |
Re: This is an excellent object lesson! Overrunning an array will not always result in a segmentation fault. So, you can often read data beyond the end of your array without error. If you are not careful, you may end up processing this junk data, and then you will spend a … | |
Re: [QUOTE=Anarionist;1129424] [CODE] s[0]=="badword1"; s[1]=="badword2"; s[2]=="badword3"; s[3]=="badword4"; [/CODE][/QUOTE] These four lines will do absolutely nothing. You need to be careful to differentiate between the assignment and equivalent operators. | |
Re: You can use a stringstream to convert the string first to an integer, then use a stringstream with the hex keyword to convert the integer back to a string Lookup [URL="http://www.cplusplus.com/reference/iostream/istringstream/"]stringstream[/URL] and the [URL="http://www.cplusplus.com/reference/iostream/manipulators/hex/"]hex[/URL] keyword first. Should be easy after you read up. | |
Re: [QUOTE=invisi;1129021]Well I wrote this programme, hoping what I wrote is a lenear sorting algorithm if it's not pls tell me :-O [CODE] for (int j = 0; j < 10; j++) { for (int i = 0; i < 10; i++) { //some operation... } } }}[/CODE][/QUOTE] It's not. I … | |
Re: The pop() command does not return the value popped, so first you need to put the top element of stack1 onto stack2, then pop it from stack 1 Still, your logic won't work at all, because you are simply moving everything from one stack to the other. You need to … | |
Re: The second line is a constructor. Constructors are allowed to have [URL="http://www.cprogramming.com/tutorial/initialization-lists-c++.html"]initialization lists[/URL]. This simply means that since val is a member of Day, it val be set to d by the initialization call. Initialization lists follow this fomat: [code] Struct Generic{ int a; float b; char c; Generic( int … | |
Re: Look at [URL="http://www.cplusplus.com/reference/iostream/stringstream/"]<stringstream>[/URL] in the stl. You know how you can pass any standard numeric type to cout and it knows how to print it? Well, stringstream knows how to convert any standard numeric type to a string. Furthermore, stringstreams allow iomanip formatting, so you can pad numbers and other … | |
Re: Did you know that asking someone else to do your homework for you is cheating? Did you know that you will learn [B]nothing[/B] by cheating on your homework? Did you know you are flushing your money down the toilet if you cheat on a college class that you are paying … | |
Re: [QUOTE=c++student01;1127304]I am in a c++ class and I am doing a program which requires me to read in a text file and do change it. I need to know if something is in " " or ' ' to do this program. I can get the " " by doing … | |
Re: [QUOTE=Cyberhacker;1127274]Hello my name is roman I have this project to do that involves the following: I need to take a text document full of numbers and output the lowest of those numbers and the highest of those numbers but they first have to be put into an array then outputted... … | |
Re: You need to use virtual functions: [code] Class Base{ int val; .... virtual int doIt(){ return val; } }; Class Derived: public Base{ .... virtual int doIt(){ return val + val; } } [/code] Look up virtual functions and do some reading. Virtual functions are important and a powerful part … | |
Re: [quote][code] [COLOR="Red"]void operator= (monomial & p);[/COLOR] monomial operator* ( monomial &p); monomial operator/ (monomial &p); ... monomial a1("a:b:c"); monomial a2("a:c"); monomial a8; a8=a1/a2 a8.print(); cout<<endl;[/CODE][/quote] The problem, i believe, is that you are trying to pass a non const monomial reference to the assignment operator. This is fine if you … | |
Re: [QUOTE=xcarbonx;1127202]hello, i just had a very simple question about float, so i am not going to post the full coding, only what matters in this instance. my output of program shows the computed number as 4, instead of 4.00, even though it is declared as float Here is the example: … | |
Re: Here's a compileable solution. It will grade a test of any length with any sort of single letters as answers. It should be somewhat fault tolerant, though I'll leave it to you to add in extra protection. Hope this helps: [code] #include <iostream> #include <fstream> #include <string> using namespace std; … | |
Re: [QUOTE=rlindsey;1126824] [code] class HARD_SPHERE_COORDS // Class to contain all system's spheres and operate on them { ... [COLOR="Red"]COORD_STRUCT *COORDINDATES[/COLOR]; // Pointer to array to hold system's coordinates ... } HARD_SPHERE_COORDS::~HARD_SPHERE_COORDS() // Cleanup memory delete [] [COLOR="Red"]COORDINATES[/COLOR]; } [/code][/quote] First check spelling: COORDINDATES COORDINATES | |
Re: One more note on the rotate function: Because the bitshift operators can take negative numers as the rvalue aruments, there is not really a need for two macros. You can simply use a negative index to rotate in the opposite direction: [code] #include <iostream> #include <climits> #define UINT_BITS ( CHAR_BIT … | |
Re: [QUOTE=LostnC;1126994] I have an example of a bubble sort, but I dont' understand how to appy it to my program because of the STRUCTURE. I don't know how to name the items using the dot operator. I would appreciate any assistance given. [/QUOTE] If you don't know how to access … | |
Re: 1. In general, you shouldn't/can't initialize any variables inside of a switch statement. This has caused me problems before as well. Try initializing your fstreams before of the switch statement. 2. The bool [I]isDone[/I] is never initialized. You need to do this outside of the switch also 3. I would … | |
Re: I hate to rain on your parade, but as long as you are using classes from the standard template library (string), you might as well use methods from the library as well: [code] #include <string> #include <algorithm> using namespace std; int main(int argc, char *argv[]){ string alphabet = "abcdefghijklmnopqrstuvwxyz"; random_shuffle( … | |
Re: 1. Post the code (at least some of it) so we can get a better idea of what's going on. 2. Why don't you use an XML library to parse the code. There are hundreds of XML libraries out there. Such libraries can save you a ton of work and … | |
Re: Using the standard fstream libraries should enable you to read from a large file just fine. Here's some example code that compiles and works for parsing a 5.3 GB file I made just for this experiment [code=c++] #include <fstream> using namespace std; int main(int argc, char *argv[]){ ifstream ifile( "op.txt" … | |
Re: For this task, you should really use [B]Regular Expressions[/B]. There aren't any regular expression parsers built into standard c++, so you will need to install a library. [URL="http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/index.html"]Boost[/URL] has a good one that I know of, but there are others. Now, you might be saying, "screw that, regular expressions seem … | |
Re: [QUOTE=firstPerson;1118929]clock() returns the time in mili seconds, [/quote] Not so. This returns the number of clock ticks since the last call to clock(). What this number means varies by hardware and os. [QUOTE=firstPerson;1118929] CLOCKS_PER_SEC is the conversion factor from the value returned by clock() into seconds. [/quote] That is so. … | |
Re: I would actually unify the two base classes. Instead of implementing the Update() as a pure virtual function, make it a callable function that is essentially a no-op: [icode]virtual void Update(){}[/icode]. Then, all classes that need to be updated will implement their own Update() function. Now, all of your objects … | |
Re: [QUOTE=sidra 100;1122965]plz guide me i m having some error at line 28[/QUOTE] 1. [I]Explain your problem more clearly[/I]. Saying "plz guide me" is not very helpful for us, and it's ridiculously presumptuous that we will respond with thorough help when you can't type more than one sentence. 2. [I] Post … | |
Re: Here are a couple of functions I designed to convert between numeric types and strings [code=c++] /** Converts a number to a string * @param number - The number to convert * @param prec - Floating point precision to use * @param w - Width of the string * @return … | |
Re: If those variables are truly defined externally, you should really uncomment line 24 & 25. Declaring an extern variable isn't helpful if the declaration is in a comment. | |
Re: [QUOTE=Jfunch;1122264]Hi i'm writing this program where the user chooses whether to print out a square, a forward triangle, and a backwards triangle using the "*" character. I got the square and the backwards triangle to work and the forward triangle, but i cant figure out how to do the back … | |
Re: [QUOTE=SpyrosMet;1120077]I need to make a program that takes one character as an input and instantly continues execution and the time limit for the user to enter that character is 2 or 3 seconds. please help me and if possible ppost an example. Thanks for your help.[/QUOTE] Please read [URL="http://www.daniweb.com/forums/thread78223.html"]this[/URL]. There … | |
Re: [QUOTE=b.bob;1121295]Hi, I am a newbie to C++ (and programming in general) [/quote] Since you are new, and have a fresh, open mind, I would recommend that you start using the Standard Template Library now. This library is powerful, helpful, and relatively easy to learn, and it works in all [B]c++[/B] … | |
Re: [QUOTE=mmasny;1120083]Would you be so kind and help me solve this problem? It doesn't compile. Compiler says that the line 23 causes problems and I don't know why. It says class OknoWlasciwe has no member called ojciec and how come?? I mean, OknoWlasciwe is a public subclass of NieDesktop, which has … | |
Re: [QUOTE=lparras;1119988]I have a weird problem with destructors. My code works in older machines with g++-2.95, g++-3.3, g++-4.0, g++-4.0.1 and not in my machine with g++-4.4.1. Do you know why? Here I show a small example that reproduces the error (in my machine): [CODE] #include <iostream> class Matrix{ public: Matrix(){}; Matrix(int … | |
Re: [QUOTE=lima01;1119124]Hello, I am making some program, and have some problem, i want to list all files that are on HD, and if I want to list all files in C: with this command with only one backslash after C:( system(dir C:\ /s/b/a-d> C.txt)) it only list files that are in … | |
Re: You have some obvious problems that need correcting: Problem 1: [CODE] template <class T> T min(vector<T> a) { [/code] Don't use the name "min". There is already min and max functions in the standard template library, and you shouldn't override these. Use something like vectorMin(), or vMin() Problem 2: [code] … | |
Re: [QUOTE=weaslem32;1118955]I need help with an assignment. I have to modify the program below to determine the number that was entered the most times in a row and display the output. I can not use files or arrays. I am having trouble with the logic and need some guidance. Thanks. [/quote] … | |
Re: [QUOTE=philipbas;1118641]i don know about class n pointers,can u explain it with essy examples please[/QUOTE] You should learn about google (perhaps you could google it? AAAHHH recursion! ). There are so many simple c++ tutorials and examples [b]THAT ALREADY EXISTS AND ARE 1 GOOGLE SEARCH AWAY[/b]. Please try to solve your … | |
Re: No need for two loops here: Given an array (arr), the starint index (j), the ending index (k) and the number of elements in the array (n): [code=c++] int sum =0; for( int i=j; i<k; i++ ) sum += arr[i]; [/code] You will need to ensure that i >= 0 … | |
Re: You could also use the standard template library containers like vector, deque, list, etc. These are very handy, and vectors almost match arrays for performance. They are much harder to break (though still very possible), and can save you a lot of heart ache. If you want a simple solution, … | |
Re: [QUOTE=khevz09;1116078]this is the code ..but it is not displaying the first and the last number that came from the user. anyone can help me with this small problem?? [/QUOTE] 1. Use an index variable in your loops 2. You don't need to iterate over all of the values, testing each … | |
Re: [QUOTE=terabithia;1116003]Hi, Could someone please let me know how to terminating char pointer array properly? [code] void constructSet (ptr s,int size) { ptr ch; ptr first = s; int i; for (i = 0;i<=size;i++) { ch = new char; *ch =static_cast <char> ((rand()%26) + 65); if (checkSet (*ch , first , … | |
Re: [QUOTE=rusydi_10;1116487]Write a program for multiplication and division of two numbers for different base number. Programme structure: The program should contain 1. Should have an infinite loop which is the program is always running. 2. An option for a user to select base number of the first number. (For example: base … | |
Re: [QUOTE=tylerc101;1116598]Alright, well I figured out this solution while I was continuing working on it. Could someone brief over it and tell me if there's any memory issues? [CODE] double* loadfile (string path){ double garray[96],temparray[192][79],firstaveragearray[96][79]; ... double * address = & garray[0]; return address; else cout << "could not open file"; … |
The End.