How to keep a string and return a variable's total with flowgortiham - flowchart

In flowgorithm, how do I keep a string and return a variable's total? Then also return the remainder of total divided by another variable.
Here is what I need to complete.

How do I keep a string and return a variable's total?
In the output box, type something like: "this is my string"&myVariable
See: http://www.flowgorithm.org/documentation/index.htm
Then also return the remainder of total divided by another variable
There is a box called "Assign". In that you can assign whichever variable and use the basic math functions to do what you're asking.
See: http://www.flowgorithm.org/documentation/operators.htm

Related

How to change returned value of function

There is a function in this program, that currently returns a 1. I would prefer for it to return a 0.
uregs[R_PC] is the program counter.
arg0 is the program counter offset from where we left the function (assembly, "ret").
From this I deduce: we can add the offset to the program counter, uregs[R_PC]+arg0, to find the address of the return value.
I have allocated a 32-bit "0", and I try to write 2 bytes of it into the address where the return value lives (our function expects to return a BOOL16, so we only need 2 bytes of 0):
sudo dtrace -p "$(getpid)" -w -n '
int *zero;
BEGIN { zero=alloca(4); *zero=0; }
pid$target::TextOutA:return {
copyout(zero, uregs[R_PC]+arg0, 2);
}'
Of course I get:
dtrace: error on enabled probe ID 2 (ID 320426: pid60498:gdi32.dll.so:TextOutA:return): invalid address (0x41f21c) in action #1 at DIF offset 60
uregs[R_PC] is presumably a userspace address. Probably copyout() wants a kernel address.
How do I translate the userspace address uregs[R_PC] to kernel-space? I know that with copyin() we can read data stored at user-space address, into kernel-space. But that doesn't give us the kernel address of that memory.
Alternatively: is there some other way to change the return value using DTrace?
DTrace is not the right tool for this. You should instead use a debugger like dbx, mdb or gdb.
In the meantime, I'll try to clarify some of the concepts that you've mentioned.
To begin, you may well see in the source code for a simple function that there is a single return. It is quite possible that the compiled result, i.e. the function's machine-specific implementation, also contains only a single point of exit. Typically, however, the implementation is likely to contain more than one exit point and it may be useful for a developer to know from which specific one a function returned. It is this information, described as an offset from the start of the function, that is given by a return probe's arg0. Your D script, then, is attempting to update part of the program or library itself; although the addition of arg0 makes the destination address somewhat random, the result is most likely still within the text section, which is read-only.
Secondly, in the common case, a function's implementation returns a value by storing it in a specific register; e.g. %rax on amd64. Thus overriding a return value would neccessitate overriding a register value. This is impossible because DTrace's access to the user-land registers is read-only.
It is possible that a function is implemented in such a way that, as it returns, it recovers the return value from a specific memory location before writing it into the appropriate register. If this were the case then one could, indeed, modify the value in memory (given its location) just before it is accessed. However, this is going to work for only a subset of cases: the return value might equally be contained in another register or else simply expressed as a constant in the program text itself. In any case, it would be far more trouble than it's worth given the existence of more appropriate debugging tools.

How do I to make a member variable equal another member variable which is set in main()?

Consider the following C++ code for my program: CODE
When I run this program, it outputs the following:
**Chocolate mass: 41
Chocolate density: nan**
I want the program to output the volume variable divided by the mass variable. It seems to be doing this correctly, but it is dividing the values initialized to the variables in the object class, rather than dividing the values assigned to the variables in the main() function. How do I fix this?
All help is greatly appreciated!
You told the software the "updated" input i.e. weight, volume and mass but you never told the software to update its density given the new values of volume and mass. The value of density is calculated once in the constructor, which is only called once when you created the object (not to mention that I feel pretty nervous when people do things like 0/0). Need a separate function to update the density and call it.
Ok there is a bug in your program...
Change this line:
Double getDensity()const{return density;}
To:
Double getDensity(){density=volume/mass;return density;}
And replace:
Double density = volume/mass;
To:
Double density;
Next time please paste code. Screen shots will not work...
I hope the following tips will help:
Initialize the class members using class constructors, that's why constructors exist.
Use the existing setters to update the density. Each time setMass or setVolume is called, recalculate the density.
Whenever you use division, make sure you don't divide by 0.
Initialize variable with constants of the proper type. 0 is of type int by default while 0.0 is of type double.

Is it possible to get the value of a CString return value (eg. a name) from a SQL stored procedure using ADO and C++

I have been having trouble retrieving the vale us a CString return value. I do not have access to the stored procedure, but, I believe the programmer who wrote it used RETURN NextEDB where NextEDB is a CString. GetRecordCount() = 1 and GetFieldCount() = 1, but, NextEDB has no value. Here is where I setup the return value parameter:
CADOParameter resultParam(CADORecordset::typeVarChar, sizeof(char) * 20, CADOParameter::paramReturnValue);
Here is where I try to retrieve the value:
resultParam.GetValue(NextEDBID)
All of the other code in the function is the same in a bunch of other functions that retrieve declared parameters and all of the other functions work. I am able to retrieve values of return value when they are integers, but, the CString doesn't want to reveal itself. What am I doing wrong.
The return code of a stored procedure (RETURN statement) is always 32-bit signed integer. It is intended to indicate success (zero) or non-zero (error/warning) rather than return data.
Consider using an output parameter or result set to return data from the stored procedure rather than return code. That will provide flexibility with regards the data types.

Get the value of a variable using the hexadecimal memory address

I just want to get the value using the hex address:
#include<stdio.h>
int main()
{
int *hold, value=10;
hold = &value;
printf("%p",hold);
}
It gives me the address 0x7fffd7c24334. I just want to know that if there is a way in C or C++ so that I can get directly the value of "value" using hex number 0x7fffd7c24334 for the time being. I suppose the address of the variable hold is the same for sometime so that 0x7fffd7c24334 still point to value, but I am not sure.
Assuming that this address is consistent upon every execution of your program, you can use this:
int value2 = *(int*)0x7fffd7c24334;
But please note that this assumption is generally wrong!
The address of a local variable in a function depends on the state of the stack (the value of the SP register) at the point in execution when the function is called.
It might possibly work in main, since this function is called only once, and the SP register should have the same value upon every execution of your program. But even if it does work, that address will change as soon as you add variables before value. To put it in simple words, don't use this method.
printf("%d",*hold);
De-reference and use %d.
You cannot rely on the hex address.
See here: http://ideone.com/RdY4Ni
I think you can use this:
printf("%x", hold);

Default value of an integer?

My program requires several floats to be set to a default number when the program launches. As the program runs these integers will be set to their true values. These true values however can be any real number. My program will be consistently be checking these numbers to see if their value has been changed from the default.
For example lets say I have integers A,B,C. All these integers will be set to a default value at the start (lets say -1). Then as the program progresses, lets say A and B are set to 3 and 2 respectfully. Since C is still at the default value, the program can conclude than C hasn't been assigned a non-default value yet.
The problem arises when trying to find a unique default value. Since the values of the numbers can be set to anything, if the value its set to is identical to the default value, my program won't know if a float still has the default value or its true value is just identical to the default value.
I considered NULL as a default value, but NULL is equal to 0 in C++, leading to the same problem!
I could create a whole object consisting of an bool and a float as members, where the bool indicates whether the float has been assigned its own value yet or not. This however seems like an overkill. Is there a default value I can set my floats to such that the value isn't identical to any other value? (Examples include infinity or i)
I am asking for C/C++ solutions.
I could create a whole object consisting of an bool and a integer as
members, where the bool indicates whether the number has been assigned
its own value yet or not. This however seems like an overkill.
What you described is called a "nullable type" in .NET. A C++ implementation is boost::optional:
boost::optional<int> A;
if (A)
do_something(*A);
On a two's complement machine there's an integer value that is less useful than the others: INT_MIN. You can't make a valid positive value by negating it. Since it's the least useful value in the integer range, it makes a good choice for a marker value. It also has an easily recognizable hex value, 0x80000000.
There is no bit pattern you can assign to an int that isn't an actual int. You need to keep separate flags if you really have no integer values that are out of bounds.
If the domain of valid int values is unlimited, the only choice is a management bit indicating whether it is assigned or not.
But, are you sure MAX_INT is a desired choice?
There is no way to guarantee that a value you assign an int to is not going to be equal to another random int. The only way to assure that what you want to happen occurs, is to create a separate bool to account for changes.
No, you will have to create your own data type which contains the information about whether it has been assigned or not.
If as you say, no integer value is off limits, then you cannot assign a default "uninitialised" value. Just use a struct with an int and a bool as you suggest in your question.
I could create a whole object consisting of an bool and a integer as
members, where the bool indicates whether the number has been assigned
its own value yet or not. This however seems like an overkill.
My first guess would be to effectively use a flag and mark each variable. But this is not your only choice of course.
You can use pointers (which can be NULL) and assign dynamically the memory. Not very convenient.
You can pick a custom value which is almost never used. You can then define this value to be the default value. Ofc, some time, you will need to assign this value to your floats, but this case won't happen often and you just need to keep track of this variables. Given the occurrence of such case, a simple linked list should do.