COP+1000+Daily+Notes


 * COP 1000 Daily Notes**

There are two books for the course. The first four weeks, the main goal is to get everyone comfortable with the concepts of computer programming. We will do this by creating "programs," i.e., flowcharts, in Raptor one week and then re-creating the same programs in C the next week.
 * Week 1**

Be sure to have the latest version of Raptor and Dev C++ installed on your personal computer

You should be able to print directly from Raptor. You should check the "Print Scale" from the File menu first and then check "Print Preview" to see how your program lays out on the printed page. OR To capture the output screen at the same time: Use Snipping tool to capture screen, print from there. If you have a version of Windows without Snipping, use Print Screen, paste the image into a word processor.
 * Printing from Raptor**


 * Variables** - two basic types in Raptor - numbers or strings/text

__//**remember to use the internet zoom function so it is easier for the class to see. - This is a reminder for the instructor.**//__


 * Input and Output**

If you want to ask the user a **question** - use **input**

To display a **result** - use **output**

To perform a **calculation** - use **assignment.** Variables must always be declared first and in Raptor, they must be given an initial value.

To make a **choice** or **decision** - use **selection**

Programs from class: Note two good examples of sequencing, i.e., choosing carefully where to put a particular statement. 1) "You are " + Years + " under age" - placed in the "under 21" branch of the selection statement 2) "Your age is " + Age - placed below selection statement so that all ages will see the display of this output statement Each of the above output statements can be challenging when you are first learning to program. However, here are some hints: To display words, put them in quotes. The same goes for spaces between words and variable values. To display variable values, use the variable name without quotes. To display multiple pieces of words and values put a + in between each piece of quoted text and a variable name and between variable names (if you are displaying two variable values next to each other. You wouldn't normally do this with two numeric variables, but with a numeric variable and a string/text variable.

Note how the grades are "used up" by starting with grades >= 90 and then cascading down with similar comparisons. By using this approach, there is no comparison for a grade of "F." It is the only choice left at this point of the cascade.

This program provides a great demonstration of "Create a small program. Test it. Get it to run. Build on it. Each of the selection statements was added one at a time and then testing.


 * Week 2**

If you haven't already installed Bloodshed's Dev-C++ compiler on you home computer, you should now. You will need it for the homework in C.





Helpful hints:
 * C is a case sensitive language, Grade and grade are two different variables
 * C variables can contain under_scores
 * C variables cannot start with a number, but can contain numbers
 * Every program must have a main function so that the compiler knows where to start execution
 * Variables must be declared before they are used in calculations, scanf, printf, etc.
 * Enter braces in pairs, e.g., { } (one on each line of course). If not, it is very hard to find where you have a mismatched brace.
 * Be sure to correctly indent your code to be able to see where your braces match up. Correct formatting is also 10% of each program's grade.
 * Be sure to use #include  to be able to use printf and scanf for output and input
 * Be sure to use #include  to be able to run system("pause");
 * And you need system("pause"); to be able to see your system window where the output is
 * **Remember** the & in front of your variable name in scanf
 * Be sure to use %d for an integer in scanf. Be careful not to use d%
 * \n inside the " " for printf forces output to a newline, e.g., printf("Your grade is A \n");
 * Remember that your friends and neighbors will almost always find your error much, much faster than you will. That's just how our minds work.
 * In Dev C++, on the Tools menu, select "Editor Options" and then change:
 * Uncheck "Smart Tabs"
 * In the "Carat" box, check "Highlight matching braces/parentheses"
 * **BIG HINT: When you prepare to calculate the commission in C, you may want to change all of your variables from int to float. You at least need to declare the commission percentage and the resulting commission amount as floats our you will get incorrect answers, mainly zero.**

Please check your homework before turning it in to be sure that you have included a print screen of your output (Raptor's Master Console).
 * Week 3**

We will begin with loops that have a counter and end when a certain limit is reached. These are similar to FOR loops found in most programming languages.

This implies that you will always need: 1) A limit, i.e., a number, specifically, an integer to hold the limit. The limit value may be hard coded or user input. Remember from Week 1 to always test your code first, and then provide user input. 2) A counter variable, again, an integer. Your counter will almost always start (be initialized to zero or one). This value is very critical in that if you are incorrect, you may process on less item than you intended or one more item than intended.

Another critical consideration is your stopping condition. Walk through the values of your looping variables, the limit and the counter to determine if your condition should be a number exactly, greater than a number, or less than a number, or some combination. Again, you may procees the incorrect number of elements if you condition is incorrect. Like most of programming, practice helps a lot, as does walking through the program by hand. This is also known as desk checking.

Here is an example of how to NOT add three grades up. It does work, but, what are some of the disadvantages if you were asked to modify the program? What are the shortcomings to the Grade1, Grade2, Grade3 approach, especially if you are asked later to change the number of grades. Also, if you took this approach, how would you go about finding the maximum and minimum values?

Instead of using three different variables, any time you are repeating an operation, in this case, reading grades from user input, a loop provides a much more efficient and more adaptable structure. Please see below. The MakeChange program illustrates multiple loops and provides a good example of problem solving. Please note that this is just one way to solve the problem of providing a customer change. There are almost always multiple ways to solve a problem, each with benefits and drawbacks.

Create a program that uses looping to repeated add to simulate multiplication. For example, if you want to multiply 4 by 3, add 4 to a total, do this three times. Your result will be 12. After going over Factorial and MultiplyByAdding, we worked on While it is tempting to solve the Divide by Subtracting by modifying the current MultiplyByAdding program, you may find that division is a little more challenging than it first appears. Here are some other programs to practice more with loops. There is a small error in MakeChange.rap that you can find later on your own.

You may need to save these files first, open Raptor, and then open the saved program.

Most importantly, while a loop structure worked well from GradesTotal.rap, it is not the best approach to MakeChange.rap. 1) The RomanNumerals program provides a very basic conversion from an Arabic number, e.g., 425 to a rough Roman numeral, CCCCXXIIIII. We didn't belabor the 4 = IV, 9 = IX details. The main goal of the program was to provide an example of using mod to get the remainder from a division. Note: mod is an operator like +, -, *, /. It is not a function. Using mod provides a quick and easy way to process 425 into Roman numerals.

2) Program to first, calculate the factorial value of a number. For example, 6! (6 factorial) = 720. You get this because 6! = 6 * 5 * 4 * 3 * 2 * 1 = 720. Second, after getting the correct value, also display all the factors as shown in the previous sentence.

Extra practice: Convert the MakeChange program to use mod instead of loops for the numberOfQuarters, etc.

Make Sure - When using a loop, make sure you do your output and processing BEFORE incrementing the loopCount.


 * Week 4**

Loops in C are similar in concept to loops in Raptor. However, in Raptor, the loops continues until the condition becomes true. This represents a repeat-until loop. Unfortunately, C doesn't have a repeat-until construct. However, there are several looping constructs in C that work just fine, once you get the idea that the conditions in C loops are slightly different that those in Raptor.

It seems easiest to move from Raptor loops into C by following a basic path beginning with a basic while loop:

Notice that the above looping program runs until a condition is met, just like in Raptor. However, this presents a rather cumbersome way to create a loop in C. A better way is to create a loop that executes while a condition is true as in the program below.



COP 1000 Daily Notes - Weeks 5 - 8