PowerPoint Presentation

Published on
Embed video
Share video
Ask about this video

Scene 1 (0s)

[Audio] OBJECTIVE: We will use character variables, and we will look at number systems common in programming. We've discussed that there are two types of data: numeric and text. We've looked at one of the numeric data types (integers), and today we're going to look at one of the text data types. Text data can be broken up into two subcategories: characters and strings; today's program will be focused on characters. A character is one, single letter, number, or other mark or sign used in writing or printing. For example, if you ask a user to enter Yes or No (Y or N), the Y or N that they type is one character. In your program, characters are always surrounded by single quotation marks (or apostrophes). I always remember it by thinking ONE LETTER = ONE QUOTATION MARKS, while MORE THAN ONE LETTER = TWO QUOTATION MARKS..

Scene 2 (1m 50s)

[Audio] Notice in the example program on the screen, that we have two locations that assign different values to the variable letter. After each of the two locations, there's a cout statement, which is why you see two, separate outputs in the Program Output section. Any value that is saved in a variable replaces whatever value was stored in the variable previously. Please note that ANYTHING you put inside the single quotation marks will be treated as a char. Even if you type a number, if it is in the single quotation marks, it is actually used like a letter, and you can't do calculations with letters..

Scene 3 (2m 45s)

[Audio] In our program today, CharDeclare, we will declare (which is when assign a data type and the program assigns it some memory to store values) and initialize (which is where we give the variable its original/initial value) TWO (no more, no less) character variables for the data in the directions: Your worst letter grade currently in your classes (or what you never ever wish to see as your grade, if you have all As), and Your first name initial. You will output the two variable values in a meaningful and formatted manner. This means you can't just output the letter; you have to include words to make it make sense to the user. THEN you will change your worst letter grade to a grade you want or think you should have in that class. Finally, you will output your updated letter grade in a meaningful and formatted manner. REMEMBER: Output descriptive words in your couts to give the data meaning or context (see the example in the directions). Only declare TWO variables, NOT three. Output the values stored inside the variables. Don't "hard code" the output. Use THREE cout statements. No more, no less. Format your code and your output with whitespace (indentations and blank lines). Don't forget to include FULL COMMENTS that are specific to this program. On the plan, first, let's sketch out the plan boxes. Notice that I've added a new box. Soon, we're going to need to give the user directions before doing the input, processing, and final output. For now, though, we don't know what to do with that box, so we'll cross it out. We haven't talked about constants, yet, or doubles, or strings. We still don't know how to cin data, and we haven't practiced using calculations in our programs. Now, we're going to go back up to the variable spreadsheet to create our two variables. I think "grade" and "initial" are good names, so that's what I'm going with. I'm also going to mark their data type as CHAR, since that's what this program is about. Then, I'm going to assign them values. We need to fill in the notes section with the important parts of the directions before ending our plan by filling in a program purpose and what the user will see in the final output..

Scene 4 (5m 23s)

[Audio] Finally, let's set up your program. We start with our normal three comments: the program name, the programmer's name, and the purpose statement, from our plan. We add our preprocessor and using directive. Then, we set up the beginning of our main function. In our function, we are going to pull our comments directly from our program. Number 1 in the directions says to only make TWO variables, Number 2 says to output the two variables, Number 3 says to change our letter grade, and Number 4 says to output the updated grade. This is the last program in Chapter 2 that I will be helping you set up the program itself, so make sure you know what to do on your own for next time. Have fun coding!.