You did an excellent job copying from the book Absolute C++ By Savitch. I remember reading that exact code a while ago.
To quote the Moderators:
But to get you on the right track, the new classes that you need to write will all inherit some of the base classes you just copied. For example: temporary, administrative, and permanent employees are all Savitch employees. You can use that as a base class. In your new classes you can further...
User Profile
Collapse
-
Weaknessforcats , you hit the nail on the head. That was the situation that was in the book with dynamically allocated assets being deleted before being reassigned. I was curious if there was ever a situation where that code would be done intentionally or if it was just programmer error.
Thanks for the response!...Leave a comment:
-
I understand the safety code part, but I couldn't think of an intentional situation where the code would have same object on both sides of the assignment operator.Leave a comment:
-
Overloading the =Operator
Hello,
I was taking a look at overloading the = operator in a C Plus Plus book. Part of the code of the overloaded =operator included checking for the case when the same object was on both sides of the equal sign. When and why would you have a situation like this?
Thank YouCode:someobject1=someobject1;
-
Thanks,
I figured out what was causing the problem. Thewasn't the problem. What was causing the program to crash was inside the while loop. I didn't realize that getline will actually return a string with nothing in it for an empty line. As I was parsing the data, if there was a white space, the string length was (previously not so obvious to me) 0. I had a couple of functions that assumed that the string length...Code:while(getline(file,line)){Leave a comment:
-
Inputting From an External File and Testing for End of File
Hello,
Several Weeks ago I asked a question about testing for the end of an input file.
I have been using this method pretty well for inputting information from an external file. I am using C++.
Where line is a c-string and file is an input stream. But this only reads until the first space it encounters. I now want to try to take in an entire line, regardless of what...Code:char line[50]; while(file>>line){ -
Constructor Statements
Hello,
I was (once again) experimenting with some CPP code using constructors. I defined a constuctors 2 different ways. I believe the end result is the same, but what causes the difference in run-time for the program. Specifically, the first code took my computer 9 seconds to run, while the second code took 15 seconds, a 66% difference. I repeated the "experiment " several times and got the same result. I'm guessing that the first... -
Thanks for the very detailed response; it was very informative! I was considering using the getline function, but I wasn’t sure how I could parse the data inside of the string. Would it be correct to assume if I were to take in the entire line, and it happened to be an empty string, I could test for it and then end the loop?
Would you consider this code to be more robust?
...Code:#include<iostream> #include<fstream>
Leave a comment:
-
Testing for End of File in I/O
I am experimenting with several ways to test for the end of file for an input file .txt
If, for example, I have a text (test.txt) file that had:
ab 5
fgd 3
fdfe 3
aasa 4
(intentionally blank line)
where the first input is a character array and the second is an integer value.
I could write...Code:#include<iostream> #include<fstream> using namespace
-
Could you perhaps provide a (simple) example to help me get started?
Thank you...Leave a comment:
-
Thanks, but is there a way I can put very large numbers in? I can put a lage (50+ digit) number into an array, but I'm not sure how i could handle division in this case.
I am particularly interested in the RSA- Factoring Challenge where the numbers can be as long as 600+ digits.
http://en.wikipedia.org/wiki/RSA_Factoring_Challenge
Any advice?
I tried the unsigned long long int and that worked, but I wanted...Leave a comment:
-
Program to Test Large Number for Prime
For a fun challenge, I am trying to create a C++ program that will determine if a number is prime. I am getting to problems when I reach a large values (over 9 or so digits).
How can I increase the number of digits i can use?
For example, when i use the number 4362206209 (which I know for a fact is prime) it returns 2 as a factor, which it isn't.
Eventually, I would like to get to long (50+ digit) numbers. I know this calculation... -
-
Quick question with char in logic statement
I am trying to create a program that will accept either a character or integer value and then use it in a logic statement. However, when I run this sample program, if i put 1 in for choice, it will not run the if statement. What am I missing?
#include<iostre am>
using namespace std;
int main () {
char choice;
cout<<"choice: ";
cin>>choice;
...
No activity results to display
Show More
Leave a comment: