The only other method to count 1 to 1000 is using recursion. According to C language, j has ‘1’as its value at the beginning. When 1 <= j < 1000, &main + (&exit - &main)*(j/1000) always evaluated to &main, which is the memory address of main. (&main)(j+1) is the next iteration we want to get, which would print ‘2’ on the screen, etc. The stop condition of this recursion is that When j hits 1000, &main + (&exit - &main)*(j/1000) evaluates to &exit, which will elegantly exit this process, and has the error code 1001 returned to the operating system.
is evaluated each time thus: &exit - &main is the offset from the start of main to the start of exit j/1000 will evaluate to zero for all vaules of j less than 1000
Multiplying those two values together gives zero if j is less than 1000.
Add that to &main (the address of main) and you get the same address, so main gets called with the parameter value j+1.
This continues until the value of j reaches 1000 at which time: j/1000 results in the value 1
That is multiplied by the offset of exit which returns that offset.
Add that value to main and the next call will go to exit rather than main.
I have an application developed in non-CLR C++ (unmanaged) in VS2003 (or earlier) but working with VS2005 after some converting. Note that I didn’t do that converting.
My employer decided to update the code to CLR VS2010 for easier maintenance. I am a C# programmer and haven’t done C++ for a while and not within VS so I’m not the most skilled in this task.
I’ve set it to CLR and corrected the errors and most of the warnings, but I’m having a problem with some image resources in the Form1.resX file (took me a while to even figure out that the resources were IN that .resx file I can see them in there and the Form [Design] editor can see the resource and paints the image as a background for its tab:
The resX file is version 1.3 of the schema or so it says rather than the 2.0 that a newly created windows forms application has but seems OK otherwise.
Microsoft ResX Schema
The resource looks something like this:
So the call seems correctly formed and it’s good enough for the design editor inside Visual Studio. But when you run it you get an error:
An unhandled exception of type
'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "PRG.Form1.resources" was correctly embedded or linked into assembly "PRG" at compile time, or that all the satellite assemblies required are loadable and fully signed.
As you can see, the culture is neutral so the fact that there is no culture in the call seems right. I tried deleting the culture tag from the resource entirely but that had no effect. I don’t know quite what the program wants me to do in order to get this image to come up in the running application. I wondered if anyone has an idea of what I might try next.
Just wanted to add the line that connects the resource file to the form because i'm thinking that could be a problem but I don't know quite how.
Create an STL vector of 10 integers and store initial values (0 to 9 is fine).
Use the std::random_shuffle algorithm to shuffle the list.
Print the list. (try to do this one with an std iterator)
Use the std::sort algorithm to sort the list.
Print the list again. (you can use for each instead of an iterator)
See if you can locate the documentation for random_shuffle and sort either in VS help or with Google. Once you leave this class, you will need to be able to find information like this on your own.
1. Did NOT create a folder for the solution
2. Project/solution named correctly
3. Correct comments at top
4. Consistent indentation
5. Good variable names
6. Overall neat organization
7. Comments in code explain what's being done
8. Correct division of code into .h and .cpp files
9. Use of #pragma once in .h files (or, #ifndef)
10. #include "stdafx.h" in cpp files (or, suppress pch)