Thursday, August 30, 2018

day 2 8/30/18

Femur and Humerus problems

#1  Modify the program so that it converts the output values from inches to feet. The input would still be entered in inches. Use a single value for the output, such as 6.5 feet.

#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double femur, femur_ht_f, femur_ht_m, humerus, humerus_ht_f,
humerus_ht_m;
/* Get user input from the keyboard. */
printf("Enter Values in Inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
/* Compute height estimates. */
femur_ht_f = (femur*1.94 + 28.7)/12;
femur_ht_m = (femur*1.88 + 32)/12;
humerus_ht_f = (humerus*2.8 + 28.2)/12;
humerus_ht_m = (humerus*2.9 + 27.9)/12;
/* Print height estimates. */
printf("\nHeight Estimates in Feet \n");
printf("Femur Female Estimate: %5.2f \n",femur_ht_f);
printf("Femur Male Estimate: %5.2f \n",femur_ht_m);
printf("Humerus Female Estimate: %5.2f \n",humerus_ht_f);
printf("Humerus Male Estimate: %5.2f \n",humerus_ht_m);
/* Exit program. */
return 0;
}

#2 Modify the program so that it asks the user to enter the values in feet. The program would then need to convert the values in feet to inches before doing the computations. The output would also print the output heights in feet, as in 6.5 feet.

#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double femur, femur_ht_f, femur_ht_m, humerus, humerus_ht_f,
humerus_ht_m;
/* Get user input from the keyboard. */
printf("Enter Values in feet. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
/* Compute height estimates. */
femur=femur*12;
humerus=humerus*12;
femur_ht_f = (femur*1.94 + 28.7)/12;
femur_ht_m = (femur*1.88 + 32)/12;
humerus_ht_f = (humerus*2.8 + 28.2)/12;
humerus_ht_m = (humerus*2.9 + 27.9)/12;
/* Print height estimates. */
printf("\nHeight Estimates in Feet \n");
printf("Femur Female Estimate: %5.2f \n",femur_ht_f);
printf("Femur Male Estimate: %5.2f \n",femur_ht_m);
printf("Humerus Female Estimate: %5.2f \n",humerus_ht_f);
printf("Humerus Male Estimate: %5.2f \n",humerus_ht_m);
/* Exit program. */
return 0;
}

#3 Modify the program so that it reads the input values in inches and then estimates the output heights using feet and inches. (Note that you are printing two output values for each height estimate.)

#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double femur, femur_ht_f_i,femur_ht_f_f, femur_ht_m_i,femur_ht_m_f, humerus, humerus_ht_f_i, humerus_ht_f_f,
humerus_ht_m_i, humerus_ht_m_f;
/* Get user input from the keyboard. */
printf("Enter Values in inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
/* Compute height estimates. */
femur_ht_f_f = (femur*1.94 + 28.7)/12;
femur_ht_m_f = (femur*1.88 + 32)/12;
humerus_ht_f_f = (humerus*2.8 + 28.2)/12;
humerus_ht_m_f = (humerus*2.9 + 27.9)/12;
femur_ht_f_i = (femur*1.94 + 28.7);
femur_ht_m_i = (femur*1.88 + 32);
humerus_ht_f_i = (humerus*2.8 + 28.2);
humerus_ht_m_i = (humerus*2.9 + 27.9);
/* Print height estimates. */
printf("\nHeight Estimates in Feet \n");
printf("Femur Female Estimate: %5.2f \n",femur_ht_f_f);
printf("Femur Male Estimate: %5.2f \n",femur_ht_m_f);
printf("Humerus Female Estimate: %5.2f \n",humerus_ht_f_f);
printf("Humerus Male Estimate: %5.2f \n",humerus_ht_m_f);
printf("\nHeight Estimates in Inches \n");
printf("Femur Female Estimate: %5.2f \n",femur_ht_f_i);
printf("Femur Male Estimate: %5.2f \n",femur_ht_m_i);
printf("Humerus Female Estimate: %5.2f \n",humerus_ht_f_i);
printf("Humerus Male Estimate: %5.2f \n",humerus_ht_m_i);
/* Exit program. */
return 0;
}

#4 Modify the program so that it reads the input values in feet and inches, and then estimates the output heights using feet and inches. (Note that you are reading two input values for each bone and you are printing two output values for each height estimate.)

#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double femur_i, femur_f, femur_ht_f_i,femur_ht_f_f, femur_ht_m_i,femur_ht_m_f, humerus_i, humerus_f, humerus_ht_f_i, humerus_ht_f_f,
humerus_ht_m_i, humerus_ht_m_f;
/* Get user input from the keyboard. */
printf("Enter Values in inches. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur_i);
printf("Enter humerus length: \n");
scanf("%lf",&humerus_i);
printf("now enter the values in feet.\n");
printf("Enter femur length: \n");
scanf("%lf",&femur_f);
printf("Enter humerus length: \n");
scanf("%lf",&humerus_f);
/* Compute height estimates. */
femur_f=femur_f*12;
humerus_f=humerus_f*12;
femur_ht_f_f = (femur_f*1.94 + 28.7)/12;
femur_ht_m_f = (femur_f*1.88 + 32)/12;
humerus_ht_f_f = (humerus_f*2.8 + 28.2)/12;
humerus_ht_m_f = (humerus_f*2.9 + 27.9)/12;
femur_ht_f_i = (femur_i*1.94 + 28.7);
femur_ht_m_i = (femur_i*1.88 + 32);
humerus_ht_f_i = (humerus_i*2.8 + 28.2);
humerus_ht_m_i = (humerus_i*2.9 + 27.9);
/* Print height estimates. */
printf("\nHeight Estimates in Inches \n");
printf("Femur Female Estimate: %5.2f \n",femur_ht_f_i);
printf("Femur Male Estimate: %5.2f \n",femur_ht_m_i);
printf("Humerus Female Estimate: %5.2f \n",humerus_ht_f_i);
printf("Humerus Male Estimate: %5.2f \n",humerus_ht_m_i);
printf("\nHeight Estimates in Feet \n");
printf("Femur Female Estimate: %5.2f \n",femur_ht_f_f);
printf("Femur Male Estimate: %5.2f \n",femur_ht_m_f);
printf("Humerus Female Estimate: %5.2f \n",humerus_ht_f_f);
printf("Humerus Male Estimate: %5.2f \n",humerus_ht_m_f);
/* Exit program. */
return 0;
}

#5 Modify the program so that it reads the bone values in centimeters and outputs the height estimates in centimeters. (Recall that 1 in = 2.54 cm.)

#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables. */
double femur, femur_ht_f, femur_ht_m, humerus, humerus_ht_f,
humerus_ht_m;
/* Get user input from the keyboard. */
printf("Enter Values in centimeters. \n");
printf("Enter femur length: \n");
scanf("%lf",&femur);
printf("Enter humerus length: \n");
scanf("%lf",&humerus);
/* Compute height estimates. */
femur=femur/2.54;
humerus=humerus/2.54;
femur_ht_f = (femur*1.94 + 28.7)*2.54;
femur_ht_m = (femur*1.88 + 32)*2.54;
humerus_ht_f = (humerus*2.8 + 28.2)*2.54;
humerus_ht_m = (humerus*2.9 + 27.9)*2.54;
/* Print height estimates. */
printf("\nHeight Estimates in centimeters \n");
printf("Femur Female Estimate: %5.2f \n",femur_ht_f);
printf("Femur Male Estimate: %5.2f \n",femur_ht_m);
printf("Humerus Female Estimate: %5.2f \n",humerus_ht_f);
printf("Humerus Male Estimate: %5.2f \n",humerus_ht_m);
/* Exit program. */
return 0;
}

Arduino Blink Light (in class)

const kled=2; void setup() { pinMode(2, OUTPUT); } void loop() { digitalWrite(kled, HIGH); delay(1000); digitalWrite(kled, LOW); delay(1000); }

Arduino chasing LED
I set up a few different ideas of how this could work.
#1 most basic back and forth

const int kLed = 2;

const int kLed2 = 3;

const int kLed3 = 4;
const int kLed4 = 5;

void setup()
{
    pinMode(kLed, OUTPUT);
    pinMode(kLed2, OUTPUT);
    pinMode(kLed3, OUTPUT);
    pinMode(kLed4, OUTPUT);
}

void loop()
{
    digitalWrite(kLed, HIGH);
    delay(50);
    digitalWrite(kLed, LOW);
    delay(50);
    digitalWrite(kLed2, HIGH);
    delay(50);
    digitalWrite(kLed2, LOW);
    delay(50);
    digitalWrite(kLed3, HIGH);
    delay(50);
    digitalWrite(kLed3, LOW);
    delay(50);
    digitalWrite(kLed4, HIGH);
    delay(50);
    digitalWrite(kLed4, LOW);
    delay(50);
    digitalWrite(kLed3, HIGH);
    delay(50);
    digitalWrite(kLed3, LOW);
    delay(50);
    digitalWrite(kLed2, HIGH);
    delay(50);
    digitalWrite(kLed2, LOW);
    delay(50);
}
#2 little more complex first light stays on and creates chain reaction

const int k_numLEDs = 4; const int kPinLeds[k_numLEDs] = {2,3,4,5}; void setup() { for(int i = 0; i < k_numLEDs; i++){ pinMode(kPinLeds[i], OUTPUT); } } void loop() { for(int i = 0; i < k_numLEDs; i++){ digitalWrite(kPinLeds[i], HIGH); delay(100); } for(int i = k_numLEDs - 1; i >= 0; i--){ digitalWrite(kPinLeds[i], LOW); delay(100); } }

#3 code that makes the first example speed up and slow down

const int kLed = 2; const int kLed2 = 3; const int kLed3 = 4; const int kLed4 = 5; void setup() { pinMode(kLed, OUTPUT); pinMode(kLed2, OUTPUT); pinMode(kLed3, OUTPUT); pinMode(kLed4, OUTPUT); } void loop() { digitalWrite(kLed, HIGH); delay(150); digitalWrite(kLed, LOW); delay(175); digitalWrite(kLed2, HIGH); delay(200); digitalWrite(kLed2, LOW); delay(175); digitalWrite(kLed3, HIGH); delay(150); digitalWrite(kLed3, LOW); delay(125); digitalWrite(kLed4, HIGH); delay(100); digitalWrite(kLed4, LOW); delay(75); digitalWrite(kLed3, HIGH); delay(50); digitalWrite(kLed3, LOW); delay(25); digitalWrite(kLed2, HIGH); delay(50); digitalWrite(kLed2, LOW); delay(75); digitalWrite(kLed, HIGH); delay(100); digitalWrite(kLed, LOW); delay(125); digitalWrite(kLed2, HIGH); delay(150); digitalWrite(kLed2, LOW); delay(175); digitalWrite(kLed3, HIGH); delay(200); digitalWrite(kLed3, LOW); delay(175); digitalWrite(kLed4, HIGH); delay(150); digitalWrite(kLed4, LOW); delay(125); digitalWrite(kLed3, HIGH); delay(150); digitalWrite(kLed3, LOW); delay(100); digitalWrite(kLed2, HIGH); delay(50); digitalWrite(kLed2, LOW); delay(50); digitalWrite(kLed, HIGH); delay(100); digitalWrite(kLed, LOW); delay(125); digitalWrite(kLed2, HIGH); delay(150); digitalWrite(kLed2, LOW); delay(175); digitalWrite(kLed3, HIGH); delay(200); digitalWrite(kLed3, LOW); delay(175); digitalWrite(kLed4, HIGH); delay(150); digitalWrite(kLed4, LOW); delay(75); digitalWrite(kLed3, HIGH); delay(50); digitalWrite(kLed3, LOW); delay(25); digitalWrite(kLed2, HIGH); delay(50); digitalWrite(kLed2, LOW); delay(75); }

Amino Acid Molecular weight problems

#1 Write a program to compute and print the molecular weight of glycine.

#include <stdio.h>
#include <math.h>
int main(void)
{
/*Declare and initialize variables. */
double O=15.9994, C=12.011, N=14.00674, S=32.066, H=1.00794, weight;
/*solves for molecular weight of glycine*/
weight= 2*O + 2*C + N + 5*H;
/*print*/
printf("The molecular weight of Glycine is %5.4f" ,weight);
//exit program
return 0;
}

#2 Write a program to compute and print the molecular weights of glutamic and glutamine.

#include <stdio.h>
#include <math.h>
int main(void)
{
/*Declare and initialize variables. */
double O=15.9994, C=12.011, N=14.00674, S=32.066, H=1.00794, weight, weight2;
/*solves for molecular weight of glutamic and glutamine*/
weight= 4*O + 5*C + N + 8*H;
weight2= 3*O +5*C + 2*N +10*H;
/*print*/
printf("The molecular weight of Glutamic is %5.4f and the molecular weight of glutamine is %5.4f" ,weight, weight2);
//exit program
return 0;
}

#3 Write a program that asks the user to enter the number of atoms of each of the five elements for an amino acid. Then compute and print the molecular weight for this amino acid.

#include <stdio.h>
#include <math.h>
int main(void)
{
//print
printf("Enter each amount of atom and we will do the rest! \nHow many Oxygen atoms?");
/*Declare and initialize variables. */
double O=15.9994,On, C=12.011,Cn, N=14.00674,Nn, S=32.066,Sn, H=1.00794,Hn, weight;
//scan for amount of atoms
scanf("%lf", &On);
printf("How many Carbon atoms?");
scanf("%lf", &Cn);
printf("How many Nitrogen atoms?");
scanf("%lf", &Nn);
printf("How many Sulfur atoms?");
scanf("%lf", &Sn);
printf("How many Hydrogen atoms?");
scanf("%lf", &Hn);
/*solves for molecular weight of entered atom values*/
weight= O*On + C*Cn + N*Nn + S*Sn + H*Hn;
/*print*/
printf("The molecular weight of the entered values is %4.1f ",weight);
//exit program
return 0;
}
(NOTE: Tried to make it so it would also compute which amino acid it was but couldnt figure it out.)

#4 Write a program that asks the user to enter the number of atoms of each of the five elements for an amino acid. Then compute and print the average weight of the atoms in the amino acid.

#include <stdio.h>
#include <math.h>
int main(void)
{
//print
printf("Enter each amount of atom and we will do the rest! \nHow many Oxygen atoms?");
/*Declare and initialize variables. */
double O=15.9994,On, C=12.011,Cn, N=14.00674,Nn, S=32.066,Sn, H=1.00794,Hn, avg, n;
//scan for amount of atoms
scanf("%lf", &On);
printf("How many Carbon atoms?");
scanf("%lf", &Cn);
printf("How many Nitrogen atoms?");
scanf("%lf", &Nn);
printf("How many Sulfur atoms?");
scanf("%lf", &Sn);
printf("How many Hydrogen atoms?");
scanf("%lf", &Hn);
/*solves for average weight of all atoms*/
n= On + Cn + Nn + Sn + Hn;
avg= (O*On + C*Cn + N*Nn + S*Sn + H*Hn)/n;
/*print*/
printf("The average weight of the entered values is %4.1f ",avg);
//exit program
return 0;
}

Wednesday, August 29, 2018

calculating the area of a sector of a circle

#include <stdio.h>
#include <math.h>
int main(void)
{
/*Declare and initialize variables. */
double d=50, radius=4, sector, pi=3.14159265359;
/*solves for area of a sector*/
sector = pi*radius*radius*(d/360);
/*print Nicole's code*/
printf("The area of the sector of the circle is ""%5.2f \n" "units^2" ,sector);
//exit program
return 0;
}

computing the area of an ellipse

#include <stdio.h>
#include <math.h>
int main(void)
{
/*Declare and initialize variables. */
double a=50, b=50, ellipse, pi=3.14159265359;
/*solves for area of an ellipse*/
ellipse = pi*a*b;
/*print Nicole's code*/
printf("The area of the ellipse is ""%5.2f \n" "units^2" ,ellipse);
//exit program
return 0;
}

conversion of degrees Celsius to degrees Rankine

#include <stdio.h>
#include <math.h>
int main(void)
{
/*Declare and initialize variables. */
double celsius=10, rankine;
/*converts celsius to rankine*/
rankine = (celsius+273.15)*9/5;
/*print Nicole's code*/
printf("The conversion from ""%5.2f \n""degrees celsius to degrees rankine is ""%5.2f\n""degrees rankine",celsius,rankine);
//exit program
return 0;
}

meters to miles conversion

#include <stdio.h>
#include <math.h>
int main(void)
{
/*Declare and initialize variables. */
float meters=10000, miles, convert=.000621371;
/*converts meters to miles*/
miles = convert*meters;
/*print Nicole's code*/
printf("The conversion from ""%5.2f \n""meters to miles is""%5.2f\n""miles",meters,miles);
//exit program
return 0;
}

distance code

#include <stdio.h>
#include <math.h>
int main(void)
{
/*Declare and initialize variables. */
double x1=2, y1=4, x2=2, y2=4, side_1, side_2, distance;
/*compute sides of a right triangle.*/
side_1 = x2-x1;
side_2 = y2-y1;
distance = sqrt(side_1*side_1 + side_2*side_2);
/*print Nicole's code*/
printf("The distance between the two points is""%5.2f \n",distance);
//exit program
return 0;
}