|
1980soyo wrote: I'm trying to load picture which size is 256x256, but when I use DrawImage, the picture that is drawn within the client area is larger(about 30%).
Just a little ?, Do u know GDI+ library is very heavy,if you loading general FORMAT like jpeg,gif etc, then you can try your HAND in IPicture Interface, which provide light way to Display picture in your Program!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I wrote on example from Graphic for you but I suggest if you need to open jpeg file and draw use CImage
whitesky
|
|
|
|
|
Hi guys,
i need some help, how can i make that the user not be able to undock the toolbars from the mainframe?
thanks in advance...
|
|
|
|
|
Removing the CBRS_GRIPPER style from the toolbar should do it.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
or remove this function DockControlBar(&m_wndToolBar);
whitesky
|
|
|
|
|
Kleser wrote: i need some help, how can i make that the user not be able to undock the toolbars from the mainframe?
pass 0 as parameter in CControlBar::EnableDocking function!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
hi; I need your help to create a program which can connect 2 modems and send & receive some data with using phone line.
A.H.M 834
|
|
|
|
|
|
Hello
I have writen this in C++ (using the compiler Visual C++ 2005 Express Edition). I am now having some trouble with calculations. I want to work out each sample scores variance (which is used in statistics). I have a bunch of scores that hte user inputs and I can work out the average, that is the program will do that part, but when it comes to working variance the answers are wrong. The variance is worked out like this - each score minus the mean, to the power of two (or times by itself), all these scores then have to be divided by the Number of scores that are in the sample. The program cannot calculate this. For example, there are 2 scores, 1st score = 5, 2nd score = 4; it works out the mean (average) okay which is the total of all the scores divided by the number of scores in the sample. It gets very close to figuring the right amount for the variance, but not quiet. Please help me figure out where I've gone wrong. Thank You in advance. Here is my code:
#include <iostream>
using namespace std;
int main(void)
{
float M, N, total, score1, score2, score3, score4, score5, score6, score7, score8, V1, V2, V3, V4, V5, V6, V7, V8, s1, s2, s3, s4, s5, s6, s7, s8, Variance;
cout << "Input the number of people in sample ";
cin >> N;
cout << "input the 1st score ";
cin >> score1;
cout << "input the 2nd score ";
cin >> score2;
cout << "input the 3rd score ";
cin >> score3;
cout << "input the 4th score ";
cin >> score4;
cout << "input the 5th score ";
cin >> score5;
cout << "input the 6th score ";
cin >> score6;
cout << "input the 7th score ";
cin >> score7;
cout << "input the 8th score ";
cin >> score8;
total = score1 + score2 + score3 + score4 + score5 + score6 + score7 + score8;
M = total / N;
cout << "the mean for these scores is: " << M << "\n";
s1 = (float) score1 - M;
V1 = (float) s1 * s1;
s2 = (float) score2 - M;
V2 = (float) s2 * s2;
s3 = (float) score3 - M;
V3 = (float) s3 * s3;
s4 = (float) score4 - M;
V4 = (float) s4 * s4;
s5 = (float) score5 - M;
V5 = (float) s5 * s5;
s6 = (float) score6 - M;
V6 = (float) s6 * s6;
s7 = (float) score7 - M;
V7 = (float) s7 * s7;
s8 = (float) score8 - M;
V8 = (float) s8 * s8;
cout << "the variance for these scores is: " << (float) (V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8) / N << "\n";
return 0;
}
linda
|
|
|
|
|
What do you mean by not quite? If what you have is a sample, are you supposed to divide by N and not N - 1?
|
|
|
|
|
Hi
thanks, what i mean by quet is that sometimes it will give the answerr that is close to the answer and tother times the answer is way off. I do not know what to do. I want to calculate the variance of a single sample thus it is /N, /N-1 is only used in test that have two sets of samples.
Thanks
linda
|
|
|
|
|
How much is the difference between what you are expecting and the value you are getting?
Two things could be happening here.
First, floating point numbers are only represented approximately. A float value in this case is represented in 32 bits: 24 bits for a signed mantissa, and 8 bits for a signed exponent if I remember right. This means that when the user enters "5.0", for example, the closest internal representation might actually be the value 4.999998. This introduces one type of difference.
Secondly, you are using float variables for your calculations. The maximum precision you will see in calculations using float is the value of the FLT_EPSILON constant found in math.h. For VC++, this constant has the value 1.192092896e-07F , which basically means that using float values the best precision you can get is around 7 decimal places. Practically speaking, you can probably expect 5 or 6 decimal places with your program.
One thing to try is to change all of your float values to double values. The double type is represented in 64 bits, with correspondingly higher precision.
A side note: toward the end of your code, you've got statements like this:
s8 = (float)score8 - M;
V8 = (float)s8 * s8; The (float) cast's aren't necessary. The compiler already knows that all of the variables in the statements are of type float .
Software Zen: delete this;
|
|
|
|
|
Hi
Thanks for your reply. I have insert double instead of float but I still get the same mistakes. he mistakes sometimes are way off from the true answer, so onlsy sometimes are they close to the answer. In this case the answer came back way off again, by about 40! Anyway, I am sure my logic is correct so it mst be the code somehow. Please help.
Here is my code:
#include <iostream>
using namespace std;
int main(void)
{
double M, N, total, score1, score2, score3, score4, score5, score6, score7, score8, V1, V2, V3, V4, V5, V6, V7, V8, s1, s2, s3, s4, s5, s6, s7, s8, Variance;
cout << "Input the number of people in sample ";
cin >> N;
cout << "input the 1st score ";
cin >> score1;
cout << "input the 2nd score ";
cin >> score2;
cout << "input the 3rd score ";
cin >> score3;
cout << "input the 4th score ";
cin >> score4;
cout << "input the 5th score ";
cin >> score5;
cout << "input the 6th score ";
cin >> score6;
cout << "input the 7th score ";
cin >> score7;
cout << "input the 8th score ";
cin >> score8;
total = score1 + score2 + score3 + score4 + score5 + score6 + score7 + score8;
M = total / N;
cout << "the mean for these scores is: " << M << "\n";
s1 = score1 - M;
V1 = s1 * s1;
s2 = score2 - M;
V2 = s2 * s2;
s3 = score3 - M;
V3 = s3 * s3;
s4 = score4 - M;
V4 = s4 * s4;
s5 = score5 - M;
V5 = s5 * s5;
s6 = score6 - M;
V6 = s6 * s6;
s7 = score7 - M;
V7 = s7 * s7;
s8 = score8 - M;
V8 = s8 * s8;
cout << "the variance for these scores is: " << (double) (V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8) / N << "\n";
return 0;
}
linda
|
|
|
|
|
1. You should initialize your variables score1 through score8 to 0.0.
2. Even though you let the user enter N , the number of samples, your calculation for the mean M and the variance assumes that all 8 scores are used. This means that the user must enter 0.0 for any scores greater than or equal to N for the calculations to work correctly.
Software Zen: delete this;
|
|
|
|
|
Hi
Thanks for your help. How do I initilize these variables, I am very new to this. So, this will only work for certain scores? Like, if I input a score that is higher then the mean then the variance will not work? (is that what you meant at the end?). How would I get it to work for all scores then, is there any special way or code I can use to fix this?
Thanks once again.
Much appreciated.
linda
|
|
|
|
|
using namespace std;
int main(void)
{
double M, N, total, score1, score2, score3, score4, score5, score6, score7, score8,
V1, V2, V3, V4, V5, V6, V7, V8, s1, s2, s3, s4, s5, s6, s7, s8, Variance;
score1 = 0.0;
score2 = 0.0;
score3 = 0.0;
score4 = 0.0;
score5 = 0.0;
score6 = 0.0;
score7 = 0.0;
score8 = 0.0;
cout << "Input the number of people in sample ";
cin >> N;
cout << "input the 1st score ";
cin >> score1;
cout << "input the 2nd score ";
cin >> score2;
cout << "input the 3rd score ";
cin >> score3;
cout << "input the 4th score ";
cin >> score4;
cout << "input the 5th score ";
cin >> score5;
cout << "input the 6th score ";
cin >> score6;
cout << "input the 7th score ";
cin >> score7;
cout << "input the 8th score ";
cin >> score8;
total = score1 + score2 + score3 + score4 + score5 + score6 + score7 + score8;
M = total / N;
cout << "the mean for these scores is: " << M << "\n";
s1 = score1 - M;
V1 = s1 * s1;
s2 = score2 - M;
V2 = s2 * s2;
s3 = score3 - M;
V3 = s3 * s3;
s4 = score4 - M;
V4 = s4 * s4;
s5 = score5 - M;
V5 = s5 * s5;
s6 = score6 - M;
V6 = s6 * s6;
s7 = score7 - M;
V7 = s7 * s7;
s8 = score8 - M;
V8 = s8 * s8;
Variance = (V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8) / N;
cout << "the variance for these scores is: " << Variance << "\n";
return 0;
} My modifications are highlighted in bold .
To give you another view, here is how I would do this:
int main(void)
{
int N = 0;
double score[8];
for (int i = 0; i < 8; i++) score[i] = 0.0;
cout << "Enter number of people in sample [1-8] ";
cin >> N;
if ((N > 0) && (N <= 8)) {
double total = 0;
for (int i = 0; i < N; i++) {
cout << "Enter score " << (i + 1) << " ";
cin >> score[i];
total = total + score[i];
}
double mean = total / (double)N;
double variance = 0.0;
for (int i = 0; i < N; i++) {
variance = variance + ((score[i] - mean) * (score[i] - mean));
}
variance = variance / (double)N;
cout << "Variance is " << variance;
}
else {
cout << "Incorrect number of samples.";
}
} First, instead of having 8 discrete variables score1 through score8 , I use an array. This makes it easier to step through each value using a for loop. Next, I initialize the score array, even though the logic doesn't strictly require it; it's just good practice to always initialize your variables. I then prompt the user for the number of samples. Note that I tell them the range of values that they may enter, e.g. the [1-8] . The if statement ensures that the number they enter is valid; if not, they get an error message. This is an example of a fundamental principle: always validate input from a user. The for loop that follows prompts them for N samples. Note that I compute the 'total' of the scores as the user enters them. I then compute the mean of the scores after the for loop. The next for loop computes the sum of the squares of the deviation values, and the statements after the for computes and outputs the variance.
Taking a guess, it sounds like this is one of your very first programs. My first program was something similar; let the user enter three test scores, and print the average. My intention in posting my alternative was not to do your homework for you, but to give you an example to think about.
Good luck.
Software Zen: delete this;
|
|
|
|
|
Hi
Thanks so much for all this help, it is much appreciated. This is my first program, good guess! I would like to eventually work out some more things but I think I must hit the books about it before that will happen, very much lacking in knowledge. Thank you all for all your help regarding this problem.
:->
linda
|
|
|
|
|
Just one more question.
This 0.0 declaration works well now it will work out the variance but only if all scores are input, what if you only have 2 scores, how do you leave the other fields blank.
Thanks
linda
|
|
|
|
|
My alternative handles this case.
You could place an 'if ' around each prompt, something like this:
if (N >= 3) {
cout << "Enter score 3 ";
cin >> score3;
}
if (N >= 4) {
cout << "Enter score 4 ";
cin >> score4;
} Doing that, you only prompt for and read in the number of scores that you need.
Software Zen: delete this;
|
|
|
|
|
First use double not float. Second lose the (float) cast: the fact that a C-style cast is used at all in a C++ program is bad enough (not everyone agrees with this; the ones that don’t are wrong!) but score1 is already a float anyway.
Steve
|
|
|
|
|
Can you provide with a sample input data and expected mean and variance. I can't see anything wrong in the code. Only thing I can think of is you are computing biased variance in the code but true answer with which you are comparing with might be un-biased variance. See here[^] for more information about variance.
-Saurabh
|
|
|
|
|
Hi, I really appreciate your help here. The variance is worked out like the first example that you redirected my browser to regarding variance (the website about it). Example: Numberofscores(N)=2, score1=2, score2=5, all the other scores are input as 0 (seeing there is no scores). The mean is worked out as 2 + 5 / 2 = 3.5 (the program will do this calculation). Variance is worked out like this: (score1 - Mean) to the power of 2 + (score2 - Mean) to the power of 2 / 2 (N). I did not know what power was in C++ so I times it by itself. I think maybe there is something wrong with the compiler I am using as it will not recognise some commands. It does not return any errors but the calculations are wrong for the variance.
Here is my code:
#include <iostream>
using namespace std;
int main(void)
{
double M, N, total, score1, score2, score3, score4, score5, score6, score7, score8, V1, V2, V3, V4, V5, V6, V7, V8, s1, s2, s3, s4, s5, s6, s7, s8;
cout << "Input the number of people in sample ";
cin >> N;
cout << "input the 1st score ";
cin >> score1;
cout << "input the 2nd score ";
cin >> score2;
cout << "input the 3rd score ";
cin >> score3;
cout << "input the 4th score ";
cin >> score4;
cout << "input the 5th score ";
cin >> score5;
cout << "input the 6th score ";
cin >> score6;
cout << "input the 7th score ";
cin >> score7;
cout << "input the 8th score ";
cin >> score8;
total = score1 + score2 + score3 + score4 + score5 + score6 + score7 + score8;
M = total / N;
cout << "the mean for these scores is: " << M << "\n";
s1 = score1 - M;
V1 = s1 * s1;
s2 = score2 - M;
V2 = s2 * s2;
s3 = score3 - M;
V3 = s3 * s3;
s4 = score4 - M;
V4 = s4 * s4;
s5 = score5 - M;
V5 = s5 * s5;
s6 = score6 - M;
V6 = s6 * s6;
s7 = score7 - M;
V7 = s7 * s7;
s8 = score8 - M;
V8 = s8 * s8;
cout << "the variance for these scores is: " << (double) (V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8) / N << "\n";
return 0;
}
linda
|
|
|
|
|
Notice that if score3 to score8 is 0, the values for V3 to V8 is (0 - 3.5)^2 and you use these in your calculation for variance.
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
vector<double> scores;
double score;
double mean;
double total = 0;
double variance = 0;
int numberOfPeople;
cout << "Input the number of people in sample: ";
cin >> numberOfPeople;
for(int n = 0; n < numberOfPeople; n++)
{
cout << "Input the score for person " << n+1 << ": ";
cin >> score;
scores.push_back(score);
total += score;
}
mean = total / numberOfPeople;
cout << "The mean for these scores is: " << mean << "\n";
for(int n = 0; n < numberOfPeople; n++)
{
double temp = scores[n] - mean;
variance += temp * temp;
}
variance /= numberOfPeople;
cout << "The variance for these scores is: " << variance << "\n";
return 0;
}
|
|
|
|
|
Hi there
Thanks for that
I appreciate your code, it is good.
I think I need to study some more before attempting to write calculations like this
linda
|
|
|
|
|
Oh I got it now, your code is correct but you are using it incorrectly. You have written code for computing variance of 8 numbers but you are trying to use it for only two numbers. Let me explain.
Code for mean is M = (s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8) / N;
when you give N =2, s1 = 2, s2 = 5 and rest equal to zero.
mean becomes M = (s1 + s2 + 0 + 0 + 0 + 0 + 0 + 0) / N = (s1 + s2) = N
which is correct so mean is computed correctly.
Code for variance is [(s1-M)*(s2-M) + (s1-M)*(s2-M) + ... + (s8-M)*(s8-M)] / N. Now when you give N =2, s1 = 2, s2 = 5 and rest equal to zero. Variance becomes [(s1-M)*(s2-M) + (s1-M)*(s2-M) + (0-M)*(0-M) + ... + (0-M)*(0-M)] / N which is not what you want. Correct formula for variance of two numbers is [(s1-M)(s1-M) + (s2-M)(s2-M)]/2.
I hope this helps.
-Saurabh
|
|
|
|
|