Archive for the ‘Science’ Category

Why?

This poor soul just doesn’t understand.

Read more

Recursion Practice

Write a recursive function named two_ele_subs with one character string argument. The function will print all of the two-element subsets of a given set of letters. Write a main function with a loop to test the two_ele_subs function with different input character strings.

To leave the loop press ‘^’ and ‘z’ key while holding down the control key:

‘control’ + ‘^’ then ‘control’ + ‘z’

Iterative Version:

#include <stdio.h>
#include <string.h>

#define max_length 50

void two_ele_subs(char * str){

 int n = strlen(str);
 int i = 0;
 int j = 1;

     while(i < n){
         while(j < n){
            printf("[%c,%c]\n", str[i], str[j]);
              ++j;
         }
      ++i;
      j = i + 1;
    }
 printf("\n\nEnter your string: ");
}

int main(void){

    char str[max_length];

      printf("Enter your string: ");
    while(scanf("%s", &str) != EOF){
      two_ele_subs(str);
    }

system("pause");
return 0;
}

Recursive Version:

 #include <stdio.h>
 #include <string.h>

 #define max_length 50

 void two_ele_subs(char * str){

 int n = strlen(str);
 int i = 0;
 int j = 1;
     if(n > 1){
         while(j < n){
             printf("[%c,%c]\n", str[i], str[j]);
             ++j;
         }if(i < n){
            ++i;
         }
      two_ele_subs(str+1);
     }
}

int main(void){

char str[max_length];

    printf("Enter your string: ");
  while(scanf("%s", &str) != EOF){
     two_ele_subs(str);
     printf("\n\nEnter your string: ");
 }

system("pause");
return 0;
}

Array Practice

Problem Description:

Each year the Department of Traffic Accidents receives accident count reports from a number of cities and towns across the country. To summarize these reports, the department provides a frequency distribution printout that gives the number of cities reporting accident counts in the following ranges:

0 – 99
100 – 199
200 – 299
300 – 399
400 – 499
500 or above

The department needs a computer program to take the number of accidents for each reporting city or town and add one to the count for the appropriate accident range. After all the data have been processed, the resulting frequency counts are to be displayed.

Traffic Accident Addition (.exe)


#include <stdio.h>

#define size 6

void updateRange (int *i, int *a_range){
     *i = 0;
   while(*i >= 0){
        printf("Enter an accident count (negative to end): ");
        scanf("%d", &*i);
                if (*i <= 0){
                }else if (*i <= 99){
                   a_range[0]++;
                }else if (*i <= 199){
                   a_range[1]++;
                }else if (*i <= 299){
                   a_range[2]++;
                }else if (*i <= 399){
                   a_range[3]++;
                }else if (*i <= 499){
                   a_range[4]++;
                }else if (*i >= 500){
                   a_range[5]++;
                }
         }
}

void displayRange (int *a_range){
  int y = 0;
  int numRange1 = 0;
  int numRange2 = 99;
    printf("\n   Range  Frequency\n\n" );
    printf("%4d-%3d%10d\n ",numRange1, numRange2, a_range[y]);
    ++y;
        while(y < 5){
          numRange1 += 100;
          numRange2 += 100;
            printf("%d-%d%10d\n ", numRange1, numRange2, a_range[y]);
            ++y;
        }
    numRange1 += 100;
    printf("%d or above%5d\n\n",numRange1, a_range[y]);
}

int main(void){
  int i = 0;
  int a_range[size];
      while (i < size){
          a_range[i] = 0;
        ++i;
      }
  updateRange(&i, &*a_range);
  displayRange(&*a_range);
system("pause");
return 0;
}

Projectile Program (slowly working on)

/* This program calculates for the standard projectile physics problem in two directions */

#include <stdio.h>
#include <math.h>

#define g -9.81            /* Gravity Constant */
#define rconstant .017453 /* 180/pi or radian conversion constant */

/* All motion in towards ground will have to be negative */

/* Shelved until later - Hang Time */
double t_unkown_hangtime (double *viy, double *yi, double *yf, double *angle, double *t, double *tmax){

     if(((*angle) < 180) && ((*yf) > (*yi))){
     /* Make sure this works for the proper time... need to do it when awake */
               *tmax = (-((*viy)) - (sqrt((pow((*viy), 2)) - ((2*(g)*(-(*yf) +  (*yi)))))) / (g));
     }else if((*angle > 180) && ((*yf) < (*yf))){
               *tmax = (-((*viy)) - (sqrt((pow((*viy), 2)) - ((2*(g)*(-(*yf) +  (*yi)))))) / (g));
     }
     return (*tmax);
}

/* Calculate Distance Traveled */
double distance_final_x(double *xi, double *xf, double *yi, double *yf, double *viy, double *vix, double *vfx, double *t){

       double change_in_x;
       double change_in_y;

       if (*yi == 0 && *yf == 0 && *t != 9999){
          *xf = (*xi) + ((*vix)*(*t)) + (.5*g)*(pow((*t), 2));
       }else if (*yi == 0 && *yf == 0 && *t == 9999){
          change_in_x = (((pow((*vfx), 2)) - (pow((*vix), 2))) / (2*g));
          (*yf) = (change_in_y - (*yi));
       }}

/* Breaks the vi into components */
void components_vi_with_vi (double *vi, double *angle, double *viy, double *vix){
       double radians;
              radians = ((*angle) * (rconstant));
              *viy = ((*vi) * (sin(radians)));
              *vix = ((*vi) * (cos(radians)));
       }          

/* Breaks the vf into components */
void components_vf_with_vf (double *vf, double *angle_impact, double *vfy, double *vfx){
     double radians;
            radians = ((*angle_impact) * (rconstant));
              *vfy = ((*vf) * (sin(radians)));
              *vfx = ((*vf) * (cos(radians)));
      }

int
main (void){

double vi;
double viy;
double vix;
double vf;
double vfy;
double vfx;
double xi;
double xf;
double yi;
double yf ;
double t;
double angle;
double angle_impact;
double tmax;

     printf("This program should calculate for the unkowns in a  physic projectile problem.\n");
     printf("\nThe program is limited to two variable (x and y directions)\n");
     printf("and should tell you the max height, hang time, and an unknown\n");
     printf("Please enter the data with using the unit circle as your guide. ");

     printf("\n\nPlease enter the initial velocity: ");
     scanf("%lf", &vi);
     printf("\nPlease enter the angle fired from ground (x-axis) in degrees: ");
     scanf("%lf", &angle);
     printf("\nPlease enter the final velocity (zero if hitting the ground): ");
     scanf("%lf", &vf);
     printf("\nPlease enter the angle of impact from the -x direction: ");
     scanf("%lf", &angle_impact);
     printf("\nPlease enter the inital position in x direction,\n");
     printf("(Enter 0 if you have not been told otherwise): ");
     scanf("%lf", &xi);
     printf("\nPlease enter the final position in x direction: ");
     scanf("%lf", &xf);
     printf("\nPlease enter your inital position off the ground (y): ");
     scanf("%lf", &yi);
     printf("\nPlease enter your final position off the ground (y): ");
     scanf("%lf", &yf);
     printf("\nPlease enter time (if time isn't required please type ""9999"" for hang time): ");
     scanf("%lf", &t);
     while ((360 <= angle) || (-360 >= angle)){
     printf("\n FAILURE, PLEASE ENTER AN ANGLE BETWEEN -360 and 360: ");
     scanf("%lf", &angle);
     }
     while ((360 <= angle_impact) || (-360 >= angle_impact)){
           printf("\n FAILURE, PLEASE ENTER AN ANGLE BETWEEN -360 and 360: ");
     scanf("%lf", &angle);
     }

          components_vi_with_vi(&vi, &angle, &viy, &vix);

          components_vf_with_vf (&vf, &angle_impact, &vfy, &vfx);

          t_unkown_hangtime (&viy, &yi, &yf, &angle, &t, &tmax);

          distance_final_x (&xi, &xf, &yi, &yf, &viy, &vix, &angle, &t);

     printf("\nTesting Functions: %.2f \n", angle_impact);     

 system("pause");
return 0;
}

Programming Problem

 Found on a website and figured I would whirl!

The electric company charges according to the following rate schedule:

9 cents per kilowatt-hour (kwh) for the first 300 kwh

8 cents per kwh for the next 300 kwh (up to 600 kwh)

6 cents per kwh for the next 400 kwh (up to 1,000 kwh)

5 cents per kwh for all electricity used over 1,000 kwh.

 

Write a function to compute and return the total charge for each customer. Write a main function to call the charge calculation function using the following data:

 

Customer Number             Kilowatt-hours used

123                                         725

205                                         115

464                                         600

596                                         327

601                                         915

613                                       1,011

722                                          47

 

The program should print a three-column chart listing the customer number, the kilowatt-hours used, and the charge for each customer. The program should also compute and print the number of customers, the total kilowatt-hours used, and the total charges.

 

My Solution:/* Problem Description:

/* Problem Description:
* The electric company charges according to the following rate schedule:
* 9 cents per kilowatt-hour (kwh) for the first 300 kwh
* 8 cents per kwh for the next 300 kwh (up to 600 kwh)
* 6 cents per kwh for the next 400 kwh (up to 1,000 kwh)
* 5 cents per kwh for all electricity used over 1,000 kwh.
* Write a function to compute and return the total charge for each customer.
*/
#include <stdio.h>
#include <math.h>

#define first .09 /* 9 cents per kwh for first 300 kwh */
#define second .08 /* 8 cents per kwh for next 300 kwh */
#define third .06 /* 6 cents per kwh for next 400 kwh */
#define fourth .05 /* 5 cents per kwh for remaining kwh’s */

/* Ouput Variables */

double cost;
double total_cost = 0;
int total_customers = 0;
int total_kwh = 0;

/* Cost Calculating (for kwh) */
double charge_calc_kwh (int *kwhp, int *cust){

if(*kwhp < 300){
cost = ((*kwhp) * (first));
}else if(*kwhp < 600){
cost = (300 * first) + ((*kwhp – 300) * (second));
}else if(*kwhp < 1000){
cost = (300 * first) + ((300) * (second))
+ ((*kwhp – 600) * (third));
}else if(*kwhp > 1000){
cost = ((300) * (first)) + ((300) * (second))
+ ((400) * (third)) +
((*kwhp – 1000) * (fourth));
}
if(*cust && *kwhp != -1){
printf(“\nCustomer Num: %d”, *cust);
printf(” KWH used: %d”, *kwhp);
printf(” Charge: %.2f\n”, cost);
}
return(cost);
}

/* Totaling Values for Final Print */
int totaling(int *kwhp, double *cost){

if(*kwhp != -1){
total_cost += *cost;
total_kwh += *kwhp;
total_customers = ++total_customers;
}else{
printf(“\nTotal Customers: %d”, total_customers);
printf(” Total KWH used %d”, total_kwh);
printf(” Total Charges %.2f\n”, total_cost);
}
return(total_cost, total_kwh, total_customers);
}

int
main(void){
/* Input Values */
int kwh; /* kilowatt-hours per customer */
int cust; /* customer number */

while(kwh != -1 && cust != -1){
printf(“Enter customer number and KWH (-1 to quit): “);
scanf(“%d %d”, &cust, &kwh);
charge_calc_kwh(&kwh, &cust);
totaling(&kwh, &cost);
}

system(“pause”); /* MMMmm windows */
return (0);
}

 

 

C Programming Exercise #1 (Linux)

/* Program which averages  temperatures and states the number of “cool,” “pleasant,” and “warm” days */

#include <stdio.h>
#include <math.h>

int
main(void){

int temp;
int h = 0;
int p = 0;
int c = 0;
int a = 0;
double avg;

printf(“Enter the temprature (-99 to stop): “);
scanf(“%d”, &temp);
while (temp != -99) {

if (temp >= 85) {

h = (h + 1);
a = (a + temp);

} else if (60 > temp) {

c = (c + 1);
a = (a + temp);

} else if (60 <= temp < 85) {

p = (p + 1);
a = (a + temp);

}

printf(“Enter the temprature (-99 to stop): “);
scanf(“%d”, &temp);

}

avg = (((double)a)/(double)(h+p+c));

printf(“\nThe number of hot days is %d. \n”, h);
printf(“The number of pleasant days is %d. \n”, p);
printf(“The number of cold days is %d. \n\n”, c);

printf(“The average tempreture is %.2f.\n”, avg);

return 0;
}

Letter to my Senetor

Topic: Immigration

Title: PROTECT IP Act

I used the topic of immigration here because I felt it was fitting, although not exactly the subject I intend to write about. Here it is, pass that act and i’ll emigrate as soon as possible and will do anything in my power to protest such an act. I wish to be free in my own country, to protect myself on the internet as much as I can protect my home. This bill is threatening my freedom AND security at the same time.

Amendment I to the Constitution -
“Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press”

In this case you are effectively abridging the freedom of speech/press.

Amendment IV to the Constitution -
“The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.”

The government would effectively be entitled to the search and seizure of online effects without a warrant and I feel this is unreasonable. If I do not have a right to secure a means of exchange, then why should I live here? Or anyone for that matter?

Amendment V to the Constitution -
“No person shall be held to answer for a capital, or otherwise infamous crime, unless on a presentment or indictment of a Grand Jury, except in cases arising in the land or naval forces, or in the militia, when in actual service in time of war or public danger; nor shall any person be subject for the same offense to be twice put in jeopardy of life or limb; nor shall be compelled in any criminal case to be a witness against himself, nor be deprived of life, liberty, or property, without due process of law; nor shall private property be taken for public use without just compensation.”

My and many others exist on the internet intellectual property , you are depriving me of my liberty previous to a process of law. The right to protecting myself was upheld by the courts throughout the history of this country. Toss aside that right, allow myself to be tracked, monitored, my data stolen, and allow companies to do the same and I will have no choice, but to leave this country.

Amendment IX to the Constitution -
“The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.”

Disable my rights and I am no more than a slave.

Please give this to who ever you feel can make a difference, I cannot stand for it, I cannot suffer it. Please submit it to everyone in the house and senate if you need to.

A Child Parent

Those who know me would probably call me the most stubborn person they know, my parents, my girlfriend, my teachers, my closest friends, all believe I am one of the most stubborn they have ever met. Well here is why, I refuse to do something that I do not understand, I did not want to learn to read because it was not explained to me why I should. Once it was explained I quickly went on to the highest of reading levels simply because I realized that reading was good for me. My father had a similar story with punishment which he loves to tell anyone who listens, when I was younger any time my parents attempted to punish me by telling me to do something such as sitting in a chair I would simply say “no.” They would then attempt to place me there and hold me while I struggled, punching, nawing anything to hurt them or myself to cause them pity. I sound like a brat right? Interesting enough, eventually I told them what their problem was, at the age of ten I explained that they needed to be fair. I understood I had as much power as they did to command, only less physical force. However, to my advantage I had their pity for me and reluctance of using their strength. Which led me to simply explain to them that if they treat me fair and deal with me by giving me chores in order to give me freedom, I would be willing to do as I am told. I was not willing to accept punishments for something which I did not understand or something that I did not agree to.

Take this lesson to all parents, learn to teach your children how to trade, explain every action. I do not remember one time where I have accepted punishment which I felt to be unjust, nor have I ever committed what I would consider a crime or broken a rule which I felt to be just. I have never stolen, never hurt another unless force was used on me, I avoided arguments, I avoided discussing in class unless called upon, I never speak at my job except to ask or answer questions. This is how I have been my whole life, even since I was a child, perhaps if children were taught that this is the right way to act, to trade to communicate, to discuss WHY to do something parents would have a better handle on their children as well as teach them how to react in the world.

Armadillo Lizard

Today I am venturing out to purchase my first armadillo lizard, not even technically mine, rather a gift for a friend who will obtain it on a future date. I intend to put up a full care sheet (including eventually how to entice them to mate), and add as much information as I can. When looking on the internet I could not find any information pertaining to raising, breeding, or even where to obtain these lizards, I now intend to do all of that on my own.

 

From current reading this is what I understand to be the way in which you care for them:

  • 20 gallon tank (screen lid)
  • coconut sub-strait (3 inches thick)
  • hiding place
  • water dish
  • crickets for food
  • UVB and heat lamp
  • a couple large rocks for basking (100 degrees)
  • up to three can be housed in that 20 gallon tank (though not recommended) and only one male per.
  • lighting is on for 8-10 hours per day

Republican Debate 12/10/11 Looking Back.

I sat down to one of the many debates scheduled for the Republican candidates to state there positions and apparently feelings on why they should be President. The only ones who did not seem to state why they feel they should be President of the United States is Rick Santorum and Ron Paul from what I could tell. The new beast, that is Newt-Romney, has so elegantly stated how I feel about the two of them. The new Newt-Romney beast has forever tied together the two leading candidates, a good call Michele Bachmann’s crew, hopefully forming a lasting tie in all the viewers brains that will hold Newt Gingrich and Mitt Romney as a single unit, forcing a split between their votes. It has yet to be seen how many jokes will be made, but it is certain that the new Newt-Romney monstrosity will dampen the hopes of both parties, or at least, brighten the spirits of those listening to jokes!

Read more

Return top
  • Copyright ©  2011-2012  Lettergram
  • Powered by Lettergram!