Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2008 by Ivor Horton; ISBN: 9780470225905
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 3rd, 2012, 03:05 PM
Authorized User
Points: 96, Level: 1
Points: 96, Level: 1 Points: 96, Level: 1 Points: 96, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 2 Times in 2 Posts
Default Chapter 4 exercise 4

If any one has a problem with this exercise here is my solution
Code:
// Solu4_4.cpp : main project file.
/*  The exercise was to create an array with a random number between 10
	to 20 elements with values ranging between 100 and 1000 values. The
	author did not want the array sorted by Array::Sort. After checking
	several books on C++ for sorting there was no solution. I check on
	a book for C programming and found several sort methods including
	Exchange, Selection and Insertion. One sort that I used here is an
	exchange sort called "The Bubble Sort". 
*/
	
#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
	// Generate a number between 10 and 20 and store it in count.
	Random^ generator = gcnew Random;
	int count = generator->Next(10,20);
	// Print the number of values generated.
	Console::WriteLine(L"The number of items generated is {0}",count);

	// Now create an array of values containing the number generated.
	array<int>^ values = gcnew array<int>(count);

	// Now filled an array with the number of values in count.
	for(int i = 0; i < count; i++)
		values[i] = generator->Next(100,1000);

	// Now we sort the values using "The Bubble Sort".
	int temp = 0;		// Temporary store for values.
	for(int x = 1 ; x < count; ++x)
		for(int i = count-1; i >= x; --i)
		{
			if(values[i-1] > values[i])
			{
				temp = values[i-1];
				values[i-1] = values[i];
				values[i] = temp;
				temp = 0;
			}
		}

	// Now print out sorted ascending values five to a line.
	for(int i = 0; i < count; i++)
	{
		Console::Write(L"{0,10}",values[i]);
		if((i+1)%5 == 0)
			Console::WriteLine();
	}
	Console::WriteLine();
    return 0;
}
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8 exercise 3 Will BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 8 March 4th, 2010 04:15 AM
Chapter 8 exercise 1 Will BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 2 March 2nd, 2010 03:26 PM
chapter 3 exercise 4 walkamongus BOOK: Beginning JavaScript 3rd Ed. ISBN: 978-0-470-05151-1 0 September 10th, 2007 09:34 PM
Chapter 5 - Exercise 1 scgtman BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 3 May 16th, 2006 08:10 PM
Chapter 4, Exercise 3 DRAYKKO BOOK: Beginning Java 2 3 July 9th, 2004 02:34 PM



All times are GMT -4. The time now is 08:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.