// 04232008.cpp, Anderson, Apr 23, '08
// lll h nnnn

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#define UPPER(x) (((x)>='a') && ((x)<='z')) ? ((x)-'a' + 'A') ? (x)

int main(void)
{
    int val, hi_lo, letter_index, n, num;
    char letters[8] = {'a', ' b', 'c', 'w' , 'v', 'y', 'x', 'f'}, ch;
    
    while(1)
    {
        printf(":");
        scanf("%x", &val);
        printf("%d %o %x\n", val, val, val);
        
        num = val & 0x0f;
        hi_lo = (val >> 4) & 0x01;
        letter_index = (val >> 5) & 0x07;
        
        for (n=0; n<num; n++)
        {
            if (hi_lo == 1)
            {
                ch = letters[letter_index];
                ch = toupper(ch);
                printf("%c", ch); 
            }
            else
            {
                printf("%c", letters[letter_index]);
            }
        }

        printf("\n");
        while(getchar() != 'x')
        {
        }

        printf("\n");
    }
}                
                
#ifdef LOG
       
    for (n=0; n<=NUM_POINTS; n++)
    {
        w = exp(log(10.0) + (log(10.0e3)- log(10.0 )) * n / NUM_POINTS);
        H = 1.0 / hypot(5000, w);  // for pole at -5000
        printf("%d %f %f\n", n, w, H);
        fprintf(fw, "%d %f %f\n", n, w, H);// 04232008b.cpp

#include 
#include 

void reverse_string(char s[]);
void join_string(char s1[], char s2[]);  // s1 = s1 + s2
void make_alpha_only(char s[]);
int compare_strings(char s1[], char s2[]);

int main()
{
   char s1[80], s2[80];
   int v;

   strcpy(s1, "olleH");
   strcpy(s2, "World");
 
   reverse_string(s1);
   printf("reversed string is %s\n", s1);

   join_string(s1, s2);
   printf("combined string is %s\n", s1); 

   strcpy(s1, "A^v(456d");
   make_alpha_only(s1);
   printf("alpha only string is %s\n", s1); 

   v = compare_strings(s1, s2);
   printf("%d\n", v);

   while(getchar() != 'x')
   {
   }
}

void reverse_string(char s[])
{  // stub
   int len, tmp;
   len = strlen(s);
   
   tmp = s[0];  s[0] = s[len-1], s[len-1] = tmp;  // in this stub, I only reversed first and last ltrs
}

void join_string(char s1[], char s2[])  // s1 = s1 + s2
{ // stub
   int len;
   len = strlen(s1);
   s1[len] = s2[0];  // I only added the first letter of s2
   s1[len+1] = '\0';
}

void make_alpha_only(char s[])
{ // stub
   char s2[80];
   strcpy(s2, s);
   // now traverse s2 and if character is alphabetical, put it in s
}

int compare_strings(char s1[], char s2[])
{ // stub
    if (s1[0] == s2[0])
    {
        return(0);
    }
    else if (s1[0] < s2[0])
    {
        return(-1);
    }
    else
    {
        return(1);
    }
}

///////////////////////////////////

// 04282008c.cpp, P H Anderson, Apr 23, '08 

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

float find_slope(float x1, float x2, float y1, float y2);

FILE *fw;

int main(void)
{
	float x1, x2, y1, y2, slope, x_mean;
    int n;

    fw = fopen("c:\\data.txt","wt");

    for (n=0; n<100; n++)
    {
		x1 = 1.0e-6 + 4.0 * M_PI * n /100;
		x2 = 1.0e-6 + 4.0 * M_PI * (n+1) /100;
		y1 = sin(x1) / x1;
		y2 = sin(x2) / x2;

		slope = find_slope(x1, x2, y1, y2);
		x_mean = ((x2 - x1) / 2.0) + x1;
		printf("%f %f\n", x_mean, slope);
		fprintf(fw, "%f, %f\n", x_mean, slope);
		
		if (((n % 20)==0) && (n!=0)) // pause every 20 lines
		{
		    while(getchar() != 'x')
		    {
		    }    
		}    
	}
	fclose(fw);
	
	while(getchar() != 'x')
	{
	}    
}

float find_slope(float x1, float x2, float y1, float y2)
{
	return( (y2 - y1) / (x2 - x1) );
}


    }   
#endif
  
///////////////////////