|
Thank you for your explanation. Now I know more ( about casts) and therefore I am more dangerous to myself.
I guess in the case of BITMAP the LPVOID pointer could have been just char *
since it points to byte array anyway. But it makes it more challenging for weekend programmers like me.
Thanks again
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: the LPVOID pointer could have been just char *
Yes but I think this is to allow a general structure which can contain a pointer to any format of bitmap in the future and not just a simple BYTE array.
It's time for a new signature.
|
|
|
|
|
what if you wanted to put this in to a bitfield. I have a bit map that has one bit per pixel and measures 7x70
|
|
|
|
|
Sorry, I'm not sure I understand your question.
I must get a clever new signature for 2011.
|
|
|
|
|
I have a binary (monochrome) bitmap that is 70x7 pixels would like to put it in an array that is 70x7 as binary. I know that bit fields would be a good choice. ie:
struct
{
unsigned byte d0:1;
unsigned byte d1:1;
unsigned byte d2:1;
unsigned byte d3:1;
....
} test
|
|
|
|
|
how would you cast this pointer to a bit field?
ie:
struct 7bitfield
{
unsigned byte d0:1;
unsigned byte d1:1;
unsigned byte d2:1;
unsigned byte d3:1;
unsigned byte d4:1;
unsigned byte d5:1;
unsigned byte d6:1;
} 7bits;
The reason for asking is I have an monochrome bitmap that is 70x7 and need to retrieve the data as an array of 1's and 0's. These will be used to control the on/off state of an led display.
Thanks
|
|
|
|
|
Are you saying that the fields are packed, such that the second field starts at the last bit of the byte containing the first field and so on? Something like:
byte0 + byte1 + byte2 +
01234567|01234567|01234567|01234567
01234560123456012345601234560123
00000001111111222222233333334444 - pixel numbers
In this case you would probably need to use a BYTE pointer and adjust it manually as you traverse the array.
I must get a clever new signature for 2011.
|
|
|
|
|
Adding ButtonsGroup with subbuttons to RibbonStatusbar. the buttongroup's button have showed images,but subbuttons didn't.here is my code, It was so surprising to me.
std::auto_ptr<CMFCRibbonButtonsGroup> apSBGroup(new CMFCRibbonButtonsGroup);<br />
<br />
CMFCToolBarImages images1;<br />
images1.SetImageSize(CSize(16, 16));<br />
images1.Load(IDB_TOOLBAR_SNAPTOOL);<br />
<br />
apSBGroup->SetImages(&images1, NULL, NULL);<br />
apSBGroup->SetID(ID_GROUP_SNOP);<br />
<br />
apSBGroup->AddButton(new CMFCRibbonButton(ID_DYNA, NULL, 0));<br />
<br />
std::auto_ptr<CMFCRibbonButton> pBtSnopPt(new CMFCRibbonButton(ID_HEAD, NULL, 5));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_HEAD, NULL, 5));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_CENTER, NULL, 6));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_CROSS, NULL, 7));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_LIMIT, NULL, 8));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_PEAK, NULL, 9));<br />
pBtSnopPt->AddSubItem(new CMFCRibbonButton(ID_ON, NULL, 10));<br />
apSBGroup->AddButton(pBtSnopPt.release());<br />
<br />
std::auto_ptr<CMFCRibbonButton> pBtPopCoor(new CMFCRibbonButton(ID_NUMBER, NULL, 11));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_NUMBER, NULL, 11));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_THREEOK, NULL, 12));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_THREE, NULL, 13));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_GRID, NULL, 14));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_RELATEXY, NULL, 15));<br />
pBtPopCoor->AddSubItem(new CMFCRibbonButton(ID_NEWOXOY, NULL, 16));<br />
apSBGroup->AddButton(pBtPopCoor.release());<br />
<br />
m_wndRibStatusBar.AddExtendedElement(apSBGroup.release(), _T(""));<br />
|
|
|
|
|
Greetings.
I need to write a function that has the following interface:
double average (int size, double values []);
The function should return the average of the first size values in the array values.
Here's an example of what I need to accomplish.
Enter number of values to be input : 5
Enter item 1 : 22.3
Current average is 22.3.
Enter item 2 : 54.2
Current average is 38.25.
Enter item 3 : 74
Current average is 50.1667.
Enter item 4 : 83.1
Current average is 58.4.
Enter item 5 : -90.
Final average is 28.72.
|
|
|
|
|
What have you done yet to try to solve this _very_ simple school problem ? did you even try to write some code for it ? or were you expecting someone else to do it for you ?
anyway, should be quite easy with a simple loop, a couple of std::cin and std::cout , an accumulator, a counter, * and / ...
I'm certain if you try to do it by yourself, you will be so proud that you will feel ashame to even have posted this question.
M.
Watched code never compiles.
|
|
|
|
|
Since the question is just to write a function, NO, I didn't try to run a program.
I Think the answer to this is:
Double average (int size, double values []);
{return (a);} {return (a + b) / 2;} {return (a + b + c) /3;} {return (a + b + c + d / 4;}
{return (a + b + c + d + e / 5;}
I really don't have a clue what I'm doing so I'm winging it to say the least. I'm thinking the above is in the ball park because in my text book, there's a program called Average.c that goes like this:
#include <stdio.h>
double average (double a, double b);
int main(void)
{
double x, y, z;
printf("Enter three numbers: ");
scanf("%1f%1f%1f", &x, &y, &z);
printf("average of %g and %g: %g\n", x, y, average (x, y));
printf("average of %g and %g: %g\n", x, y, average (y, z));
printf("average of %g and %g: %g\n", x, y, average (x, z));
return 0;
}
double average (double a, double b)
{
return (a + b) / 2;
while(1);
}
Am I in the ball-park for the function part???
Oh ya, I have no idea what Maximilien was talking about with all the
"simple loop, a couple of std::cin and std::cout , an accumulator, a counter, * and / ..." Sounds like what adults sound like on Peanuts cartoons.
|
|
|
|
|
Tim Dappen wrote: I really don't have a clue what I'm doing
So maybe some time with your text books would be time well spent.
It's time for a new signature.
|
|
|
|
|
Don't you want to use a std::vector to hold the numbers entered by the user?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
no need to keep an history of the input, just "accumulate" and divide by the count (number of inputs).
Watched code never compiles.
|
|
|
|
|
Maximilien wrote: no need to keep an history of the input, just "accumulate"...
accumulate() has to have an array of some sort to work with.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
If he's that clueless, he's not ready for templates.
Once you agree to clans, tribes, governments...you've opted for socialism. The rest is just details.
|
|
|
|
|
The basic idea is simple: keep a running total and a count of the number of numbers entered. After each number is entered the average is the total divided by the number of numbers entered.
Steve
|
|
|
|
|
One thing to remember when doing programming assignments: Accademic computer scientists love recursion. You should try and introduce it to everything you do. So the best way to implement the function you're trying to write is:
double sum_array( int size, double values[] )
{
if( size > 0 ) return values[0] + sum_array( size - 1, values + 1 );
return 0;
}
double average( int size, double values[] )
{
return sum_array( size, values ) / size;
}
Another cool thing is that the solution doesn't have any side effects so it's pure within the mathematical idea of a function and the CS ideas of functional programming.
You can test it with something like:
int main()
{
double values[ 10 ] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
std::cout << average( 10, values ) << std::endl;
}
The I/O should be easy to sort out.
Cheers,
Ash
|
|
|
|
|
Aescleal wrote: Accademic computer scientists love recursion.
They do seem to. I'm not the biggest fan myself.
Steve
|
|
|
|
|
I prefer divide and conquer:
double sum(std::size_t size, double values[]) {
if (0==size)
return 0.0;
else
return sum(size/2, values) + sum(size-size/2, values+size/2);
}
double average(std::size_t size, double values[]) {
return sum(size, values)/size;
}
Of course, if your goal is to repeatedly calculate the 'running average' of a stream of numbers, a more efficient implementation might look like this:
double incremental_average(double pre_avg, std::size_t new_size, double new_value) {
if (new_size > 1)
return (new_value + pre_avg*(new_size-1))/new_size;
else
return new_value;
}
int main () {
double values[] = {3.5, 5, 7, -2, 3.14, 2.71, 6, 7, 8, 9};
double avg = 0;
for (std::size_t i = 0; i < sizeof(values)/sizeof(double); ++i) {
avg = incremental_average(avg, i+1, values[i]);
std::cout << "average[" << i+1 << "] = " << avg << std::endl;
}
}
modified on Tuesday, September 28, 2010 8:52 AM
|
|
|
|
|
Hi everyone, I want to write an application that can analyse data given in grids like those in Excel. I want to write the application in the Win32 API. How can I add such grid tools in this application? Does using this tool require learning other API before doing it? I will also be glad if I am directed to tutorials and documentations about doing this. Thanks.
|
|
|
|
|
|
I do not know MFC, and going into it means possibly learning another language, although it is in C++. Please do you have any idea of how I can write one on my own if there are no other ways. Brief ideas and sources will be appreciated. Thanks.
|
|
|
|
|
how much effort it needs and LOC it takes to develop such a control in plain win32 without using MFC, just guess.
|
|
|
|
|
I would probably write the GUI in .NET and if you need any high performance calculation, then implement this in a standard unmanaged dll.
|
|
|
|
|