Saturday, May 22, 2010

Homework help in C++?

Ok I have a hw assignment and I need help with it. I don't know what to do. Here is the instructions:


Write a program in C++, and using the BG functions, that shows the process of sorting a set of numbers (in decreasing order).Write a function mySetColor that, given an integer from 1..16, will set a color. The 16 colors that you use should be easy to distinguish from one another.


Read in an array of integers from a text file called sortinput.txt, which I will give to you.


Animate the (bubble) sorting process in a loop, with a 1 second pause between steps:


For each number N in the array, draw a circle whose radius = N and whose color is mySetColor(N). Remember to update the display after drawing all the circles!


Set a variable changed to indicate that the array has not changed. Compare each pair of numbers in the array. If a bigger number follows a smaller number, swap the numbers in the array, and indicate that the array has changed. Exit the loop if the array has not changed

Homework help in C++?
Honey, you left too many details out for us to be able to help you. You mention the "BG functions". I presume those are functions either given you by your teacher or developed by you in class to perform a Bubble Sort. He wants you to read in an array from a text file: well, if you were doing ANSI standard C++, that would be straightforward. You'd use %26lt;fstream%26gt; and open a file stream to the file you want for reading. If you call the file stream "fin", then you'd use it just like cin. Stick it in a loop, along the lines of





n = 0;


while (not fin.eof())


{


fin %26gt;%26gt; array[n];


++n;


}





Run the array through the functions to sort it. Then start drawing your circles.





The problem is that you don't seem to be using ANSI standard C++. You don't tell us what OS you're using, or if you're using MFC or Toolbox or DirectDraw or just what. Graphics in C++ are highly dependent on the target platform. Even the file read functions may be different from the ones I mentioned above.





I'd strongly suggest you check your notes. It will take you an awful lot of time to bring anyone here up to speed on the tools you're using before we could help you.


No comments:

Post a Comment