CS 1160 C/C++ Programming 12 MWF - Spring 2016

April 4th thru April 8th - Week #12 Square root day thru Power day


Monday 04/04/2016 - square root day


  1. Assignment POLYNOMIALS: Functions to read a polynomial from a file, to add two polynomials together to create a third polynomial, and to output a polynomial.
    DUE BY 11:30 pm on Tuesday April 5th.

  2. HOMEWORK SUBMISSION IS READY for programming assignment polynomials.
    Login with your UNI CatID and passphrase.
    Choose CS 1160, C++, Jacobson and then click the Continue button.

    HOMEWORK SUBMIT system: C++ Homework SUBMISSION for C++ Assignments for Jacobson

      polynomials.cpp
    
    DUE BY 11:30 pm on Tuesday April 5th.

  3. STRINGS - Chapter 10: Characters, C-Strings, and More About the String class.

  4. Snowball sentence data file.

  5. POLYNOMIALS: setw() to right justify exponents and to right justify coefficients and 'x' in the output of a polynomail. In class example.
    Poly #1:
            6        5        3        2 <--- Exponents
      123.4x    11.1x     3.2x      17x  <--- Coefficients + "x"
    
    Poly #2:
            7        6        4        2        0
        5.5x  -123.4x    12.3x   12.21x     105x 
    
    Poly #1 + #2:
            7        5        4        3        2        0  <--- Exponents
        5.5x    11.1x    12.3x     3.2x   29.21x     105x   <--- Coefficients + "x"
    
  6. HANDOUT - See page 570 of textbook, Program 10-13: char.cpp C array of characters example.

    VIP: the backslash 0 null character: '\0' signals the end of the "C STRING".
    How does the nameSlice() void function use what char.cpp demonstrates? Page 570 or handout.

  7. HANDOUT - Textbook pages 584-585 Program 10-23:
    Enter a dollar amount in the form nnnnn.nn please: 43123.75
                         Here is the amount formatted: $43,123.75
    
    Study the dollarFormat() void function 
      and the C++ string class find() and insert() methods.
    
    Note that dollarFormat() has one argument, 
            and that argument
                    is passed by REFERENCE.
    

Wednesday 4/06/2016


  1. Here is the output of Program 10-23 from textbook pages 584-585.
    jacobson[weblab]:~$ g++ currency.cpp
    
    jacobson[weblab]:~$ ./a.out
    
    Enter a dollar amount in the form nnnn.nn :  1234567890.75
                  Here is the amount formatted: $1,234,567,890.75
    
    Question:  Using your textbook and/or the handout:
    
               1. What was the value of int variable dp?
    
               2. trace the code and tell exactly what values
                  that for loop index x took on for the above
                  example.
    
  2. Here is the code for dollarFormat() function.
    void dollarFormat(string ¤cy)   // <====== (Why the "&"?)
    {
        int dp;
    
        dp = currency.find('.');
    
        if (dp > 3)
           for (int x = dp - 3; x > 0; x-= 3)
               currency.insert(x, ",");
    
        currency.insert(0, "$");
    }
    
  3. Another output example:
    jacobson[weblab]:~$ ./a.out
    
    Enter a dollar amount in the form nnnn.nn :  1234567.25
                  Here is the amount formatted: $1,234,567.25
    
  4. Here is the Program 10-23 C++ code , with additional comments
             and review of the WHAT dollarFormat() does
                          versus the HOW dollarFormat() does it class discussion.

    Always very vigorously separate WHAT from HOW!

  5. What is programming? It is ---> VET SAT AUC TVV SO YMDC
    Page 107 of a book of speeches and articles by EWD (Edsgar W. Dijkstra) 
      on the 10% of the teaching programming versus the hidden 90% of what
      programming and problem solving involve.  
    
    The VET who SAT down to watch AUC (All U Children) on TVV, 
      SO what if this was at the YMDC (i.e., the YMCA in Washington, DC) 
      where the Gulf War or Vietnam Vet was staying.  
    
      VET-SAT-AUC, TVV-SO-YMDC is the string of the first letters 
      from a quote by Dijkstra.
      
    Programming, when stripped of all the circumstantial irrelevancies 
      is nothing more and nothing less than "very effective thinking 
      so as to avoid unmastered complexity, to very vigorous 
      separation of your many different concerns".
    
    very effective thinking so as to avoid unmastered complexity,
    v    e         t        s  a  t  a     u          c          = vet sat auc
    vet                     sat      auc
    VET                     SAT      AUC
    
    to very vigorous separation of your many different concerns.
    t  v    v        s          o  y    m    d         c         = tvv so ymdc
    tvv              so            ymdc
    TVV              SO            YMDC
    
  6. The two main concerns of programming are WHAT you wanna do and HOW you are going to do it.

    YMDC becomes YTDC, i.e. Your Two Different Concerns... or perhaps
    YTMC, i.e. Your Two Main Concerns. Very Vigorously Separate YTMC!

    YTCC has a nice poetic sound Y T C C - Your Two Chief Concerns...


Friday 4/08/2016 - power day

                   2    3    4
                  2    2    2          
                                 4/8/16 and 11 years until 3/9/27


  1. How would you take this four line input file and produce these 22 lines of output, using C++?
    I do not know where family doctors acquired illegibly perplexing handwriting; 
    nevertheless, extraordinary pharmaceutical intellectuality, 
    counterbalancing indecipherability, 
    transcendentalizes intercommunications' incomprehensibleness.
    

    I
    do
    not
    know
    where
    family
    doctors
    acquired
    illegibly
    perplexing
    handwriting
    nevertheless
    extraordinary
    pharmaceutical
    intellectuality
    counterbalancing
    indecipherability
    transcendentalizes
    intercommunications
    incomprehensibleness
    
  2. Program wordPerLine.cpp that outputs the first line of the file with the snowball sentence. Prints one word per line.
    The output is:
    jacobson[weblab]:~/web/cpp$ cat snowOutput.txt 
    jacobson[weblab]:~$ ./a.out
    
    
    I                      1
    do                     4
    not                    8
    know                  13
    where                 19
    family                26
    doctors               34
    acquired              43
    illegibly             53
    perplexing            64
    handwriting;          77
                          -1
    
    I do not know where family doctors acquired illegibly perplexing handwriting; 
    
    I do not know where family doctors acquired illegibly perplexing handwriting; 
    012345678901234567890123456789012345678901234567890123456789012345678901234567          
    1         2         3         4         5         6         7
    
    snowOutput.txt