|
I am still learning. I was not required to write a code for this but just a draw a flowchart. Any pointers would be appreciated.
|
|
|
|
|
Hi,
not tested:
float getNumber(char* prompt, float* delta) {
float number;
printf(prompt);
scanf("%f", number);
... add whatever checking you consider important
*delta=number;
return number!=0;
}
int main(void) {
float balance, delta;
int more;
printf("BANK RECONCILIATION FOR: 10/21/98");
printf("\n\nEnding balance on statement:");
scanf("%f", &balance);
do {
more=getNumber("Enter Outstanding dep (or 0 to quit)", &delta);
balance+=delta;
while(more);
do {
more=getNumber("Outstanding check/withdrawal (or 0 to quit)");
balance-=delta;
while(more);
printf("Your final balance in your checkbook should be $ %f" , balance);
return 0;
}
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Dear Expert,
The following code is for displaying DialIn tab of user object in active directory.
can any one covert this code to visual c++ using adsi
On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Const FourthOctet = 1
Const ThirdOctet = 256
Const SecondOctet = 65536
Const FirstOctet = 16777216
Set objUser = GetObject _
("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
blnMsNPAllowDialin = objUser.Get("msNPAllowDialin")
WScript.Echo "Remote Access Permission (Dial-in or VPN)"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Control access through Remote Access Policy"
Err.Clear
Else
If blnMsNPAllowDialin = True Then
WScript.Echo "Allow access (msNPAllowDialin)"
Else
WScript.Echo "Deny access (msNPAllowDialin)"
End If
End If
WScript.Echo
arrMsNPSavedCallingStationID = objUser.GetEx("msNPSavedCallingStationID")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "No Caller-ID specified."
Err.Clear
Else
WScript.Echo "Verify Caller ID (msNPSavedCallingStationID): "
For Each strValue in arrMsNPSavedCallingStationID
WScript.echo strValue
Next
objUser.GetEx "msNPCallingStationID"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Calling station ID(s) specified but not assigned."
Err.Clear
Else
WScript.echo "Calling station ID(s) assigned."
End If
End If
WScript.Echo
intMsRADIUSServiceType = objUser.Get("msRADIUSServiceType")
WScript.Echo "Callback Options"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "No Callback"
Err.Clear
Else
strMsRADIUSCallbackNumber = objUser.Get("msRADIUSCallbackNumber")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Set by caller (Routing and Remote Access Service only)"
Err.Clear
strMsRASSavedCallbackNumber = objUser.Get("msRASSavedCallbackNumber")
If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Unused value of " & strMsRASSavedCallbackNumber & _
" appears in the Always Callback to field."
Else
Err.Clear
End If
Else
WScript.Echo "Always Callback to: " & _
strMsRADIUSCallbackNumber & " (msRADIUSCallbackNumber)"
End If
End If
WScript.Echo
intMsRASSavedFramedIPAddress = objUser.Get("msRASSavedFramedIPAddress")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "No static IP address assigned."
Err.Clear
Else
If sgn(intMsRASSavedFramedIPAddress) = -1 Then
intIP = intMsRASSavedFramedIPAddress
WScript.StdOut.Write 256 + (int(intIP/FirstOctet)) & "."
intFirstRemainder = intIP mod FirstOctet
WScript.StdOut.Write 256 + (int(intFirstRemainder/SecondOctet)) & "."
intSecondRemainder = intFirstRemainder mod SecondOctet
WScript.StdOut.Write 256 + (int(intSecondRemainder/ThirdOctet)) & "."
intThirdRemainder = intSecondRemainder mod ThirdOctet
WScript.Echo 256 + (int(intThirdRemainder/FourthOctet))
Else
intIP = intMsRASSavedFramedIPAddress
WScript.StdOut.Write int(intIP/FirstOctet) & "."
intFirstRemainder = intIP mod FirstOctet
WScript.StdOut.Write int(intFirstRemainder/SecondOctet) & "."
intSecondRemainder = intFirstRemainder mod SecondOctet
WScript.StdOut.Write int(intSecondRemainder/ThirdOctet) & "."
intThirdRemainder = intSecondRemainder mod ThirdOctet
WScript.Echo int(intThirdRemainder/FourthOctet)
End If
objUser.Get "msRADIUSFramedIPAddress"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Static IP address specified but not assigned."
Err.Clear
Else
WScript.Echo "Static IP Address assigned."
End If
End If
WScript.Echo
arrMsRASSavedFramedRoute = objUser.GetEx("msRASSavedFramedRoute")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "No static Routes specified."
Err.Clear
Else
WScript.echo "Static Routes (msRASSavedFramedRoute):"
WScript.Echo vbTab & "CIDR 0.0.0.0 Metric"
For Each strValue in arrMsRASSavedFramedRoute
WScript.echo vbTab & strValue
Next
objUser.GetEx "msRADIUSFramedRoute"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "Static Routes specified but not assigned."
Err.Clear
Else
WScript.echo "Static Routes assigned."
End If
End If
|
|
|
|
|
raja 4 wrote: can any one covert this code to visual c++ using adsi
I'm sure someone can, but the question is will they? In the interim, read #2 and #4 here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all,
I am new to C# development.I have application in which i need to enable / disbale too many toolbar buttons based on the tree node selection,due to this my screens is flickering to a greater extnet...please suggest me a good approach through which i can avoid the screen flickering.
Thanks in advance.....
|
|
|
|
|
hariakuthota wrote: I am new to C#
Welcome in the C++ forum...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi,
I have a defined a function template as follows.
template<typename T, typename Function, typename K>
std::vector<K> find( std::vector<T> &a, Function _predicate )
{
std::vector<K> b(a.size());
//... some Code ..//
return(b);
}
which gives a compile error when i try to compile it using VC++
stating that it cannot deduce argument for parameter K.
I have attached the sample code below,
any suggestions from anyone?
Thank you
/********* File main.cpp **********/
#include <iostream>
#include "prog.h"
int main()
{
std::vector<int> a(10);
for( int i = 0; i < 10; i++)
{
a[i] = i;
}
std::vector<int> b = find( a, is_true<int>() );
for( int i = 0; i < 10; i++)
{
cout << "Value " << i << " : " << b[i] << endl;
}
}
#indef PROG_H_INCLUDED
#define PROG_H_INCLUDED
#include <vector>
//Function Predicate to check whether a value is true
template <typename T>
class is_true
{
public:
is_true()
{}
bool operator() (const T &element) const
{
if( element )
{
return true;
}
else
{
return false;
}
}
};
//Function Predicate to check whether a value is true
template <typename T>
class is_false
{
public:
is_false()
{}
bool operator() (const T &element) const
{
if( !element )
{
return true;
}
else
{
return false;
}
}
};
template<typename T, typename Function, typename K>
std::vector<K> find( std::vector<T> &a, Function _predicate )
{
std::vector<K> b(a.size());
for( int i = 0; i < a.size(); i++ )
{
if( _predicate(a[i]) )
{
b[i] = K(a[i]);
}
}
return(b);
}
#endif // PROG_H_INCLUDED
|
|
|
|
|
You cannot do that (as the message clearly states). An option would be making vector<K> an out argument, i.e. for instance:
template<typename T, typename Function, typename K>
void find( std::vector<T> &a, Function _predicate, std::vector <K> & v)
{
v.resize(a.size());
for( unsigned int i = 0; i < a.size(); i++ )
{
if( _predicate(a[i]) )
{
v[i] = K(a[i]);
}
}
}
and then
int main()
{
std::vector<int> b;
find( a, is_true<int>(), b );
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
C++ doesn't look at the return type when doing deducing types (or overload resolution for that matter), so you can't do what you want directly.
However, try defining find like this:
template<typename K, typename T, typename Function>
std::vector<K> find( std::vector<T> &a, Function _predicate )
{
}
and using it like this, specifying K explicitly:
std::vector<int> b = find<int>( a, is_true<int>() );
BTW - a better name for the function would be 'filter' or 'find_if' (IMNSHO)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
modified on Wednesday, October 14, 2009 2:45 PM
|
|
|
|
|
Hi All,
I am having a dialog based application and i want to add a status bar to the dialog.
Code Sample:
I have written this in the OnInitDialog:
CStatusBar status;
status.CreateEx((AfxGetMainWnd),SBARS_SIZEGRIP,WS_CHILD|WS_VISIBLE|CBRS_TOP));
When the dialog lunches there is no status bar!!!
Can anyone tell me what i am doing wrong!!!
Thanks,
hari
|
|
|
|
|
Hari_16 wrote: Can anyone tell me what i am doing wrong!!!
Well, first of all you've created the CStatusBar object on the stack so it will be destroyed when OnInitDialog returns.
You should have a look at this nice article[^] written by Nish. It will show you exactly how to do it.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hari_16 wrote: status.CreateEx((AfxGetMainWnd),SBARS_SIZEGRIP,WS_CHILD|WS_VISIBLE|CBRS_TOP));
This does not even compile. Read #5 here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
status.CreateEx((AfxGetMainWnd),SBARS_SIZEGRIP,WS_CHILD|WS_VISIBLE|CBRS_TOP);
I think you are referring to one extra parenthesis at the end right???
Sorry for that typo!!!
|
|
|
|
|
Hari_16 wrote: I think you are referring to one extra parenthesis at the end right???
That was one of the problems.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I know basic numbers conversion..but what about this number -16.735.. how to convert this real to binary?
first 8 bits if i am right are 0001000 than how continue conversion for 0.735??
Can i use c++ as help?
|
|
|
|
|
You need to do a bit or research.
How you convert it depends on what you want to do with the end result.
You can have fixed point binary fractions... So, first bunch of bits are the whole number, last bunch are (eg 8 bits) are 256ths. This is quite common in motor controllers, as it makes their fractions into slightly hard integers.
Or you can have a moving "binary" point, so the fraction is represented as: 1.xxxxx * 2^yyyy.
The 1. is not needed to be stored, as it always exists. How many bits you put to xxx's and how many to yyy's is variable. These are called mantissa and exponent , so have fun googling!
Try this:
float d = 1;
BYTE *by = (BYTE*)(&d);
d = 2;
d = 1.1;
d = 1.00001;
Now look at the memory d is stored in (using your debugger) and see how it changes when you put these different numbers in.
Short answer to your question: However you like!
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Aljaz111 wrote: I know basic numbers conversion
There's no such thing as number conversion. What you are talking about is converting from one representation (decimal) to another representation (binary). The number itself remains the same. So, your question is not clear: do you have a float and would like to print it's binary representation ? Is that what you are trying to do ? Do you want to learn how floating points number are encoded in binary ?
Please clarify your question.
|
|
|
|
|
Aljaz111 wrote: first 8 bits if i am right are 0001000
Probably no. Usually the sign is the very first bit and usually it is 1 for negative numbers...
Anyway as Iain & Cédric pointed out, your question, as it stands, make no much sense.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I want to present -16,735 in binary...how should i do it? Lets say manually on list of paper? As i know it goes like this:
1.first you must put 16,735 in binary..you get 00010000 , ...?
2.than you put comma behind 1 and you get exponent 4 so 2^4.
3.next you must read manttis..but how could i read manttis if i don't know how is 735 represented with 1 and 0??
4.we get exponent for 64-bit number 1024+4=1028(10) --> thats 0010 0000 0000 0100.
5. we change first bit to 1 and we get 1 0010 0000 0000 0100 ......? -->here same as in step 3. how to get binary from 0.735??
I hope i made myself clearly now.
When i typed in online numbering calc real number 0735 it gave me this binary..
10111100001010001111010111000010100011110101110000101
53 bits... too much as i think?
|
|
|
|
|
Not being sure that I understand exactly.
The floating point numbers are stored binary in memory already.
Assuming the system is little-endian and the number is 64 bit real and also according to IEEE 754;
double d = -16.735;
char *p = (char *)&d;
p[7] ... p[0]
if you convert 8 hex. digits to ascii-binary,
you' ll get binary representation of the number like below.
1100 .... 1100
if you want to, you can split it into parts.
First bit is sign, next 11 are biased exponent, others are mantissa without first (set) bit. You can also unbias the exponent. If you put a 1 in front of the last 52 bits, you will get the same long string of binary digits in your post for 0.735 same as with online number calculator.
As you may also want to know, there are also some functions (ANSI compatible, i think) in math library, (so <math.h> has to be included).
frexp() function - To split FP number into human readable (10 based) mantissa and exponent parts.
modf() function - To split it into fractional and integer parts.
|
|
|
|
|
Hi,
the easiest way probably is like this for converting val to (sign,exp,mant):
0. threat special values separately (mainly zero); for others do:
1. sign=0;
2. if (val<0) {sign=1; val=-val;}
3. exp=0;
4. while (val>=1) {exp++; val/=2;}
5. while (val<0.5) {exp--; val*=2;}
6. now val is in [0.5,1); we assume you want M bits for mantissa, then:
7. val*=1<<m;
8. mant="(int)val;" this="" will="" give="" exactly="" m="" bits
possible="" deviations:
-="" the="" exponent="" may="" be="" biased="" (e.g.="" always="" add="" 0x80)
-="" step="" 8="" perform="" rounding="" instead="" of="" truncation
-="" 7="" and="" act="" as="" if="" is="" one="" more,="" then="" drop="" highest="" bit="" (as="" it="" set)
=""
<div="" class="ForumSig">Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Is it -16.735 or -16,735?
-16.735 = -10000.1011110000101000111101011100001010001111010111
-16,735 = -100000101011111
The general procedure is to do integer and fraction part separately.
For integer part N :
1. If N is not zero, divide N by 2
2. If remainder is 1 write down 1, if its 0 write down 0
3. N = N/2 - remainder. Go back to Step 1.
Finally, write the 0 and 1 in reverse order.
Example, N = 40
1. 40/2 = 20. Remainder = 0. Write 0
2. 20/2 = 10. Remainder = 0. Write 0
3. 10/2 = 5. Remainder = 0. Write 0
4. 5/2 = 2 + 1/2. Remainder = 1/2. Write 1
5. 2/2 = 1. Remainder = 0. Write 0
6. 1/2 = 0 + 1/2. Remainder = 1/2. Write 1
Threfore, 40 = 101000
For fraction part F,
1. If F is not zero, Multiply F by 2.
2. If result is greater than or equal to 1, write down 1. F = (F * 2) - 1
3. If result is not greater than 1, write down 1. F = (F * 2)
4. If F > 0 go back to step 1.
Example, F = 0.25
1. 0.25 * 2 = 0.5. Write down 0
2. 0.5 * 2 = 1. Write down 1
Thus 0.25 = 0.01
|
|
|
|
|
Hello,
I have already implemented that my application starts when a file associated with it is doubleclicked in explorer. However, this only works when my program does not run when the doubleklick happens. It then opens the associated file.
I want to implement the same behaviour when my application is already running, i.e. my app is up and waiting, and someone doubleclicks a file associated with it. What's the best way to get that message in my application?
|
|
|
|
|
What currently happens if you double-click a file within Explorer and your app is already running? Does a second instance come up?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Sorry, of course I should have mentioned this before: my application is dialog-based, and it is a single-instance application already. That means I use Findwindow when I start my program, and if I find another instance of it running I quit. Instead, I should post some kind of message telling the running instance that I want to open a file instad, this is what I haven't figured out yet.
|
|
|
|