Sindbad~EG File Manager

Current Path : /usr/home/beeson/MathXpert/getprob/
Upload File :
Current File : //usr/home/beeson/MathXpert/getprob/ProblemLibrary.c

// ProblemLibrary.c
// MathXpert Calculus Assistant
//
// Created by Michael Beeson on 11/27/23.

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "tdefn.h"  // topic names and numbers
#include "errbuf.h"  // COMMENTARYBUFLENGTH 
#include "ProblemLibrary.h"


int stringToTopic(const char *topicparam);
/*_______________________________________________________________*/
static char* topicStrings[] =
{
    "dummy",                                    // 0
    "ordinary_graph",                           // 1
    "ordinary_graph_quadratic",                 // 2
    "ordinary_graph_polynomial",                // 3
    "ordinary_graph_linear",                    // 4
    "ordinary_graph_rational",                  // 5
    "ordinary_graph_fractexp",                  // 6
    "ordinary_graph_exponential",               // 7
    "ordinary_graph_log",                       // 8
    "ordinary_graph_algvariety",                // 9
    "ordinary_graph_sincos",                    // 10
    "ordinary_graph_trig",                      // 11
    "ordinary_graph_arctrig",                   // 12
    "ordinary_graph_htrig",                     // 13
    "ordinary_graph_trigvariety",               // 14
    "ordinary_graph_bessel",                    // 15

    "graph_taylor",                             // 16
    "graph_fourier",                            // 17
    "compare_same",                             // 18
    "compare_different",                        // 19
    "graph_ineq",                               // 20
    "graph_set",                                // 21
    "graph_circle",                             // 22
    "graph_ellipse",                            // 23
    "graph_parabola",                           // 24
    "graph_hyperbola",                          // 25
    "graph_relation",                           // 26

    "polyroots",                                // 27
    "parametric_graph",                         // 28
    "polar_graph",                              // 29
    "comparefandfprime",                        // 30
    "comparetwoderivs",                         // 31
    "contour_plot",                             // 32
    "complex_contour_plot",                     // 33
    "solve_ode",                                // 34
    "solve_two_odes",                           // 35
    "high_order_ode",                           // 36
    "riemann_sums",                             // 37
    "trapezoid_rule",                           // 38
    "simpsons_rule",                            // 39
    "space_curve",                              // 40
    "nonparametric_surface",                    // 41
    "polar_nonparametric_surface",              // 42
    "parametric_surface",                       // 43

    /* Algebra 1 */
    "evaluate_numerically",                     // 44
    "verify_algebraic_identity",                // 45
    "solve_linear_equation",                    // 46
    "multiply_polynomials",                     // 47
    "alg1_absolute_value",                      // 48
    "numerical_exponents",                      // 49
    "alg1_exponents",                           // 50
    "simple_factoring",                         // 51
    "alg1_factor_quadratic",                    // 52
    "factor_by_grouping",                       // 53

    "complete_the_square",                      // 54

    "alg1_linear_inequality",                   // 55
    "alg1_linear_systems",                      // 56
    "alg1_simplify",                            // 57
    "add_numerical_fractions",                  // 58

    "simplify_fractions",                       // 59
    "numerical_compound_fractions",             // 60
    "alg1_compound_fractions",                  // 61
    "equations_containing_fractions",           // 62
    "numerical_radicals",                       // 63
    "alg1_radicals",                            // 64

    /* Linear Algebra */
    "solve_linear_eqn",                         // 65
    "eqns_by_substitution",                     // 66
    "eqns_by_adding_eqns",                      // 67
    "eqns_in_matrix_form",                      // 68
    "gauss_jordan",                             // 69
    "eqns_by_matrix_inverse",                   // 70
    "cramers_rule",                             // 71

    /* Algebra 2 */
    "simplify",                                 // 72
    "simple_commondenom",                       // 73
    "advanced_commondenom",                     // 74
    "compound_fractions",                       // 75
    "simplify_polynomials",                     // 76
    "simple_exponents",                         // 77
    "simplify_rational_functions",              // 78
    "negative_exponents",                       // 79
    "eliminate_negative_exponents",             // 80
    "radicals",                                 // 81
    "absolute_value",                           // 82
    "fractional_exponents",                     // 83
    "eliminate_fractional_exponents",           // 84
    "factor_quadratics",                        // 85
    "quadratic_formula",                        // 86
    "solve_quadratic_equation",                 // 87
    "advanced_factoring",                       // 88
    "solve_higher_degree_equation",             // 89
    "solve_rational_equation",                  // 90
    "solve_root_equation",                      // 91
    "solve_fractions_and_roots",                // 92
    "solve_linear_inequality",                  // 93
    "solve_polynomial_inequality",              // 94
    "solve_rational_inequality",                // 95
    "solve_root_inequality",                    // 96
    "cubic_one_root",                           // 97
    "solve_equation",                           // 98
    "simplify_roots_and_powers",                // 99
    "simplify_roots_and_fractions",             // 100
    "simplify_any_function",                    // 101
    "verify_alg2_identity",                     // 102
    /* end Algebra 2 */

    /* Precalculus */
    "evaluate_trig",                            // 103
    "basic_trig",                               // 104
    "trig_addition",                            // 105
    "double_angle",                             // 106
    "half_angle",                               // 107
    "trig_product",                             // 108
    "trig_factor",                              // 109
    "trig_simplify",                            // 110
    "trig_identities",                          // 111
    "inverse_trig_functions",                   // 112
    "simple_trig_eqn",                          // 113
    "trig_eqn",                                 // 114
    "complex_arithmetic",                       // 115
    "logarithms",                               // 116
    "change_log_base",                          // 117
    "exponentials",                             // 118
    "simplify_logpower",                        // 119
    "log_eqn",                                  // 120
    "exp_eqn",                                  // 121
    "polar_form",                               // 122
    "de_moivre",                                // 123
    "hyperfunctions",                           // 124
    "hyperfunctions2",                          // 125
    "complex_trig",                             // 126
    "complex_quadratics",                       // 127
    "complex_cubics",                           // 128
    "sigma_notation",                           // 129
    "binomial_theorem",                         // 130
    "complex_roots",                            // 131

    /* Calculus 1  */
    "polynomial_limits",                        // 132
    "simple_limits",                            // 133
    "diff_from_def",                            // 134
    "diff_polynomial",                          // 135
    "diff_basics",                              // 136
    "lim_trig",                                 // 137
    "diff_trig",                                // 138
    "chain_rule",                               // 139
    "difreview",                                // 140
    "higher_order_diff",                        // 141
    "implicit_diff",                            // 142
    "related_rates",                            // 143
    "minmax",                                   // 144
    "rational_limits",                          // 145
    "limits_at_infinity",                       // 146
    "infinite_limits",                          // 147
    "sigma_notation1",                          // 148
    "int_poly",                                 // 149
    "simple_int",                               // 150
    "fundamental_theorem",                      // 151
    "int_by_substitution",                      // 152
    "int_by_parts1",                            // 153
    "intreview",                                // 154

    /* Calculus 2 */
    "lim_exp",                                  // 155
    "lhopitals_rule",                           // 156
    "limleadingterm",                           // 157
    "limits_any_function",                      // 158
    "diff_exp_from_defn",                       // 159
    "diff_exp",                                 // 160
    "diff_logs",                                // 161
    "logarithmic_differentiation",              // 162
    "diff_arctrig",                             // 163
    "diff_hyperbolic",                          // 164
    "diff_any_function",                        // 165
    "int_by_parts2",                            // 166
    "int_logs",                                 // 167
    "trigpower_integrals",                      // 168
    "trig_substitution",                        // 169
    "integrate_rational_functions",             // 170
    "rationalizing_substitutions",              // 171
    "integrate_any_function",                   // 172
    "improper_integrals",                       // 173
    "sum_series",                               // 174 // find the sum of a series
    "integral_test",                            // 175
    "comparison_test",                          // 176
    "root_ratio_tests",                         // 177
    "power_series1",                            // 178 // beginning power series
    "power_series2"                             // 179 // assumes basic series are known
};
/*_________________________________________________________________*/
int stringToTopic(const char *topicparam)
// topicparam should be one of the strings in the topicStrings array
// return the index of that string in the array, which should be the
// integer #defined in tdefn.h for that topic.  If the string passed
// is not in the array, return -1 to signal an error.
// It's a small array, not worth the trouble to make finding the entry more efficient.
{ int k;
  for(k=1; k < sizeof(topicStrings)/sizeof(char *); k++)  // k = 0 is "dummy"
     { if(!strcmp(topicparam, topicStrings[k]))
         return k;
     }
  return 1;
}
/*_________________________________________________________________*/

extern char *problems1[]; extern char *problems2[]; extern char *problems3[]; extern char *problems4[]; extern char *problems5[];
extern char *problems6[]; extern char *problems7[]; extern char *problems8[]; extern char *problems9[]; extern char *problems10[];
extern char *problems11[]; extern char *problems12[]; extern char *problems13[]; extern char *problems14[]; extern char *problems15[];
extern char *problems16[]; extern char *problems17[]; extern char *problems18[]; extern char *problems19[]; extern char *problems20[];
extern char *problems21[]; extern char *problems22[]; extern char *problems23[]; extern char *problems24[]; extern char *problems25[];
extern char *problems26[]; extern char *problems27[]; extern char *problems28[]; extern char *problems29[]; extern char *problems30[];
extern char *problems31[]; extern char *problems32[]; extern char *problems33[]; extern char *problems34[]; extern char *problems35[];
extern char *problems36[]; extern char *problems37[]; extern char *problems38[]; extern char *problems39[]; extern char *problems40[];
extern char *problems41[]; extern char *problems42[]; extern char *problems43[]; extern char *problems44[]; extern char *problems45[];
extern char *problems46[]; extern char *problems47[]; extern char *problems48[]; extern char *problems49[]; extern char *problems50[];
extern char *problems51[]; extern char *problems52[]; extern char *problems53[]; extern char *problems54[]; extern char *problems55[];
extern char *problems56[]; extern char *problems57[]; extern char *problems58[]; extern char *problems59[]; extern char *problems60[];
extern char *problems61[]; extern char *problems62[]; extern char *problems63[]; extern char *problems64[]; extern char *problems65[];
extern char *problems66[]; extern char *problems67[]; extern char *problems68[]; extern char *problems69[]; extern char *problems70[];
extern char *problems71[]; extern char *problems72[]; extern char *problems73[]; extern char *problems74[]; extern char *problems75[];
extern char *problems76[]; extern char *problems77[]; extern char *problems78[]; extern char *problems79[]; extern char *problems80[];
extern char *problems81[]; extern char *problems82[]; extern char *problems83[]; extern char *problems84[]; extern char *problems85[];
extern char *problems86[]; extern char *problems87[]; extern char *problems88[]; extern char *problems89[]; extern char *problems90[];
extern char *problems91[]; extern char *problems92[]; extern char *problems93[]; extern char *problems94[]; extern char *problems95[];
extern char *problems96[]; extern char *problems97[]; extern char *problems98[]; extern char *problems99[]; extern char *problems100[];
extern char *problems101[]; extern char *problems102[]; extern char *problems103[]; extern char *problems104[]; extern char *problems105[];
extern char *problems106[]; extern char *problems107[]; extern char *problems108[]; extern char *problems109[]; extern char *problems110[];
extern char *problems111[]; extern char *problems112[]; extern char *problems113[]; extern char *problems114[]; extern char *problems115[];
extern char *problems116[]; extern char *problems117[]; extern char *problems118[]; extern char *problems119[]; extern char *problems120[];
extern char *problems121[]; extern char *problems122[]; extern char *problems123[]; extern char *problems124[]; extern char *problems125[];
extern char *problems126[]; extern char *problems127[]; extern char *problems128[]; extern char *problems129[]; extern char *problems130[];
extern char *problems131[]; extern char *problems132[]; extern char *problems133[]; extern char *problems134[]; extern char *problems135[];
extern char *problems136[]; extern char *problems137[]; extern char *problems138[]; extern char *problems139[]; extern char *problems140[];
extern char *problems141[]; extern char *problems142[]; extern char *problems143[]; extern char *problems144[]; extern char *problems145[];
extern char *problems146[]; extern char *problems147[]; extern char *problems148[]; extern char *problems149[]; extern char *problems150[];
extern char *problems151[]; extern char *problems152[]; extern char *problems153[]; extern char *problems154[]; extern char *problems155[];
extern char *problems156[]; extern char *problems157[]; extern char *problems158[]; extern char *problems159[]; extern char *problems160[];
extern char *problems161[]; extern char *problems162[]; extern char *problems163[]; extern char *problems164[]; extern char *problems165[];
extern char *problems166[]; extern char *problems167[]; extern char *problems168[]; extern char *problems169[]; extern char *problems170[];
extern char *problems171[]; extern char *problems172[]; extern char *problems173[]; extern char *problems174[]; extern char *problems175[];
extern char *problems176[]; extern char *problems177[]; extern char *problems178[]; extern char *problems179[];
/*_________________________________________________________________________________*/
/* stored_problems[34], for example, is an array of strings,
each string giving one problem */

static char **stored_problems[]= { NULL, problems1, problems2,problems3, problems4, problems5, problems6, problems7, problems8, problems9, problems10,
 problems11, problems12,problems13, problems14, problems15, problems16, problems17, problems18, problems19, problems20,
 problems21, problems22,problems23, problems24, problems25, problems26, problems27, problems28, problems29, problems30,
 problems31, problems32,problems33, problems34, problems35, problems36, problems37, problems38, problems39, problems40,
 problems41, problems42,problems43, problems44, problems45, problems46, problems47, problems48, problems49, problems50,
 problems51, problems52,problems53, problems54, problems55, problems56, problems57, problems58, problems59, problems60,
 problems61, problems62,problems63, problems64, problems65, problems66, problems67, problems68, problems69, problems70,
 problems71, problems72,problems73, problems74, problems75, problems76, problems77, problems78, problems79, problems80,
 problems81, problems82,problems83, problems84, problems85, problems86, problems87, problems88, problems89, problems90,
 problems91, problems92,problems93, problems94, problems95, problems96, problems97, problems98, problems99, problems100,
 problems101, problems102,problems103, problems104, problems105, problems106, problems107, problems108, problems109, problems110,
 problems111, problems112,problems113, problems114, problems115, problems116, problems117, problems118, problems119, problems120,
 problems121, problems122,problems123, problems124, problems125, problems126, problems127, problems128, problems129, problems130,
 problems131, problems132,problems133, problems134, problems135, problems136, problems137, problems138, problems139, problems140,
 problems141, problems142,problems143, problems144, problems145, problems146, problems147, problems148, problems149, problems150,
 problems151, problems152,problems153, problems154, problems155, problems156, problems157, problems158, problems159, problems160,
 problems161, problems162,problems163, problems164, problems165, problems166, problems167, problems168, problems169, problems170,
 problems171, problems172,problems173, problems174, problems175, problems176, problems177, problems178, problems179 };
 
/*_______________________________________________________________________*/
char ** getStoredRawProblems(int topicnumber)
/*  return an array of problems appropriate to the topic (as defined in tdefn.h). Each entry begins with a number and period, like this:
   "12.   x^2 + 5"
   There can also be an author's comment, beginning with @.
    The last entry is an empty string.
    These strings all live in static space, and can
    therefore be accessed before there is a heap.  
*/
   
{
  if (topicnumber <= 0)
     return NULL;   // an error
  if (topicnumber > sizeof(stored_problems)/sizeof(char *))
     return NULL;   // an error
  return stored_problems[topicnumber];
}

/*_______________________________________________________________________*/
int getStoredProblem(int topicnumber, int problemnumber, char *ans, char *ranges, char commentary[COMMENTARYBUFLENGTH])
/*  char ans[2048], char ranges[1000]
    Fetches the problem specified by topicnumber and problemnumber, writing
    it into ans (as parseable text).  Problem numbers start with 1, so entering 0 is an error.
    Return 0 for success, 1 for something out of range or problem too long.
    If there are graph ranges or an author's commentary, put them in the last arguments.
*/
   
{
  if (topicnumber <= 0)
     return 1;   // an error
  if (topicnumber > sizeof(stored_problems)/sizeof(char *))
     return 1;   // an error
   if(problemnumber <= 0)
     return 1;
   char **problems = getStoredRawProblems(topicnumber);
   char *x;
   char temp[1000];
   strcpy(temp,problems[problemnumber-1]);
   // so temp can be modified without messing up the stored problems
   x = temp;
   while (*x && *x != '.')
      ++x;
   ++x;
   while(*x == ' ')
      ++x;
   // now x contains the problem, but perhaps also a comment
   assert(*x);   // there has to be something after the period
   char *marker;
   char flag = '\0';
   if( (marker = strchr(x,'|'))|| (marker = strchr(x,'@')))
           { // @ introduces an author's comment and |
             //  introduces range restrictions,  which are
             //  processed below.
             flag = *marker;
             *marker = '\0';
           }
   strcpy(ans, x);
   if(flag == '|')
      { // there were range restrictions, put them in the passed space
        x = marker+1;
        marker = strchr(x,'@');
        if(!marker)
           { // no author's commentary
             strcpy(ranges,x);
             commentary[0] = '\0';
             return 0;
           }
        // there was an author's commentary
        flag = '@';
        *marker = '\0';
        strcpy(ranges, x);
        strncpy(commentary,marker+1, COMMENTARYBUFLENGTH);
        return 0;
      }
   ranges[0] = '\0';  // there were no range restrictions
   if(topicnumber == _polar_graph)
      { strcpy(ranges, "0 <= theta <= 2 pi");  // supply the parameter interval
      }
   if(flag == '@')
      {  // there was an author's commentary
         strcpy(commentary,marker+1);
      }
   else
      { strcpy(commentary, "");  // make sure it's empty
      } 
   return 0;
}

/*______________________________________________________________________*/

int getmaxTopic(void)
/* Return the maximum topic number that has stored problems.
Remember the 0-th entry in stored_problems is NULL.
*/
{ return sizeof(stored_problems)/sizeof(char *)-1;
}

/*______________________________________________________________________*/

int getnProblems(int topicnumber)
/* Return the number of problems for that topic.
The last entry in the problems array is an empty string. */
{ char **p = getStoredRawProblems(topicnumber);
  for(int k= 0; k<=100;k++)
     { if(strlen(p[k]) == 0)
         return k;
     }
  assert(0);   // malformed problem list not ending in ""
  return -1;
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists