Click here to Skip to main content
14,878,932 members

Comments by Andreas Gieriet (Top 200 by date)

Andreas Gieriet 9-Oct-20 9:29am View
   
If you want to make it robust, you also have to consider empty arrays. I.e. what to do for min/max/avg on empty arrays? Not to talk about overflow when calculating avg for large arrays/big numbers?
Andreas Gieriet 9-Oct-20 9:26am View
   
You tagged as C++. So, you might want to look for something like this: http://www.cplusplus.com/reference/algorithm/count_if/
Andreas Gieriet 21-Oct-18 12:21pm View
   
1. you should learn to ask questions such that we understand what your problem is. A statement like "does not work" is far far too fuzzy. What exectly do you do and what symptom tells you that it does not work? What is the expected behaviour?

2. You cannot expect anyone to compile and execute your code. Assume that one only reads your code and tries to make sense of it. See also item 1. above: we do not know what the expected behaviour is...

3. Looking at your code, I must assume that your code does not compile: you define a function *within* the main function. C/C++ do not allow for this.

4. If the code does not compile, you won't be able to execute it and thus, cannot expect any "output" from (not) executing the program ;-)

Cheers
Andi
Andreas Gieriet 21-Oct-18 8:49am View
   
Hey, you obviously don't take the time to write a decent question. Simply throwing code snippets at our faces is probably not the nicest approach...
Why should we take any time to "help" you.
You want something from us, so, make it easy for us to help you!
Regards
Andi
Andreas Gieriet 1-May-17 17:33pm View
   
Any suggestion?
Andi
Andreas Gieriet 28-Jun-16 2:51am View
   
Mine too. My 5!
Cheers
Andi
Andreas Gieriet 25-Jun-16 7:05am View
   
Compile it with all warnings on!
E.g. n is not set but you create an array with n elements...
Why do you use pointer arithmetic when you could do it with far less pain with array indices? E.g. cin >> p_array[i];
Cheers
Andi
Andreas Gieriet 20-Jun-16 9:30am View
   
There are several components involved in the whole story:
1) your editor: what character encoding do you use? You cannot trust that what you see is what the compiler gets. I.e. try to enter the character as a hex code L'\x..\x..' etc.
2) The console where your printf goes to: the console gets the byte sequence from the printf output and has to make sense of the bytes. Make sure that your console knows how to properly display the respective byte sequences. E.g. my console only knows 7-bit ASCII - other characters are displayed as "garbage".
Cheers
Andi
Andreas Gieriet 19-Jun-16 21:54pm View
   
Why do you think you are in an infinite loop? What is the symptom? What is the last text you see on the screen?
BTW: Your player has no start money, and you do not print his money (you should call one.money and not Player().money).
You also have wrong index calculation in rand() % 25 - you only have indices 0...23, so it should be ...% 24.
Regards
Andi
Andreas Gieriet 19-Jun-16 21:40pm View
   
What exactly is the symptom?
- you have no variable book
- the fprintf call does have hard coded non-sense string arguments
- the b[100] is not used
- you do not check for errors from scanf

Cheers
Andi
Andreas Gieriet 17-Jun-16 18:09pm View
   
That's the UNIX tr command, right? I sometimes wonder why one has to re-invent such a tool on Windows environments...
Cheers
Andi
Andreas Gieriet 8-Apr-16 16:30pm View
   
Hm, I wonder why you cook this up after more than two years of the original post...
Be assured that I see many uses of XML in daily work.
In my universe, however, I see the *serialization* feature as a means to transport objects in *some* format over process boundaries and to persist data in *some* format for later retrieval (not necessarily intended for humans to read). There are many serialization formats, one happens to be XML. E.g. a C++ compiler might serialize its objects from memory into an ELF file and the linker de-serializes the ELF files again and works internally with the de-serialized objects to link them.
If I want an XML file that is read by humans, then I want to control far more than just adding comments, e.g. also indentation etc.
In my eyes, *serialization* in its narrower sense is not the tool to create nicely formatted and nicely commented files. So, my point is, if you want to have control that goes beyond the basic serialization, you might need to invent your own (de-)serializer.
BTW: You seem to get me wrong in saying I don't esteem the value of comments.
Regards
Andi
Andreas Gieriet 7-Mar-16 9:18am View
   
Do you want to learn something from the assignment or just submit anything?
I'm pretty sure you have discussed sufficient material in your course to allow you to complete the task with reasonable effort.
Cheers
Andi
Andreas Gieriet 29-Feb-16 8:41am View
   
This is too cheep: no proper question, simply copy-paste what you have tried - you seem not to have tried anything. My vote of 1.
Andreas Gieriet 21-Feb-16 15:43pm View
   
C'mon! If he fails, he deserves it!
He got the chance to learn from template - it's up to him to make the best from it. No reason to down-vote.
Cheers
Andi
PS: This post was from two years ago! Why the heck does it re-appear so high up?
Andreas Gieriet 21-Feb-16 15:37pm View
   
My vote of 1: if you are too lazy to tell what you tried and simply copy-paste the text again, you do not deserve any attention.
Andi
Andreas Gieriet 21-Feb-16 15:33pm View
   
What don't you understand with the error message. It says it all!
_mag is a variable and not a function.
What do you intend to do with _mag?
Cheers
Andi
Andreas Gieriet 21-Feb-16 5:07am View
   
I don't get it.
I understand the OP that he want a "more efficient" solution. Building a (hash) table of all characters and their positions to only tweak with a certain character on all their instances is not very efficient nor robust. E.g. a comma might have a meaning within some string, but another outside the string. So, this approach is rather useless in my eyes...
Regards
Andi
Andreas Gieriet 21-Feb-16 4:28am View
   
Useful links, my 5!
Cheers
Andi
Andreas Gieriet 21-Feb-16 4:25am View
   
Thanks!
Andi
Andreas Gieriet 20-Feb-16 14:00pm View
   
Seriously? Not really, right? I mean, preparing some data structure to then replace unrelated use of some characters is not leading anywhere. And: how to remove (i.e. replace by nothing)?
Regards
Andi
Andreas Gieriet 19-Feb-16 8:14am View
   
Some part is missing in the "What I have tried". With what code?
Andi
Andreas Gieriet 19-Feb-16 8:13am View
   
What you mean by "all at once"? In the end, each character has to be inspected individually. If this is by your own loop or within some read-to-use function is irrelevant. Or am I missing something?
Cheers
Andi
Andreas Gieriet 19-Feb-16 7:41am View
   
So, in that case, I don't get what you want.
What is the expected outcome after your operation?
Can you give for the input data the respective output data?
What do you mean by "the above filter"? Do you mean below?
Regards
Andi
Andreas Gieriet 19-Feb-16 6:47am View
   
Please read my text carefully - not only the criticism.
If you enter the text above in Google (without quotes) you get the answers to your question. And I repeated the solution: give the top-left cell only for the destination.
My comment on wondering why you ask every 10 day a question in average might be a trigger for you to re-think how you seek for answers. You should develop the ability to search the internet for decent answers...
Regards
Andi
Andreas Gieriet 18-Feb-16 17:20pm View
   
Have you read the documentation as I suggested? It's all there.
Your array of 2000 wchar_t has a length of 2000, so pass these 2000 to the respective parameter. Note that it will not be null-terminated after the conversion (see the documentation)!
You do not give in your code above the source string. Where the heck should the function find the source string from?
I'm a bit puzzled why you cannot figure out the semantics from the description...
Regards
Andi
PS: Why the cast? A cast is by definition a code smell that needs to be described! Have you tried without the cast to const char*? How is BYTE defined? Does it need to be BYTE? The function is meant to be used with char arrays.
Andreas Gieriet 18-Feb-16 15:03pm View
   
Have you read mbstowcs - C++ Reference?
What is bpString?
What is bpStringLen? This should be the length of the wSStr array, not of the source buffer.
Cheers
Andi
Andreas Gieriet 18-Feb-16 14:35pm View
   
Homework assignment? You seem not to have tried anything. What you report as what you've tried is crap. This can't compile - you've left away some code: si, pi, etc. Please don't fool us (and especially yourself)!
Andi
Andreas Gieriet 18-Feb-16 13:39pm View
   
This is a repost of your post of two day ago! Why? See I want to implement mv function from unix, using c. Modify your initial post if there is something new to be added. I marked this post as repost and down voted so it eventually becomes deleted...
Andreas Gieriet 18-Feb-16 13:36pm View
   
What means: "did not succeeded"?
What is the (compiler?) error message?
You seem to assume that one takes the time to reverse engineer your problem.
Help us to help you!
Andi
Andreas Gieriet 17-Feb-16 16:36pm View
   
Have you removed the reference?
On which line is this error reported?
What if you rename the parameter name duration to something like duration_in_sec?
Andi
Andreas Gieriet 17-Feb-16 16:16pm View
   
Thanks for your 5!
Cheers
Andi
Andreas Gieriet 17-Feb-16 15:43pm View
   
What is the error message?
Cheers
Andi
Andreas Gieriet 17-Feb-16 4:34am View
   
Repeating the question in the "what I have tried" is too sloppy. Please tell what you did try - what is missing if you search the internet? What is your background? Is this a school project task? Homework assignment?
Andreas Gieriet 17-Feb-16 4:29am View
   
Have you checked the MSDN documentation of ReferenceEquals?
Cheers
Andi
Andreas Gieriet 16-Feb-16 17:49pm View
   
Completely unclear question.
The input data is not clear. Give a proper example or describe such that the rest of us understands the question...
Is it about C#?
Do you have an EF DbSet to work on?
Is it about formatting the output?
Where exactly do you struggle?
Regards
Andi
Andreas Gieriet 16-Feb-16 17:06pm View
   
Thanks for your 5!
Andi
Andreas Gieriet 16-Feb-16 16:01pm View
   
My 5, Maciej!
I have a similar solution posted (#3) with Regex and SelectMany.
Cheers
Andi
Andreas Gieriet 3-Feb-16 13:25pm View
   
Your for (...); loop is broken!
What is the body of your loop? A semi-colon = empty statement.
What you get is probably fact = n+1.
Cheers
Andi
Andreas Gieriet 3-Feb-16 4:50am View
   
My 5, Sergey.
Cheers
Andi
Andreas Gieriet 3-Feb-16 4:42am View
   
I fully agree. However, when re-arranging the predicates, one must take care to not break the logic by swapping "tightly" connected predicates. E.g. if (record != null && record.name == "abc" ...) must not become re-arranged to if (record.name == "abc" && record != null ...). This is the only thing that makes it "harder". Not really "hard", though.
BTW: I observed quite often that software developers sometimes have a hard time to properly transform Boolean expressions. E.g. some seem not to be fluent in De Morgan's Law and other transformations. This makes it difficult for them to come to a correct solution. To shed light on *this* topic could be worth a CP tip/trick ;-)
Cheers
Andi
Andreas Gieriet 2-Feb-16 18:35pm View
   
With my proposed approach, I use placeholders for the predicates: A, C, D, etc. These abstract from the actual expressions. That's why I regard it as "harder" to distinguish on that abstraction level if a predicate depends on short circuit evaluation or not.
Cheers
Andi
Andreas Gieriet 2-Feb-16 17:41pm View
   
Thank you for your 5, Sergey!
Yes, I thought of this too. I.e. short circuit evaluation makes life harder while re-arranging. I "magically" collapsed that in the sentence "[...] Here you need to know basics of Boolean logic transformations.[...]". ;-)
Cheers
Andi
Andreas Gieriet 31-Jan-16 17:00pm View
   
What's the problem exactly?
You read in three values (cin >> t_f, etc.), calculate from these values the value of k (#include <cmath>, use the proper "log" function, etc.), then the value of t_h, and finally print t_h (cout << t_h, etc.).
So, again: what's the problem? Choose the right types? choose the right logarithm? C++ as such (includes, namespaces, main function, ...)?
Do you have test data to check against?
Cheers
Andi
Andreas Gieriet 31-Jan-16 16:55pm View
   
My 5!
Cheers
Andi
Andreas Gieriet 29-Jan-16 11:21am View
   
We both know that this is broken code, and I wanted to highlight to the OP that due to that it's not worth to analyze *why*. This is not obvious in your answer - one might interpret your solution as intended behavior. That's all :-)
Cheers
Andi
Andreas Gieriet 29-Jan-16 10:31am View
   
What if the last called function is a void function? E.g. the ARM Procedure Call Standard passes arguments under certain conditions in R0, R1, R2 and R3 and returns the value in R0. If the function is a void function, the last R0 assigned value would be the one passed to the last function and not any kind of return value.
It's far to dangerous to even "know" about this, I'd say, because it does not even hold always for one compiler.
Cheers
Andi
Andreas Gieriet 29-Jan-16 10:20am View
   
I fully agree! My 5 too!
Cheers
Andi
Andreas Gieriet 29-Jan-16 10:14am View
   
The behavior is undefined, i.e. anything may happen. See also my solution #4.
Cheers
Andi
Andreas Gieriet 29-Jan-16 9:49am View
   
My 5, too!
Cheers
Andi
Andreas Gieriet 29-Jan-16 9:49am View
   
My 5!
Cheers
Andi
Andreas Gieriet 29-Jan-16 8:53am View
   
Thanks for your 5!
I'll take into consideration to post it as tip - if I find some (more) spare time to spend... ;-)
Cheers
Andi
Andreas Gieriet 29-Jan-16 8:49am View
   
You are welcome.
Cheers
Andi
Andreas Gieriet 29-Jan-16 8:49am View
   
I prefer functions since you only evaluate them when needed (with variables, you often have to evaluate upfront) and values that have meaningful content (if you evaluate upfront, the expression might not have meaningful result value since the respective control path will never be executed with the given values).
Cheers
Andi
Andreas Gieriet 28-Jan-16 22:05pm View
   
Yep. Agreed.
Cheers
Andi
Andreas Gieriet 28-Jan-16 22:04pm View
   
Sure.
Cheers
Andi
Andreas Gieriet 28-Jan-16 22:02pm View
   
I fully agree!
Cheers
Andi
Andreas Gieriet 28-Jan-16 21:47pm View
   
Let's abstract a bit from the given example and talk about how to interface from C++ to C functions. It is a common pattern to use those containers from C++ which guarantee contiguous memory. This are std::vector for pre-C++11 plus std::array for C++11 and above.
If the client code is C++, I prefer C++ containers.
Since the OP had a similar intent as far as I understand, I gave him the criterion to decide: "contiguous memory container".
In C/C++ you can always do anything - these languages *enable* you to do great things - if you use the languages wisely.
If it is advised to change "running" code without cause is another topic, I'd say.
Cheers
Andi
Andreas Gieriet 28-Jan-16 21:35pm View
   
Yes, if the string is declared as you show in your example, it would work. We can only guess what kind of declaration the OP has in his code.
Cheers
Andi
Andreas Gieriet 28-Jan-16 20:03pm View
   
I agree with Midi_Mick: you cannot use a variable in the cases.
You can neither call a void function in a ... ? ... : ....
Finally, a switch without a default can be considered as a code smell, where an if ... else if ... without an else is fine.
Cheers
Andi
Andreas Gieriet 28-Jan-16 19:53pm View
   
Depends on the C++ standard you are using.
Before C++11, std::vector is the way to do it.
With C++11 and above, std::array is preferred, I agree.
The member would then be defined as std::array<Byte, MY_MESSAGE_SIZE> buffer, initializing with buffer() and accessing with buffer (ore likewise &(buffer[0])).
Thanks for your hint and your 4!
Cheers
Andi
PS: What it buys you is the "hidden" memory management and the C++ way to access the container by iterators etc. It's a matter of what goal you try to achieve an also a matter of taste, I'd say.
Andreas Gieriet 28-Jan-16 19:33pm View
   
You missed if (alk.Count > 1) ....
Andi
Andreas Gieriet 28-Jan-16 19:03pm View
   
Thanks for your 5.
Cheers
Andi
Andreas Gieriet 28-Jan-16 17:11pm View
   
Thanks for your 5!
Cheers
Andi
Andreas Gieriet 28-Jan-16 17:08pm View
   
What do you mean by "hex"? If it's about the 0x80000000, then you need to learn about how to enter a numeric value in C. Internally, numbers are stored as bit patterns, e.g. for a 32-bit system an int as a 32 bit wide bit pattern. You can provide numeric integral values as decimal number (e.g. 1234, without leading zero = binary 00000000000000000000010011010010), as octal number (e.g. 01234, with leading zero and digits 0...7 = decimal 668 = binary 00000000000000000000001010011100), as hex number (e.g. 0x1234, with leading 0x or 0X and digits 0...9 and letters a...f and A...F, = decimal 4660 = binary 00000000000000000001001000110100). Unfortunately, you cannot enter the binary values, only decimal, octal and hex is supported.
Andi
Andreas Gieriet 28-Jan-16 16:52pm View
   
Thanks for your 5 too!
Cheers
Andi
Andreas Gieriet 28-Jan-16 16:52pm View
   
Thanks for your 5, Bruno!
Cheers
Andi
Andreas Gieriet 28-Jan-16 13:53pm View
   
If you learn something by example, I'm happy to help. Otherwise, it's a pity...
Cheers
Andi
Andreas Gieriet 28-Jan-16 11:26am View
   
As far as I know, there is no intrinsic support for this in Excel. You can transpose records in Excel, but this does not help if you have larger files and hundreds of files as you say.
So, you might need some tool to convert the text into some CSV file.
Can you program such a tool (e.g. do you know programming C# or any other language)? If yes, what is the problem? If no - too bad... (this forum is not to ask for the service to build a tool for you).
Cheers
Andi
Andreas Gieriet 23-Jan-16 15:16pm View
   
Hello Bruno,
thanks for your 5 (again?) ;-)
Cheers
Andi
Andreas Gieriet 20-Jan-16 8:08am View
   
This is not a question. If you don't take care to ask a decent question you do not deserve any answer. This is just carelessly throwing code at the rest of us.
Andi
Andreas Gieriet 20-Jan-16 8:05am View
   
Richard, in principle, I agree with you. And for me it's still a dilemma. Sometimes I give an answer (see solution #3) - and sometimes not.
Cheers
Andi
Andreas Gieriet 20-Jan-16 7:59am View
   
Regular expression is not suited for this. Regular expressions cannot nest nor count. Having that said, you may do a rough check with regular expression assuming the entered expressions are very basic (i.e. no nesting).
The regex would be something like (.Net regex):
^\s*([-+]?\s*(\d+|\w+))(\s*[-+*/]\s*([-+]?\s*(\d+|\w+)))*\s*$
Cheers
Andi
Andreas Gieriet 20-Jan-16 7:51am View
   
Hello Richard,
it's a bit of a dilemma. Answering such simple things may help opening the blocking knot. In the end, they have to be able to explain the solution to their teacher - and finally pass the exams, I guess. Giving a bit of a hint in what direction it might go may serve as some kind of a kick-start ;-).
Cheers
Andi
Andreas Gieriet 20-Jan-16 7:29am View
   
No need for the full code - nobody will run your code! This is a *Quick Answer Forum*. Tell in concise form what you want to achieve, what the problem with this is (e.g. ...with xxx input I get yyy output, but I expect zzz as output...). Finally tell what you tried so far. Only then you may add code that shows what you tried. The smaller the better. Please spend your time to make it a question that allows us to grasp quickly. If a question requires larger code sections to be reverse engineered, then this is not considered a concise question.
Remember: we do not spend hours on your problem - if it is not clear or needs too much of effort from our side, you won't get decent answers.
Cheers
Andi
Andreas Gieriet 18-Jan-16 7:46am View
   
Or instead of using push_back, create a vector in the first place with n entries and replace the respective entries by indexing with the calculated ones.
Cheers
Andi
Andreas Gieriet 18-Jan-16 7:17am View
   
As you requested, I've added a second solution. I noticed that your splitting does not always produce a vector of n entries. If the source string is shorter than n characters, your method cuts the resulting vector to the number of characters.
Cheers
Andi
Andreas Gieriet 18-Jan-16 6:50am View
   
I see in the code the comments. But please keep in mind to make it easy for us to help you. If we have to read the code before we understand what the problem might be, there is a far littler chance that you get any useful help. Say in the main text in a concise statement what the problem is so that one can decide if it's worth to look into the code.
Regards
Andi
PS: What has multi-threading to do with your problem?
Andreas Gieriet 18-Jan-16 2:11am View
   
You are asking us something you have to answer yourself!
It seems to me that you have your design not under control.
What is the purpose to use multi-inheritance at all? I would not use multi inheritance with concrete classes without cause - it makes all complicated.
If you insist on doing so: your derived class has two GetX() methods "for free" - the derived classes provide these - you have to tell which is meant in the client code. Why would you want to override these with some other meaning?
Some more notes: why do you make one of the base classes virtual, but the other not? Why do you fool the client by actually *setting* the value in the *getter* method (the GetX()) - this is bad practice. Initialize the value in the constructor's initializer list instead!
Cheers
Andi
Andreas Gieriet 18-Jan-16 2:02am View
   
Even I agree with your listed facts, I think you should not use offensive wording. Does that help anybody?
Cheers
Andi
Andreas Gieriet 18-Jan-16 1:58am View
   
This is not exponential as far as I can tell, it's polynomial by n^3 or so. How do you come to the conclusion that this is exponential complexity?
Andi
Andreas Gieriet 18-Jan-16 1:47am View
   
Not clear. Please elaborate.
What's the relation between capital X and lower case x?
The variables x, y, z are implementation details of the classes - why does it matter what their value is - you hopefully have some methods which return some meaningful values.
What do you mean by "I cannot change the call"? Which call?
Finally: please make the code samples properly typed, e.g. the cxclass2 is probably not properly spelled.
You expect some help from us, so please make it easy for us to help you by providing proper code examples and stating the problem in a clear and concise way. You expect us to spend time on your problem, so, please spend your time too to ask the question in a decent way (spelling, problem statement, what did you try, etc.).
Thanks
Andi
Andreas Gieriet 18-Jan-16 1:37am View
   
What means "does not function". You have to tell us what is not working as expected. We will not run your code and do reverse-engineering.
Cheers
Andi
Andreas Gieriet 3-Jan-16 9:32am View
   
My 5!
Cheers
Andi
Andreas Gieriet 28-Dec-15 11:18am View
   
My 5 for your detailed answer!
Cheers
Andi
Andreas Gieriet 28-Dec-15 11:18am View
   
Thanks for your 5!
I agree with your concerns.
Cheers
Andi
Andreas Gieriet 25-Dec-15 18:33pm View
   
See my updated solution. My fault - I gave the wrong method name.
Where do you have such a weird data structure from. This is a code smell. You should create reasonable classes which abstract the data structures. In my opinion, such nested data structures are very bad design.
Cheers
Andi
Andreas Gieriet 25-Dec-15 17:08pm View
   
Still not clear.
What is "index[0]", etc.?
What are the allowed elements? "zero"? "minus three"? "one thousand three hundred seventy five"? How to decide if two elements are "next to each other"? In the sense of numeric values?
Andi
Andreas Gieriet 25-Dec-15 14:46pm View
   
In addition to 0x01AA's comments: Your compiler should issue a warning (at least, if not an error) since not all control flow path of function Priority return an explicit value. E.g. what is the return value if neither of ( / * + - is passed as argument to that function?
Cheers
Andi
Andreas Gieriet 25-Dec-15 14:35pm View
   
If I wrote a solution in the field below, it was possible to vote for it and to accepted it as a solution. I'm not after this. So, the comments here are not good for getting "rewards". ;-)
BTW: Please understand that we get huge numbers of "homework" assignment questions here. For questions like yours, people started to kind of ignore them. Make sure your question is stated in a way that comes exactly to the point and allows to distinguish immediately from homework assignments.
Cheers
Andi
Andreas Gieriet 25-Dec-15 14:26pm View
   
You asked in the comment *why* they are *assigned* values. They are *not* *assigned* values, they are *initialized*. When a variable is defined, it may get an initial value (e.g. char c = 0). Later in the code, the variable may be *assigned* a new value (e.g. c = 'A').
You also ask, what it helps: it helps writing robust code, i.e. code that does not "fall apart" when you later in the day fancy to changes the code slightly further down in the text. That's why I say "is considered as good practice".
Cheers
Andi
Andreas Gieriet 25-Dec-15 14:13pm View
   
Hm, K&R C is stone-age C. Try to get a later copy of this book. E.g. see The C Programming Language - ANSI C. See also C Programming/C Reference/stdio.h/getchar for better examples on getchar() and the advise on what to do with EOF, etc.
Andreas Gieriet 25-Dec-15 14:11pm View
   
See my PPS above.
In short: local variables should be explicitly initialized since they have otherwise an undefined value.
Andreas Gieriet 25-Dec-15 13:58pm View
   
This is not a solution - please remove it.
You seem to be out for a no-effort solution on your side.
Sorry for you.
Regards
Andi
Andreas Gieriet 25-Dec-15 13:51pm View
   
Tell us your interpretation for each line and we might help in agreeing or correcting if necessary.
E.g. "walk" through the code an write on paper the current code line and the value of each variable. Do that step by step. That's the best way to learn what a program does.
Cheers
Andi
PS: What book is this? If the text is literally taken from that book, then I have some doubts that this book is up to date. I.e. nowadays, no one writes main without return type, e.g. main() { ... } should at least be int main() { ... }.
PPS: The comments seem to ask some questions to the code.
Explicitly initializing local variables is considered good practice. Not explicitly initialized variables have *undefined* value.
Conversion from/to integral types of different size need to be explained in your book. If not, dump it. Integral types may become promoted from smaller to larger types, larger types may become truncated to smaller ones (thus, potentially changing the value to something else - truncating is *not* necessarily identical to rounding...). If changing from/to signed/unsigned, more elaborate rules apply. Since getchar() returns an int, the program does not handle gracefully end-of-file situation (which is given with return value -1. Under that aspect, the code snippet is of second choice at best.
Andreas Gieriet 24-Dec-15 15:44pm View
   
Go ahead and write the recursion down on paper. That's the only way to learn how it works.
Make a column for the static variable and one column of each level of recursion of the main function. Write down the value of i from the beginning to the end of the recursion and write down in the respective value plus in the recursion row the current statement of execution.
This will teach you the machinery of recursion.
E.g.
level 0: i=5 static int i = 5;
level 0: i=4 if (--i)
level 0: i=4 main()
level 1: i=3 if (--i)
level 1: i=3 main()
level 2: i=2 if (--i)
level 2: i=2 main()
level 3: i=1 if (--i)
level 3: i=1 main()
level 4: i=0 if (--i)
level 4: i=0 return 0
level 3: i=0 printf(0)
level 3: i=0 return 0
level 2: i=0 printf(0)
level 2: i=0 return 0
level 1: i=0 printf(0)
level 1: i=0 return 0
level 0: i=0 printf(0)
level 0: i=0 return 0
Cheers
Andi
Andreas Gieriet 24-Dec-15 8:50am View
   
This is neither C nor C++ syntax. You need to show us a proper C/C++ program in order to help you. E.g. what do you mean by telling "I am using struct"?
Regards
Andi
Andreas Gieriet 22-Dec-15 15:44pm View
   
Thanks for your 5!
Cheers
Andi
Andreas Gieriet 21-Dec-15 15:42pm View
   
The OP is from Malaysia. So, if you slightly change the starting words of the question from "should we ask..." to "How to ask...", everything makes sense - at least to me... ;-) I'm guessing, but I think this was the intent.
Cheers
Andi
Andreas Gieriet 20-Dec-15 3:54am View
   
To start with, don't do any "math", just count from the beginning. Your calendar specification is too imprecise to produce a generally valid formula from that. See also my solution below. The leap days are needed when the calculated year length is "sufficiently" out-of-sync compared with the actual "stellar" year length. You assume here a "stellar" calendar as it looks like. "Lunar" calendars have a different concept of cycles. Or do you assume a year on earth as the base for your calendar?
You see, your specification on what you want to achieve is too imprecise to make reasonable statements on it...
Cheers
Andi
Andreas Gieriet 19-Dec-15 16:43pm View
   
The OP asks for a C solution, not C++.
Cheers
Andi
Andreas Gieriet 19-Dec-15 16:42pm View
   
Did you understand my question on ownership at all? This is the crucial part for a working program. The rest is syntax.
Cheers
Andi
Andreas Gieriet 19-Dec-15 13:19pm View
   
To start with, forget about the implementation (the "control*). First you have to have a precise definition of your calendar and what the parameters are.
E.g. each month equally long? What is the leap-year rule? I.e. by what parameters you steer the function of your calendar?
Only if this is given, you can think about how to partition into a "model" of the calendar (the storage and machinery to produce dates) and the "view" of the calendar (how to present and provide edit function to the user). The glue logic between the model and the view will then be the "controller", assuming a MVC (Model-View-Controller) approach.
Cheers
Andi
Andreas Gieriet 19-Dec-15 13:08pm View
   
The Player *player is not initialized. Missing relation to the team variable...(?)
Additionally: what is the ownership rule of your pointer members of the Player struct? I.e. how do you destroy a Player* instance? Should player1 be a pointer? Otherwise it would be implicitly member-wise copied while passed to the function...
Finally, your if condition contains a "strange" & prefix - why? What do you try to achieve with that operator there?
Cheers
Andi
Andreas Gieriet 19-Dec-15 13:06pm View
   
Thanks for your 5!
Cheers
Andi
Andreas Gieriet 18-Dec-15 4:52am View
   
See edited solution.
Cheers
Andi
Andreas Gieriet 18-Dec-15 4:45am View
   
The OP is not too clear, i.e. we must invent the data an guess what exactly is the content of the lists (tables?). Bit I think the query the OP wants is "grouping", e.g. var query = from su in skilledUserRelation group su.SkillId by su.UserId into userWithGroupedSkills select new { User = userWithGroupedSkills.Key, Skills = userWithGroupedSkills.ToList() };. He might add filtering before grouping.
Cheers
Andi
Andreas Gieriet 18-Dec-15 1:41am View
   
Here my quick review findings:
1) signature in randomize functions: no need for references.
E.g. double randomize(double minVal, double maxVal) ...
2) Make the global randomize functions protected members of Fighter.
3) Too extensive use of auto: make functions return a concrete type
E.g. getHealth returns a double
4) void newBattle(deque<a> &goodSide, deque<b> &badSide): no need for templates
E.g. void newBattle(deque<fighter> &goodSide, deque<fighter> &badSide) ...
5) void GenerateArmy(deque<T> &wars, const int &number, const char &strength): must be template (since you create an instance of T in the function) but the deque is fine if concrete
E.g. void GenerateArmy(deque<fighter> &wars, const int &number, const char &strength)...
If you do not intend to create a class hierarchy with Fighter, you may remove the template and construct a Fighter within the function instead of T(...): Fighter(...).
Cheers
Andi
Andreas Gieriet 18-Dec-15 1:27am View
   
You are welcome.
Cheers
Andi
Andreas Gieriet 17-Dec-15 17:17pm View
   
If you show me the linker error I might show you a solution for it. ;-)
Cheers
Andi
Andreas Gieriet 17-Dec-15 16:23pm View
   
Hm, if you want my honest answer? Rejected.
1) Far too much copy-paste code.
All classes have the same structure but only slightly varying "weights"...
2) Far too much dead code.
If operators are not used, remove all that code.
3) Stream handling is weird/broken.
E.g. you pass an ostream parameter but write in the function
to cout instead...
My estimation: the whole functionality could be coded in 5% of the code.
I.e. 95% of the code is waste or copy-paste.

This code in not maintainable.
"Less" would be "more".

I know, this is a harsh comment...
Regards
Andi
Andreas Gieriet 17-Dec-15 16:09pm View
   
Thanks for your 5, Sergey!
Cheers
Andi
Andreas Gieriet 17-Dec-15 14:07pm View
   
Be careful!
C++ makes clear statements on performance - no guessing.
Removing from front in a vector is bad: a vector is kind of a dynamic array and it is best added/removed in the back, not the front or in between.
E.g. see http://www.cplusplus.com/reference/vector/vector/ and http://www.cplusplus.com/reference/algorithm/.
Check for the "complexity" sections of each function.
Cheers
Andi
PS: In your code, the logic is wrong! Fix that first before contemplating on "weird" optimizations...
Andreas Gieriet 17-Dec-15 12:49pm View
   
Thanks for your 5!
Cheers
Andi
Andreas Gieriet 17-Dec-15 7:53am View
   
I read your question carefully. It does not make sense to me. What is "upper codes in that format"? And "where I can change format" is too broad of a "question". A similarly broad answer was: "in the code".
Sorry for my sarcasm, but please try to ask a precise answer before telling me to read carefully...
Cheers
Andi
PS: You tagged as C++, but this is plain C code. You might consider to change the tag to C.
Andreas Gieriet 17-Dec-15 7:47am View
   
Pseudo code:

f = open file
foreach byte in bytearray do
t = convert byte to hex
write t to f
write space to f
end foreach
close f

What of the above mentioned pseudo code causes troubles?
Cheers
Andi
Andreas Gieriet 17-Dec-15 7:36am View
   
What is the problem? You do not know how to convert a byte value into a hex text representation? or how to add a space?
By what means "efficient"? Easy to write/read as a programmer? Quick execution? Little memory usage? ...?
Where does the text go to? Into an std::string or into a std::ostream, or anything else?
Cheers
Andi
Andreas Gieriet 17-Dec-15 7:14am View
   
So you need a function which identifies the trailing number in a given string and increment that number? What if there is no trailing number? What if the number has less positions than needed, e.g. ABC-0, ... ABC-9, ABC-10 (makes two digits out of initially one)? Is it supposed to respect leading zeros? E.g. UVW-01, ... UVW-09, UVW-10 (or UVW-010)?
Cheers
Andi
Andreas Gieriet 17-Dec-15 7:11am View
   
Far too little information to give a reasonable answer here.
What is the expectation? First, for finding the shortest path, there are various algorithms, e.g. see Shortest path problem. The calculation complexity may vary on your constraints, e.g. see the Travelling salesman problem.
Secondly, what is the expected function of the GUI? E.g. how do you enter the graphs? Interactively? What is the expected output (display the path on the GUI, etc.)?
Cheers
Andi
Andreas Gieriet 17-Dec-15 7:04am View
   
So what is the question?
This is completely unclear. What do you try to achieve? You increment already, right?
Andi
Andreas Gieriet 17-Dec-15 7:01am View
   
What exactly is the problem? Is it the algorithm that you do not know how to adapt or is it lack of C++ knowhow, or anything else?

What did you try so fat and where do you struggle?
Cheers
Andi

PS: We do not do your homework assignments.
Andreas Gieriet 6-Dec-15 18:44pm View
   
Why the heck do you open a four years old thread without cause - and even worse - with an off-topic "solution"?
Andreas Gieriet 28-Nov-15 7:21am View
   
Have you changed your identity? 0x01AA <-> Member 12172345? :-D
On topic: In VisualStudio: run it in the debugger and add a breakpoint at the end of the main function. Or run it without debugger and it will show the console and ask for a key press to close the console. Or run it after compiling from a command prompt (cmd.exe).
Regards
Andi
Andreas Gieriet 28-Nov-15 7:03am View
   
Check your timeouts. You must allow for sufficient time to let the UI automation identifying the respective UI elements.
Regards
Andi
Andreas Gieriet 13-Nov-15 16:12pm View
   
Agreed. But I'm still puzzled that no one applying scanf() uses scanf("%19s", buffer) with a buffer of 20 chars.
Cheers
Andi
Andreas Gieriet 11-Nov-15 5:29am View
   
Your naming scheme is very confusing. You seem to confuse singular and plurals. Even it sounds irrelevant: give decent names to your "item(s)" and you see you get more sense out of it (say: you see that you confuse things). Then try to get stepwise to the correct *query* by splitting into steps and dump by console. E.g. foreach(var item in xdoc.Descendants("database")) Console.Writeline(item);. If this succeeds, extend further, etc.
Regards
Andi
Andreas Gieriet 11-Nov-15 5:08am View
   
What exactly do you want to achieve?
Where is the problem?
Andi
Andreas Gieriet 9-Nov-15 7:07am View
   
What says your textbook about the assignment? No hint there?
Andi
Andreas Gieriet 1-Nov-15 18:56pm View
   
Thanks for your 5, Sergey!
Cheers
Andi
Andreas Gieriet 28-Oct-15 16:30pm View
   
The difficult thing is to distinguish between a different record and an additional/missing record. How to synchronize where to continue searching for matches? Or are both CSV files assumed to be of same number or records and same "sorting" or records?
Regards
Andi
Andreas Gieriet 25-Oct-15 13:04pm View
   
Already tried to run in the debugger? Where does the exception occur?
Regards
Andi
Andreas Gieriet 25-Oct-15 10:28am View
   
What is the definition of Abstract?
Why do you use shared_ptr and move?
I would store plain pointers and return a reference to the object.
Regards
Andi
Andreas Gieriet 25-Oct-15 7:04am View
   
What exactly do you want to protect? In which sense? Protect from seeing how it works or protect to make sure no one tampered with the executable?
In any case, everyone with the right tools and the readiness to put effort into it can reverse engineer your program.
Is your code really worth to be protected? If so, make a decent risk analysis and act accordingly.
BTW: I regard obfuscating useless - it adds noise to your code but the logic must still be the same.
Regards
Andi
Andreas Gieriet 22-Oct-15 15:25pm View
   
No problem.
Cheers
Andi
Andreas Gieriet 22-Oct-15 15:23pm View
   
Thanks for your 5!
Cheers
Andi
Andreas Gieriet 22-Oct-15 10:42am View
   
You have the conditions wrong! It should be && and not ||. See also my solution #2 to avoid such subtle mistakes.
E.g. your first if matches any number greater than or equal 1, like 10000. The other ifs will not be reached...
Regards
Andi
Andreas Gieriet 22-Oct-15 10:29am View
   
What with smaller than 1? What with equal 2000?
Regards
Andi
Andreas Gieriet 22-Oct-15 8:58am View
   
It seems to serve the purpose to show you how to pass *any* type to a template argument. In the examples before (Array, Stack), there are always built-in types used as template parameters. In the last example, the Holder class gets another class as template parameter. The Number class is just a simple class to show this. Don't take any intrinsic meaning out of the fact that this Number class is not useful for anything.
Do not project too much (meaning) into the example - it only shows various usages of template parameters.
Regards
Andi
Andreas Gieriet 22-Oct-15 8:21am View
   
You still talk about value- versus reference type. There is no such thing in C++! Everything is by value. If you want to pass something "by reference" you pass the address of the object, either by pointer or by reference operator. This can be done for any instance of any type. If you have a vector of *pointers* to some type, than it can be a pointer to a class as well as to a float, etc. The object that is stored in the vector is then the *address* to some entity (note that you cannot store a *reference* to any type in a vector).
Regards
Andi
Andreas Gieriet 22-Oct-15 3:21am View
   
Still incorrect information. You seem to mix up C# generics with C++ templates. The class in template<class T> is not restricting the usage of types here - you may use any type, no matter if a class or a struct or an enum or a composed type or a built-in type, etc. Instead of class T you can likewise write typename T without changing the meaning. I wonder if I misread completely your text...? What I read simply does not make sense for C++.
Regards
Andi
Andreas Gieriet 21-Oct-15 17:27pm View
   
Your solution is incorrect also with respect of if float is usable in templates. C++ allows to use any type as template parameter as long as the applied operations (e.g. like comparison or arithmetic, etc.) is supported by that given type.
Regards
Andi
PS: I was tempted to down-vote your solution, but it was not me. I opted for discussion the issue ;-)
Andreas Gieriet 21-Oct-15 10:42am View
   
This is C++, not C# or alike. So, no such thing like value versus reference type. Or am I missing something?
Regards
Andi
Andreas Gieriet 19-Oct-15 16:02pm View
   
Thanks for your 5 too!
Cheers
Andi
Andreas Gieriet 19-Oct-15 16:02pm View
   
Thanks for your 5!
Cheers
Andi
Andreas Gieriet 19-Oct-15 16:01pm View
   
To my understanding, both numbers have to be split with respect to the same base B. The algorithm does not work if you split the numbers differently. E.g. if your base is 2 and you split to 3 bits, your x is 3 + 3 bits, y is 1 + 3 bits.
Regards
Andi
Andreas Gieriet 18-Oct-15 13:55pm View
   
My advise: set yourself a task an try to design and implement it in C/C++.
Nothing with graphics - since C/C++ as languages do not provide any framework to render any nice graphics - you always depend on some libraries that take their time to learn how to use...
Select a topic based on your pet/favorite topic and try to get it working. Ask some specific questions here if you get stuck.
Regards
Andi
Andreas Gieriet 18-Oct-15 13:45pm View
   
Thanks for your 5.
I was reluctant to post it. But, hey, it's showing some approaches to read a file line-wise, create a aux structure to sort/filter items and return the items again.
If it's a homework assignment, the OP has to chew something ;-) If it's for production code, I think it's worthwhile to consider such a solution.
Cheers
Andi
Andreas Gieriet 18-Oct-15 13:42pm View
   
Thanks for your 5!
Cheers
Andi
Andreas Gieriet 18-Oct-15 3:54am View
   
Please do yourself and us the favor and read the documentation on the four C++ cast operators yourself.
Regards
Andi
Andreas Gieriet 18-Oct-15 2:43am View
   
The error tells it all: "...qualifiers...": you cannot cast away constness with the static_cast operator - use ...<const int*>...
Regards
Andi
PS: Why do you change from double to int?
Andreas Gieriet 17-Oct-15 18:17pm View
   
Thanks for your 5, Zoltán!
Cheers
Andi
Andreas Gieriet 17-Oct-15 17:55pm View
   
What error? We do not compile it for you. This is a *quick answer* forum! Please provide all necessary info to us so that we can decide by reading your question on how to help you. Why should one spend time to compile it for you if you are to "lazy" to tell us what you see.
Regards
Andi
Andreas Gieriet 17-Oct-15 17:46pm View
   
What does your textbook tell about casting in C++?
Regards
Andi
Andreas Gieriet 17-Oct-15 7:15am View
   
Thanks for your 5!
Cheers
Andi
Andreas Gieriet 17-Oct-15 6:26am View
   
Do you have some example?
What is the purpose - sounds a very odd requirement...
Homework assignment?
Regards
Andi
Andreas Gieriet 16-Oct-15 10:39am View
   
You are welcome!
Cheers
Andi
Andreas Gieriet 15-Oct-15 15:00pm View
   
I see that your pattern is to be interpreted as C# regex. Ok.
What is strange is that you do not search for consecutive matches but for overlapping matches.
Search for the first match, then cut the first char and search for the next match, etc. With that approach, you have to avoid duplicate matches at the same positions, though.
Regards
Andi
Andreas Gieriet 15-Oct-15 12:56pm View
   
What exactly is the semantic of your pattern? What exactly identifies a "substring"? Assuming the * stands for "any character", then in C# Regex, this would be [01]*. But still, you don't say where a substring starts and ends. In C# Regex, this is given by (...).
Please clarify.
Regards
Andi
Andreas Gieriet 14-Oct-15 16:25pm View
   
How about perl2brain2bat? ;-)
This is nonsense: bat lacks many features intrinsic to Perl.
The only way: call Perl from the bat file :-)
Regards
Andi
Andreas Gieriet 14-Oct-15 6:00am View
   
I agree with all except the "compiler dependent" part. It is not compiler dependent.
See the C Standard.

Static storage duration

Section 5.1.2, paragraph 1: static storage duration: objects are set to their initial values before program startup.

Section 6.2.4, paragraph 3: static storage duration: those objects with internal or external linkage or those declared static.

Section 6.7.8, paragraph 10: objects with static storage duration: implicit initialization to zero/null if not initialized explicitly.

Automatic storage duration

Section 6.2.4, paragraph 4: automatic storage duration: all objects with no linkage and not declared static.

Section 6.7.8, paragraph 10: objects with automatic storage duration: initial value is indeterminate unless explicitly initialized.

Regards
Andi
Andreas Gieriet 13-Oct-15 2:47am View
   
What is hexadecimal code of a file? Do you mean, reading a file into memory? A file is a sequence of bytes. There is no such thing like "hexadecimal code from a file".
Regards
Andi
Andreas Gieriet 11-Oct-15 19:05pm View
   
How do you identify the doc file? Through an url (e.g. http://...)?
If so, open a socket and get the data through that and store locally. Then you can do whatever you want with the file.
Google for C socket library and/or C socket tutorial.

If you do not need to download via an url but rather mean by "upload" to open a local file and slurp it into memory, then you might consult http://www.cprogramming.com/tutorial/cfileio.html. Be aware that file IO on Windows platforms is "broken" in the sense that it does awkward magic assuming text files. Therefore, you have to follow the instructions as detailed in what's the differences between r and rb in fopen.

Regards
Andi
PS: I agree with Philippe Mori: Doc is a binary file while docx is a zip file of a directory tree of XML files. You cannot handle both the same way.
Andreas Gieriet 11-Oct-15 18:45pm View
   
Well, in your suggested solution you use global variables without cause. You may consult any state-of-the art coding guideline: they all say that global variables should be avoided when ever possible. There are many reasons to avoid global variables. Only the most simple single-threaded programs may safely live with global variables.
I wonder how one can argue on this topic ...
Regards
Andi
Andreas Gieriet 11-Oct-15 18:13pm View
   
What is "upload" and what is "hexadecimal" values?
I mean, both terms tell me something, but not in the context you are asking.
Please explain in more detail.
E.g. do you mean "downloading" from a server some file and store locally?
When you download a file, it's a pile of bytes you get, so what do you mean by hexadecimal value? Do you mean the binary data(?) or is this a hash code you are talking about?
Regards
Andi
Andreas Gieriet 11-Oct-15 15:12pm View
   
Show us the code.
Regards
Andi
PS: Once you programmed it, try it out as Zoltan suggests...
Andreas Gieriet 11-Oct-15 15:00pm View
   
What is a "mini" search engine? In which "pond" are you trying to "fish"? :-)
I.e. what data do you take as data base. How do you want to express search text (plain words or'ed together, Regex, ...)? What text are you supposed to match (only full match, or also partial match)? What data of the searched "documents" are you supposed to search (document names, titles, first line, the whole content, ...)?
The result weight is seemingly the alphabetic sorting, so you have to sort by title or by first found word, or ...?

Your question is completely useless. No one will give you any useful substantial answer to such a loose question.

Cheers
Andi
Andreas Gieriet 11-Oct-15 11:05am View
   
Please give an example on what exactly you want to do?
Regards
Andi
Andreas Gieriet 8-Oct-15 16:23pm View
   
Thanks for your support, CHill60!
I saw it too and decided to not start any arguments about it.
Why bother on immature kids who play from the anonymity of the internet.
If he feels better like this, let him be happy. Seems to me paltry behavior.
Cheers
Andi
PS: Reported as Troll - I could not resist.
Andreas Gieriet 8-Oct-15 16:11pm View
   
I have no clue how you get to your replies to my items 3) and 4)...
You do not give any evidence that allows to follow your reasoning.
I cannot follow your thought - too weird, sorry.

The OP's program is very well defined - no room for interpretation. Just a flaw the in the comparison. If using =, the else-branch is taken, if using ==, the if-branch is taken.
Or am I missing something?
Regards
Andi
Andreas Gieriet 8-Oct-15 10:13am View
   
1) What hinders you to read the Wikipedia article?
2) If using conio.h or not is up to you - it's not right or wrong. But *you* should have a clear understanding *yourself* why you think you need to use a proprietary version of e.g. getch() and why you think that the standard functions (like getch() from stdio.h) are not sufficient. I personally don't use conio.h since the standards (stdio.h) all deliver what I need - like getch() - and I never had the need to clear the screen and alike.
3) Your advise to *not* initialize the variable is at least strange in my eyes - or is it a language issue? Your reasoning is very odd.
4) You do not answer the OP's question. Therefore, your solution is not worth anything with respect to the OP's question.

If you write a batch application (I deliberately say "batch", not "Console" since this is the basic motivation for me to write such programs at all), the point of it is that you can automate something. So, the application should take some input and process it to produce an output. If you want to feed some output of some program into your program, you should be able to "pipe" it from STDOUT of the predecessor to the STDIN of you program. Likewise with your output.
If you want to program a batch application that shows "menu" like UI on the terminal window (Console), then you might use console focused I/O - but you can perfectly live without, too. I consider this kind of usage a tiny minority of batch programs. Consider also this: conio is not portable - it was made for DOS. If you go in your professional life to other systems (e.g. embedded toys like Arduino and alike), then you have no such thing like conio.h. There you have terminal emulations at best. But even for these, try to live without - there is more hassle than benefit if your are not going over STDIN/OUT/ERR.

Regards
Andi
Andreas Gieriet 8-Oct-15 7:42am View
   
See solution#1.
Regards
Andi
Andreas Gieriet 8-Oct-15 7:10am View
   
Regarding conio.h: see my comment above.
Regarding = versus ==: all what we see is the code in your question, and that code has the obvious flaw of having an assignment in the condition. Now you say differently, so, why not fixing it in the question and tell that that was a typo only which should not distract from the real question, etc. etc.
Regards
Andi
Andreas Gieriet 8-Oct-15 7:05am View
   
getch() comes from stdio.h (see stdio.h).
conio.h is not a standard C header file and might come with some compilers on some systems (see conio.h.
The odd thing is that both header files declare a getch() function and it's a matter of the linker command arguments sequence on which implementation is finally linked into the program.
Regards
Andi
PS: If you start your program in a console, it will not disappear when completed. If you run it during development in Visual Studio, then it will/will not disappear, depending on if you run it in/ouitside the Debugger (F5 versus CTRL-F5).
Andreas Gieriet 8-Oct-15 6:53am View
   
There is nothing wrong. It's just to put the thing into the right relation.
Regards
Andi
Andreas Gieriet 8-Oct-15 5:51am View
   
No re-post, please!
Andreas Gieriet 8-Oct-15 5:47am View
   
What are "illegal" characters?
What is the problem?
Regards
Andi
Andreas Gieriet 8-Oct-15 5:46am View
   
Code block formatting added.
Andi
Andreas Gieriet 8-Oct-15 5:43am View
   
This is crap, sorry.
Why the heck should the variable *not* be initialized?!
You are not answering the OP's question.
And conio.h is not needed at all, or am I missing something?
The obvious problem in the OP's question is that he does not know the difference between = and ==.
Regards
Andi
Andreas Gieriet 8-Oct-15 5:07am View
   
How paranoid are you? I.e. it's not meant as a personal offense, but as "what do you need to protect"?
If you have such a sensitive application, then you need to do a proper risk analysis and if you lack the technical possibilities yourself hire a contractor who consults you in doing the right mitigations.
Regards
Andi
Andreas Gieriet 6-Oct-15 14:52pm View
   
Try this:
std::vector<std::vector<int>> matrix(outer, std::vector<int>(inner, 0));
Cheers
Andi
Andreas Gieriet 6-Oct-15 4:38am View
   
Is this the original formatting?
I generally refuse to read such carelessly formatted code.
If someone does not bother to present the code in at least half way readable form, I think he does not deserve that anyone spends time on it...
Make it easy to anyone to help you by at least format the program in a decent way.
Regards
Andi
Andreas Gieriet 6-Oct-15 0:20am View
   
Thanks for your 5, Maciej!
Cheers
Andi
Andreas Gieriet 6-Oct-15 0:19am View
   
Thanks for your 5, Sergey!
Cheers
Andi
Andreas Gieriet 5-Oct-15 16:28pm View
   
My 5 for the plain-old C-array description.
On the other hand, the OP asks about std::array and not plain-old C-arrays. The memory layout is identical but the initialization is weird for multidimensional std::array. See my solution #2.
Cheers
Andi
Andreas Gieriet 5-Oct-15 15:41pm View
   
No shouting please... ;-)
Andreas Gieriet 5-Oct-15 15:28pm View
   
Homework assignment? What does your text book tell about this?
Andi
Andreas Gieriet 5-Oct-15 15:25pm View
   
Well, I deliberately wrote "4 bit" since the sum *is* 4 bits and the carry is the potential 5th bit.
Andreas Gieriet 5-Oct-15 15:16pm View
   
What does your text book say about this?
Andreas Gieriet 5-Oct-15 15:14pm View
   
A 4 bit adder in hardware has always a *4* bit result. The carry is the indicator that a fifth bit was needed to represent the full result.
Or am I missing something?
Take any CPU (which has an ALU) which has only N-bit registers (e.g. 32 bits). Unsigned adding two 32 bit registers results in a 32 bit value *plus* an indicator if there was a carry (i.e. the result cannot be fully represented in 32 bits).
Regards
Andi
Andreas Gieriet 5-Oct-15 15:04pm View
   
You don't have to repeat your title here again. It is obviously ambiguous, or more precisely: leaves open crucial "details". May I use the plus operator? in which form is the output expected (you mention that you enter decimal numbers to be converted to binary - so, the result is decimal again - or binary?). What do you need in the end? Mimic hardware? E.g. have a 4-bit adder build out of four full adders connected by carries, and each full adder composed by two half adders plus an or gate? We cannot know what the goal of this exercise is, what your background is, etc.
A possible implementation, given your C++ tag is to create components (classes) in C++ which represent the various pieces of hardware and communicate over variables (which may play the role of wires). What is the whole context? What are you expected to learn from this exercise?
If it's about mimicking hardware, I suggest to at least make functions for the individual functional parts.
Regards
Andi
Andreas Gieriet 5-Oct-15 14:56pm View
   
What is the correct result for e.g. 9 and 11? for me: carry = 1, result = 4. I.e. a *4* bit adder has a *4* bit result *plus* a carry flag that indicates - a carry.
Regards
Andi
Andreas Gieriet 5-Oct-15 0:21am View
   
Well, that's reading between the lines ;-). My point is, that if the "requirement" is not clear enough, the solution will be just "anything".
Regards
Andi
PS: But you are right, the intent was maybe to mimic hardware implementation.
Andreas Gieriet 4-Oct-15 19:20pm View
   
Assignments are usually in line with the text book or the teachers lecture. So, please look up the solution in your material.
It all starts with formatting. Then you will easily see what is wrong. In addition, learn to read the error message of the compiler. You cannot ask for advise with each and every error message produced. You did not even bother to tell the full error message to us...! Learn to communicate problems properly so that it is easy for us to help. Do you really expect us to run your code to find out what exact error message is produced? This is a *quick* answer forum - not a "gimme code for free" nor "please invest time to do the work for me since I'm too lazy to look the solution up in my text book"...
E.g. check what an if-else statement looks like: if cond statement else statement. What is statement? One single statement or a block. Now it's up to you again...
Regards
Andi
Andreas Gieriet 4-Oct-15 13:56pm View
   
Where did you dig out this hair-raising code?
All these defines on top are crap, sorry.
Rewrite it first into decent C++ code before any attempt to translate into something else.
Regards
Andi
Andreas Gieriet 4-Oct-15 13:45pm View
   
Is it a ballistic trajectory?
What are the input parameters?
What the needed/expected output form?
What is the model (formulas)?
You give far too little detail!
Regards
Andi
PS: If this is a homework assignment, we won't answer to such broad questions anyways.
Andreas Gieriet 30-Sep-15 15:58pm View
   
No, I won't. This is not a quick-answer question, but a gimme code question. This forum is not for this kind of questions. You might first read the "code of conduct" of this forum before you whine about no one helping you.
Regards
Andi
Andreas Gieriet 28-Sep-15 18:59pm View
   
Please *stop* reposting!
Regards
Andi
Andreas Gieriet 28-Sep-15 3:44am View
   
See my comment below.
Andreas Gieriet 28-Sep-15 3:44am View
   
The solution is you digging into the internet and search for one, try to understand it so it fits your needs and go ahead.
This is not a "gimme code" forum - we help if you have concrete technical problems and a specific question for it, but not beyond that.
Regards
Andi
Andreas Gieriet 27-Sep-15 18:23pm View
   
I suggest you read the text book first to understand the assignment.
This is pseudo code - not C nor C++ nor Java nor any other programming language.
This code should help to express the stated problem in a more formal way than prose.
The "function" is intended to be a function definition...
"forever" means that the loop turns forever...
I don't like to say this, but if you already struggle with these terms, I doubt that you have a chance to implement "read_number" or "read_action"...
I thought that these are obvious terms if you have the faintest idea of any programming language. Otherwise google what a function is and what a forever-loop in C++ is (e.g. C++ forever, or C++ read number, etc.).
Regards
Andi