|
I'm working on setting up a menu to choose which type of sort is wanted, as well as how many numbers in the array, and the numbers for the array.
Trying to figure out how to get my values into the array isn't going according to the examples in the book. I could really use help!
I've pasted my code below.
Thank you!
#include <iostream>;
using namespace std;
// Function prototypes
void selectionSort(int [], int);
void showArray(int [], int);
void sortArray(int [], int);
void showMenu ();
void displayName();
void numberOfValues(int);
void enterValues(int);
int main()
{
int choice; // To hold a menu choice
// Find out the type of sort wanted
do
{
// Display the menu and get the user's choice.
showMenu();
cin >> choice;
if (choice != 3)
{
if (choice = 1)
numberOfValues(int numbers);
enterValues();
sortArray(int [], int);
else if (choice = 2)
numberOfValues(numbers);
enterValues();
selectionSort();
}
}
}while (choice !=3);
Return 0;
}
}
//**************************************************************
// Definition of function selectionSort. *
// This function performs an ascending order selection sort on *
// array. size is the number of elements in the array. *
//**************************************************************
void selectionSort(int array[], int size)
{
// Display the values.
cout << "The unsorted values before the first selection pass are:\n";
cout << "\t\t\t ";
showArray(values, SIZE);
int startScan, minIndex, minValue;
int x = 1;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = array[startScan];
for(int index = startScan + 1; index < size; index++)
{
if (array[index] < minValue)
{
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minValue;
cout << "After pass #" << x << " the values are ";
showArray(array, index);
x = x + 1;
// Display the values again.
cout << "The final sorted values for this selection sort are:\n";
cout << "\t\t\t ";
showArray(array, SIZE);
}
// Display the values.
cout << "The unsorted values before the first bubble pass are:\n";
cout << "\t\t\t ";
showArray(array, SIZE);
sortArray(array, SIZE);// Sort the values.
// Display them again.
cout << "The final sorted values for this bubble sort are:\n";
cout << "\t\t\t ";
showArray(array, SIZE);
//return 0;
}
//***********************************************************
// Definition of function sortArray *
// This function performs an ascending order bubble sort on *
// array. size is the number of elements in the array. *
//***********************************************************
void sortArray(int array[], int size)
{
bool swap;
int temp;
int x = 1;
do
{
swap = false;
for (int count = 0; count < (size - 1); count++)
{
if (array[count] > array[count + 1])
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
}
}
cout << "After pass #" << x << " the values are ";
showArray(array, 6);
x = x + 1;
} while (swap);
}
//*************************************************************
// Definition of function showArray. *
// This function displays the contents of array. size is the *
// number of elements. *
//*************************************************************
void showArray(int array[], int size)
{
for (int count = 0; count < size; count++)
cout << array[count] << " ";
cout << endl;
}
void showMenu ()//choose type of sort to do
{
cout << "What would you like to do?\n";
cout << "\t1\tBubble Sort\n";
cout << "\t2\tSelection Sort\n";
cout << "\t3\tQuit\n";
cout << "Enter your selection:\n";
cin >> selection;
}
void displayName()
{
cout << "This program was created by Laura Sullivan.\n";
}
void numberOfValues(int numbers)
{
int numbers; //size of array
cout << " How many values do you want in the array (enter 6, 7, 8, 9 only):\n";
cin >> numbers;
}
void enterValues()
{
int numbers; //size of array
const int SIZE = numbers;
int values[SIZE] = {numbers};
cout << "Enter your values (0 through 9), with a space between each value:\n";
cin >> values[numbers];
}
|
|
|
|
|
Do you know that equality test operator is == (while = is the assignment operator)?
BTW use <pre> tags to enclose code snippets, for instance:
<pre>
</pre>
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.
[my articles]
|
|
|
|
|
Hello everyone!
Miss me? No? Aww.
Anyway, I'm trying to make a very simplistic Paint clone. I have a question: I trap mouse drawing with WM_MOUSEMOVE. However, it draws in dots, as in, if I want a doodle I have to go very slowly. How would I fix this? Maybe interpolating; drawing a line between the previous and current dots? But that would be very squareish...
Can somebody fill me with their wisdom so I can figure this out? Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Windows does not send the application a WM_MOUSEMOVE message for each pixel the mouse pointer passes on, hence you have to deal with a discrete set of disconnected points. You can either (as you realized) connect them with straight lines the obtained point or use some curve (for instance splines) to make the path appear smoother.
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.
[my articles]
|
|
|
|
|
I'll try the straight line then and then the curved one, if it doesn't look good. Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Hi
One for the hardcore coders ..
I would like to display a window in a VC++ app that is a web view, in that the source for the view is a .SVG file (the Web XML vector graphics format).
BUT .. I need to be able to interact with the view from the C++ code - I need to modify the colour of certain parts of the picture (tagged appropriately in the SVG file). The colours may change dynamically, depending on other parts of the program.
Anyone done anything like this ?
cheers,
Neil
|
|
|
|
|
I've been dealing with SVGZ files (the compressed version of SVG) for the last couple of weeks. From what I've seen, there's very little in the way of libraries that support displaying SVG or SVGZ data directly in a window.
Adobe has a thing called Adobe SVG Viewer that might be of some help to you. Be warned, however. They have discontinued support for it.
It appears that most people's interest is in adding support for SVG to various web browsers. It's indirect, but you might investigate hosting the browser in a window, which then hosts the SVG.
My interest was quite limited (I have some static SVG's I need to display), so I ended up using Adobe Illustrator to convert the SVGZ files to enhanced metafiles and displaying those. I don't know how difficult it is, but that might be another option for you. Here's[^] an article in the MSDN on metafiles to get you started.
|
|
|
|
|
Thanks for that.
I am going to try the ActiveX adobe.svgctl for the moment, and see if I can figure out how to do the necessary directly from VC++. I'll post again if I get it working!
cheers,
Neil
|
|
|
|
|
Hi,
I ahve a problem with one of my Doc-View Application. In fact, I am novice in doc-view apps. I have a CFormView based SDI app coded in Visual C++ 6.0 environment. The user interface has three modeless dialogs embedded in a CTabCtrl, One ChartCtrl and CListCtrl. I observed a funny behaviour while opening a stored document (not Word document) by double clicking on it. The view is not getting updated correctly. But if I open the the file by File-> Open command, every thing working fine.
Let me explain a bit about how I coded the app for better comprehension.
1. The document has a user defined class which handles the serialization on its own (based on Ravi Bhavnani code).
2. The List control paints its contents using NMCustomDraw feature.
3. By digging into the code I could find that OnNewDocument() function is not getting called while opening tha App from Shell (i.e. by double clicking on the file), instead the OnOpenDocument() is called. And all other Doc->DeleteContents() and Serailization, View->IntialUpdate() and View->OnUpdate() working OK but the List Control not getting updated.
4. But if you open the file by File ->Open command, since the SDI app gets started with a new document every thing looks OK.
5. Same is the case by opening with command line Start-> Run-> MyApp xyz.tnf .
6. I found even the OnCustomDraw() function getting called.
7. I then tried to get into the undocumented DocManager classes etc. but I couldn't get much help. Even opening file from the Shell, I find App gets one empty document. This I got confirmed with DocManager class other functions.
Finally what I could find is that, the View and Document connection in the low level framework is at fault.
I would be grateful for any help in this regard.
I remain,
Shanmukha
|
|
|
|
|
Updated:
I add /Op as a compiler option for release version, it's ok.
It quite likes a comparing inaccuracy problem.
Try tomorrow...
zzzzzz
-----------------------
I use these functions to change the lum of an rgb color.
The debug version and release versions have different result.
Why? Thanks.
void RGB2HSL(COLORREF rgb,REAL *pH,REAL *pS,REAL *pL)
{
REAL var_R=REAL(GetRValue(rgb))/255.f;
REAL var_G=REAL(GetGValue(rgb))/255.f;
REAL var_B=REAL(GetBValue(rgb))/255.f;
REAL var_min=min(var_R,var_G);
var_min=min(var_min,var_B);
REAL var_max=max(var_R,var_G);
var_max=max(var_max,var_B);
REAL delta_max=var_max-var_min;
*pL=(var_max+var_min)*0.5f;
if (delta_max==0.f) {
*pH=0.f;
*pS=0.f;
} else {
if (*pL<0.5f)
*pS=delta_max/(var_max+var_min);
else
*pS=delta_max/(2.f-var_max-var_min);
REAL delta_R=(((var_max-var_R)/6.f)+(delta_max*0.5f))/delta_max;
REAL delta_G=(((var_max-var_G)/6.f)+(delta_max*0.5f))/delta_max;
REAL delta_B=(((var_max-var_B)/6.f)+(delta_max*0.5f))/delta_max;
if (var_R==var_max)
*pH=delta_B-delta_G;
else if (var_G==var_max)
*pH=(1.f/3.f)+delta_R-delta_B;
else if (var_B==var_max)
*pH=(2.f/3.f)+delta_G-delta_R;
if (*pH<0.f) ++*pH;
if (*pH>1.f) --*pH;
}
}
inline REAL Hue_2_RGB(REAL v1,REAL v2,REAL vH)
{
if(vH<0.f)
++vH;
if(vH>1.f)
--vH;
if((vH*6.f)<1.f)
return(v1+(v2-v1)*vH*6.f);
if((vH*2.f)<1.f)
return(v2);
if((vH*3.f)<2.f)
return(v1+(v2-v1)*((2.f/3.f)-vH)*6.f);
return(v1);
}
void HSL2RGB(REAL H,REAL S,REAL L,COLORREF &rgb)
{
REAL R,G,B;
if (S==0.f) {
R=L*255.f;
G=L*255.f;
B=L*255.f;
} else {
REAL var_1,var_2;
if (L<0.5f)
var_2=L*(1.f+S);
else
var_2=(L+S)-(S*L);
var_1=L*2.f-var_2;
R=Hue_2_RGB(var_1,var_2,H+(1.f/3.f))*255.f;
G=Hue_2_RGB(var_1,var_2,H)*255.f;
B=Hue_2_RGB(var_1,var_2,H-(1.f/3.f))*255.f;
}
rgb=RGB(R,G,B);
}
modified on Saturday, February 02, 2008 1:02:11 PM
|
|
|
|
|
So what is the difference while compile (or executable) in kind of two mode?
|
|
|
|
|
I don't known in detail.
I'm finding a quick answer.
|
|
|
|
|
I chnaged the way of equality comparison from
S==0.f
to
S>-0.000001f && S<0.000001f
It seems ok, and must be faster than using
"/Op" or pragma optimize("p",on)
|
|
|
|
|
I'm not complete sure on what is the problem because i never worked before on such like works-area just as go deeply into it. You might use to the #ifdef statement at this like condition.
#ifdef _DEBUG<br />
#pragma optimize("p", on or off
|
|
|
|
|
Fine, another good choice.
|
|
|
|
|
Hi,
I am on the road (abroad) and find that I have to resolve a support issue on a product written MFC C++ in MSVC6. My laptop does not have it - and the guy who is responsible cannot attend to it. I can have someone hunt for the original CDs couriered to me - but this will take some time that I really do not have. Is there any where I cann download it. We have MSDN but have not found a download for that - even though I located the SP6 update. Any Ideas? Please help!!
|
|
|
|
|
Hmm, Ah, Ah ACHHHgoogleHHO!, sorry my nose is crazy today, Ah, Ah ACHHtorrent!
I dunno were you can find it, why ask us when you can ask Google?
//Johannes
|
|
|
|
|
*snicker*
Johannes I got your email - i had a conference call yesterday - I'll get back to you on that stuff.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Cool,
Why not go on MSN for a bit?
//Johannes
|
|
|
|
|
'm only here for about 20 more minutes...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Have someone dig up the disks and copy them to a server you can download them from
Should be a little faster than courier...
Of course, any real developer on the road should have the disks along
as part of his "hero kit"
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: "hero kit"
Discs in the checked luggage, another copy in the carry-on, and a third copy on the memory stick in the pocket.
Quite a change from the first time I traveled when I had a second suitcase just for the nine-track tapes. Yes, I said tapes. All right now, dammit, stop snickering at the old guy and his pathetic reminiscing.
|
|
|
|
|
Heh. Maybe you're just a little older more seasoned than me...
My first kits were 5 1/4" floppies
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In my day men were men, women were women, and a microVAX was as personal as a computer got.
|
|
|
|
|
Gary R. Wheeler wrote: ...and a microVAX...
Is this the laptop?[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|