Another Day 17

#include <stdio.h>
#define FILENAME "storms2.txt"
/* Define structure to represent a hurricane. */
struct hurricane
{
char name[10];
int year, category;
};
int main(void)
{
/* Declare variables and function prototype. */
int max_category = 0, k = 0, npts;
struct hurricane h[100];
FILE *storms;
void print_hurricane(struct hurricane h);
/* Read and print information from the file. */
storms = fopen(FILENAME, "r");
if (storms == NULL)
printf("Error opening data file. \n");
else
{
printf("Hurricanes with Maximum Category \n");
while (fscanf(storms, "%s %d %d", h[k].name, &h[k].year,
&h[k].category) == 3)
{
if (h[k].category > max_category)
max_category = h[k].category;
k++;
}
npts = k;
for (k = 0; k <= npts - 1; k++)
if (h[k].category == max_category)
print_hurricane(h[k]);
fclose(storms);
}
/* Exit program */
return 0;
}
/*?????????????????????????????????????????????????????????????*/
/* This function prints the hurricane information. */
void print_hurricane(struct hurricane h)
{
printf("Hurricane: %s \n", h.name);
printf("Year: %d, Category: %d \n", h.year, h.category);
return;

}
#include <stdio.h>
#include<string.h>
#define FILENAME "waves2.txt"
/* Define structure to represent a tsunami. */
struct tsunami
{
string a;
int mo, da, yr, fatalities;
double max_height;
char location[20];
};
int main(void)
{
/* Declare variables. */
int k = 0, npts,max_i,max_iyr=0,max_fts=0,fts_yr,count_loc=0;
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, "%d %d %d %s %lf %d", &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;
max_i=k;
}
if(t[k].fatalities>max_fts)
{
max_fts=t[k].fatalities;
fts_yr=k;
}
k++;
}
npts = k;
ave = sum / npts;
printf("Summary Information for Tsunamis \n");
printf("Maximum Wave Height (in feet): %.2f \n", max*3.28);
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);


if(t[max_i].yr==t[k].yr)
max_iyr++;

}

printf("\nThe number of tsunamis in the file during the same year as the maximum wave height is %d\n\n",max_iyr);
printf("The tsunami with the largest number of fatalities is %s\n\n",t[fts_yr].location);

printf("\nTsunamis with over 100 fatalities: \n");
for (int k = 0; k <= npts - 1; k++)
if (t[k].fatalities > 100)
printf("%s \n", t[k].location);

printf("\nTsunamis that occurred during the month of July: \n");
for (k = 0; k <= npts - 1; k++)
if (t[k].mo == 7)
printf("%s \n", t[k].location);

char temp[10]={'P','e','r','u'};
for (k = 0; k <= npts - 1; k++)
if (t[k].location[0] == 'P')
if (t[k].location[1] == 'e')
if (t[k].location[2] == 'r')
if (t[k].location[3] == 'u')
count_loc++;


printf("\nThe number of tsunamis in Peru: %d \n",count_loc);


fclose(waves);
}
return 0;

}



lab:
const int BUTTON1_INT=0;
const int LIGHT2_INT=1;
const int RED=11;
const int GREEN=10;
const int BLUE=9;
volatile int selectedLED=BLUE;
void setup()
{
  pinMode(RED,OUTPUT);
  pinMode(GREEN,OUTPUT);
  pinMode(BLUE,OUTPUT);
  attachInterrupt(BUTTON_INT,swap,RISING);
  attachInterrupt(LIGHT_INT,red,RISING);
}
void swap()
{
  analogWrite(selectedLED,0);
  if(selectedLED==GREEN)
  selectedLED=RED;
  else if(selectedLED==RED)
  selectedLED=BLUE;
  else if(selectedLED==BLUE)
  selectedLED=GREEN;
}
void red()
{
  analogWrite(selectedLED,0);
  selectedLED=RED;
  
  
}
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);
  }
}


Comments

Popular posts from this blog

Homework 6

Another Day 23

Homework4