day 18
LAB:
const int BUTTON_INT = 0;
const int RED = 11;
const int GREEN = 10;
const int BLUE = 9;
volatile int selectedLED = RED;
void setup()
{
pinMode (RED, OUTPUT);
pinMode (GREEN, OUTPUT);
pinMode (BLUE, OUTPUT);
attachInterrupt (BUTTON_INT, swap, RISING);
}
void swap()
{
analogWrite (selectedLED, 0);
if (selectedLED == GREEN)
{
selectedLED = RED;
}
else if(selectedLED == RED)
{
selectedLED = BLUE;
}
else if(selectedLED == BLUE)
{
selectedLED = GREEN;
}
}
void loop()
{
for(int i = 0; i<256; i++)
{
analogWrite(selectedLED, i);
delay(10);
}
for(int i = 255; i >= 0; i--)
{
analogWrite(selectedLED, i);
delay(10);
}
}
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
int mo, da, yr, fatalities;
double max_height;
char location[20];
};
int main(void)
{
/* Declare variables. */
int k=0, i=0, npts, wave_max, num_year = 0, max_year;
double max=0, sum=0, ave;
struct tsunami t[100];
FILE *waves;
/* Read and print information from the file. */
waves = fopen(FILENAME,"r");
if (waves == NULL)
{
printf("Error opening data file. \n");
}
else
{
while (fscanf(waves,"%i %i %i %s %lf %i",&t[k].mo,&t[k].da, &t[k].yr ,t[k].location,&t[k].max_height,&t[k].fatalities) == 6)
{
sum = sum + t[k].max_height;
if (t[k].max_height > max)
{
max = t[k].max_height;
wave_max = k;
}
k++;
}
printf("%i\n",t[wave_max].yr);
max_year = t[wave_max].yr;
for(i=0; i<=k;i++)
{
if(t[i].yr == max_year)
{
num_year++;
}
}
npts = k;
ave = sum/npts;
printf("Summary Information for Tsunamis \n");
printf("Maximum Wave Height (in feet): %.2f \n",max*3.28);
printf("Number of tsunamis that year: %i\n", num_year);
printf("Average Wave Height (in feet): %.2f \n",ave*3.28);
printf("Tsunamis with greater than average heights: \n");
for (k=0; k<=npts-1; k++)
{
if (t[k].max_height > ave)
{
printf("%s \n",t[k].location);
}
}
fclose(waves);
}
return 0;
}
#include <stdio.h>
int main(void){
return 0;
}#include <stdio.h>
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
int mo, da, yr, fatalities;
double max_height;
char location[20];
};
int main(void)
{
/* Declare variables. */
int k=0, i=0, npts, wave_max, max_fata, num_fata;
double max=0, sum=0, ave;
struct tsunami t[100];
FILE *waves;
/* Read and print information from the file. */
waves = fopen(FILENAME,"r");
if (waves == NULL)
{
printf("Error opening data file. \n");
}
else
{
while (fscanf(waves,"%i %i %i %s %lf %i",&t[k].mo,&t[k].da, &t[k].yr ,t[k].location,&t[k].max_height,&t[k].fatalities) == 6)
{
sum = sum + t[k].max_height;
if (t[k].max_height > max)
{
max = t[k].max_height;
wave_max = k;
}
k++;
}
for(i=0; i<=k;i++)
{
if( max_fata < t[i].fatalities)
{
max_fata = t[i].fatalities;
num_fata = i;
}
}
npts = k;
ave = sum/npts;
printf("Summary Information for Tsunamis \n");
printf("Maximum Wave Height (in feet): %.2f \n",max*3.28);
printf("Largest number of fatalities: %i \n", max_fata);
printf("Date: %i/%i/%i \n", t[num_fata].mo, t[num_fata].da, t[num_fata].yr);
printf("Average Wave Height (in feet): %.2f \n",ave*3.28);
printf("Tsunamis with greater than average heights: \n");
for (k=0; k<=npts-1; k++)
{
if (t[k].max_height > ave)
{
printf("%s \n",t[k].location);
}
}
fclose(waves);
}
return 0;
}
//tsunamis with over 100 fatalities
#include <stdio.h>
int main(void){
return 0;
}#include <stdio.h>
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
int mo, da, yr, fatalities;
double max_height;
char location[20];
};
int main(void)
{
/* Declare variables. */
int k=0, i=0, npts, wave_max, num_year = 0, max_fata;
double max=0, sum=0, ave;
struct tsunami t[100];
FILE *waves;
/* Read and print information from the file. */
waves = fopen(FILENAME,"r");
if (waves == NULL)
{
printf("Error opening data file. \n");
}
else
{
while (fscanf(waves,"%i %i %i %s %lf %i",&t[k].mo,&t[k].da, &t[k].yr ,t[k].location,&t[k].max_height,&t[k].fatalities) == 6)
{
sum = sum + t[k].max_height;
if (t[k].max_height > max)
{
max = t[k].max_height;
wave_max = k;
}
k++;
}
printf("Tsunamis with over 100 fatalities:\n");
for(i=0; i<=k;i++)
{
if( 100 < t[i].fatalities)
{
printf("%s \n",t[i].location);
}
}
npts = k;
ave = sum/npts;
printf("Summary Information for Tsunamis \n");
printf("Maximum Wave Height (in feet): %.2f \n",max*3.28);
//printf("Largest number of fatalities: %i\n", max_fata);
printf("Average Wave Height (in feet): %.2f \n",ave*3.28);
printf("Tsunamis with greater than average heights: \n");
for (k=0; k<=npts-1; k++)
{
if (t[k].max_height > ave)
{
printf("%s \n",t[k].location);
}
}
fclose(waves);
}
return 0;
}
//tsunamis with over 100 fatalities
#include <stdio.h>
int main(void){
return 0;
}#include <stdio.h>
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
int mo, da, yr, fatalities;
double max_height;
char location[20];
};
int main(void)
{
/* Declare variables. */
int k=0, i=0, npts, wave_max, num_year = 0, max_fata;
double max=0, sum=0, ave;
struct tsunami t[100];
FILE *waves;
/* Read and print information from the file. */
waves = fopen(FILENAME,"r");
if (waves == NULL)
{
printf("Error opening data file. \n");
}
else
{
while (fscanf(waves,"%i %i %i %s %lf %i",&t[k].mo,&t[k].da, &t[k].yr ,t[k].location,&t[k].max_height,&t[k].fatalities) == 6)
{
sum = sum + t[k].max_height;
if (t[k].max_height > max)
{
max = t[k].max_height;
wave_max = k;
}
k++;
}
printf("Tsunamis with over 100 fatalities:\n");
for(i=0; i<=k;i++)
{
if( 100 < t[i].fatalities)
{
printf("%s \n",t[i].location);
}
}
npts = k;
ave = sum/npts;
printf("Summary Information for Tsunamis \n");
printf("Maximum Wave Height (in feet): %.2f \n",max*3.28);
//printf("Largest number of fatalities: %i\n", max_fata);
printf("Average Wave Height (in feet): %.2f \n",ave*3.28);
printf("Tsunamis with greater than average heights: \n");
for (k=0; k<=npts-1; k++)
{
if (t[k].max_height > ave)
{
printf("%s \n",t[k].location);
}
}
fclose(waves);
}
return 0;
}
//tsunamis with over 100 fatalities
#include <stdio.h>
int main(void){
return 0;
}#include <stdio.h>
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
int mo, da, yr, fatalities;
double max_height;
char location[20];
};
int main(void)
{
/* Declare variables. */
int k=0, i=0, npts, wave_max, num_year = 0, max_fata;
double max=0, sum=0, ave;
struct tsunami t[100];
FILE *waves;
/* Read and print information from the file. */
waves = fopen(FILENAME,"r");
if (waves == NULL)
{
printf("Error opening data file. \n");
}
else
{
while (fscanf(waves,"%i %i %i %s %lf %i",&t[k].mo,&t[k].da, &t[k].yr ,t[k].location,&t[k].max_height,&t[k].fatalities) == 6)
{
sum = sum + t[k].max_height;
if (t[k].max_height > max)
{
max = t[k].max_height;
wave_max = k;
}
k++;
}
printf("Tsunamis with over 100 fatalities:\n");
for(i=0; i<=k;i++)
{
if( 100 < t[i].fatalities)
{
printf("%s \n",t[i].location);
}
}
npts = k;
ave = sum/npts;
printf("Summary Information for Tsunamis \n");
printf("Maximum Wave Height (in feet): %.2f \n",max*3.28);
//printf("Largest number of fatalities: %i\n", max_fata);
printf("Average Wave Height (in feet): %.2f \n",ave*3.28);
printf("Tsunamis with greater than average heights: \n");
for (k=0; k<=npts-1; k++)
{
if (t[k].max_height > ave)
{
printf("%s \n",t[k].location);
}
}
fclose(waves);
}
return 0;
}
const int BUTTON_INT = 0;
const int RED = 11;
const int GREEN = 10;
const int BLUE = 9;
volatile int selectedLED = RED;
void setup()
{
pinMode (RED, OUTPUT);
pinMode (GREEN, OUTPUT);
pinMode (BLUE, OUTPUT);
attachInterrupt (BUTTON_INT, swap, RISING);
}
void swap()
{
analogWrite (selectedLED, 0);
if (selectedLED == GREEN)
{
selectedLED = RED;
}
else if(selectedLED == RED)
{
selectedLED = BLUE;
}
else if(selectedLED == BLUE)
{
selectedLED = GREEN;
}
}
void loop()
{
for(int i = 0; i<256; i++)
{
analogWrite(selectedLED, i);
delay(10);
}
for(int i = 255; i >= 0; i--)
{
analogWrite(selectedLED, i);
delay(10);
}
}
Homework:
//number of tsunamis the year of the largest wave
#include <stdio.h>
results:
//largest fatalities with date mod
#include <stdio.h>
int main(void){
return 0;
}#include <stdio.h>
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
int mo, da, yr, fatalities;
double max_height;
char location[20];
};
int main(void)
{
/* Declare variables. */
int k=0, i=0, npts, wave_max, max_fata, num_fata;
double max=0, sum=0, ave;
struct tsunami t[100];
FILE *waves;
/* Read and print information from the file. */
waves = fopen(FILENAME,"r");
if (waves == NULL)
{
printf("Error opening data file. \n");
}
else
{
while (fscanf(waves,"%i %i %i %s %lf %i",&t[k].mo,&t[k].da, &t[k].yr ,t[k].location,&t[k].max_height,&t[k].fatalities) == 6)
{
sum = sum + t[k].max_height;
if (t[k].max_height > max)
{
max = t[k].max_height;
wave_max = k;
}
k++;
}
for(i=0; i<=k;i++)
{
if( max_fata < t[i].fatalities)
{
max_fata = t[i].fatalities;
num_fata = i;
}
}
npts = k;
ave = sum/npts;
printf("Summary Information for Tsunamis \n");
printf("Maximum Wave Height (in feet): %.2f \n",max*3.28);
printf("Largest number of fatalities: %i \n", max_fata);
printf("Date: %i/%i/%i \n", t[num_fata].mo, t[num_fata].da, t[num_fata].yr);
printf("Average Wave Height (in feet): %.2f \n",ave*3.28);
printf("Tsunamis with greater than average heights: \n");
for (k=0; k<=npts-1; k++)
{
if (t[k].max_height > ave)
{
printf("%s \n",t[k].location);
}
}
fclose(waves);
}
return 0;
}
//tsunamis with over 100 fatalities
#include <stdio.h>
int main(void){
return 0;
}#include <stdio.h>
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
int mo, da, yr, fatalities;
double max_height;
char location[20];
};
int main(void)
{
/* Declare variables. */
int k=0, i=0, npts, wave_max, num_year = 0, max_fata;
double max=0, sum=0, ave;
struct tsunami t[100];
FILE *waves;
/* Read and print information from the file. */
waves = fopen(FILENAME,"r");
if (waves == NULL)
{
printf("Error opening data file. \n");
}
else
{
while (fscanf(waves,"%i %i %i %s %lf %i",&t[k].mo,&t[k].da, &t[k].yr ,t[k].location,&t[k].max_height,&t[k].fatalities) == 6)
{
sum = sum + t[k].max_height;
if (t[k].max_height > max)
{
max = t[k].max_height;
wave_max = k;
}
k++;
}
printf("Tsunamis with over 100 fatalities:\n");
for(i=0; i<=k;i++)
{
if( 100 < t[i].fatalities)
{
printf("%s \n",t[i].location);
}
}
npts = k;
ave = sum/npts;
printf("Summary Information for Tsunamis \n");
printf("Maximum Wave Height (in feet): %.2f \n",max*3.28);
//printf("Largest number of fatalities: %i\n", max_fata);
printf("Average Wave Height (in feet): %.2f \n",ave*3.28);
printf("Tsunamis with greater than average heights: \n");
for (k=0; k<=npts-1; k++)
{
if (t[k].max_height > ave)
{
printf("%s \n",t[k].location);
}
}
fclose(waves);
}
return 0;
}
//tsunamis with over 100 fatalities
#include <stdio.h>
int main(void){
return 0;
}#include <stdio.h>
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
int mo, da, yr, fatalities;
double max_height;
char location[20];
};
int main(void)
{
/* Declare variables. */
int k=0, i=0, npts, wave_max, num_year = 0, max_fata;
double max=0, sum=0, ave;
struct tsunami t[100];
FILE *waves;
/* Read and print information from the file. */
waves = fopen(FILENAME,"r");
if (waves == NULL)
{
printf("Error opening data file. \n");
}
else
{
while (fscanf(waves,"%i %i %i %s %lf %i",&t[k].mo,&t[k].da, &t[k].yr ,t[k].location,&t[k].max_height,&t[k].fatalities) == 6)
{
sum = sum + t[k].max_height;
if (t[k].max_height > max)
{
max = t[k].max_height;
wave_max = k;
}
k++;
}
printf("Tsunamis with over 100 fatalities:\n");
for(i=0; i<=k;i++)
{
if( 100 < t[i].fatalities)
{
printf("%s \n",t[i].location);
}
}
npts = k;
ave = sum/npts;
printf("Summary Information for Tsunamis \n");
printf("Maximum Wave Height (in feet): %.2f \n",max*3.28);
//printf("Largest number of fatalities: %i\n", max_fata);
printf("Average Wave Height (in feet): %.2f \n",ave*3.28);
printf("Tsunamis with greater than average heights: \n");
for (k=0; k<=npts-1; k++)
{
if (t[k].max_height > ave)
{
printf("%s \n",t[k].location);
}
}
fclose(waves);
}
return 0;
}
//tsunamis with over 100 fatalities
#include <stdio.h>
int main(void){
return 0;
}#include <stdio.h>
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
int mo, da, yr, fatalities;
double max_height;
char location[20];
};
int main(void)
{
/* Declare variables. */
int k=0, i=0, npts, wave_max, num_year = 0, max_fata;
double max=0, sum=0, ave;
struct tsunami t[100];
FILE *waves;
/* Read and print information from the file. */
waves = fopen(FILENAME,"r");
if (waves == NULL)
{
printf("Error opening data file. \n");
}
else
{
while (fscanf(waves,"%i %i %i %s %lf %i",&t[k].mo,&t[k].da, &t[k].yr ,t[k].location,&t[k].max_height,&t[k].fatalities) == 6)
{
sum = sum + t[k].max_height;
if (t[k].max_height > max)
{
max = t[k].max_height;
wave_max = k;
}
k++;
}
printf("Tsunamis with over 100 fatalities:\n");
for(i=0; i<=k;i++)
{
if( 100 < t[i].fatalities)
{
printf("%s \n",t[i].location);
}
}
npts = k;
ave = sum/npts;
printf("Summary Information for Tsunamis \n");
printf("Maximum Wave Height (in feet): %.2f \n",max*3.28);
//printf("Largest number of fatalities: %i\n", max_fata);
printf("Average Wave Height (in feet): %.2f \n",ave*3.28);
printf("Tsunamis with greater than average heights: \n");
for (k=0; k<=npts-1; k++)
{
if (t[k].max_height > ave)
{
printf("%s \n",t[k].location);
}
}
fclose(waves);
}
return 0;
}


Comments
Post a Comment