.....procrastinating is the cause of many late nights :(
god damn assignment due tommorrow
im up for a late one, anyone else?
Turley
29-05-2003, 10:41 PM
Haha, Yep, I have an assignmnet due tommorow, but I have just finished so beddy byes for me and chemistry prac in the morning :)
Stay tuned for my live progress report! (dont worry I expect everyone to ignore this :P).
0 words of 2000....
I have exams coming up, an outcome tomorrow, had 4 periods of outcomes yesterday, had an outcome today, had outcomes on Monday and Tuesday as well (outcomes are assessed tests that count towards ya TER). I haven't done any homework for a week or two.
CHEWY
29-05-2003, 10:45 PM
i have a IT exam tomorrow, but as if im gonna study for that!
Title Page completo!
/me wonders if this counts in the word limit
How shit is this site: http://www.ausfish.com.au
thats what i have to waste my sleep crapping on about
im up for one....stupid ankle
CHEWY
29-05-2003, 11:18 PM
Title Page completo!
/me wonders if this counts in the word limit
How shit is this site: http://www.ausfish.com.au
thats what i have to waste my sleep crapping on about
sounds really intersting......
have fun im goin ta bed haha
Doogs
29-05-2003, 11:35 PM
anyone know how to program c?
i am in need of help
life as an arts student sure is easy :)
Gutty
30-05-2003, 09:59 AM
well atleast there is one benefit of being an old fart. I haven't had to sit an exam or do an assignment in over 10 years. :)
what's up doogs (if u still need help)?
wombat
30-05-2003, 10:12 PM
Ah the good ol' last minute job. I did the HSC (year 12) last year and my two best assessment results were in 3 unit English: two 6 week assignments, two 1 day jobs (one was actually half a day) and two 100% assessment results, booyah!
On a completely unrelated note, satire was the best topic we ever studied at school: Catch 22, MASH, the simpsons, and other countless bits of side splitting, but incredibly sharp humour. Satire is the best sort of comedy around; it's sophistication wipes the floor with any slapstick....when it's done properly anyway.
Doogs
30-05-2003, 10:49 PM
Hey Zac,
here's my assignment (asked to do)
"This assignment is to find temperate distributions on a metal plate where isolated points can be held at a fixed temperature.
Brief description
If a point on a metal plate is not held at a fixed temperature, then its temperature will tend to be the average of the temperatures around it. There is an easy algorithm to establish the temperature distributions on such a plate. Simply repeatedly replace every temperature with averages around it until no temperature changes very much any more.
Full description
The program should maintain a two dimensional array of temperatures, representing a metal plate. It should also maintain a two dimensional array of integers, which are 1 for points which are to be held at a fixed temperature, and 0 for points which depend on their surrounding points.
The program should accept various commands from the input. The following commands must be available.
q – quit (terminate the program)
h – help (print out a list of available commands)
p height width temperature – hold the point at location height, width to temperature temperature
v – view (draw a representation of the plate)
c – clear (clear the data so that no points are fixed)
Note that this will require performing character input. The program should read one character, and then decide how to handle the rest of the line. The "p" command should be followed by two integers and a real number, to locate a fixed point and its temperature.
The height locations allowed on input should range from 0 to 20 inclusive. The width locations should range from 0 to 70 inclusive. Note that the number of points is thus 21 times 71. Using odd numbers allows one to specify points in the middle of the plate for symmetrical temperature distributions. Temperatures must range from 0 to 1 inclusive. This represents the range from minimum to maximum, rather than being an absolute temperature value. If the input numbers for the "p" command are not valid, then an error message must be given and the command ignored.
Calculating the temperature distribution
To find the temperature distribution, repeatedly replace the temperature of every point which is not fixed with the average of points around it. Take care how you handle the edges and corners. It does not matter whether you use the initial or the final temperature which adding up the temperatures of neighbours. It is sufficient to keep all temperatures in one two dimensional array.
As new averages are being calculated, also find the maximum change which occurs at any point.
Repeatedly calculate the average until the maximum change is small. Small, in this context, can mean less than 1e-5. The program will run faster as this number becomes larger, but it will be less accurate. You can get strange results if this value is too big. For perfectly symmetrical results, this bound should be very small. The sample results shown in this document were produced with the bound set to 1e-9.
Viewing the temperature distribution
You should display the plate as a block of characters on the screen. Use different characters for range of temperatures. The following table of characters can be used.
0 .. 0.025 '0' 0.025 .. 0.075 '.'
0.075 .. 0.125 '1' 0.125 .. 0.175 '.'
0.175 .. 0.225 '2' 0.225 .. 0.275 '.'
0.275 .. 0.325 '3' 0.325 .. 0.375 '.'
0.375 .. 0.425 '4' 0.425 .. 0.475 '.'
0.475 .. 0.525 '5' 0.525 .. 0.575 '.'
0.575 .. 0.625 '6' 0.625 .. 0.675 '.'
0.675 .. 0.725 '7' 0.725 .. 0.775 '.'
0.775 .. 0.825 '8' 0.825 .. 0.875 '.'
0.875 .. 0.925 '9' 0.925 .. 0.975 '.'
0.975 .. 1 '*'
This will give nice bands to help reveal the pattern, with numbers to indicate approximate values. Here is a convenient expression (and declarations) to map from a value in the range 0 to 1 to the appropriate character.
#define NumScales 20
char Scale[] = "0.1.2.3.4.5.6.7.8.9.*";
Scale[(int)(value*NumScales+0.5)]
The "(int)" operator converts a real number to an integer by rounding down to the nearest integer. See if you can figure out why this expression works!
Testing the program
You must produce test data to check that your program works as expected. You should test the program for a variety of cases. It is a good idea to keep test cases very simple, so that you can predict the results. You should test for error conditions, as well as for valid inputs.
The test output should ideally show the input as well as the output. To help you do this, here is some sample code which will display the input that is received. Note that you will have to add suitable comments!
#define MAXINPUT 128
char input[MAXINPUT];
char command;
int height, width;
double temperature;
int numargs;
printf("Command: ");
if ( scanf("%c", &command) != 1 ) {
command = 'q';
printf("q\n");
} else if ( command == '\n' ) {
printf("\n");
} else {
/*
* This reads and displays the rest of the line.
* The rest of the line is stored into an array.
* Any command arguments are read from the array
* with sscanf, rather than from input with scanf.
*/
(void)fgets(input, MAXINPUT, stdin);
printf("%c%s", command, input);
if ( command == 'p' ) {
numargs = sscanf(input, "%d %d %lf",
&height, &width, &temperature);
}
}
Sample executions
Here is an example of a run for the sample solution. This output was generated by running the program using input from a file, and sending output to a file. The output shows the input using the method given above. To run with input from a file and output to a file, select the "Project" menu and then the "Settings" submenu. In the dialog box, click on the tab marked "Debug", and under program arguments, enter the string "<inputfile >outputfile". Make sure there is no space after < or >.
Here is an image of the settings dialog.
Here is the input file used:
h
p 0 0 1
p 20 70 0
v
p 0 0 .3
v
p 0 0 fred
x
q
Here is the output file.
Command: h
p # # # - point (height width temperature)
Height is from 0 to 20
Width is from 0 to 70
Temperature is from 0 to 1
c - clear the plate
v - view (draw the plate)
q - quit
h - this help message
Command: p 0 0 1
Command: p 20 70 0
Command: v
*9..88....7777......666666......5555555.......4444 444........3333333333
99..88....7777......666666......5555555.......4444 444........3333333333
...888...77777......666666......5555555.......4444 444........3333333333
..888....77777......666666......5555555.......4444 444........3333333333
88888....77777......666666......5555555.......4444 44........33333333333
8888.....77777......666666......5555555.......4444 44........33333333333
88......777777......666666......5555555......44444 44........33333333333
.......777777......6666666......5555555......44444 44........33333333333
.......777777......6666666......5555555......44444 44.......333333333333
......7777777......6666666......5555555......44444 44.......333333333...
.....7777777.......6666666......5555555......44444 44.......3333333.....
...777777777.......6666666......5555555......44444 44......3333333......
777777777777.......6666666......5555555......44444 44......333333.......
77777777777........6666666......5555555......44444 44......333333.......
77777777777........6666666......5555555......44444 4......333333......22
77777777777........666666.......5555555......44444 4......33333.....2222
77777777777........666666.......5555555......44444 4......33333....22222
7777777777........6666666.......5555555......44444 4......33333....222..
7777777777........6666666.......5555555......44444 4......33333...222...
7777777777........6666666.......5555555......44444 4......3333....22..11
7777777777........6666666.......5555555......44444 4......3333....22..10
Command: p 0 0 .3
Command: v
33......22222222222222222......................111 111111111111111111111
3.......22222222222222222......................111 111111111111111111111
.......222222222222222222......................111 111111111111111111111
.......222222222222222222......................111 111111111111111111111
.......222222222222222222......................111 111111111111111111111
......2222222222222222222......................111 111111111111111111111
.....22222222222222222222......................111 111111111111111111111
....222222222222222222222......................111 111111111111111111111
..22222222222222222222222.....................1111 111111111111111111111
2222222222222222222222222.....................1111 111111111111111111111
2222222222222222222222222.....................1111 111111111111111111111
2222222222222222222222222.....................1111 111111111111111111111
2222222222222222222222222.....................1111 1111111111111111111..
222222222222222222222222......................1111 11111111111111111....
222222222222222222222222......................1111 1111111111111111.....
222222222222222222222222......................1111 111111111111111......
222222222222222222222222......................1111 11111111111111.......
222222222222222222222222......................1111 11111111111111.......
222222222222222222222222......................1111 11111111111111.......
222222222222222222222222......................1111 1111111111111.......0
222222222222222222222222......................1111 1111111111111......00
Command: p 0 0 fred
Invalid point command.
Command: x
Illegal command: x
Command: q
Style requirements (almost a marking guide!)
· All variables should be local variables inside a function, without exception.
· All numeric values used in the program should be declared as constants using #define or some such method. Exceptions are values like 0 or 1 or 0.5 where the reason for that value is obvious.
· Appropriate used of functions. To get full marks, your program must include some functions for some important tasks. You should have functions for at least the following operations.
· Read one user command, including arguments. This should handle any command display.
· Draw the plate.
· Put the plate in a stable condition by repeated averaging for unfixed points.
If you do not include functions you can still pass; but functions are required for a good mark.
· The code should be properly indented.
· All variables and functions must have meaningful names.
· All functions must have a comment that describes their use.
· You must include a comment with every variable declaration.
· You must include a general descriptive comment at the very start of your code in the general declarations section that gives your name, your student number, and a brief description of the application. This should be just a few lines long.
· You must provide adequate test data to show all the ways in which inputs can be in error, as well as some more tests of valid inputs. You must include the two tests cases shown in this document, plus at least two other cases of your own choosing.
Submission:
Do not submit the assignment of computing module to Engineering. Submit it to Information Technology in room S609.
You must submit the following items:
1. A floppy disk containing the C program code.
2. A printout of the C program code. The best way to print is direct from Visual C++ itself. Pasting into Word or other programs is likely to show indentation incorrectly.
3. A printout of your test runs, with the input and the output visible.
Room S607 has printing facilities. You will need a photocopy card to print from these machines. This is same card as used for copying in the library.
You must keep at least one backup of the project for yourself. You must not modify this backup. It may be required if we have problems reading your submission disk.
The floppy disk and the listings must be placed in a document wallet, and submitted at the resource desk in room 609 of S block, before 4:30pm on the due date. The resource desk supplies little paper pockets for holding a floppy disk. You should attach the paper pocket to your document wallet using sticky tape, and then insert the disk into the paper pocket. Do not put sticky tape directly on the disk.
Your assignment will be returned through the resource room after marking.
This is an individual assignment. Students will find it helpful to talk to one another about the program, but in the end each student must write their own program.
Note: If you have any problem, please contact lecturers during their consultation hours.
HINTS
To declare an array with two dimensions
#define Height 21
#define Width 71
double Plate[Height][Width]; /* But make sure declarations are inside functions */
To write a function which sets finds the largest value in a 2D array
double max(double Plate[Height][Width])
{
int i, j; /* Step through array indices */
double maxval; /* Holds the largest value so far */
maxval = Plate[0][0];
for(i = 0; i < Height; i++) {
for(j = 0; j < Width; j++) {
if ( Plate[i][j] > maxval ) {
maxval = Plate[i][j];
}
}
}
return maxval;
}
To write a function using pointers.
/* This gets the minimum and maximum values */
void MinMax(double Plate[Height][Width], double *min, double *max)
{
int i, j; /* Step through array indices */
*min = *max = Plate[0][0];
for(i = 0; i < Height; i++) {
for(j = 0; j < Width; j++) {
if ( Plate[i][j] > *max ) {
*max = Plate[i][j];
} else if ( Plate[i][j] < *min ) {
*min = Plate[i][j];
}
}
}
}
To write a function which sets every element to the average of its neighbours
/* This has bugs! */
void Average(double Plate[Height][Width])
{
int i, j; /* Step through array indices */
for(i = 0; i < Height; i++) {
for(j = 0; j < Width; j++) {
Plate[i][j] = (Plate[i-1][j] +
Plate[i+1][j] +
Plate[i][j+1] +
Plate[i][j-1] ) / 4.0;
}
}
}
"
here's my .c file
"
#include <stdio.h>
#include <math.h>
#define HEIGHT 21
#define WIDTH 71
#define NUMSCALES
char Scale[] = "0.1.2.3.4.5.6.7.8.9.*";
#define MAXINPUT 128
int menu()
{
char input[MAXINPUT];
char command;
int numargs,
height,
width;
double temperature,
maxinput;
double PlateFixedPoints[HEIGHT][WIDTH];
double Plate[HEIGHT][WIDTH];
printf ("Please make your choice:\n q - Quit\n h - Help (This Menu)\n p height width temperature - Fixed point\n v - View\n c - clear\n ");
do{
printf("Command:");
if (scanf("%c", &command)!= 1) {
command = 'q';
printf("q\n");
}else if (command =='\n') {
printf("\n");
}else {
(void)fgets(input, MAXINPUT,stdin);
printf("%c%s", command, input);
if (command == 'p') {
numargs = sscanf(input, "%d %d %lf", &height, &width, &temperature);
printf("%i\n", numargs);
PlateFixedPoints[height][width] = 1;
Plate[height][width] = temperature;
}
}
}while (command != 'v');
if (command == 'v'){
AveragePoints();
}
return(0);
}
/* printf ("Please make your choice:\n q - Quit\n h - Help (This Menu)\n p height width temperature - Fixed point\n v - View\n c - clear\n ");
do{
printf("\nCommand:");
scanf("%c", &command);
if (command == 'c'){
printf ("c\n");
}else if (command == 'h'){
printf ("h\n");
}else if (command =='v'){
printf("v");
}else if(command=='p') {
scanf(" %i %i %lf", &height, &width, &temperature);
printf("%c %i %i %4.2lf\n", command, height, width, temperature);
if ( temperature< 0){
printf("error, temperature must be withing 0 and 1");
}else{
PlateFixedPoints[height][width] = 1;
Plate[height][width] = temperature;
}
}else {
printf("READ ERROR '%c'", command);
}
}while (command !='q');
if (command == 'q') {
printf ("q\n");
}*/
void DrawPlate(){
int i,j;
double Plate[HEIGHT][WIDTH];
for(i =0;i<HEIGHT;i++){
for(j = 0 ; j<WIDTH;j++){
printf("%c",Scale[(int)(Plate[i][j]*NUMSCALES+0.5)]);
}
printf("\n");
}
}
int AveragePoints() {
double Change;
do{
int i,j;
double Summation;
double Number;
double Original;
double Plate[HEIGHT][WIDTH];
double PlateFixedPoints[HEIGHT][WIDTH];
Change = 0.0;
Number = 4.0;
for(i = 0; i < HEIGHT;i++){
for(j = 0; j<WIDTH;j++){
double Original;
Original=Plate[i][j];
Summation=0;
Number=0;
if(!PlateFixedPoints[i][j]){
if(j){
Summation+=Plate[i][j-1];
Number++;
}
if(j!=WIDTH-1){
Summation+=Plate[i][j+1];
Number++;
}
if(i){
Summation+=Plate[i-1][j];
Number++;
}
if(i!=HEIGHT-1){
Summation+=Plate[i+1][j];
Number++;
}
Plate[i][j]=Summation/Number;
if(fabs(Original-Plate[i][j])>Change)
Change = fabs(Original-Plate[i][j]);
}
}
}
}while(Change>1e-9);
DrawPlate();
return (0);
}
int main()
{
menu();
return(0);
}
"
ps. it has to be done in C, not C++ (although use MSVC++ to write in, just saved it as a .c file)
sorry for the huge post...moderaters please dont delete :)
CHEWY
30-05-2003, 10:53 PM
damn, i dont think anyones gonna read that!
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.