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

April 18th thru April 22nd - Week #14


Monday 04/18/2016


  1. Introduction to SCRATCH programming. Using SCRATCH to draw a 24 sided polygon with PEN DOWN to leave a trail, moving forward 10 steps or units and then turning clockwise 15 degrees for the body of a FOR loop that is REPEATED 24 times.
  2. Rectangles and OOP (Object Oriented Programming) - introduction to C++ classes.

    Member data, member functions, private and public, accessors and mutators, OOP, classes and objects.

  3. Programming project to preview: Inventory Objects problem #6 from the textbook.

  4. TRIVIA GAME - Guessing Competition: Questions and Answer Choices - make up your own TRIVIA questions.

Wednesday 4/20/2016


  1. The assignment (Page 797 - Trivia Game) is due on or before Sunday, MAY 1st at 11:55 PM.
    TRIVIA GAME - Guessing Competition: Questions and Four Answer Choices - make up your own TRIVIA questions if you wish.

    Here is my data file trivia.txt consisting of 10 trivia questions:

    jacobson[weblab]:~$ wc trivia.txt   <------ Do the wc word count command
      60  218 1210 trivia.txt
      --  --- ----
    
      It has 60 lines, 218 words and 1,210 characters (bytes).
    
      There are 6 lines for each question, so it does have 10 questions.
    
      Example question from trivia.txt file...
    
    What does the acronym VET stand for in VET SAT AUC TVV SO YMDC?
    Viral Effects Treated        <--- choice #1
    Vensim Email Target          <--- choice #2
    Very Effective Thinking      <--- choice #3
    Various Effects Tuning       <--- choice #4
    3                         <---- What is number of correct answer?  3 for this one.
    
    Note:  The first line is the question.
           The 2nd line to the 5th line of a group is the four choices.
           The 6th and last line of a group is the number of the correct
               choice and answer to the question.
    

  2. Here is the running and output of the test program that just prints out the very first question stored in trivia.txt data file.
    jacobson[weblab]:~$ ./a.out
    QUESTION: What is the name of the character that Kevin Costner plays in Dances With Wolves?
        1. Stands With A Fist
        2. Smiles A Lot
        3. John Dunbar
        4. Joseph Snitker
    The correct answer is: 3
    
  3. Here is the C++ code that read that trivia.txt files first question.
    int main ()
    {
       ifstream qFile;           // qFile is the file handle... q as in question
       qFile.open("trivia.txt"); // -----                       -       -
       string theString;
    
       for (int j = 0; j <= 5; j++)
       {
          getline(qFile, theString);
          if (j == 0)
              cout << "QUESTION: " << theString;
          else if (j < 5)
              cout << setw(5) << j << ". " << theString;
          else
              cout << "The correct answer is: " << theString 
                   << endl;
    
          cout << endl;
       }
    
       return 0;
    }
    


Friday 4/22/2016
Earth Day