Advertisement
EnderWolf1013

Untitled

Sep 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4.  
  5. int main(void)  {
  6.     char form[25];
  7.     char var[10];
  8.     int a, h, k;
  9.     int vertex;
  10.     int upDown = 0;
  11.     int oldK, oldH = 0;
  12.     float aTwo, b, c;
  13.     char parabola[10];
  14.     float five = 0.0;
  15.     float y, x;
  16.    
  17.     printf("Hello, would you like to use vertex form or standard form? \n");
  18.     scanf("%s", form);
  19.    
  20.     printf("\n --------------------------------- \n \n");
  21.    
  22.     if(strcmp(form, "vertex") == 0) {
  23.         printf("Vertex form is Y = a(x-h)² + k \n");   //PEMDAS
  24.        
  25.         printf("\n --------------------------------- \n \n");
  26.        
  27.         printf("Do you have the variables a, h, and k? Answer Yes or No.\n");
  28.         scanf("%s", var);
  29.        
  30.         printf("\n --------------------------------- \n \n");
  31.        
  32.         if(strcmp(var, "yes") == 0) {   //This program tells the user about the various things that their formula gives them
  33.             printf("Please enter the variables in the following order: a, h, and then k \n");
  34.             scanf("%d %d %d", &a, &h, &k);
  35.            
  36.             printf("\n --------------------------------- \n \n");
  37.            
  38.             //int oldKTwo = k;
  39.             oldH = h;
  40.            
  41.             //Movement left and right
  42.             if(h>0) {   //so if H is positive, continue
  43.                 //H will go right
  44.                 printf("The X goes right by %d \n", h);
  45.             }
  46.             else    {   //So the H is negative here
  47.                 //H will go left
  48.                 printf("The X goes left by %d \n", abs(h));
  49.             }
  50.            
  51.            
  52.             //Movement up and down
  53.             if(k>0) {   //K is positive here
  54.                 //K goes up here
  55.                 printf("The Y will go up by %d \n", k);
  56.             }
  57.             else    {   //K is negative here
  58.                 //K will move down here
  59.                 printf("The Y will go down by %d \n", abs(k));
  60.             }
  61.            
  62.             if(a>1) {
  63.                 printf("The parabola has been stretched by a factor of %d \n", a);
  64.             }
  65.             else    {
  66.                 printf("The parabola has been compressed by a factor of %d, and has been flipped across the X axis. \n", abs(a));
  67.                 upDown = 1;
  68.             }
  69.            
  70.             //Axis of symmetry; X = H
  71.             printf("The Axis of Symmetry is X = %d \n", h);
  72.            
  73.             //Max or Min; if upDown == 1, then it's opening down, and it will have a Max
  74.             if(upDown == 1) {
  75.                 printf("The maximum is %d \n", k);
  76.             }
  77.             else    {
  78.                 printf("The minimum is %d \n", k);
  79.             }
  80.            
  81.             //Domain & Range
  82.             printf("The Domain is = all real numbers \n");
  83.             if(upDown == 1) {
  84.                 printf("The Range is = all real numbers LESS than or EQUAL to %d \n", k);
  85.             }
  86.             else    {
  87.                 printf("The Range is = all real numbers GREATER than or EQUAL to %d \n", k);
  88.             }
  89.            
  90.            
  91.             //Vertex
  92.             printf("Vertex is (%d, %d) \n", h, k);
  93.            
  94.            
  95.             printf("\n --------------------------------- \n \n");
  96.            
  97.            
  98.             if(h<0) {
  99.                
  100.                 if(k<0) {
  101.                     printf("Your vertex formula is Y = %d(x+%d)² - %d \n", a, abs(h), abs(k));
  102.                 }
  103.                 if(k>0) {
  104.                     printf("Your vertex formula is Y = %d(x+%d)² + %d \n", a, abs(h), k);
  105.                 }
  106.                
  107.             }
  108.            
  109.             if(h>0) {
  110.                
  111.                 if(k<0) {
  112.                     printf("Your vertex formula is Y = %d(x-%d)² - %d \n", a, h, abs(k));
  113.                 }
  114.                 if(k>0) {
  115.                     printf("Your vertex formula is Y = %d(x-%d)² + %d \n", a, h, k);
  116.                 }
  117.                
  118.             }
  119.            
  120.             printf("\n --------------------------------- \n \n");
  121.            
  122.             //Vertex to Standard form
  123.             //(a+b)² = a² + 2ab + b²
  124.            
  125.             /*                          Example
  126.                     Y = a(x-h)² + K    >>> Y = Ax² + Bx + C
  127.                     (a+b)² = a² + 2ab + b²
  128.                     (x-h)² = x² + 2x*(-h) + (-h)²    *
  129.                    
  130.                     Y = 2(x+3)² - 22
  131.                     (x+3)² = x² + 6x + 9
  132.                     Y = 2(x² + 6x + 9) -22
  133.                     Y = 2x² + 12x + 18 - 22
  134.                     Y = 2x² + 12x - 4
  135.                    
  136.                     Y = a(x-h)² + k
  137.                     Y = a(x² + 2x(-h) + (-h)²) + k
  138.                     Y = ax² + a*2x(-h) + a(-h)² + k
  139.                     Then                            ^ combine ^
  140.             */
  141.            
  142.             if(h<0) {
  143.                
  144.             //printf("Y = %d(x-(%d))² + (%d) \n", a, h, k);
  145.             int kaiser = 2 * h;
  146.             int schibbe = pow(h, 2);
  147.             //printf("(x+(%d))² = x² + %dx + (%d) \n", h, abs(kaiser), schibbe);
  148.            
  149.             //printf("Y = %d(x² + %dx + (%d) + %d \n", a, abs(kaiser), schibbe, k);
  150.             int lacht = a * schibbe;
  151.             int rein = a * abs(kaiser);
  152.             int kurwa = lacht + k;
  153.             printf("Your standard formula is Y = %dx² + (%d)x + (%d) \n", a, rein, kurwa);
  154.             }
  155.            
  156.             if(h>0) {
  157.             int kaiser = 2 * h;
  158.             int schibbe = pow(h, 2);
  159.            
  160.             int lacht = a * schibbe;
  161.             int rein = a * abs(kaiser);
  162.             int kurwa = lacht + k;
  163.             printf("Your standard formula is Y = %dx² - (%d)x + (%d) \n", a, rein, kurwa);
  164.             }
  165.            
  166.             /*printf("Y = %d(x-(%d))² + (%d) \n", a, h, k);
  167.             int kaiser = 2 * h;
  168.             int schibbe = pow(h, 2);
  169.             printf("(x+(%d))² = x² + %dx + (%d) \n", h, kaiser, schibbe);
  170.             printf("Y = %d(x² + 2x(%d) + (%d)²) + %d \n", a, h, h, k);
  171.             printf("Y = %dx² + %d * 2x(%d) + %d(%d)² + %d \n", a, a, h, a, h, k);*/
  172.            
  173.            
  174.            
  175.             //printf("Your standard formula is Y = ")
  176.            
  177.         }
  178.        
  179.         /*if(strcmp(var, "no") == 0)    {   //This program will write the formula for the user based on the things they input
  180.             printf("Please enter the following: \n");
  181.            
  182.             //Enter vertex
  183.             printf("Vertex \n");
  184.             scanf("%d %d", &h, &k);
  185.            
  186.             //Does it open up or down
  187.             //printf("Does it open or down? \n");
  188.             //scanf("%s", parabola);    //If up, the a will be positive. If down, the a will be negative
  189.            
  190.             //if the points move by something, you can find out what a is by putting Y/X and simplifying
  191.            
  192.             printf("What is another point? (x,y)\n");
  193.             scanf("%d %d", &x, &y);
  194.            
  195.             printf("\n --------------------------------- \n \n");
  196.            
  197.            
  198.             //printf("Your current two points are v(%d, %d) and (%d, %d) \n \n \n", h, k, x, y);
  199.            
  200.             float aa = y/x;
  201.            
  202.             printf("The formula is Y = %g(x - (%d)) + (%d) \n", aa, h, k);
  203.            
  204.            
  205.             //Y = a(x-h)² + k
  206.         }*/
  207.        
  208.     }
  209.    
  210.     if(strcmp(form, "standard") == 0)   {
  211.         printf("Standard form is Y = Ax² + Bx + C \n \n");
  212.        
  213.         printf("Please enter the variables in this order: a, b, c. \n \n");
  214.         scanf("%g %g %g", &aTwo, &b, &c);
  215.         printf("\n --------------------------------- \n \n");
  216.        
  217.        
  218.         //Parabola opening
  219.         if(aTwo>0)  {
  220.             printf("The parabola opens upward.\n ");
  221.         }
  222.         else    {
  223.             printf("The parabola opens downward.\n");
  224.         }
  225.        
  226.        
  227.         //Axis of Symmetry
  228.         float psy = b * -1;
  229.         float dave = 2*aTwo;
  230.         float axis = b/dave;
  231.         axis*=-1.0;
  232.         printf("The Axis of Symmetry is X = %g \n", axis);  //Axis of Symmetry
  233.        
  234.        
  235.         //Y coordinate
  236.         float one = pow(axis, 2);
  237.         float two = one * aTwo;
  238.         float three = b * axis;
  239.         float four = c;
  240.         float five = two + three + four;
  241.         printf("The Y coordinate is %g \n", five);  //Y coordinate
  242.        
  243.        
  244.         printf("The vertex is (%g, %g) \n", axis, five);    //vertex
  245.        
  246.        
  247.         printf("The y-intercept is (0, %g) \n", c); //Y intercept
  248.        
  249.         //Max and Min
  250.         if(aTwo>0)  {
  251.             printf("The minimum is %g \n", five);
  252.         }
  253.         else    {
  254.             printf("The maximum is %g \n", five);
  255.         }
  256.        
  257.         //Range
  258.         if(aTwo>0)  {
  259.             printf("The range is Y ≥ %g \n", five);       //Minimum
  260.         }
  261.         else    {
  262.             printf("The range is Y ≤ %g \n", five);   //Maximum
  263.         }
  264.        
  265.        
  266.        
  267.         //Turn the standard form into vertex form using the vertex.
  268.         //Vertex form is Y= a(x-h)² + K
  269.         //standard form is Y= Ax² + Bx + C
  270.         //aTwo=a, axis=h, five=k
  271.         printf("The vertex form is Y = (%g)(x - (%g)) + (%g) \n", aTwo, axis, five);
  272.        
  273.        
  274.     }
  275.    
  276.     return 0;
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement