1,358 Posted Topics
Re: Is this supposed to be a response to a question on an exam or something? It is only partially correct. If I were the instructor, I would probably take away about half of this question's points. First, this statement is only partially true: [QUOTE]The base stream class for handling input … | |
Re: I would call it neither "bad practice" nor "perfectly normal". It really depends on your situation and whether or not it warrants it. I would call it "acceptable". Ideally, your constructor would be written in such a way as to guarantee creation of a valid object. Additionally all of your … | |
Re: I don't use linux, but just as a general debugging guideline you should always address the first error first. It is likely that the first error is the root/cause of others in the list. If you fix it successfully, it may eliminate most (if not all) of the others for … | |
Re: [URL="http://www.daniweb.com/forums/faq.php?faq=daniweb_policies"]You obviously didn't read the rules before you posted.[/URL] [URL="http://www.daniweb.com/forums/announcement8-2.html"]We can't help you with homework until you show some effort.[/URL] Here's something to get you started:[CODE] #include <iostream> using std::cout; using std::cin; using std::endl; int main() { return 0; }[/CODE] | |
Re: No one here will re-write it for you (or at least they shouldn't). Right now you're taking the user's input and counting down. I suggest you start by first establishing a way to count up from (0) to a certain max value (10 for example). Once you figure that out, … | |
Re: When you write equations like this, you are dealing with a whole lot of undefined behavior stemming from what are sometimes called "side effects". You should [B]never[/B] write such a statement because the results are unpredictable at best. | |
Re: The code you posted is a good example of a pass "by value". What you are asking about is called a pass "by reference". There are 2 ways to accomplish this. You can do it with a pointer or you can do it with a reference. Pass by reference using … | |
Re: A vector is based on a C++ system called a "template". You don't have to worry about exactly what a template is and how they work at this point, I'm sure you'll learn soon enough. In absolute simplest terms, a template allows you to define a class or function one … | |
Re: So it compiles then while it's running it crashes, correct? | |
Re: Please use [URL="http://www.daniweb.com/forums/announcement8-3.html"][B][COLOR="red"][noparse][CODE]...code tags...[/CODE][/noparse][/COLOR][/B][/URL]. They make your posted code easier to read. [B]>>(do I get this from it)[/B] Have you compiled and run it? You should be able to answer this question yourself. A couple of things I noticed: Your main() is declared void. It should be declared int and … | |
Re: It sounds like you're trying to update some old code. What IDE are you currently using? Are you actually using Borland C++ v6 as your IDE or are you using something else? | |
Re: [QUOTE=Software guy;1384379]I am pretty sure that 64 bit processors are faster than 32 bit.[/QUOTE] Yes, but nearly all modern processors are at least 64-bit (both of these definitely are). Whether 64-bit processing occurs or not is dependent primarily on whether your O/S is 64-bit or not. Based on the OP's … | |
Re: I can see a few things: [LIST=1] [*]You are not calculating the average properly. The average of a set of values is [ICODE]totalSum / setSize[/ICODE]. Replace vals[i] with a more appropriate variable in your average calculation. [*]You should only calculate your average after you have accumulated the total sum. Move … | |
Re: Is this a variable declaration that uses explicit initialization? If so, try an implicit initialization:[CODE] int matrixSize = Parser::CircleElems.size();[/CODE] | |
Re: Please post the relevant portion of your main(). Without seeing it, all we can do is speculate. And, as jonsca said:[QUOTE=jonsca]... You may want to pass the number of elements in the array into your function instead of size. Global variables are never a good idea.[/QUOTE] Based on what you … | |
Re: [B]>>You appear to create a variable called "array" (type double)[/B] From what I can see, "array" shouldn't even exist in main() anyway. It's the name of the first function parameter for SumN() and nothing more. Once the scoping of SumN() is corrected, it will be completely worthless. In main(), the … | |
Re: [URL="http://www.daniweb.com/forums/announcement8-2.html"]Not until you help yourself.[/URL] Show us your attempt first. | |
Re: I'm sorry, but I fail to comprehend the relevance of this... | |
Re: It is commonly taught that you can only have one (1) return statement in a function. This is not true, it's a technically-inaccurate educational device designed by instructors and included in many assignments to stress a different, yet marginally related, point. Usually, what is actually meant by teaching this is … | |
Re: Just learn it and don't worry about it. Most of the stuff in C++0x is features added to the language. Besides, if you wait for C++0x to come out before you learn it, why not wait until the next version after that comes out? Standards are constantly evolving. They have … | |
Re: [URL="http://en.wikipedia.org/wiki/Memory_leak"]Do you know what memory leaks are?[/URL] This piece of code is full of them and is extremely dangerous. After you read the wiki article, I suggest you read about proper dynamic memory usage: [URL="http://www.cplusplus.com/doc/tutorial/dynamic/"]Dynamic Memory Tutorial.[/URL] Using those statements, it is possible to dynamically allocate arrays, but you must … | |
Re: [QUOTE=mike_2000_17;1390414]Welcome! I also hope you have solved the problem already, but it won't be from the help of the previous answers (sorry guys). What you need to do is loop until you hit the end of the file. The end-of-file is found by simply using "inputFile.eof()". It returns true if … | |
Re: Care to be more specific? Your request is pretty broad/generic. Is there anything in particular you are looking for? I've read "Object Oriented Design Heuristics" by Arthur Riel. It's a good guide to designing for OOP if you're looking for something like that. It's more of a way to verify … | |
Re: You'll have to explain this better, and provide some code. What you are talking about is generally not advisable. If you've designed your system correctly, you really shouldn't have to pass "this" to something. I think you need to take a closer look at your design. | |
Re: [QUOTE][CODE]//Add 2 Rational numbers void Rational::addition(Rational f) { //Add numerators and denominators numerator += f.GetNumerator(); //accessor defined elsewhere in this class denominator += f.GetDenominator(); //GetNumerator defined elsewhere in this class }[/CODE][/QUOTE] There are several issues with this, but the biggest is that your class doesn't have an assignment operator defined. … | |
Re: What do you need to find exactly? Do you need to find just 3*7, 3*8, 3*2, and 3*-3 or do you need to continue on to 7*3, 7*8, etc...? I expect you should be able to do this with 2 loops. I'm not really sure why you think you need … | |
Re: I think you need to be a little more clear about your intentions. What exactly do you mean by "I want the size to vary"? Do you want to use a vector so that the [B]number of Database objects[/B] can vary? Or do you want [B]the actual size of a … | |
Re: [QUOTE=low_coder;1384667]you should include <string>[/QUOTE] Probably your best choice. This is one thing that I really don't like about how C++ works. The type std::string is a "built-in" class, but you need to #include the <string> header in order to do anything with it. You can't even create a vector, map, … | |
Re: You should be able to create some sort of boolean field, otherwise use a small integer field (like a "tinyint", or whatever your DB calls it). Once created, use a true/non-zero value as yes/checked. Your form then would have the programming to know what that value means. Obviously you need … | |
Re: I'd love to help, but there are just too many unexplained variables floating around in this clip. I can't make sense of it. This is why when posting you should: [LIST=1] [*]comment your code [*]provide a clear description of what the code is supposed to do [/LIST] | |
Re: Your function implementation doesn't match your function declaration. Implementation of overloaded constructor from Patient.cpp:[QUOTE][CODE]Patient::Patient(string pName, int pDay, int pMonth, int pYear) { name = pName; dateOfOp.setDay(pDay); dateOfOp.setMonth(pMonth); dateOfOp.setYear(pYear); }[/CODE][/QUOTE] This is how you've implemented your overloaded constructor. Have a closer look at the function's header line:[CODE]Patient::Patient(string pName, int pDay, int … | |
Re: Why not look them up? [URL="http://www.cplusplus.com/reference/iostream/istream/get/"]istream::get[/URL] [URL="http://www.cplusplus.com/reference/iostream/istream/ignore/"]istream::ignore[/URL] Basically, they're both input statements, but get() lets you keep the characters extracted from the stream and ignore() doesn't. | |
Re: Hmmm... This comes across as more of a general question about function use, not a question about using functions to calculate values related to a circle. Therefore, I'm going to reply with a little different slant than is perhaps suggested by your thread title. In C++, every operator you use … | |
Re: [QUOTE=Software guy;1384373]Hi, How about using char far *s2? Using char far will allocate 4 bytes of memory for your pointer(in simple words) which is double the size of the ordinary char pointer.[/QUOTE] Hunh?:confused: The OP isn't talking about the size of the pointer itself (which should already be either 4 … | |
Re: [QUOTE][CODE]*ps.Working_Hours=10;[/CODE][/QUOTE]The "dot" operator has a higher prededence than the dereference operator. You can do it this way, but you need to use parentheses to make it work properly, which tends to make it klunky.[CODE](*ps).Working_Hours = 10;[/CODE] Alternatively, you can avoid this issue completely by using the "arrow" operator to handle … | |
Re: [QUOTE](1) When you post your program source code on the internet, you ARE violating the FSU honor code.[/QUOTE] I am both in industry and a college student. My school has a "Truth in Learning" policy that's similar to your "Honor Code". DaniWeb's forum rules are written and enforced in such … | |
Re: There might be a reason you're "Kind off dumb when it comes to c/c++". It's rather amazing how well you can learn a subject when you actually put the effort into [B]doing your own homework[/B]. [URL="http://www.daniweb.com/forums/announcement8-2.html"]Try doing it yourself, then ask for help[/URL]. | |
Re: Usually a "bad_alloc" is associated with a pointer, but I don't see any in your code. My suspicions: [QUOTE][CODE]extPersonType myExt;[/CODE][/QUOTE] This declaration creates a "default" object. The problem is that you have no default constructors, you have "//commented them out". The system is not providing you a default constructor because … | |
Re: [QUOTE][CODE]string (PlrNameConfirm);[/CODE][/QUOTE] Why do you have parentheses in this declaration? They're really not necessary. You seem to be missing some braces. Your loop seems to work correctly, but the formatting isn't technically correct. [CODE] do { //<---I don't see this brace /*... statements ...*/ } while (condition); //<--- I also … | |
Re: [URL="http://www.cplusplus.com/doc/tutorial/control/"]Here's a link to some info about C++ control structures.[/URL] You'll find information about the C/C++-Style for loop in it. | |
Re: >>can any1 help me wid diz plz!!! [URL="http://www.daniweb.com/forums/thread78223.html"]Afraid not, your post doesn't give us anything to work with...[/URL] We can't help you unless you help us understand your problem. Shouting at us about some unexplained problem in txt and subsequently barfing some code into a post doesn't do anybody any … | |
Re: You are using the [B]int[/B] variable "t" as your temporary value when you do your swap. When you try to store a double to an int it truncates the floating point part of the number. C++ arrays start at element 0, NOT element 1. The reason your first element is … | |
Re: That will most likely be a problem in both languages. The typedef isn't complete. A typedef is similar to an "alias" in other languages. It is an alternative name for the dataType. Take a vector of integers for example:[CODE]std::vector<int> myVec;[/CODE] If you want to create an iterator for this vector, … | |
Re: [URL="http://www.daniweb.com/forums/announcement8-2.html"]Generally, you'll get better help if you show us you've made an effort.[/URL] That lets us look at what you've done and point you in the right direction. Plus, it makes you actually learn what you're supposed to be learning. | |
Re: Why not get a calculator and do the math on a piece of paper? It'll be substantially quicker than waiting for a forum reply. [B]>>I got a) 35 b)28.8 c) 24.96. Is that anywhere close?[/B] Quickly doing it in my head, I believe situation "a" is correct. | |
Re: A stringstream is an I/O stream just like ifstream, ofstream, etc. It just uses a string as the I/O medium instead of a file. You "output" to the string, then display the string. It is possible to overload the injection "<<" and extraction ">>" operators for a class to make … | |
Re: By default, an std::string is passed to a function [B]by value[/B]. When you pass an argument to a function by value, a copy of the argument is made and stored in the parameter. Because it's a copy, any changes you make to it within the scope of the function are … | |
Re: For starters[CODE]char letter[1]; ifstream file("let.txt",ios::out); file.close(); ofstream file2("let.txt",ios::in);[/CODE] The variable "letter" doesn't need to be an array, get rid of the "[1]" part. You have your file streams configured wrong. An ifstream should be configured for ios::in and an ofstream should be configured for ios::out. Also, you close your input … | |
Re: [QUOTE][CODE]public static void main( String[] args )[/CODE][/QUOTE] Um..... if this is a Java question you may want to post it in [URL="http://www.daniweb.com/forums/forum9.html"]the [B]Java[/B] (not [B]C++[/B]) forums[/URL]. | |
Re: If your algorithm is implemented correctly, all you should have to do is reverse your comparison to change the sort order. |
The End.