/*****************************************************************************/ /* ECE-1011 Summer 2003 */ /* Section:......... 0 */ /* Assignment:...... 1 */ /* Programmer:...... BAHN, William L. */ /* File Contents:... SOURCE CODE */ /* Filename:........ s10_bahw.c */ /* Due Date:........ 11 JUN 03 */ /* E-mail Address:.. wbahn@eas.uccs.edu */ /*****************************************************************************/ /*****************************************************************************/ /***************************** INCLUDE FILES *********************************/ /*****************************************************************************/ #include // printf() #include // sin() /*****************************************************************************/ /********************* PROGRAMMER DEFINED CONSTANTS **************************/ /*****************************************************************************/ #define PI (3.1415926345) #define PERIOD (25) /*****************************************************************************/ /***************************** MAIN PROGRAM **********************************/ /*****************************************************************************/ int main(void) { int t, col; int y_sq, y_sine, y_tri, y_saw; t = 0; while(t < 250) { y_sine = 9 * sin( ((2*PI)/PERIOD) * t); y_saw = 2 * 9 * ((double) (t%PERIOD) / (double) PERIOD); // Amp changed if(sin(((2*PI)/PERIOD) * t) < 0.0) y_sq = -9; else y_sq = 9; // NEW CODE for HW#1 ========================================== // CALCULATE TRIANGLE WAVE VALUE // A SawTooth wave goes from min to max in 1 period. // A Triangle wave goes from min to max is 1/4 period. // So a Triangle wave has four times the slope. y_tri = 4 * 9 * ((double) (t%PERIOD) / (double) PERIOD); // Move it down so that it starts at the minimum point. y_tri -= 9; // If the sine function is negative, invert the function. if(0.0 > y_sine) { y_tri *= -1; // And adjust so that ending point is at the minimum. // Original value of y_tri at the end would be 36 (actually, 35) // After the above offset it would be 36-9 = 27 // After the inversion it would be -27 // To get it back to -9 we need to add 18 y_tri += 18; } // END NEW CODE for HW#1 ====================================== for(col=1; col<20; col++) { if(col-10 == y_sine) printf("o"); else printf(" "); } for(col=1; col<20; col++) { if(col == y_saw) // Scaling changed to match amplitude change above. printf("\\"); else printf(" "); } for(col=1; col<20; col++) { if(col-10 == y_sq) printf("|"); else printf(" "); } // NEW CODE for HW#1 ========================================== // Code Block for y_sq above copied and edits made as noted. for(col=1; col<20; col++) { if(col-10 == y_tri) // y_sq changed to y_tri on this line. { if(0.0 < y_sine) // if() block added to get character right. printf("\\"); else printf("/"); } else printf(" "); } // END NEW CODE for HW#1 ====================================== printf("\n"); t++; } return(0); }